import React, { useState } from 'react'; import type { ComponentMeta } from '@storybook/react'; import type { CheckboxListOrientation } from '@tih/ui'; import { HorizontalDivider } from '@tih/ui'; import { CheckboxInput, CheckboxList } from '@tih/ui'; const CheckboxListOrientations: ReadonlyArray = [ 'horizontal', 'vertical', ]; export default { argTypes: { description: { control: 'text', }, label: { control: 'text', }, orientation: { control: { type: 'select' }, options: CheckboxListOrientations, }, }, component: CheckboxList, title: 'CheckboxList', } as ComponentMeta; export function Basic({ description, label, orientation, }: Pick< React.ComponentProps, 'description' | 'label' | 'orientation' >) { const items = [ { label: 'Apple', name: 'apple', value: true, }, { label: 'Banana', name: 'banana', value: true, }, { label: 'Orange', name: 'orange', value: false, }, ]; return ( {items.map(({ label: itemLabel, name, value: itemValue }) => ( ))} ); } Basic.args = { description: 'Selected fruits will be served after dinner', label: 'Select your favorite fruits', orientation: 'vertical', }; export function Controlled() { const items = [ { label: 'Apple', value: 'apple', }, { label: 'Banana', value: 'banana', }, { label: 'Orange', value: 'orange', }, ]; const [values, setValues] = useState(new Set(['apple'])); return ( {items.map(({ label: itemLabel, value: itemValue }) => ( { if (newValue) { setValues(new Set([...Array.from(values), itemValue])); } else { setValues( new Set(Array.from(values).filter((v) => v !== itemValue)), ); } }} /> ))} ); } export function Disabled() { const items = [ { description: 'A red fruit', disabled: false, label: 'Apple', value: 'apple', }, { description: 'A yellow fruit', disabled: true, label: 'Banana', value: 'banana', }, { description: 'An orange fruit', disabled: false, label: 'Orange', value: 'orange', }, ]; const [values, setValues] = useState(new Set(['apple', 'banana'])); return (
{items.map(({ disabled, label: itemLabel, value: itemValue }) => ( { if (newValue) { setValues(new Set([...Array.from(values), itemValue])); } else { setValues( new Set(Array.from(values).filter((v) => v !== itemValue)), ); } }} /> ))}
); } export function ItemDescriptions() { const items = [ { description: 'A red fruit', label: 'Apple', value: 'apple', }, { description: 'A yellow fruit', label: 'Banana', value: 'banana', }, { description: 'An orange fruit', label: 'Orange', value: 'orange', }, ]; const [values, setValues] = useState(new Set(['apple', 'banana'])); return (
{items.map(({ description, label: itemLabel, value: itemValue }) => ( { if (newValue) { setValues(new Set([...Array.from(values), itemValue])); } else { setValues( new Set(Array.from(values).filter((v) => v !== itemValue)), ); } }} /> ))}
); } export function Orientation() { const items = [ { label: 'Apple', name: 'apple', value: true, }, { label: 'Banana', name: 'banana', value: false, }, { label: 'Orange', name: 'orange', value: true, }, ]; return (
{items.map(({ label: itemLabel, name, value: itemValue }) => ( ))} {items.map(({ label: itemLabel, name, value: itemValue }) => ( ))}
); }