Skip to content

Commit

Permalink
feat: publish
Browse files Browse the repository at this point in the history
  • Loading branch information
heshanera committed Dec 31, 2022
1 parent c283010 commit db541c3
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
Dynamic form creation module implemented using react. Can generate forms and interact with the generated from with view and edit modes. Layout generator has build in field element types and allows adding custom elements.

## Modes

<div style={{ display: 'flex', justifyContent: 'space-between' }}>
<img src="https://github.com/heshanera/react-form-generator/blob/develop/assets/layoutEditMode.png" alt="Layout Edit" width="33%">
<img src="https://github.com/heshanera/react-form-generator/blob/develop/assets/editMode.png" alt="Form Edit" width="33%">
<img src="https://github.com/heshanera/react-form-generator/blob/develop/assets/viewMode.png" alt="Form View" width="33%">
</div>

## Usage

```js
const FormGenerator = () => {
const [form, setFormLayout] = useState([]);
Expand All @@ -29,29 +31,33 @@ const FormGenerator = () => {
)
}
```

<br/>

## Component Props
| Prop | Type | Description |
| :---------- | :----------- | :----------- |
| formState | ```string``` | State of the form component. This can be layout editable, form editable or form view. <br /> <code>LAYOUT_EDIT \| FORM_EDIT \| FORM_VIEW</code> |
| layout | ```array[]``` | Structure of the form. This is an array of arrays. Each array in the layout structure represent a row and the inner array has objects which has each column data. <code>[[{}, {}], [{}, {}, {}]]</code> |
| setLayout | ```func``` | Method to update the form structure when the form layout is updated. Takes the updated layout as the argument |
| allowDefaults | ```bool``` | To allow or to hide the inbuild field element types |
| customFieldTypes | ```array``` | List of [custom elements](https://github.com/heshanera/react-form-generator/blob/master/src/stories/assets/NumberInput.jsx). These elements will be available in the layout generation once added |
| value | ```object``` | Object with key value pairs which has the form data. <code>Key: Field Id</code> <code>Value: Value</code> |
| setValue | ```function``` | Method to update the form field values. Takes the updated field values object as the argument |

| Prop | Type | Description |
| :--------------- | :--------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| formState | `string` | State of the form component. This can be layout editable, form editable or form view. <br /> <code>LAYOUT_EDIT \| FORM_EDIT \| FORM_VIEW</code> |
| layout | `array[]` | Structure of the form. This is an array of arrays. Each array in the layout structure represent a row and the inner array has objects which has each column data. <code>[[{}, {}], [{}, {}, {}]]</code> |
| setLayout | `func` | Method to update the form structure when the form layout is updated. Takes the updated layout as the argument |
| allowDefaults | `bool` | To allow or to hide the inbuild field element types |
| customFieldTypes | `array` | List of [custom elements](https://github.com/heshanera/react-form-generator/blob/master/src/stories/assets/NumberInput.jsx). These elements will be available in the layout generation once added |
| value | `object` | Object with key value pairs which has the form data. <code>Key: Field Id</code> <code>Value: Value</code> |
| setValue | `function` | Method to update the form field values. Takes the updated field values object as the argument |

<br/>

## Custom Field Element

Custom field elements can be passed to the component to be available in the form generation.<br/>
Sample Element: [Number Input](https://github.com/heshanera/react-form-generator/blob/master/src/stories/assets/NumberInput.jsx)
| Prop | Type | Description |
| Prop | Type | Description |
| :---------- | :----------- | :----------- |
| type | ```string``` | Key to uniquely idenitify the element |
| displayName | ```string``` | Display name for the field |
| Control | ```React Component``` | Rendering logic for the field component |
| FieldPropertiesControl | ```React Component``` | Rendering logic for the field select view |
| type | `string` | Key to uniquely idenitify the element |
| displayName | `string` | Display name for the field |
| Control | `React Component` | Rendering logic for the field component |
| FieldPropertiesControl | `React Component` | Rendering logic for the field select view |
<br/>

## Running Locally with Storybook
Expand Down

0 comments on commit db541c3

Please sign in to comment.