1.0.1 • Published 3 years ago

mui-rhf v1.0.1

Weekly downloads
93
License
ISC
Repository
github
Last release
3 years ago

GitHub Workflow Status codecov

Quickly build powerful forms using Material UI and React Hook Form

Installation

mui-rhf is available as an npm package.

// with npm
npm install mui-rhf

// with yarn
yarn add mui-rhf

Usage

import React from 'react';

import { useForm } from "react-hook-form";
import { MuiRhfForm } from "mui-rhf";
import { Button } from "@material-ui/core";

const Form = ({ onSubmit }) => {
  // Initialize form
  const { control, handleSubmit } = useForm();

  const onSubmit = (data) => {
    // Play with retrieved data
  }

  return (
    <form onSubmit={handleSubmit(onSubmit)} noValidate>
      <MuiRhfForm
        control={control}
        fields={[
          [{ name: "firstName" }, { name: "lastName" }],
          [{ name: "email" }],
          [{ name: "rememberMe", type: "checkbox" }]
        ]}
      />
      <Button type="submit">
        Submit
      </Button>
    </form>
  )
};

Type

MuiRhfFormProps

These are props that you pass to <MuiRhfForm />

fields: MuiRhfFormField;

Fields to construct the form

type MuiRhfFormField = {
  name: string;
  label?: string;
  props?: any;
  type?: keyof MuiRhfFieldComponentMap;
  gridProps?: Pick<GridProps, "xs" | "sm" | "md" | "lg" | "xl">;
  hideCondition?: MuiRhfFormFieldHideConditions; // Union of conditions, if true, field will be hidden
  hideConditions?: MuiRhfFormFieldHideConditions; // Intersection of conditions, if true, field will be hidden
  conditionalProps?: MuiRhfFormFieldConditionalProps; // Extra props applied depending on other form fields values
};

headers?: MuiRhfFormHeader[];

An array of titles

type MuiRhfFormHeader = {
  title?: string;
};

spacing?: GridSpacing;

Spacing applied to main Grid container

watch?: RhfWatch;

Provided by React Hook Form

control: Control;

Provided by React Hook Form

Contributors ✨

This project follows the all-contributors specification. Contributions of any kind welcome!

1.0.1

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.6

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

1.0.0

3 years ago