React Boring Form ·
React Boring Form handles all of the layout boilerplate (the boring part) that’s necessary when writing forms.
Example
Before
<div ="form-group form-group--aligned"> <div ="form-group-section"> <label ="email_field" ="form-label--required"> Email Addresses </label> </div> <div ="form-group-section"> <input ="email" ="form-control" ="email_field" /> <span ="form-text">Separated by </span> </div></div>
After
<Form.Group ="aligned" > <Form.Label>Email Addresses</Form.Label> <Form.Control ="email" /> <Form.Text>Separated by </Form.Text></Form.Group>
Features
- Generates a unique
id
for the label’shtmlFor
and input’sid
props and links them - Applies
classNames
in a predictable way that reduces boilerplate and provides maximum flexibility - Allows usage of any custom inputs with
render
prop onForm.Control
- Zero-overhead integration with form state libraries like Formik and React-Final-Form
- Optional tiny set of base styles that help with aligned form layouts
Form
Props
layout?: "stacked" | "aligned"
Propagates down to all of the children Form.Group
components. stacked
is the default, which is to set all of the children to display: block
. aligned
splits all of Form.Group
’s children into two groups: "label", and "rest" so that all of the form’s labels will align to the same width.
Form.Group
Props
required?: boolean
Set classNames on the label to indicate a required field, and set the required
prop on the Form.Control
disabled?: boolean
Set classNames on the label to indicate a disabled field, and set the disabled
prop on the Form.Control
Custom Inputs
The default behavior of Form.Control
is to configure an input
element and render it. If you want to use something else, like a select
, textarea
, or a third-party library component, you can render your own component without losing the benefits of React Boring Form:
/* If the controls map to standard HTML attribute names, you can spread the props directly */<Form.Control = />; /* Otherwise, you can destructure the props and apply however is necessary */<Form.Control =/>;