select.stories.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. />
  14. )
  15. }
  16. export const WithSubtitles = () => {
  17. return (
  18. <Select
  19. items={items}
  20. itemToString={x => String(x?.value)}
  21. itemToKey={x => String(x.key)}
  22. itemToSubtitle={x => x?.group ?? ''}
  23. />
  24. )
  25. }
  26. export const WithSelectedIcon = () => {
  27. return (
  28. <Select
  29. items={items}
  30. itemToString={x => String(x?.value)}
  31. itemToKey={x => String(x.key)}
  32. itemToSubtitle={x => x?.group ?? ''}
  33. selectedIcon
  34. />
  35. )
  36. }
  37. export const WithDisabledItem = () => {
  38. return (
  39. <Select
  40. items={items}
  41. itemToString={x => String(x?.value)}
  42. itemToKey={x => String(x.key)}
  43. itemToDisabled={x => x?.key === 1}
  44. itemToSubtitle={x => x?.group ?? ''}
  45. />
  46. )
  47. }
  48. export default {
  49. title: 'Shared / Components / Select',
  50. component: Select,
  51. parameters: {
  52. controls: {
  53. include: ['disabled', 'defaultText'],
  54. },
  55. },
  56. args: {
  57. disabled: false,
  58. defaultText: 'Choose an item',
  59. },
  60. }