Design system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

73 lines
1.3 KiB

  1. import * as React from 'react';
  2. import type { Meta } from '@storybook/react';
  3. import { TextControl } from '@tesseract-design/web-base';
  4. import { ComboBox as Component, ComboBoxProps as Props } from '.';
  5. const meta: Meta<typeof Component> = {
  6. component: Component,
  7. argTypes: {
  8. label: {
  9. control: { type: 'text' },
  10. },
  11. hint: {
  12. control: { type: 'text' },
  13. },
  14. variant: {
  15. control: {
  16. type: 'select',
  17. },
  18. options: TextControl.AVAILABLE_VARIANTS,
  19. },
  20. size: {
  21. control: {
  22. type: 'select',
  23. },
  24. options: TextControl.AVAILABLE_SIZES,
  25. },
  26. indicator: {
  27. control: { type: 'text' },
  28. },
  29. children: {
  30. control: { type: 'text' },
  31. },
  32. length: {
  33. control: { type: 'number' },
  34. },
  35. onChange: {
  36. table: {
  37. disable: true,
  38. },
  39. action: 'changed',
  40. },
  41. },
  42. args: {
  43. ...(Component.defaultProps ?? {}),
  44. label: Component.displayName,
  45. children: `Chocolate
  46. Vanilla
  47. Mango
  48. Strawberry
  49. `,
  50. },
  51. };
  52. export const ComboBox = ({ children = '', ...args }: Omit<Props, 'ref'>) => (
  53. <Component
  54. {...args}
  55. >
  56. {(children ? children.toString() : '').split('\n').filter(s => s.length > 0).map((s, i) => {
  57. const [label, value = label] = s.split(':').map(s => s.trim()) as string[];
  58. return (
  59. <option
  60. key={`${s}:${i}`}
  61. value={value}
  62. >
  63. {label}
  64. </option>
  65. );
  66. })}
  67. </Component>
  68. );
  69. export default meta;