import { Meta, StoryFn } from "@storybook/react"; import React, { useState } from "react"; import { useForm, Controller, ControllerRenderProps } from "react-hook-form"; import * as Yup from "yup"; import { faker } from "@faker-js/faker"; import { yupResolver } from "@hookform/resolvers/yup"; import { Select } from ":/components/Forms/Select"; import { Button } from ":/components/Button"; import { CunninghamProvider } from ":/components/Provider"; import { getFieldState, getFieldErrorMessage, onSubmit, } from ":/tests/reactHookFormUtils"; 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}
); }; return (
); }; export const FullWidth = { render: Template, args: { label: "Select a city", options: OPTIONS, fullWidth: true, }, }; export const NotClearable = { render: Template, args: { label: "Select a city", options: OPTIONS, defaultValue: OPTIONS[4].value, clearable: false, }, }; export const DisabledOptions = { render: Template, args: { label: "Select a city", options: OPTIONS.map((option, i) => ({ ...option, disabled: i % 3 === 0 })), }, }; export const Success = { render: Template, args: { label: "Select a city", options: OPTIONS, state: "success", text: "Well done", }, }; export const Error = { render: Template, args: { label: "Select a city", options: OPTIONS, state: "error", text: "Something went wrong", }, }; export const FormExample = () => { const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); const data = new FormData(e.target as any); // eslint-disable-next-line no-console console.log(data.getAll("city")); }; return (