-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added more form stories & tests update
- Loading branch information
1 parent
949373a
commit 12534dc
Showing
12 changed files
with
503 additions
and
201 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
28 changes: 28 additions & 0 deletions
28
...s/Form/DynamicForm/_stories/ConditionalRenderingShowcase/ConditionalRenderingShowcase.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,28 @@ | ||
import { AnyObject } from '@/common'; | ||
import { useState } from 'react'; | ||
import { JSONEditorComponent } from '../../../Validator/_stories/components/JsonEditor/JsonEditor'; | ||
import { DynamicFormV2 } from '../../DynamicForm'; | ||
import { schema } from './schema'; | ||
|
||
export const ConditionalRenderingShowcaseComponent = () => { | ||
const [context, setContext] = useState<AnyObject>({}); | ||
|
||
return ( | ||
<div className="flex h-screen w-full flex-row flex-nowrap gap-4"> | ||
<div className="w-1/2"> | ||
<DynamicFormV2 | ||
elements={schema} | ||
values={context} | ||
onSubmit={() => { | ||
console.log('onSubmit'); | ||
}} | ||
onChange={setContext} | ||
// onEvent={console.log} | ||
/> | ||
</div> | ||
<div className="w-1/2"> | ||
<JSONEditorComponent value={context} readOnly /> | ||
</div> | ||
</div> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
.../src/components/organisms/Form/DynamicForm/_stories/ConditionalRenderingShowcase/index.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 @@ | ||
export * from './ConditionalRenderingShowcase'; |
80 changes: 80 additions & 0 deletions
80
...src/components/organisms/Form/DynamicForm/_stories/ConditionalRenderingShowcase/schema.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,80 @@ | ||
import { IFormElement } from '../../types'; | ||
|
||
export const schema: Array<IFormElement<any, any>> = [ | ||
{ | ||
id: 'first-name', | ||
element: 'textfield', | ||
valueDestination: 'firstName', | ||
params: { | ||
label: 'First Name', | ||
placeholder: 'Enter something to reveal some more!', | ||
}, | ||
validate: [ | ||
{ | ||
type: 'required', | ||
value: {}, | ||
message: 'First name is required', | ||
applyWhen: { | ||
type: 'json-logic', | ||
value: { | ||
'!': { var: 'forceEverythingOptionnal' }, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
id: 'reveal-more', | ||
element: 'checkboxfield', | ||
valueDestination: 'revealMore', | ||
params: { | ||
label: 'Reveal More', | ||
}, | ||
}, | ||
{ | ||
id: 'force-everything-optionnal', | ||
element: 'checkboxfield', | ||
valueDestination: 'forceEverythingOptionnal', | ||
params: { | ||
label: 'Force everything to be optionnal', | ||
}, | ||
}, | ||
{ | ||
id: 'last-name', | ||
element: 'textfield', | ||
valueDestination: 'lastName', | ||
params: { | ||
label: 'Last Name', | ||
}, | ||
hidden: [ | ||
{ | ||
engine: 'json-logic', | ||
value: { | ||
and: [{ '!': { var: 'firstName' } }, { '!': { var: 'revealMore' } }], | ||
}, | ||
}, | ||
], | ||
validate: [ | ||
{ | ||
type: 'required', | ||
value: {}, | ||
message: 'Last name is required', | ||
applyWhen: { | ||
type: 'json-logic', | ||
value: { | ||
and: [{ '!!': { var: 'firstName' } }, { '!': { var: 'forceEverythingOptionnal' } }], | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
id: 'submit', | ||
element: 'submitbutton', | ||
valueDestination: 'submit', | ||
params: { | ||
label: 'Submit', | ||
disableWhenFormIsInvalid: true, | ||
}, | ||
}, | ||
]; |
28 changes: 28 additions & 0 deletions
28
.../components/organisms/Form/DynamicForm/_stories/ValidationShowcase/ValidationShowcase.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,28 @@ | ||
import { AnyObject } from '@/common'; | ||
import { useState } from 'react'; | ||
import { JSONEditorComponent } from '../../../Validator/_stories/components/JsonEditor/JsonEditor'; | ||
import { DynamicFormV2 } from '../../DynamicForm'; | ||
import { schema } from './schema'; | ||
|
||
export const ValidationShowcaseComponent = () => { | ||
const [context, setContext] = useState<AnyObject>({}); | ||
|
||
return ( | ||
<div className="flex h-screen w-full flex-row flex-nowrap gap-4"> | ||
<div className="w-1/2"> | ||
<DynamicFormV2 | ||
elements={schema} | ||
values={context} | ||
onSubmit={() => { | ||
console.log('onSubmit'); | ||
}} | ||
onChange={setContext} | ||
// onEvent={console.log} | ||
/> | ||
</div> | ||
<div className="w-1/2"> | ||
<JSONEditorComponent value={context} readOnly /> | ||
</div> | ||
</div> | ||
); | ||
}; |
Empty file.
136 changes: 136 additions & 0 deletions
136
packages/ui/src/components/organisms/Form/DynamicForm/_stories/ValidationShowcase/schema.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,136 @@ | ||
import { IFormElement } from '../../types'; | ||
|
||
export const schema: Array<IFormElement<any, any>> = [ | ||
{ | ||
id: 'first-name-field', | ||
element: 'textfield', | ||
valueDestination: 'firstName', | ||
params: { | ||
label: 'First Name', | ||
placeholder: 'Enter your first name', | ||
}, | ||
validate: [ | ||
{ | ||
type: 'required', | ||
value: {}, | ||
message: 'First name is required', | ||
}, | ||
], | ||
}, | ||
{ | ||
id: 'last-name-field', | ||
element: 'textfield', | ||
valueDestination: 'lastName', | ||
params: { | ||
label: 'Last Name', | ||
placeholder: 'Enter your last name', | ||
}, | ||
validate: [ | ||
{ | ||
type: 'required', | ||
value: {}, | ||
message: 'Last name is required', | ||
}, | ||
], | ||
}, | ||
{ | ||
id: 'date-of-birth-field', | ||
element: 'datefield', | ||
valueDestination: 'dateOfBirth', | ||
params: { | ||
label: 'Date of Birth', | ||
placeholder: 'Enter your date of birth', | ||
}, | ||
validate: [ | ||
{ | ||
type: 'required', | ||
value: {}, | ||
message: 'Date of birth is required', | ||
}, | ||
], | ||
}, | ||
{ | ||
id: 'passport-photo', | ||
element: 'filefield', | ||
valueDestination: 'passportPhoto', | ||
params: { | ||
label: 'Passport Photo', | ||
placeholder: 'Select your passport photo', | ||
}, | ||
validate: [ | ||
{ | ||
type: 'required', | ||
value: {}, | ||
message: 'Passport photo is required', | ||
applyWhen: { | ||
type: 'json-logic', | ||
value: { | ||
'!': { var: 'iDontHaveDocument' }, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
id: 'idont-have-document-checkbox', | ||
element: 'checkboxfield', | ||
valueDestination: 'iDontHaveDocument', | ||
params: { | ||
label: "I don't have a document", | ||
}, | ||
}, | ||
{ | ||
id: 'workplaces', | ||
valueDestination: 'workplaces', | ||
element: 'fieldlist', | ||
params: { | ||
label: 'Workplaces', | ||
addButtonLabel: 'Add Workplace', | ||
}, | ||
validate: [ | ||
{ type: 'required', value: {}, message: 'Workplaces are required' }, | ||
{ | ||
type: 'minLength', | ||
value: { minLength: 2 }, | ||
message: 'At least {minLength} workplaces are required', | ||
}, | ||
], | ||
children: [ | ||
{ | ||
id: 'workplace-name', | ||
element: 'textfield', | ||
valueDestination: 'workplaces[$0].workplaceName', | ||
params: { | ||
label: 'Workplace Name', | ||
}, | ||
validate: [{ type: 'required', value: {}, message: 'Workplace name is required' }], | ||
}, | ||
{ | ||
id: 'workplace-start-date', | ||
element: 'datefield', | ||
valueDestination: 'workplaces[$0].workplaceStartDate', | ||
params: { | ||
label: 'Workplace Start Date', | ||
}, | ||
validate: [{ type: 'required', value: {}, message: 'Workplace start date is required' }], | ||
}, | ||
{ | ||
id: 'certificate-of-employment', | ||
element: 'filefield', | ||
valueDestination: 'workplaces[$0].certificateOfEmployment', | ||
params: { | ||
label: 'Certificate of Employment', | ||
}, | ||
validate: [], | ||
}, | ||
], | ||
}, | ||
{ | ||
id: 'submit-button', | ||
element: 'submitbutton', | ||
valueDestination: 'submit', | ||
params: { | ||
label: 'Submit', | ||
}, | ||
}, | ||
]; |
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.