Skip to content

daixianceng/formik-material-fields

Repository files navigation

formik-material-fields

npm npm bundle size (version) npm

A set of material style fields for formik

formik-material-fields = formik + material-ui

This library provides the following components:

  • FormikTextField
  • FormikSelectField
  • FormikRadioField
  • FormikRadioGroupField
  • FormikCheckboxField
  • FormikCheckboxGroupField
  • FormikSwitchField

Documentation

Installation

Using npm:

$ npm install --save formik-material-fields

Using yarn:

$ yarn add formik-material-fields

Usage

FormikTextField

import React, { Component } from 'react';
import { Formik, Form } from 'formik';
import * as Yup from 'yup';
import { FormikTextField } from 'formik-material-fields';

const validationSchema = Yup.object().shape({
  username: Yup.string().required(),
});

const initialValues = {
  username: '',
};

class MyForm extends Component {
  render() {
    return (
      <Formik
        initialValues={initialValues}
        validationSchema={validationSchema}
        onSubmit={this.props.onSubmit}
      >
        {({ isValid }) => (
          <Form autoComplete="off">
            <FormikTextField
              name="username"
              label="Username"
              margin="normal"
              fullWidth
            />
          </Form>
        )}
      </Formik>
    );
  }
}

License

formik-material-fields is released under the FSB License. See the bundled LICENSE for details.