select.stories.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { Select } from '@/shared/components/select'
  2. import { Meta } from '@storybook/react-webpack5'
  3. type Args = Pick<
  4. React.ComponentProps<typeof Select>,
  5. 'disabled' | 'defaultText' | 'isCiam'
  6. >
  7. const items = [1, 2, 3, 4].map(index => ({
  8. key: index,
  9. value: `Demo item ${index}`,
  10. group: index >= 3 ? 'Large numbers' : undefined,
  11. }))
  12. export const Base = (args: Args) => {
  13. return (
  14. <Select
  15. {...args}
  16. items={items}
  17. itemToString={x => String(x?.value)}
  18. itemToKey={x => String(x.key)}
  19. />
  20. )
  21. }
  22. export const WithSubtitles = (args: Args) => {
  23. return (
  24. <Select
  25. {...args}
  26. items={items}
  27. itemToString={x => String(x?.value)}
  28. itemToKey={x => String(x.key)}
  29. itemToSubtitle={x => x?.group ?? ''}
  30. />
  31. )
  32. }
  33. export const WithSelectedIcon = (args: Args) => {
  34. return (
  35. <Select
  36. {...args}
  37. items={items}
  38. itemToString={x => String(x?.value)}
  39. itemToKey={x => String(x.key)}
  40. itemToSubtitle={x => x?.group ?? ''}
  41. selectedIcon
  42. />
  43. )
  44. }
  45. export const WithDisabledItem = (args: Args) => {
  46. return (
  47. <Select
  48. {...args}
  49. items={items}
  50. itemToString={x => String(x?.value)}
  51. itemToKey={x => String(x.key)}
  52. itemToDisabled={x => x?.key === 1}
  53. itemToSubtitle={x => x?.group ?? ''}
  54. />
  55. )
  56. }
  57. const meta: Meta<typeof Select> = {
  58. title: 'Shared / Components / Select',
  59. component: Select,
  60. parameters: {
  61. controls: {
  62. include: ['disabled', 'defaultText', 'isCiam'],
  63. },
  64. },
  65. args: {
  66. disabled: false,
  67. isCiam: false,
  68. defaultText: 'Choose an item',
  69. },
  70. }
  71. export default meta