import { Meta, StoryObj } from '@storybook/react-webpack5'; import { Person as ProfileIcon, Globe as GlobeIcon } from '@transferwise/icons'; import { useState } from 'react'; import Select, { SelectItem, SelectOptionItem } from './Select'; /** * @deprecated Use **`SelectInput`** instead
[https://neptune.wise.design/blog/2023-11-28-adopting-our-new-selectinput](https://neptune.wise.design/blog/2023-11-28-adopting-our-new-selectinput) */ const meta: Meta = { component: Select, title: 'Forms/Select', tags: ['deprecated'], argTypes: { id: { control: 'text' }, size: { control: 'radio', options: ['sm', 'md', 'lg'] }, dropdownRight: { control: 'radio', options: ['xs', 'sm', 'md', 'lg', 'xl'] }, dropdownWidth: { control: 'radio', options: [undefined, 'sm', 'md', 'lg'] }, placeholder: { control: 'text' }, inverse: { control: 'boolean' }, block: { control: 'boolean' }, required: { control: 'boolean' }, dropdownUp: { control: 'boolean' }, disabled: { control: 'boolean' }, search: { control: 'boolean' }, searchPlaceholder: { control: 'text' }, options: { control: false }, selected: { control: false }, onChange: { action: 'onChange' }, onSearchChange: { action: 'onSearchChange' }, searchValue: { control: false }, }, }; export default meta; type Story = StoryObj; const ImageIcon = () => ( placeholder ); const isSelectOptionItem = (option: SelectItem | null): option is SelectOptionItem => { return option !== null && typeof option.value !== 'undefined'; }; export const Basic: Story = { args: { id: 'basic-button', size: 'md', placeholder: 'Placeholder text', dropdownRight: 'md', dropdownWidth: 'md', inverse: false, block: true, required: false, dropdownUp: false, disabled: false, search: true, searchPlaceholder: 'Search placeholder', options: [ { header: 'Basic' }, { value: -1, label: 'A thing' }, { value: 0, label: 'A thing', note: 'with a note' }, { value: 1, label: 'Another thing', secondary: 'with secondary text this time' }, { value: -2, label: 'One more thing', note: 'with a note', secondary: 'and with secondary text', }, { value: 6, icon: , label: 'An ', note: 'with a note' }, { value: 2, label: 'A disabled thing', disabled: true }, { separator: true }, { header: 'Icons' }, { value: 3, label: 'Profile', icon: }, { value: 4, label: 'USD', icon: , note: 'United States dollar - Outside of the US', }, { header: 'Currencies' }, { value: 5, label: 'British pound', currency: 'gbp' }, { value: 6, label: 'Euro', currency: 'eur' }, { value: 7, label: 'USD', currency: 'usd', note: 'United States dollar' }, { separator: true }, { value: 8, label: 'Something else' }, { header: 'Options with searchable alternatives' }, { value: 9, label: 'A thing with searchable alternatives', searchStrings: ['abbreviation', 'acronym', 'nickname'], }, { separator: true }, { header: 'Long content options' }, { value: 10, label: 'One more thing with lorem ipsum dolor sit amet, consectetur adipiscing elit consequat text', note: 'with lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor note text', secondary: 'and with lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation secondary text', }, { value: 11, icon: , label: 'One more thing with lorem ipsum dolor sit amet, consectetur adipiscing elit consequat text', note: 'with lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor note text', secondary: 'and with lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation secondary text', }, ], selected: { value: 0, label: 'A thing', note: 'with a note' }, }, render: (args) => { const initialSelected = args.selected ?? { value: 0, label: 'A thing', note: 'with a note' }; const [selected, setSelected] = useState(initialSelected); return ( { if (isSelectOptionItem(option)) { setSelected(option); } }} /> ); }, }; export const AdvancedSearch: Story = { args: { id: 'advanced-search-button', size: 'md', placeholder: 'placeholder', dropdownRight: 'md', dropdownWidth: 'md', inverse: false, block: true, required: false, dropdownUp: false, disabled: false, searchPlaceholder: 'searchplaceholder', options: [ { header: 'Basic' }, { value: -1, label: 'A thing' }, { value: 0, label: 'A thing', note: 'with a note' }, { value: 1, label: 'Another thing', secondary: 'with secondary text this time' }, { value: -2, label: 'One more thing', note: 'with a note', secondary: 'and with secondary text', }, { value: 2, label: 'A disabled thing', disabled: true }, { separator: true }, { header: 'Icons' }, { value: 3, label: 'Profile', icon: }, { value: 4, label: 'Globe', icon: }, { header: 'Currencies' }, { value: 5, label: 'British pound', currency: 'gbp' }, { value: 6, label: 'Euro', currency: 'eur' }, { separator: true }, { value: 7, label: 'Something else' }, { header: 'Options with searchable alternatives' }, { value: 8, label: 'A thing with searchable alternatives', searchStrings: ['abbreviation', 'acronym', 'nickname'], }, ], selected: { value: 0, label: 'A thing', note: 'with a note' }, }, render: (args) => { const [searchValue, setSearchValue] = useState(''); const initialSelected = args.selected ?? { value: 0, label: 'A thing', note: 'with a note' }; const [selected, setSelected] = useState(initialSelected); return ( { if (isSelectOptionItem(option)) { setSelected(option); } }} /> ); }, }; export const CustomDropdownBalances: Story = { render: () => ( <> Bye ), };