-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: added DynamicZone, related types and utilities * fix: updated props/types of ActionList for more use-cases
- Loading branch information
1 parent
e2060fb
commit f4ea469
Showing
18 changed files
with
1,058 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@smile/haring-react-shared': minor | ||
'@smile/haring-react': minor | ||
--- | ||
|
||
Added DynamicZone component, related types and utilities, updated snapshot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type IOmitRespectIndexSignature<T, K extends PropertyKey> = { | ||
[P in keyof T as Exclude<P, K>]: T[P]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
packages/haring-react/src/Form/DynamicZone/DynamicZone.mock.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import type { IDynamicZoneBlockReference } from './DynamicZoneBlock/DynamicZoneBlock'; | ||
import type { IBaseBlock, IBaseBlockButton } from '../../types'; | ||
import type { IAction } from '@smile/haring-react-shared'; | ||
|
||
import { | ||
Alien, | ||
ArrowDown, | ||
ArrowUp, | ||
Leaf, | ||
Trash, | ||
TreasureChest, | ||
} from '@phosphor-icons/react'; | ||
import { action } from '@storybook/addon-actions'; | ||
|
||
const dynamicZoneBlockActionsMock: IAction<IDynamicZoneBlockReference>[] = [ | ||
{ | ||
color: 'white', | ||
icon: <ArrowUp size={16} />, | ||
id: 'move-up', | ||
label: 'Move Up', | ||
onAction: action('Move block up'), | ||
}, | ||
{ | ||
color: 'white', | ||
icon: <ArrowDown size={16} />, | ||
id: 'move-down', | ||
label: 'Move Down', | ||
onAction: action('Move block down'), | ||
}, | ||
{ | ||
color: 'white', | ||
icon: <Trash size={16} />, | ||
id: 'delete', | ||
label: 'Delete', | ||
onAction: action('Delete block'), | ||
}, | ||
]; | ||
|
||
export const dynamicZoneBlocks: IBaseBlock[] = [ | ||
{ | ||
blockActions: dynamicZoneBlockActionsMock, | ||
blockHeader: ( | ||
<> | ||
<Alien /> | ||
First | ||
</> | ||
), | ||
blockType: 'default', | ||
id: '1', | ||
opened: false, | ||
value: 'initial', | ||
}, | ||
{ | ||
blockActions: dynamicZoneBlockActionsMock, | ||
blockFooter: 'footer', | ||
blockHeader: ( | ||
<> | ||
<Leaf /> | ||
Second | ||
</> | ||
), | ||
blockType: 'default', | ||
id: '2', | ||
opened: true, | ||
value: 'initial', | ||
}, | ||
{ | ||
blockActions: dynamicZoneBlockActionsMock, | ||
blockFooter: 'footer', | ||
blockHeader: ( | ||
<> | ||
<TreasureChest /> | ||
Third | ||
</> | ||
), | ||
blockType: 'default', | ||
id: '3', | ||
opened: false, | ||
value: 'initial', | ||
}, | ||
]; | ||
|
||
export const dynamicZoneButtons: IBaseBlockButton[] = [ | ||
{ blockType: 'default', label: 'Default', leftSection: <Alien /> }, | ||
{ blockType: 'other', label: 'Other', leftSection: <Leaf /> }, | ||
{ blockType: 'stuff', label: 'Stuff', leftSection: <TreasureChest /> }, | ||
]; |
12 changes: 12 additions & 0 deletions
12
packages/haring-react/src/Form/DynamicZone/DynamicZone.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.buttonsContainer { | ||
border-radius: 0.5rem; | ||
border: 1px dashed black; | ||
} | ||
|
||
.buttonsLabel { | ||
&:empty { | ||
display: none; | ||
} | ||
|
||
margin-bottom: 10px; | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/haring-react/src/Form/DynamicZone/DynamicZone.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { action } from '@storybook/addon-actions'; | ||
|
||
import { DynamicZone as Cmp } from './DynamicZone'; | ||
import { dynamicZoneBlocks, dynamicZoneButtons } from './DynamicZone.mock'; | ||
|
||
const meta = { | ||
component: Cmp, | ||
tags: ['autodocs'], | ||
title: '3-custom/Form/DynamicZone', | ||
} satisfies Meta<typeof Cmp>; | ||
|
||
export default meta; | ||
type IStory = StoryObj<typeof meta>; | ||
|
||
export const DynamicZone: IStory = { | ||
args: { | ||
blockOptions: dynamicZoneButtons, | ||
blocks: dynamicZoneBlocks, | ||
buttonsText: 'Ajouter un block', | ||
internalBlockCardProps: { | ||
headerCardSectionProps: { | ||
bg: 'cadetblue', | ||
c: 'white', | ||
}, | ||
toggleComponentProps: { | ||
actionIconProps: { color: 'white', variant: 'subtle' }, | ||
}, | ||
}, | ||
onAppendBlock: action('onAppendBlock, id'), | ||
onRenderBlockContent: (_b, index) => <input key={index} />, | ||
onToggleBlock: action('onToggleBlock'), | ||
}, | ||
}; |
27 changes: 27 additions & 0 deletions
27
packages/haring-react/src/Form/DynamicZone/DynamicZone.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { IBaseBlock } from '../../types'; | ||
import type { ReactElement } from 'react'; | ||
|
||
import { renderWithProviders } from '@smile/haring-react-shared/test-utils'; | ||
import { action } from '@storybook/addon-actions'; | ||
import { expect } from '@storybook/jest'; | ||
|
||
import { DynamicZone } from './DynamicZone'; | ||
import { dynamicZoneBlocks, dynamicZoneButtons } from './DynamicZone.mock'; | ||
|
||
describe('DynamicZone', () => { | ||
it('matches snapshot', () => { | ||
const onRender = (_b: IBaseBlock, index: number): ReactElement => ( | ||
<input key={index} /> | ||
); | ||
const { container } = renderWithProviders( | ||
<DynamicZone | ||
blockOptions={dynamicZoneButtons} | ||
blocks={dynamicZoneBlocks} | ||
onAppendBlock={action('onAppendBlock, id')} | ||
onRenderBlockContent={onRender} | ||
onToggleBlock={action('onToggleBlock')} | ||
/>, | ||
); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.