import "bootstrap/dist/css/bootstrap.css"; import { ErrorMessage, Form, Formik } from "formik"; import React from "react"; import { Button, FormFeedback, FormGroup, InputGroup } from "reactstrap"; import { v4 as uuid } from "uuid"; import * as Yup from "yup"; import { ComponentMeta, ComponentStory } from "@storybook/react"; import Field from "../components/Field/Field"; import Label from "../components/Label"; export default { title: 'Field', component: Field, argTypes: { active: { control: 'boolean' }, alt: { control: 'text' }, block: { control: 'boolean' }, bsSize: { control: 'select', options: ['lg', 'sm'] }, checked: { control: 'boolean' }, disabled: { control: 'boolean' }, invalid: { control: 'boolean' }, max: { control: 'text' }, maxLength: { control: 'text' }, min: { control: 'text' }, minLength: { control: 'text' }, name: { control: 'text' }, plaintext: { control: 'boolean' }, required: { control: 'boolean' }, size: { control: 'select', options: ['lg', 'md', 'sm'] }, type: { control: 'select', options: [ 'text', 'email', 'select', 'file', 'radio', 'checkbox', 'switch', 'textarea', 'button', 'reset', 'submit', 'date', 'datetime-local', 'hidden', 'image', 'month', 'number', 'range', 'search', 'tel', 'url', 'week', 'password', 'datetime', 'time', 'color', ], valid: { control: 'boolean' }, }, }, args: { name: 'firstName', }, } as ComponentMeta; const Template: ComponentStory = ({ ...args }) => ( console.log(values)} > ); export const Basic = Template.bind({}); export const CustomLabel = Template.bind({}); CustomLabel.args = { labelText: 'Custom First Name', }; export const CustomPlaceholder = Template.bind({}); CustomPlaceholder.args = { placeholder: 'Custom Placeholder', }; export const Disabled = Template.bind({}); Disabled.args = { disabled: true, }; export const Required = Template.bind({}); Required.args = { required: true, }; export const CustomId = Template.bind({}); CustomId.args = { id: 'customId', }; export const HiddenField = Template.bind({}); HiddenField.args = { hidden: true, }; export const HiddenLabel = Template.bind({}); HiddenLabel.args = { labelProps: { hidden: true, }, placeholder: 'First Name', }; export const Large = Template.bind({}); Large.args = { labelProps: { size: 'lg', }, bsSize: 'lg', }; export const Small = Template.bind({}); Small.args = { labelProps: { size: 'sm', }, bsSize: 'sm', }; export const Checkbox = Template.bind({}); Checkbox.args = { labelText: 'Accept terms', type: 'checkbox', }; export const Radio = Template.bind({}); Radio.args = { labelText: 'Accept terms', type: 'radio', }; export const MultipleRadio: ComponentStory = () => ( console.log(values)} > Radio Buttons ); export const Password = Template.bind({}); Password.args = { labelText: 'Password', type: 'password', }; export const Url = Template.bind({}); Url.args = { labelText: 'URL', type: 'url', }; export const Number = Template.bind({}); Number.args = { labelText: 'Pick a Number', type: 'number', }; export const DateTime = Template.bind({}); DateTime.args = { labelText: 'Date Time', type: 'datetime', }; export const Date = Template.bind({}); Date.args = { labelText: 'Date', type: 'date', }; export const Time = Template.bind({}); Time.args = { labelText: 'Time', type: 'time', }; export const Color = Template.bind({}); Color.args = { labelText: 'Color', type: 'color', }; export const TextArea = Template.bind({}); TextArea.args = { labelText: 'Bio', type: 'textarea', }; export const File = Template.bind({}); File.args = { labelText: 'Attachment', type: 'file', }; export const Range = Template.bind({}); Range.args = { labelText: 'Range', type: 'range', }; export const Select: ComponentStory = ({ ...args }) => ( console.log(values)} > ); export const SelectMultiple: ComponentStory = ({ ...args }) => ( console.log(values)} > ); export const SubmitWithLoading: ComponentStory = ({ ...args }) => ( { console.log('submitting...'); setTimeout(() => { console.log(JSON.stringify(values, null, 2)); setSubmitting(false); }, 3000); }} >
); export const Validation: ComponentStory = () => { const schema = Yup.object().shape({ email: Yup.string().email().required(), username: Yup.string(), }); return ( { console.log('submitting...'); setTimeout(() => { console.log(JSON.stringify(values, null, 2)); setSubmitting(false); }, 3000); }} validationSchema={schema} >
); }; export const CustomField: ComponentStory = ({ ...args }) => ( console.log(values)} > @ ); const CustomTemplate: ComponentStory = ({ ...args }) => ( console.log(values)} > {!args.withTemplate && } ); export const CustomHiddenField = CustomTemplate.bind({}); CustomHiddenField.args = { withTemplate: false, hidden: true, }; export const CustomDisabledField = CustomTemplate.bind({}); CustomDisabledField.args = { withTemplate: false, disabled: true, }; export const CustomFieldWithValidation: ComponentStory = () => { const schema = Yup.object().shape({ firstName: Yup.string().required('First Name is a required field'), }); return ( console.log(values)} > ); };