diff --git a/src/components/form-field/listbox/listbox.stories.tsx b/src/components/form-field/listbox/listbox.stories.tsx index 76d49992..379e395e 100644 --- a/src/components/form-field/listbox/listbox.stories.tsx +++ b/src/components/form-field/listbox/listbox.stories.tsx @@ -1,163 +1,230 @@ /* eslint-disable react/jsx-props-no-spreading */ -import type { Meta, StoryObj } from "@storybook/react"; -import React, { FC } from "react"; -import { FormField } from "../form-field"; +import type { Meta, StoryObj } from '@storybook/react-vite' +import { FC, useState } from 'react' +import { FormField } from '../form-field' + +type ListboxStoryArgs = { + label: string + description: string + placeholder: string + width: number + disabled: boolean +} -const meta: Meta = { - title: "Input/Listbox", - component: FormField.Listbox, -}; +const meta: Meta = { + title: 'Input/Listbox', + args: { + label: 'Label', + description: 'Description', + placeholder: 'Select...', + width: 288, + disabled: false, + }, + argTypes: { + label: { control: 'text' }, + description: { control: 'text' }, + placeholder: { control: 'text' }, + width: { control: { type: 'range', min: 200, max: 360, step: 16 } }, + disabled: { control: 'boolean' }, + }, +} -export default meta; +export default meta -type Story = StoryObj; +type Story = StoryObj interface Person { - id: number; - name: string; - isDead?: boolean; + id: number + name: string + isDead?: boolean } const people: Person[] = [ - { id: 1, name: "John Lennon", isDead: true }, - { id: 2, name: "Kenton Towne" }, - { id: 3, name: "Therese Wunsch" }, - { id: 4, name: "Benedict Kessler" }, - { id: 5, name: "Katelyn Rohan" }, -]; - -const ListboxTextWithHooks = () => { - const [selectedPerson, setSelectedPerson] = React.useState(null); - - return ( - - - Label - Description - - - - - - - {people.map((person) => ( - - - {person.name} - - - ))} - - - - ); -}; - -const ListboxTextWithMultiplePropWithHooks = () => { - const [selectedPeople, setSelectedPeople] = React.useState([]); - - return ( - - - Label - Description - - value={selectedPeople} onChange={setSelectedPeople} multiple> - - 0 - ? selectedPeople.map((person) => person.name).join(", ") - : null - } - placeholder="Select..." - /> - - - {people.map((person) => ( - - - {person.name} - - - ))} - - - - ); -}; - -const ListboxBadgeWithHooks: FC<{ disabled?: boolean }> = ({ disabled }) => { - const [selectedPerson, setSelectedPerson] = React.useState(null); - - return ( - - - Label - Description - - - - - - - - - {people.map((person) => ( - - - {person.name} - - - ))} - - - - ); -}; + { id: 1, name: 'John Lennon', isDead: true }, + { id: 2, name: 'Kenton Towne' }, + { id: 3, name: 'Therese Wunsch' }, + { id: 4, name: 'Benedict Kessler' }, + { id: 5, name: 'Katelyn Rohan' }, +] + +const ListboxTextWithHooks = ({ + label, + description, + placeholder, +}: { + label: string + description: string + placeholder: string +}) => { + const [selectedPerson, setSelectedPerson] = useState(null) + + return ( + + + {label} + + {description} + + + + + + + + {people.map((person) => ( + + + {person.name} + + + ))} + + + + ) +} + +const ListboxBadgeWithHooks: FC<{ + disabled?: boolean + label: string + description: string + placeholder: string +}> = ({ disabled, label, description, placeholder }) => { + const [selectedPerson, setSelectedPerson] = useState(null) + + return ( + + + {label} + + {description} + + + + + + + + + + {people.map((person) => ( + + + {person.name} + + + ))} + + + + ) +} + +const ListboxMultiWithHooks = ({ + label, + description, + placeholder, +}: { + label: string + description: string + placeholder: string +}) => { + const [selectedPeople, setSelectedPeople] = useState([]) + const selectedLabels = selectedPeople.map((person) => person.name).join(', ') + + return ( + + + {label} + + {description} + + + + + + + + {people.map((person) => ( + + + {person.name} + + + ))} + + + + ) +} export const Default: Story = { - render: () => ( -
- -
- ), -}; + render: ({ label, description, placeholder, width }) => ( +
+ +
+ ), +} export const Badge: Story = { - render: () => ( -
- -
- ), -}; + render: ({ label, description, placeholder, width, disabled }) => ( +
+ +
+ ), +} export const Disabled: Story = { - render: () => ( -
- -
- ), -}; + render: ({ label, description, placeholder, width }) => ( +
+ +
+ ), +} export const Multiple: Story = { - render: () => ( -
- -
- ), -}; + render: ({ label, description, placeholder, width }) => ( +
+ +
+ ), +}