Giter Club home page Giter Club logo

mui-rhf's Introduction

mui-rhf

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!

mui-rhf's People

Contributors

clement-faure avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.