select.stories.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { Select } from '../js/shared/components/select'
  2. const items = [1, 2, 3, 4].map(index => ({
  3. key: index,
  4. value: `Demo item ${index}`,
  5. group: index >= 3 ? 'Large numbers' : undefined,
  6. }))
  7. export const Base = () => {
  8. return (
  9. <Select
  10. items={items}
  11. itemToString={x => String(x?.value)}
  12. itemToKey={x => String(x.key)}
  13. defaultText="Choose an item"
  14. />
  15. )
  16. }
  17. export const WithSubtitles = () => {
  18. return (
  19. <Select
  20. items={items}
  21. itemToString={x => String(x?.value)}
  22. itemToKey={x => String(x.key)}
  23. itemToSubtitle={x => x?.group ?? ''}
  24. defaultText="Choose an item"
  25. />
  26. )
  27. }
  28. export const WithSelectedIcon = () => {
  29. return (
  30. <Select
  31. items={items}
  32. itemToString={x => String(x?.value)}
  33. itemToKey={x => String(x.key)}
  34. itemToSubtitle={x => x?.group ?? ''}
  35. defaultText="Choose an item"
  36. selectedIcon
  37. />
  38. )
  39. }
  40. export const WithDisabledItem = () => {
  41. return (
  42. <Select
  43. items={items}
  44. itemToString={x => String(x?.value)}
  45. itemToKey={x => String(x.key)}
  46. itemToDisabled={x => x?.key === 1}
  47. itemToSubtitle={x => x?.group ?? ''}
  48. defaultText="Choose an item"
  49. />
  50. )
  51. }
  52. export default {
  53. title: 'Shared / Components / Select',
  54. component: Select,
  55. }