import { Meta } from "@storybook/react-vite"; import { useState } from "react"; import { action } from "storybook/actions"; import { SelectValue, SelectLegacy } from "./Select"; import { SelectOptionComponent, SelectSelectionComponent, StarOption, departments, options, townsByDepartment, } from "./_fixtures"; const onChangeAction = action("onChange"); const meta = { title: "Components/SelectLegacy", component: SelectLegacy, decorators: [(Story) => ], } satisfies Meta; export default meta; export const Basic = () => { const [value, setValue] = useState(null); return ( <>
UnControlled
Controlled
{ onChangeAction(o); setValue(o.target.value); }} >
); }; export const Variants = () => { const [value, setValue] = useState(null); return (
{ onChangeAction(o); setValue(o.target.value); }} > { onChangeAction(o); setValue(o.target.value); }} > { onChangeAction(o); setValue(o.target.value); }} > { onChangeAction(o); setValue(o.target.value); }} > { onChangeAction(o); setValue(o.target.value); }} >
); }; export const NotRequired = () => { const [value, setValue] = useState(null); return ( { onChangeAction(o); setValue(o.target.value); }} > ); }; export const Searchable = () => { const [value, setValue] = useState(null); return ( { onChangeAction(o); setValue(o.target.value); }} > ); }; function isDepartment( department: number | string | null | readonly string[], ): department is "38" | "73" | "74" { return department !== null && ["38", "73", "74"].indexOf(department.toString()) !== -1; } export const Dynamic = () => { const [town, setTown] = useState(null); const [department, setDepartment] = useState(null); return ( <>
{ onChangeAction(o); setDepartment(o.target.value); setTown(null); }} > {isDepartment(department) && ( { onChangeAction(o); setTown(o.target.value); }} > )}
); }; const stars: StarOption[] = [ { value: 0, label: "Empty", icon: "fe-star-empty" }, { value: 1, label: "Half", icon: "fe-star-half" }, { value: 2, label: "Fill", icon: "fe-star" }, ]; // @ts-ignore export const CustomRenderer = ({ disabled, searchable, showArrow }) => { const [value, setValue] = useState(1); return ( <> { onChangeAction(o); setValue(o.target.value); }} selectSelectionComponent={SelectSelectionComponent} selectOptionComponent={SelectOptionComponent} > ); }; CustomRenderer.args = { disabled: false, searchable: false, showArrow: false, };