import React from "react"; import { yupResolver } from "@hookform/resolvers/yup"; import { Meta, StoryFn } from "@storybook/react"; import { useForm } from "react-hook-form"; import * as Yup from "yup"; import { getFieldState, getFieldErrorMessage, onSubmit, } from ":/components/Forms/Examples/ReactHookForm/reactHookFormUtils"; import { Checkbox, CheckboxGroup } from ":/components/Forms/Checkbox/index"; import { Button } from ":/components/Button"; export default { title: "Components/Forms/Checkbox", component: Checkbox, } as Meta; const Template: StoryFn = (args) => ( ); export const Default = { render: Template, args: {}, }; export const Checked = { render: Template, args: { checked: true, }, }; export const Indeterminate = { render: Template, args: { indeterminate: true, }, }; export const WithLabel = { render: Template, args: { label: "Label", }, }; export const LabelChecked = { render: Template, args: { checked: true, label: "Label", }, }; export const WithTexts = { render: Template, args: { checked: true, label: "Label", text: "This is an optional text", }, }; export const FullWidth = { render: Template, args: { checked: true, fullWidth: true, label: "Label", text: "This is an optional text", }, }; export const Disabled = { render: Template, args: { disabled: true, label: "Label", }, }; export const DisabledChecked = { render: Template, args: { checked: true, disabled: true, label: "Label", }, }; export const Error = { render: Template, args: { checked: true, label: "Label", text: "This is an optional text", state: "error", }, }; export const Success = { render: Template, args: { checked: true, label: "Label", text: "This is an optional text", state: "success", }, }; export const Group = () => (
Your offices
); export const GroupError = () => (
Your offices
); export const GroupSuccess = () => (
Your offices
); export const ReactHookForm = () => { interface CheckboxExampleFormValues { terms: boolean; } const checkboxExampleSchema = Yup.object().shape({ terms: Yup.boolean() .required() .oneOf([true], "You have to accept the terms of use"), }); const { register, handleSubmit, formState } = useForm({ defaultValues: { terms: false, }, mode: "onChange", reValidateMode: "onChange", resolver: yupResolver(checkboxExampleSchema), }); return (
); };