1.0.4 • Published 3 years ago

mui-rhf-components v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

MUI-RHF-components

MUI-RHF-components is a library that extracts common Material UI and React-Hook-Form integrations. This library provides building blocks to quickly start building forms without limiting any of the customizability that MUI offers. All of the props exposed by MUI are still accessible.

Prerequisites

Install react-hook-form and material-ui

npm install react-hook-form @material-ui/core

Installation

npm install mui-react-hook-form

Quick Start

import {
  CheckboxGroup,
  Form,
  RadioButtonGroup,
  SelectInput,
  TextField
} from 'mui-react-hook-form'
import { useForm } from 'react-hook-form'
import { Button } from '@material-ui/core'

const App = () => {
  const formMethods = useForm()
  const onSubmit = (submittedData) => console.log(submittedData)

  return (

      <Form
        formMethods={formMethods}
        onSubmit={onSubmit}>
        <TextField name="firstName" label="first name" />
        <SelectInput
          name="state"
          label="State"
          options={[
            { value: 'IL', label: 'Illinois' },
            { value: 'MO', label: 'Missouri' }
          ]}
        />
        <CheckboxGroup
          name="foods"
          label="Foods I Like"
          options={[
            { value: 'pizza', label: 'Pizza' },
            { value: 'salad', label: 'Salad' }
          ]}
        />
        <RadioButtonGroup
          name="favoriteColor"
          label="Favorite Color"
          options={[
            { value: 'red', label: 'Red' },
            { value: 'blue', label: 'Blue' }
          ]}
        />
        <Button type="submit">Submit</Button>
      </Form>
    </div>
  )
}

export default App

Examples

Basic Example

Validation Example

InitializedData Example

Custom Styles Example

API

Form

PropsOptionsRequiredDescription
formMethodsuseForm return valuesxthis prop provides the RHF form Methods to all children components
onSubmitfunction handlerxhanldes submit event

Any other props that are given will be passed down to the form component

TextField

PropsOptionsRequiredDescription
namestringxUnique Name for RHF
labelstringinput label
defaultValuestring or numberDefault Value for Controller
requiredbooleanadds required validation to useController hook as well as the MUI input
useControllerPropsuseControllerPropsallows access to RHF useController Prop

Any other props that are given will be passed down to the input component

SelectInput

PropsOptionsRequiredDescription
namestringxUnique Name for RHF
options{ value: any; label: string }[]xselect options
labelstringinput label
requiredbooleanadds required validation to useController hook as well as the MUI input
defaultValuestring or numberDefault Value for Controller
useControllerPropsuseControllerPropsallows access to RHF useController Prop

Any other props that are given will be passed down to the input component

Checkbox Group

PropsOptionsRequiredDescription
namestringxUnique Name for RHF
options{ value: any; label: string }[]xvalue/label for checkbox
labelstringlabel for group
controllerPropscontrollerPropsallows access to RHF useController Prop
formLabelPropsformLabelPropsallows access to MUI formLabel Prop
formGroupPropsformGroupPropsallows access to MUI formGroup Prop
formControlPropsformControlPropsallows access to MUI formControl Prop
formControlLabelPropsformControlLabelPropsallows access to MUI formControlLabel Prop
checkboxPropscheckboxPropsallows access to MUI Checkbox Prop

RadioButtonGroup

PropsOptionsRequiredDescription
namestringxUnique Name for RHF
options{ value: any; label: string }[]xvalue/label for checkbox
labelstringlabel for group
defaultValuestring or numberDefault Value for Controller
useControllerPropsuseControllerPropsallows access to RHF useController Prop
formLabelPropsformLabelPropsallows access to MUI formLabel Prop
radioGroupPropsradioGroupPropsallows access to MUI radioGroup Prop
formControlPropsformControlPropsallows access to MUI formControl Prop
formControlLabelPropsformControlLabelPropsallows access to MUI formControlLabel Prop
radioPropscheckboxPropsallows access to MUI Radio Prop

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago