npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mui-rhf-library

v1.5.6

Published

A set of configured Material UI form inputs configured with React Hook Form and Yup.

Downloads

649

Readme

Installation

mui-rhf-library is available as an npm package.

// with npm
npm install mui-rhf-library

// with yarn
yarn add mui-rhf-library

Demo

Check the storybook of the library: https://6256bd53e0b94a003aad40bd-cnmtmxtjgl.chromatic.com/

Usage

Here is a quick example to get you started:

import React from 'react';
import { createRoot } from 'react-dom/client';
import { TextFieldController, SelectController } from 'mui-rhf-library';
import { useForm } from 'react-hook-form';

function App() {
    const { control } = useForm();

    return (
        <>
            <TextFieldController control={control} name="name" defaultValue="" label="TextField Controller" />

            <SelectController
                name="select"
                label="Select Controller"
                control={control}
                options={[
                    { label: 'Option One', value: 'option-one', example: { name: 'example-one' } },
                    { label: 'Option Two', value: 'option-two', example: { name: 'example-two' } }
                ]}
                optionValue="example.name"
                optionLabel="example.name"
                variant="outlined"
            />
        </>
    );
}

const container = document.querySelector('#app');
const root = createRoot(container);
root.render(<App />);

Generate form fields:

import React from 'react';
import { createRoot } from 'react-dom/client';
import { FormFields } from 'mui-rhf-library';
import { useForm } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup';
import * as yup from 'yup';

function App() {
     const {
         handleSubmit
         control,
     } = useForm();

  	const fields = [
        {
            fieldType: 'textField', // 'textField' | 'select' | 'autocomplete' | 'checkbox' | 'radioGroup' | 'switch' | 'datePicker' |'custom'
            name: 'firstName',
            label: 'firstName',
            control: control,
            props: { fullWidth: true }, // Props of the field
            gridProps: {xs: 12} // Props of the Grid: "xs" | "sm" | "md" | "ld" | "xl"
        }
    ];

	const handleFormSubmit = (data) => {
        console.log({ data });
    };

    return (
        <form onSubmit={handleSubmit(handleFormSubmit)}>
            <FormFields fields={fields} control={control} />
            <button type="submit">Submit</button>
        </form>
    );
}

const container = document.querySelector('#app');
const root = createRoot(container);
root.render(<App />);

Documentation

TextField Controller

Props of Material UI TextField are also available.

| Prop | Type | Default | Definition | | ------------ | --------- | ------- | ------------------------------------------------------------------------------------------------------- | | name* | string | | The name of the input | | control* | Control | | The React Hook Form object to register components into React Hook Form. | | defaultValue | any | | The default value of the input that would be injected into React Hook Form Controller and the component |

Select Controller

Props of Material UI Select are also available.

| Prop | Type | Default | Definition | | ----------------- | ------------------------------------------- | ------- | ------------------------------------------------------------ | | name* | string | | The name of the input | | control* | Control | | The React Hook Form object to register components into React Hook Form. | | defaultValue | any | | The default value of the input that would be injected into React Hook Form Controller and the component | | options | {disabled?: boolean, [key:string]: any}[] | | The option items that is available to the component. | | optionValue | string | 'value' | Set property of options's value | | optionLabel | string | 'label' | Set property of items’s text label | | onChange | (event: SelectChangeEvent) => void | | Callback fired when a menu item is selected. | | loading | boolean | false | Displays linear progress bar | | customOptionLabel | (option: any) => any | | Display custom option label | | helperText | ReactNode | | Form helper text |

Autocomplete Controller

Props of Material UI Autocomplete are also available.

| Prop | Type | Default | Definition | | ----------------- | ------------------------------------ | ------- | ------------------------------------------------------------------------------------------------------- | | name* | string | | The name of the input | | control* | Control | | The React Hook Form object to register components into React Hook Form. | | defaultValue* | any | | The default value of the input that would be injected into React Hook Form Controller and the component | | options | {}[] | | The option items that is available to the component. | | optionValue | string | 'value' | Set property of options's value | | optionLabel | string | 'label' | Set property of items’s text label | | multiple | boolean | | If true, menu will support multiple selections. | | onChange | (event: SelectChangeEvent) => void | | Callback fired when a menu item is selected. | | disableClearable | boolean | | | | textFieldProps | TextFieldProps | | The props that will be passed to TextField component in the renderInput of AutoComplete. | | loading | boolean | false | Displays linear progress bar | | customOptionLabel | (option: any) => any | | Display custom option label |

RadioGroup Controller

| Prop | Type | Default | Definition | | ------------ | ---------------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------- | | name* | string | | The name of the input | | label | string | | The label content | | control* | Control | | The React Hook Form object to register components into React Hook Form. | | defaultValue | string | number | | The default value of the input that would be injected into React Hook Form Controller and the component | | options | Options | | The option items that is available to the component. | | onChange | (event: React.ChangeEvent) => void | | A custom method that gets triggered when the value of the input is changed |

Checkbox Controller

| Prop | Type | Default | Definition | | ------------ | ---------------------------------------------------- | ------- | ------------------------------------------------------------ | | name* | string | | The name of the input | | label* | string | | The label content | | control* | Control | | The React Hook Form object to register components into React Hook Form. | | onChange | (event: React.ChangeEvent) => void | | A custom method that gets triggered when the value of the checkbox is changed | | defaultValue | boolean | | The default value of the input that would be injected into React Hook Form Controller and the component | | helperText | ReactNode | | Form helper text |

Switch Controller

| Prop | Type | Default | Definition | | ------------ | ---------------------------------------------------- | ------- | ------------------------------------------------------------ | | name* | string | | The name of the input | | label* | string | | The label content | | control* | Control | | The React Hook Form object to register components into React Hook Form. | | defaultValue | boolean | | The default value of the input that would be injected into React Hook Form Controller and the component | | onChange | (event: React.ChangeEvent) => void | | A custom method that gets triggered when the value of the switch is changed | | helperText | ReactNode | | Form helper text |

DatePicker Controller

| Prop | Type | Default | Definition | | ------------ | ----------- | ------- | ------------------------------------------------------------ | | name* | string | | The name of the input | | label* | string | | The label content | | control* | Control | | The React Hook Form object to register components into React Hook Form. | | defaultValue | | | The default value of the input that would be injected into React Hook Form Controller and the component | | helperText | ReactNode | | Form helper text |

Custom Controller

| Prop | Type | Default | Definition | | --------------- | ------------- | ------- | ----------------------------------------------------------------------- | | name* | string | | The name of the input | | control* | Control | | The React Hook Form object to register components into React Hook Form. | | CustomComponent | React.FC | | A custom component that will be rendered. |

FormFields

| Prop | Type | Default | Definition | | --------- | --------------------- | --------- | ----------------------------------------------------------------------- | | fields* | array of FieldProps | | The name of the input | | control* | | Control | The React Hook Form object to register components into React Hook Form. |

Changelog

Please read the changelog for details of what has changed.