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

rhf-controlled-form-inputs

v0.1.1

Published

Set of reusable controlled input components provided by [MUI](https://mui.com/) and ready to be used with [react-hook-form](https://react-hook-form.com/).

Downloads

1

Readme

Visio React-Hook-Form base components

Set of reusable controlled input components provided by MUI and ready to be used with react-hook-form.

Installation

yarn add visio-react-base

npm install visio-react-base

Libraries we used

react-hook-form

MUI

react-number-format

axios-hooks

Basic usage

Import the component or components you want to use and plug them in your form. See example below:

import { useForm } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup";
import * as yup from "yup";
import {InputText} from "visio-rhf-base";
...

const schema = yup.object().shape({
  name: yup.string(),
})

const { ...methods } = useForm({
  resolver: yupResolver(schema),
  defaultValues: {
    name: "",
  },
});
<form>
  <InputText
    name="name"
    control={methods.control}
    label="Name"
    fullWidth
  />
  <Button type="submit">Send</Button>
</form>

We don't require the use of react-hook-form useFormContext wrapping the form for these simple components, but feel free to use it.

Available components

Required props

Just 2 props are required

  • control
  • name

InputText

Most basic of the elements, designed to accept text or number, you can pass all the attributes available for TextField.

<InputText name="name" control={methods.control} label="Name" />

InputNumber

This is based on numeric-format from react-number-format. It is going to allow only number inputs and will return a float when you type. You can extend this components using the props in the documentation, you can specify decimals, format as a currency or just as a good old number. Below you have 2 examples

<InputNumber
  name="creditScore"
  control={methods.control}
  label="Credit Score"
/>
<InputNumber
  name="amount"
  control={methods.control}
  label="Amount"
  thousandSeparator=","
  prefix="$"
  decimalScale={2}
/>

InputPattern

This is based on pattern-format from react-number-format. It is going to format your string according to the format parameter you pass, this returns a formatted string. You can extend this using any props in the react-number-format and MUI libraries. Examples below for a FEIN and a US phone:

<InputPattern
  name="fein"
  label="FEIN"
  control={control}
  format="##-#######"
  allowEmptyFormatting
  mask="_"
/>
<InputPattern
  name="phone"
  label="Phone"
  control={control}
  format="(###) ###-####"
  allowEmptyFormatting
  mask="_"
/>

InputSelect

Select component which is going to accept a group of options and display them as a combobox.

<InputSelect
  name="contactMethod"
  control={methods.control}
  label="Contact Method"
  options={
    ({ label: "Phone", value: "Phone" }, { label: "Email", value: "Email" })
  }
/>

InputRadio

Radio component which is going to accept a group of options and display them as radio options.

<InputRadio
  name="contactMethod"
  control={methods.control}
  label="Contact Method"
  options={
    ({ label: "Phone", value: "Phone" }, { label: "Email", value: "Email" })
  }
/>

InputCheckbox

Checkbox component to render boolean fields. It will send a boolean value to the form

<InputCheckbox
  name="vaccinated"
  control={methods.control}
  label="Vaccinated?"
/>

FUTURE FEATURES WIP

Find a clean way to add * to required fields