-
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 initial demo & bugfixes & updated tests
- Loading branch information
1 parent
7f07d19
commit fbc135a
Showing
37 changed files
with
644 additions
and
265 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
10 changes: 10 additions & 0 deletions
10
packages/ui/src/components/organisms/Form/DynamicForm/DynamicForm.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,10 @@ | ||
import { DynamicFormV2 } from './DynamicForm'; | ||
import { InputsShowcaseComponent } from './_stories/InputsShowcase/InputsShowcase'; | ||
|
||
export default { | ||
component: DynamicFormV2, | ||
}; | ||
|
||
export const InputsShowcase = { | ||
render: () => <InputsShowcaseComponent />, | ||
}; |
144 changes: 144 additions & 0 deletions
144
...s/ui/src/components/organisms/Form/DynamicForm/_stories/InputsShowcase/InputsShowcase.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,144 @@ | ||
import { AnyObject } from '@/common'; | ||
import { useState } from 'react'; | ||
import { JSONEditorComponent } from '../../../Validator/_stories/components/JsonEditor/JsonEditor'; | ||
import { DynamicFormV2 } from '../../DynamicForm'; | ||
import { IFormElement } from '../../types'; | ||
|
||
const schema: Array<IFormElement<any, any>> = [ | ||
{ | ||
id: 'TextField', | ||
element: 'textfield', | ||
valueDestination: 'textfield', | ||
params: { | ||
label: 'Text Field', | ||
placeholder: 'Enter text', | ||
}, | ||
validate: [ | ||
{ | ||
type: 'required', | ||
value: {}, | ||
message: 'Text field value is required', | ||
}, | ||
], | ||
}, | ||
{ | ||
id: 'AutocompleteField', | ||
element: 'autocompletefield', | ||
valueDestination: 'autocomplete', | ||
params: { | ||
label: 'Autocomplete Field', | ||
placeholder: 'Select an option', | ||
options: [ | ||
{ value: 'option1', label: 'Option 1' }, | ||
{ value: 'option2', label: 'Option 2' }, | ||
{ value: 'option3', label: 'Option 3' }, | ||
], | ||
}, | ||
}, | ||
{ | ||
id: 'CheckboxListField', | ||
element: 'checkboxlistfield', | ||
valueDestination: 'checkboxlist', | ||
params: { | ||
label: 'Checkbox List Field', | ||
options: [ | ||
{ value: 'option1', label: 'Option 1' }, | ||
{ value: 'option2', label: 'Option 2' }, | ||
{ value: 'option3', label: 'Option 3' }, | ||
], | ||
}, | ||
}, | ||
{ | ||
id: 'DateField', | ||
element: 'datefield', | ||
valueDestination: 'date', | ||
params: { | ||
label: 'Date Field', | ||
}, | ||
}, | ||
{ | ||
id: 'MultiselectField', | ||
element: 'multiselectfield', | ||
valueDestination: 'multiselect', | ||
params: { | ||
label: 'Multiselect Field', | ||
options: [ | ||
{ value: 'option1', label: 'Option 1' }, | ||
{ value: 'option2', label: 'Option 2' }, | ||
{ value: 'option3', label: 'Option 3' }, | ||
], | ||
}, | ||
}, | ||
{ | ||
id: 'SelectField', | ||
element: 'selectfield', | ||
valueDestination: 'select', | ||
params: { | ||
label: 'Select Field', | ||
options: [ | ||
{ value: 'option1', label: 'Option 1' }, | ||
{ value: 'option2', label: 'Option 2' }, | ||
{ value: 'option3', label: 'Option 3' }, | ||
], | ||
}, | ||
}, | ||
{ | ||
id: 'CheckboxField', | ||
element: 'checkboxfield', | ||
valueDestination: 'checkbox', | ||
params: { | ||
label: 'Checkbox Field', | ||
}, | ||
}, | ||
{ | ||
id: 'FieldList', | ||
element: 'fieldlist', | ||
valueDestination: 'fieldlist', | ||
params: { | ||
label: 'Field List', | ||
}, | ||
children: [ | ||
{ | ||
id: 'Nested-TextField', | ||
element: 'textfield', | ||
valueDestination: 'textfield[$0]', | ||
params: { | ||
label: 'Text Field', | ||
placeholder: 'Enter text', | ||
}, | ||
validate: [], | ||
}, | ||
], | ||
}, | ||
{ | ||
id: 'SubmitButton', | ||
element: 'submitbutton', | ||
valueDestination: 'submitbutton', | ||
params: { | ||
label: 'Submit Button', | ||
}, | ||
}, | ||
]; | ||
|
||
export const InputsShowcaseComponent = () => { | ||
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
packages/ui/src/components/organisms/Form/DynamicForm/_stories/InputsShowcase/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 './InputsShowcase'; |
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
Oops, something went wrong.