@data-driven-forms/react-form-renderer
v3.23.4
Published
React Form Renderer. Data Driven Forms converts JSON form definitions into fully functional React forms.
Downloads
38,353
Readme
Data Driven Forms is a React library used for rendering and managing forms with a lot of provided features based on React Final Form.
:question: Why to use Data Driven Forms? :question:
- All forms shared the same functionality!
- Components are controlled in one place!
- You can easily migrate to different sets of components!
- All functionality is provided (see below!)
:tada: Features :tada:
- Easily readable schema, you don't need to know any HTML or JS to be able to write your own form schemas!
- You can use your own components or use one of our provided mappers!
- Form state managing out-of-the-box (including error states!)
- Fully customizable (you can use your own buttons, actions, etc.)!
- Conditional fields!
- Custom field validation with basic set included!
- Datatype validation!
- Cross-field validation!
- Asynchronous validation supported!
- Supporting Wizard forms!
- Supporting Final Form Field Array!
- ... and a lot more!
:book: For more information please visit the documentation. :book:
Table of Contents
- Installation
- Usage
- Basic provided components
- Documentation
- Useful links
- Development setup
- Contribution
- LICENSE
Installation
Add React Form Renderer
React Form Renderer
$ npm install @data-driven-forms/react-form-renderer -S
$ yarn add @data-driven-forms/react-form-renderer
Optionally you can install one of provided mappers:
Material-UI Mapper
$ npm install @data-driven-forms/mui-component-mapper -S
$ yarn add @data-driven-forms/mui-component-mapper
PatternFly 4 Mapper
$ npm install @data-driven-forms/pf4-component-mapper -S
$ yarn add @data-driven-forms/pf4-component-mapper
BlueprintJS Mapper
$ npm install @data-driven-forms/blueprint-component-mapper -S
$ yarn add @data-driven-forms/blueprint-component-mapper
Semantic UI Mapper
$ npm install @data-driven-forms/suir-component-mapper -S
$ yarn add @data-driven-forms/suir-component-mapper
Ant Design Mapper
$ npm install @data-driven-forms/ant-component-mapper -S
$ yarn add @data-driven-forms/ant-component-mapper
Carbon Mapper
$ npm install @data-driven-forms/carbon-component-mapper -S
$ yarn add @data-driven-forms/carbon-component-mapper
Component libraries in mappers are external dependencies. Make sure to install them in your bundles.
Usage
In order to Data Driven Forms in your component you need the renderer and a component mapper, which provides component mapper and form template.
import React from 'react';
import { FormRenderer, componentTypes } from '@data-driven-forms/react-form-renderer';
import { componentMapper, FormTemplate } from '@data-driven-forms/pf4-component-mapper';
const schema = {
fields: [{
component: componentTypes.TEXT_FIELD,
name: 'name',
label: 'Your name'
}]
}
const Form = () => (
<FormRenderer
schema={schema}
componentMapper={componentMapper}
FormTemplate={FormTemplate}
onSubmit={console.log}
/>
)
Custom mapper
You can also use custom mapper.
import React from 'react';
import { FormRenderer, componentTypes, useFieldApi } from '@data-driven-forms/react-form-renderer';
const TextField = props => {
const {label, input, meta, ...rest} = useFieldApi(props)
return (
<div>
<label htmlForm={input.name}>{label}</label>
<input {...input} {...rest} id={input.name}/>
{meta.error && <p>{meta.error}</p>}
</div>
)
}
const componentMapper = {
[componentTypes.TEXT_FIELD]: TextField,
'custom-type': TextField
}
const schema = {
fields: [{
component: componentTypes.TEXT_FIELD,
name: 'name',
label: 'Your name'
type: 'search',
}]
}
For more information, please check this page.
Mappers can be also generated by using yarn generate-template
command.
Basic provided components
Data Driven Forms supports all kinds of component, basic set is consisted of:
- Text input
- Text area
- Checkbox (Multiple checkboxes)
- Select (dropdown)
- Dual list select
- Field array
- Switch
- Radio buttons
- Date picker
- Time picker
- Tabs
- Slider
- Sub-form
- Plain text
- Wizard
Any other components can be added to mapper and renderer with the form renderer. Existing components can be also overriden.
Documentation
Please use our documentation site. In case of any problem, you can access documentation files directly in GitHub.
Useful links
- Data Driven Forms documentation
- PatternFly 4 Design documentation
- Material-UI documentation
- Ant Design documentation
- Semantic UI React
- BlueprintJS
- IBM Carbon
- NPM
Development setup
Data Driven Forms is a monorepo that uses Lerna and yarn workspaces, so you can use all its commands as well.
- Install
yarn install
- Build
yarn build
- Run a package
Each package has a small playground package/demo
, where you can test your changes.
cd packages/pf3-component-mapper
yarn start
- How to clean?
yarn lerna clean # will delete all node_modules
All packages are linked together by default, so if you run a yarn build
in a package, all other packages are updated to the latest version of that package.
Tests
Tests can be ran from the core folder or from specific packages.
yarn test
yarn test packages/pf3-component-mapper
Commits
Data Driven Forms uses Semantic Release
Format:
[type]([package]): message
fix(pf3): title accepts node
Types:
feat
: a new feature, will trigger new_.X._
releasefix
: a fix, will trigger new_._.X
release
Packages:
- Please describe which package is being changed
pf3
,renderer
, ...
Please, do not use Semantic Release, if you update only the demo.
All packages are releasing together and they share the version number.
Changes to documentation
If your changes influence API or add new features, you should describe these new options in the react-renderer-demo
repository. Thanks!
Contribution
We welcome any community contribution. Don't be afraid to report bug or to create issues and pull-requests! :trophy:
LICENSE
Apache License 2.0