diff --git a/packages/haring-react/src/Components/ActionList/ActionList.tsx b/packages/haring-react/src/Components/ActionList/ActionList.tsx index 80871669..7bfa8940 100644 --- a/packages/haring-react/src/Components/ActionList/ActionList.tsx +++ b/packages/haring-react/src/Components/ActionList/ActionList.tsx @@ -1,6 +1,7 @@ 'use client'; import type { + ActionIconProps, ButtonProps, FloatingPosition, GroupProps, @@ -34,7 +35,8 @@ export type IActionListAction> = export interface IActionListProps> extends GroupProps { - actionButtonProps?: ButtonProps; + actionButtonDefaultProps?: ButtonProps; + actionIconDefaultProps?: ActionIconProps; actionTooltipProps?: TooltipProps; actions: IActionListAction[]; isCompactStyle?: boolean; @@ -48,7 +50,8 @@ export function ActionList>( props: IActionListProps, ): ReactNode { const { - actionButtonProps, + actionButtonDefaultProps, + actionIconDefaultProps, actionTooltipProps, actions, isCompactStyle = false, @@ -140,6 +143,7 @@ export function ActionList>( leftSection={getActionIcon(action)} onClick={() => handleAction(action)} variant={action.color ? 'filled' : 'default'} + {...actionButtonDefaultProps} {...getActionComponentProps(action)} > {getActionLabel(action)} @@ -159,6 +163,7 @@ export function ActionList>( radius={4} type="button" variant="subtle" + {...actionIconDefaultProps} {...getActionComponentProps(action)} > {getActionIcon(action)} diff --git a/packages/haring-react/src/Form/DynamicZone/DynamicZone.mock.tsx b/packages/haring-react/src/Form/DynamicZone/DynamicZone.mock.tsx index 33f179df..54d01eb3 100644 --- a/packages/haring-react/src/Form/DynamicZone/DynamicZone.mock.tsx +++ b/packages/haring-react/src/Form/DynamicZone/DynamicZone.mock.tsx @@ -1,5 +1,5 @@ import type { IDynamicZoneBlockReference } from './DynamicZoneBlock/DynamicZoneBlock'; -import type { IBaseBlockButton, IBaseBlockFull } from '../../types'; +import type { IBaseBlockButtonOptions, IBaseBlockFull } from '../../types'; import type { IAction } from '@smile/haring-react-shared'; import { @@ -14,21 +14,18 @@ import { action } from '@storybook/addon-actions'; const dynamicZoneBlockActionsMock: IAction[] = [ { - color: 'white', icon: , id: 'move-up', label: 'Move Up', onAction: action('Move block up'), }, { - color: 'white', icon: , id: 'move-down', label: 'Move Down', onAction: action('Move block down'), }, { - color: 'white', icon: , id: 'delete', label: 'Delete', @@ -80,7 +77,7 @@ export const dynamicZoneBlocks: IBaseBlockFull[] = [ }, ]; -export const dynamicZoneButtons: IBaseBlockButton[] = [ +export const dynamicZoneButtons: IBaseBlockButtonOptions[] = [ { blockType: 'default', label: 'Default', leftSection: }, { blockType: 'other', label: 'Other', leftSection: }, { blockType: 'stuff', label: 'Stuff', leftSection: }, diff --git a/packages/haring-react/src/Form/DynamicZone/DynamicZone.module.css b/packages/haring-react/src/Form/DynamicZone/DynamicZone.module.css index 93edbb47..cab2f8ff 100644 --- a/packages/haring-react/src/Form/DynamicZone/DynamicZone.module.css +++ b/packages/haring-react/src/Form/DynamicZone/DynamicZone.module.css @@ -10,3 +10,11 @@ margin-bottom: 10px; } + +.button { + &:disabled, + &[data-disabled] { + border-color: var(--mantine-color-gray-4); + background-color: transparent; + } +} diff --git a/packages/haring-react/src/Form/DynamicZone/DynamicZone.stories.tsx b/packages/haring-react/src/Form/DynamicZone/DynamicZone.stories.tsx index e3e9754d..abebb507 100644 --- a/packages/haring-react/src/Form/DynamicZone/DynamicZone.stories.tsx +++ b/packages/haring-react/src/Form/DynamicZone/DynamicZone.stories.tsx @@ -19,7 +19,22 @@ export const DynamicZone: IStory = { blockOptions: dynamicZoneButtons, blocks: dynamicZoneBlocks, buttonsText: 'Ajouter un block', - internalBlockCardProps: { + onAppendBlock: action('onAppendBlock, id'), + onRenderBlockContent: (_b, index) => , + onToggleBlock: action('onToggleBlock'), + }, +}; + +export const CustomInternalProps: IStory = { + args: { + blockOptions: dynamicZoneButtons, + blocks: dynamicZoneBlocks, + internalBlockComponentProps: { + headerActionListProps: { + actionIconDefaultProps: { + color: 'white', + }, + }, headerCardSectionProps: { bg: 'cadetblue', c: 'white', diff --git a/packages/haring-react/src/Form/DynamicZone/DynamicZone.test.tsx b/packages/haring-react/src/Form/DynamicZone/DynamicZone.test.tsx index dc499208..56e26ef7 100644 --- a/packages/haring-react/src/Form/DynamicZone/DynamicZone.test.tsx +++ b/packages/haring-react/src/Form/DynamicZone/DynamicZone.test.tsx @@ -1,4 +1,4 @@ -import type { IBaseBlockOptions } from '../../types'; +import type { IBaseBlockCardOptions } from '../../types'; import type { ReactElement } from 'react'; import { renderWithProviders } from '@smile/haring-react-shared/test-utils'; @@ -10,9 +10,10 @@ import { dynamicZoneBlocks, dynamicZoneButtons } from './DynamicZone.mock'; describe('DynamicZone', () => { it('matches snapshot', () => { - const onRender = (_b: IBaseBlockOptions, index: number): ReactElement => ( - - ); + const onRender = ( + _b: IBaseBlockCardOptions, + index: number, + ): ReactElement => ; const { container } = renderWithProviders( void; onRenderBlockContent: (block: IBaseBlockFull, index: number) => ReactElement; onToggleBlock: ( @@ -39,15 +43,11 @@ export interface IDynamicZoneProps extends ContainerProps { export function DynamicZone(props: IDynamicZoneProps): ReactElement { const { - blockCardProps, blockOptions, blocks, - blocksStackProps, - bottomContainerProps, - buttonsGroupProps, buttonsText, - buttonsTextProps, - internalBlockCardProps, + internalComponentProps, + internalBlockComponentProps, onAppendBlock, onRenderBlockContent, onToggleBlock, @@ -60,15 +60,16 @@ export function DynamicZone(props: IDynamicZoneProps): ReactElement { return ( - + {blocks.map((block, index) => ( onToggleBlock(block, index, opened)} opened={block.opened} reference={{ arrayLength: blocks.length, id: block.id, index }} @@ -82,25 +83,48 @@ export function DynamicZone(props: IDynamicZoneProps): ReactElement { fluid mt="lg" p="sm" - {...bottomContainerProps} + {...internalComponentProps?.bottomContainerProps} > - - {buttonsText} - - - {blockOptions.map(({ blockType, ...button }) => ( - - ))} + {Boolean(buttonsText) && ( + + {buttonsText} + + )} + + {blockOptions.map( + ({ blockType, label, tooltipLabel, tooltipProps, ...button }) => ( + + + + ), + )} diff --git a/packages/haring-react/src/Form/DynamicZone/DynamicZoneBlock/DynamicZoneBlock.tsx b/packages/haring-react/src/Form/DynamicZone/DynamicZoneBlock/DynamicZoneBlock.tsx index 34c6ce0f..436607a3 100644 --- a/packages/haring-react/src/Form/DynamicZone/DynamicZoneBlock/DynamicZoneBlock.tsx +++ b/packages/haring-react/src/Form/DynamicZone/DynamicZoneBlock/DynamicZoneBlock.tsx @@ -28,7 +28,10 @@ export interface IDynamicZoneBlockInternalComponentProps { contentCollapseProps?: CollapseProps; contentContainerProps?: ContainerProps; footerCardSectionProps?: CardSectionProps; - headerActionListProps?: IActionListProps; + headerActionListProps?: Omit< + IActionListProps, + 'actions' | 'isCompactStyle' | 'selectedElements' + >; headerCardSectionProps?: CardSectionProps; headerGroupProps?: GroupProps; toggleComponentProps?: IDynamicZoneBlockToggleProps; diff --git a/packages/haring-react/src/Form/DynamicZone/__snapshots__/DynamicZone.test.tsx.snap b/packages/haring-react/src/Form/DynamicZone/__snapshots__/DynamicZone.test.tsx.snap index 7cc3c59d..8860d6a4 100644 --- a/packages/haring-react/src/Form/DynamicZone/__snapshots__/DynamicZone.test.tsx.snap +++ b/packages/haring-react/src/Form/DynamicZone/__snapshots__/DynamicZone.test.tsx.snap @@ -85,7 +85,7 @@ exports[`DynamicZone matches snapshot 1`] = ` aria-label="Move Up" class="haring-focus haring-active m_8d3f4000 mantine-ActionIcon-root m_87cf2631 mantine-UnstyledButton-root" data-variant="subtle" - style="--ai-radius: calc(0.25rem * var(--mantine-scale)); --ai-bg: transparent; --ai-hover: rgba(0, 0, 0, 0.12); --ai-color: white; --ai-bd: calc(0.0625rem * var(--mantine-scale)) solid transparent;" + style="--ai-radius: calc(0.25rem * var(--mantine-scale)); --ai-bg: transparent; --ai-hover: var(--mantine-color-cyan-light-hover); --ai-color: var(--mantine-color-cyan-light-color); --ai-bd: calc(0.0625rem * var(--mantine-scale)) solid transparent;" type="button" > -

@@ -529,7 +524,6 @@ exports[`DynamicZone matches snapshot 1`] = ` data-size="md" data-variant="default" data-with-left-section="true" - label="Other" style="--button-height: var(--button-height-md); --button-padding-x: var(--button-padding-x-md); --button-fz: var(--mantine-font-size-md); --button-radius: var(--mantine-radius-md); --button-bg: var(--mantine-color-default); --button-hover: var(--mantine-color-default-hover); --button-color: var(--mantine-color-default-color); --button-bd: calc(0.0625rem * var(--mantine-scale)) solid var(--mantine-color-default-border);" type="button" > @@ -564,7 +558,6 @@ exports[`DynamicZone matches snapshot 1`] = ` data-size="md" data-variant="default" data-with-left-section="true" - label="Stuff" style="--button-height: var(--button-height-md); --button-padding-x: var(--button-padding-x-md); --button-fz: var(--mantine-font-size-md); --button-radius: var(--mantine-radius-md); --button-bg: var(--mantine-color-default); --button-hover: var(--mantine-color-default-hover); --button-color: var(--mantine-color-default-color); --button-bd: calc(0.0625rem * var(--mantine-scale)) solid var(--mantine-color-default-border);" type="button" > diff --git a/packages/haring-react/src/Form/FormDynamicZone/FormDynamicZone.mock.tsx b/packages/haring-react/src/Form/FormDynamicZone/FormDynamicZone.mock.tsx index b6976fff..1a64c392 100644 --- a/packages/haring-react/src/Form/FormDynamicZone/FormDynamicZone.mock.tsx +++ b/packages/haring-react/src/Form/FormDynamicZone/FormDynamicZone.mock.tsx @@ -25,6 +25,17 @@ export const blocksMock: IBaseBlockFull[] = [ opened: true, value: 'existing value', }, + { + blockHeader: ( + <> + + Example A + + ), + blockType: 'exampleA', + id: '1', + opened: false, + }, { blockHeader: ( <> @@ -33,7 +44,7 @@ export const blocksMock: IBaseBlockFull[] = [ ), blockType: 'exampleB', - id: '1', + id: '2', opened: true, value: 'selectB', }, @@ -46,7 +57,12 @@ export const availableBlocksMock: IFormDynamicZoneBlock[] = [ opened: true, value: '', }, - blockOptions: { + blockButtonOptions: { + blockType: 'exampleA', + label: 'Example A', + leftSection: , + }, + blockCardOptions: { blockHeader: ( <> @@ -54,11 +70,6 @@ export const availableBlocksMock: IFormDynamicZoneBlock[] = [ ), }, - button: { - blockType: 'exampleA', - label: 'Example A', - leftSection: , - }, renderFunc: (b: IExampleBlock, i: number): ReactElement => { return ( @@ -85,7 +96,15 @@ export const availableBlocksMock: IFormDynamicZoneBlock[] = [ opened: true, value: '', }, - blockOptions: { + blockButtonOptions: { + blockType: 'exampleB', + label: 'Example B', + leftSection: , + maxInstances: 1, + tooltipLabel: (b) => (b.disabled ? 'Cannot add more than 1' : ''), + variant: 'outline', + }, + blockCardOptions: { blockHeader: ( <> @@ -93,11 +112,6 @@ export const availableBlocksMock: IFormDynamicZoneBlock[] = [ ), }, - button: { - blockType: 'exampleB', - label: 'Example B', - leftSection: , - }, renderFunc: (b: IExampleBlock, i: number): ReactElement => { return ( + +
+ + +
+