-
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/form dynamic zone animation example (#217)
* refactor: renamed dynamic zone components * feat: added example page with animations
- Loading branch information
1 parent
2004835
commit 4538167
Showing
24 changed files
with
745 additions
and
624 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 @@ | ||
--- | ||
'storybook-pages': minor | ||
'@smile/haring-react': minor | ||
--- | ||
|
||
Renamed components into Zone, DynamicZone, and the example page into FormDynamicZone, added example page with animations using AutoAnimate |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
133 changes: 133 additions & 0 deletions
133
packages/haring-react/src/Components/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,133 @@ | ||
import type { | ||
IBaseBlock, | ||
IBaseBlockFull, | ||
IDynamicZoneBlock, | ||
} from '../../types'; | ||
import type { ReactElement } from 'react'; | ||
|
||
import { Group } from '@mantine/core'; | ||
import { Cube, Leaf } from '@phosphor-icons/react'; | ||
|
||
export interface IExampleBlock extends IBaseBlock { | ||
value?: string; | ||
} | ||
|
||
export const dynamicZoneBlocksMock: IBaseBlockFull<IExampleBlock>[] = [ | ||
{ | ||
blockHeader: ( | ||
<> | ||
<Cube key="1" /> | ||
<span key="2">Example A</span> | ||
</> | ||
), | ||
blockType: 'exampleA', | ||
id: '0', | ||
opened: true, | ||
value: 'existing value', | ||
}, | ||
{ | ||
blockHeader: ( | ||
<> | ||
<Cube key="1" /> | ||
<span key="2">Example A</span> | ||
</> | ||
), | ||
blockType: 'exampleA', | ||
id: '1', | ||
opened: false, | ||
}, | ||
{ | ||
blockHeader: ( | ||
<> | ||
<Leaf key="1" /> | ||
<span key="2">Example B</span> | ||
</> | ||
), | ||
blockType: 'exampleB', | ||
id: '2', | ||
opened: true, | ||
value: 'selectB', | ||
}, | ||
]; | ||
|
||
export const dynamicZoneAvailableBlocksMock: IDynamicZoneBlock<IExampleBlock>[] = | ||
[ | ||
{ | ||
block: { | ||
blockType: 'exampleA', | ||
opened: true, | ||
value: '', | ||
}, | ||
blockButtonOptions: { | ||
blockType: 'exampleA', | ||
label: 'Example A', | ||
leftSection: <Cube />, | ||
}, | ||
blockCardOptions: { | ||
blockHeader: ( | ||
<> | ||
<Cube key="1" /> | ||
<span key="2">Example A</span> | ||
</> | ||
), | ||
}, | ||
renderFunc: (b: IExampleBlock, i: number): ReactElement => { | ||
return ( | ||
<Group> | ||
<input | ||
key={b.id + 1} | ||
defaultValue={b.value} | ||
id={`example.${i}.input1`} | ||
placeholder="nested field 1" | ||
required | ||
/> | ||
<input | ||
key={b.id + 2} | ||
id={`example.${i}.input2`} | ||
placeholder="nested field 2" | ||
required | ||
/> | ||
</Group> | ||
); | ||
}, | ||
}, | ||
{ | ||
block: { | ||
blockType: 'exampleB', | ||
opened: true, | ||
value: '', | ||
}, | ||
blockButtonOptions: { | ||
blockType: 'exampleB', | ||
label: 'Example B', | ||
leftSection: <Leaf />, | ||
maxInstances: 1, | ||
tooltipLabel: (b) => (b.disabled ? 'Cannot add more than 1' : ''), | ||
variant: 'outline', | ||
}, | ||
blockCardOptions: { | ||
blockHeader: ( | ||
<> | ||
<Leaf key="1" /> | ||
<span key="2">Example B</span> | ||
</> | ||
), | ||
}, | ||
renderFunc: (b: IExampleBlock, i: number): ReactElement => { | ||
return ( | ||
<select | ||
key={b.id} | ||
defaultValue={b.value} | ||
id={`example.${i}`} | ||
required | ||
> | ||
<option disabled value=""> | ||
-- Please choose an option -- | ||
</option> | ||
<option value="selectA">Value A</option> | ||
<option value="selectB">Value B</option> | ||
</select> | ||
); | ||
}, | ||
}, | ||
]; |
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
17 changes: 10 additions & 7 deletions
17
.../FormDynamicZone/FormDynamicZone.test.tsx → ...mponents/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
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
Oops, something went wrong.