import { Meta, StoryFn } from "@storybook/react"; import React, { useState } from "react"; import { useForm, FormProvider } from "react-hook-form"; import * as Yup from "yup"; import { faker } from "@faker-js/faker"; import { yupResolver } from "@hookform/resolvers/yup"; import { onSubmit } from ":/components/Forms/Examples/ReactHookForm/reactHookFormUtils"; import { Select } from ":/components/Forms/Select"; import { Button } from ":/components/Button"; import { CunninghamProvider } from ":/components/Provider"; import { RhfSelect } from ":/components/Forms/Select/stories-utils"; export default { title: "Components/Forms/Select/Mono", component: Select, } as Meta; const Template: StoryFn = (args) => (
setValue(e.target.value as string)} />
); }; export const Overflow = { render: Template, args: { label: "Select a city", options: [ { value: "1", label: "Very long long long long long long long city name", }, ], defaultValue: "1", }, }; export const SearchableEmpty = { render: Template, args: { label: "Select a city", options: OPTIONS, searchable: true, }, }; export const SearchableUncontrolled = { render: Template, args: { label: "Select a city", options: OPTIONS, defaultValue: OPTIONS[4].value, searchable: true, }, }; export const SearchableDisabled = { render: Template, args: { label: "Select a city", options: OPTIONS, defaultValue: OPTIONS[4].value, searchable: true, disabled: true, }, }; export const SearchableControlled = () => { const [value, setValue] = useState(OPTIONS[8].value); return (
Value: {value}
); }; export const ReactHookForm = () => { enum CitiesOptionEnum { NONE = "", DIJON = "dijon", PARIS = "paris", TOKYO = "tokyo", } interface SelectExampleFormValues { joTown: CitiesOptionEnum; } const selectExampleSchema = Yup.object().shape({ joTown: Yup.string() .required() .oneOf([CitiesOptionEnum.PARIS], "That's not the right town!"), }); const methods = useForm({ defaultValues: { joTown: CitiesOptionEnum.NONE, }, mode: "onChange", reValidateMode: "onChange", resolver: yupResolver(selectExampleSchema), }); return (
Where will the 2024 Olympics take place?
); };