React Form Package
Edit page
IntroductionInstallationFormSimple FormButtonFieldFieldWrapperRadioGroupSelectForm ValidationStateonFocus onChange onBlurState ManipulationCustom Error MessagesFeedback on disabled ButtonStylingCSS-in-JSstyle propCSS and classNamePassing propsDynamic FieldsDynamic Fields 2Dynamic Fields 3Bind Input FieldsBind Input Fields 2Third Party ComponentsFile UploadWhy

Styling

To style this form you have three different options, all requires to pass a React component to a form prop.

CSS-in-JS

In this section we will use a library that uses styled-components to style our form

First you have to import the this library and the Form Components you want to use for your styling. In this example we will use styled-bootstrap-components.

import {
Form,
Field,
Button,
Select,
RadioGroup,
} from 'react-form-package';
import {
FormGroup,
FormControl,
FormCheck,
FormCheckInput,
Column,
Button as Btn,
} from 'styled-bootstrap-components';

The next step is to create you form and pass the styled components as props to the <Form /> component.

style prop

In this section we will use a the style prop to style our form

To style your form pass components to the <Form /> component that are styled with the style tag. When you create your own <input />, <button /> components do not forget do bind functions like onClick, onChange, onFocus, onBlur. This functions are needed to make react-form-package work properly.

const MyButton = (props) => (
<button
type="submit"
style={{
margin: '10px 0px',
padding: '8px 24px',
borderRadius: '5px',
border: 'none',
background: '#7FDBFF',
color: '#001f3f',
cursor: 'pointer',
}}
onClick={props.onClick}
>
{props.children}
</button>
);
const MyInput = (props) => (
<input
style={{
margin: '10px 0px',
padding: '8px 3px',
border: '1px solid #7FDBFF',
borderRadius: '5px',
color: 'black',
}}
value={props.value}
placeholder={props.placeholder}
onChange={props.onChange}
onBlur={props.onBlur}
onFocus={props.onFocus}
/>
);

The next step is to create you form and pass the styled components as props to the <Form /> component.

Email

CSS and className

In this section we will use a the className prop and a css file to style our form

To style your form pass components to the <Form /> component that have className prop and use css files (make sure to have an appropriate loader for your bundler).

.button {
background: #001f3f;
border: 1px solid black;
padding: 8px 24px;
border-radius: 3px;
color: white;
cursor: pointer;
}
.input {
margin: 10px 0px;
padding: 8px 3px;
border: 1px solid #001f3f;
border-radius: 5px;
}

Import your CSS file to your application and make sure you have a proper loader for your stylesheet.

import './style.css';
const MyClassNameButton = (props) => (
<button
clssName="button"
>
{children}
</button>
);
const MyClassNameInput = (props) => (
<input
className="input"
value={props.value}
placeholder={props.placeholder}
onChange={props.onChange}
onBlur={props.onBlur}
onFocus={props.onFocus}
/>
);

The next step is to create you form and pass the styled components as props to the <Form /> component.

Email

Passing props

To make your own components work with react-form-package you have to pass some props.

components

  • The Prop is the prop on the <Form /> component.
  • HTML is the actual HTML element to use.
  • Props are the props you have to pass these components e.g. id={prop.id} or id={this.prop.id} or onChange={prop.onChange} or onChange={this.prop.onChange}.
  • Info shows you which props you have to bind.
PropHTMLPropsInfo
inputinputid, type, onChange, onBlur, onFocus
checkboxinputid,type, onChange, onBlur, onFocus
radiodivid,type, onChange, onBlur, onFocus, childrenthis is a wrapper that renders every child, and watch out for <input type="radio" value="someValue" name="theIdRadioGroup" /> and handles their state
buttoninputid, type, onClick, children
selectselectid, type, onChange, onBlur, onFocus, childrenthis is a wrapper that renders every child, and watch out for <option value="someValue" /> and handles their state
textareatextareaid, type, onChange, onBlur, onFocus

A textarea example:

const myTextarea = (props) => (
<textarea
id={props.id}
type={props.type}
onChange={props.onChange}
onBlur={props.onBlur}
onFocus={props.onFocus}
/>
);