1.0.2 • Published 4 years ago

schema-form-generator v1.0.2

Weekly downloads
6
License
ISC
Repository
github
Last release
4 years ago

React Schema Form

A React component to generate forms from JS object schema. Uses React Hook Form for form management and Chakra UI UI elements.

Basic Example

schema.js

const schema = {
  title: 'Example Form',
  fields: {
    text: {
      type: 'text',
      label: 'Text Field'
    },
    textArea: {
      type: 'textarea',
      label: 'Text Area Field'
    },
    number: {
      type: 'number',
      label: 'Number Field'
    },
    object: {
      type: 'object',
      label: 'Object Field',
      displayInline: true,
      properties: {
        text1: {
          type: 'text',
          label: 'Text Field 1',
          isRequired: true,
        },
        text2: {
          type: 'text',
          label: 'Text Field 2',
          isRequired: true
        }
      }
    },
    array: {
      type: 'array',
      label: 'Array Field',
      items: {
        type: 'number',
        label: 'Number Field'
      }
    },
    radio: {
      type: 'radio',
      label: 'Radio Field',
      optionsKey: 'radioOptions'
    },
    select: {
      type: 'select',
      label: 'Select Field',
      optionsKey: 'selectOptions'
    }
  }
};

App.js

import { Form } from 'schema-form-generator';

const App = () => {
  const handleSubmit = values => {
    console.log(values);
  };

  return <Form schema={schema} handleSubmit={handleSubmit} />;
};

Output

Alt text

Built With

  • Chakra UI - Chakra UI is a simple, modular and accessible component library that gives you all the building blocks you need to build your React applications.
  • React Hook Form - Performant, flexible and extensible forms with easy-to-use validation.

License

This project is licensed under the MIT License

0.1.12

4 years ago

0.1.10

4 years ago

0.1.11

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.9

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.2

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.16

4 years ago

0.0.14

4 years ago

0.0.15

4 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago