Skip to content

Instantly share code, notes, and snippets.

@iamdanthedev
Created February 19, 2018 13:04
Show Gist options
  • Select an option

  • Save iamdanthedev/c80faaa1707c8693f6aacfb7e6b5307d to your computer and use it in GitHub Desktop.

Select an option

Save iamdanthedev/c80faaa1707c8693f6aacfb7e6b5307d to your computer and use it in GitHub Desktop.

Revisions

  1. iamdanthedev created this gist Feb 19, 2018.
    8 changes: 8 additions & 0 deletions stories-index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    const initialValues = { comment: 'hello'; }

    storiesOf('Form Controls: Select', module)
    .addDecorator(withFormValues(initialValues)
    .add('default', () => (
    <Select name="select" label="Country..." options={selectOptions} />
    </Formik>
    ))
    20 changes: 20 additions & 0 deletions withFormValues.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    import React from 'react';
    import { Formik } from 'formik';

    /**
    * Decorates a story with Formik
    * @param initialValues
    * @param validationSchema - yup schema (formik validationSchema)
    * @returns {function(*): *}
    */


    export const withFormValues = (initialValues, validationSchema) => story => (
    <Formik
    initialValues={initialValues}
    validationSchema={validationSchema}
    onSubmit={values => console.log(values)}
    >
    {story()}
    </Formik>
    );