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

formik-material

v4.0.0

Published

Material-UI Binds for formik fields

Downloads

109

Readme

formik-material

storybook codecov Build Status

Material-UI Binds for formik fields

This library exports the Form, a Submit Button, and many types of fields, including fields with masks, currency and numeric ones.

Usage

All the input fields are based on material-ui fields, so all properties and customizations are available.
Please, refer to the documentation to check all available properties.

There is also the Storybook page with examples of all of the components.

Simple Form example

Rendering a <Form> component is required to use any of the fields from this library, regardless of how deep you put the fields or your abstraction of choice.

import { Form, SubmitButton, TextField } from 'formik-material';

function SimpleForm() {
  const initialValues = {
    firstName: 'john',
  };

  return (
    <Form
      initialValues={initialValues}
      onSubmitForm={(values, formikHelpers) => {
        // handle your form submission
        // `values` is TypeScript friendly,
        // and it will match the `initial values` type

        // once your are done, set submitting to false, to allow the user to submit again.
        formikHelpers.setSubmitting(false);
      }}
    >
      <TextField name="firstName" label="First Name:" variant="outlined" />

      <SubmitButton>Submit</SubmitButton>
    </Form>
  );
}

The Form requires 2 properties initialValues and onSubmitForm.
Fields, not present on the initialValues won't work properly, so always define the fields names.

The SubmitButton component is exposed as a convenience, and is not mandatory, it will automatically be disabled while the form is in submitting state. Feel free to use your own submit button.

Text field

TextField is the base building block for any form, its the same component exposed by material-ui bound to Formik. Please, refer to mui docs for all possible customizations.

import { TextField } from 'formik-material';

// ---

<TextField name="firstName" label="First Name:" />;

Checkbox

checkbox field

import { CheckboxField } from 'formik-material';

// ---

<CheckboxField name="read" label="Read and accept our terms" />
<CheckboxField name="accept" label="I accept receiving newsletter" color="secondary" />

Formatted fields / Fields with Mask

These fields leverage the power of the react-number-format library.

They accept Number format, Pattern/Mask format on top of all the Mui customizations, giving you the power of both libraries at the same time.

Currency Field

currency field

import { CurrencyField } from 'formik-material';

// ---
<CurrencyField name="price" label="Price in Reais:" />;
<CurrencyField prefix="$ " name="price" label="Price in Dollars:" />;
<CurrencyField prefix="¥ " name="price" label="Price in Yens:" />;

Number field

number field

import { NumberField } from 'formik-material';

// ---

<NumberField name="age" label="My age:" />;
<NumberField name="count" label="My count:" decimalSeparator="." thousandSeparator="," />;

Formatted field

Formatted field is the low level component, which will accept all properties and customizations, allowing you to create any type of number, date, or masked inputs.

Again, please refer to Number format, Pattern/Mask format documentation to check all available options.

import { FormattedField } from 'formik-material';

// ---

<FormattedField
  name="usaPhoneNumber"
  label="USA phone number"
  type="tel"
  mask="_"
  format="+1 (###) #### ###"
/>;

The bellow components are compositions on top of it.

Brazilian phone field

phone filed

import { BrazilianPhoneField } from 'formik-material';

// ---

<BrazilianPhoneField name="phone" label="My Phone:" />;

CPF field (Brazilian citizen ID)

cpf field

import { CpfField } from 'formik-material';

// ---

<CpfField name="cpf" label="User CPF:" />;

Date Field

date field

import { DateField } from 'formik-material';

// ---

<DateField name="birthday" label="My Birthday:" />;

Password field

password field

import { PasswordField } from 'formik-material';

// ---

<PasswordField name="password" label="Password:" />;