-
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: wip adding system to generate buttons and blocks from same prop…
…, common types, etc
- Loading branch information
Quentin Le Caignec
committed
Aug 27, 2024
1 parent
ac486c8
commit 10088ae
Showing
9 changed files
with
125 additions
and
44 deletions.
There are no files selected for viewing
42 changes: 41 additions & 1 deletion
42
packages/haring-react-hook-form/src/Components/FormDynamicZone/FormDynamicZone.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 |
---|---|---|
@@ -1,7 +1,47 @@ | ||
import { Alien, Leaf, TreasureChest } from '@phosphor-icons/react'; | ||
import type { | ||
IFormDynBlock, | ||
IFormField, | ||
IFormRegisterFunc, | ||
} from '../../types/form-dynamic-zone'; | ||
import type { ReactElement } from 'react'; | ||
|
||
import { Alien, Cube, Leaf, TreasureChest } from '@phosphor-icons/react'; | ||
|
||
export const blockOptionsMock = [ | ||
{ id: 'default', label: 'Default', leftSection: <Alien /> }, | ||
{ id: 'other', label: 'Other', leftSection: <Leaf /> }, | ||
{ id: 'stuff', label: 'Stuff', leftSection: <TreasureChest /> }, | ||
]; | ||
|
||
export const dynamicBlocksMock: IFormDynBlock[] = [ | ||
{ | ||
block: { | ||
blockHeader: ( | ||
<> | ||
<Cube key="1" /> | ||
<span key="2">Example</span> | ||
</> | ||
), | ||
blockType: 'default', | ||
value: 'initial', | ||
}, | ||
button: { | ||
blockType: 'default', | ||
label: 'Example', | ||
leftSection: <Cube />, | ||
}, | ||
renderFunc: ( | ||
b: IFormField, | ||
_i: number, | ||
register: IFormRegisterFunc, | ||
registerName: string, | ||
): ReactElement => { | ||
return ( | ||
<> | ||
<span>works</span> | ||
<input key={b.id} {...register(registerName)} /> | ||
</> | ||
); | ||
}, | ||
}, | ||
]; |
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
22 changes: 22 additions & 0 deletions
22
packages/haring-react-hook-form/src/types/form-dynamic-zone.ts
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,22 @@ | ||
import type { IBaseBlock, IBaseBlockButton } from '@smile/haring-react'; | ||
import type { ReactElement } from 'react'; | ||
import type { UseFormRegister } from 'react-hook-form/dist/types/form'; | ||
|
||
export interface IFormField extends IBaseBlock { | ||
// fieldName: string; | ||
value?: string; | ||
} | ||
|
||
export type IFormRegisterFunc<T extends IFormField = IFormField> = | ||
UseFormRegister<Record<string, Omit<T, 'id'>[]>>; | ||
|
||
export interface IFormDynBlock { | ||
block: Omit<IFormField, 'id'>; | ||
button: IBaseBlockButton; | ||
renderFunc: ( | ||
block: IBaseBlock, | ||
index: number, | ||
registerFunc: IFormRegisterFunc, | ||
registerName: string, | ||
) => ReactElement; | ||
} |
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
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