|
| 1 | +import { BADGE } from '@geometricpanda/storybook-addon-badges'; |
| 2 | +import { Meta, StoryObj } from '@storybook/react'; |
| 3 | +import React from 'react'; |
| 4 | +import AutoComplete from './AutoComplete'; |
| 5 | + |
| 6 | +// Auto Docs |
| 7 | +const meta = { |
| 8 | + title: 'Components / AutoComplete', |
| 9 | + component: AutoComplete, |
| 10 | + |
| 11 | + // Display Properties |
| 12 | + parameters: { |
| 13 | + layout: 'centered', |
| 14 | + badges: [BADGE.STABLE, 'readyForDesignReview'], |
| 15 | + docs: { |
| 16 | + subtitle: 'This component allows to add autocompletion', |
| 17 | + }, |
| 18 | + }, |
| 19 | + |
| 20 | + // Component-level argTypes |
| 21 | + argTypes: { |
| 22 | + dataTestId: { |
| 23 | + description: 'Optional property to set data-testid', |
| 24 | + control: 'text', |
| 25 | + }, |
| 26 | + className: { |
| 27 | + description: 'Optional class names to pass into AutoComplete', |
| 28 | + control: 'text', |
| 29 | + }, |
| 30 | + value: { |
| 31 | + description: 'Value of input', |
| 32 | + }, |
| 33 | + defaultValue: { |
| 34 | + description: 'Selected option by default', |
| 35 | + }, |
| 36 | + options: { |
| 37 | + description: 'Options available in dropdown', |
| 38 | + table: { |
| 39 | + type: { |
| 40 | + summary: 'OptionType', |
| 41 | + detail: `{ |
| 42 | + label: React.ReactNode; |
| 43 | + value?: string | number | null; |
| 44 | + disabled?: boolean; |
| 45 | + [name: string]: any; |
| 46 | + children?: Omit<OptionType, 'children'>[]; |
| 47 | +} |
| 48 | + `, |
| 49 | + }, |
| 50 | + }, |
| 51 | + }, |
| 52 | + open: { |
| 53 | + description: 'Controlled open state of dropdown', |
| 54 | + }, |
| 55 | + defaultActiveFirstOption: { |
| 56 | + description: 'Whether active first option by default', |
| 57 | + }, |
| 58 | + filterOption: { |
| 59 | + description: 'If true, filter options by input, if function, filter options against it', |
| 60 | + }, |
| 61 | + dropdownContentHeight: { |
| 62 | + description: "Height of dropdown's content", |
| 63 | + }, |
| 64 | + onSelect: { |
| 65 | + description: 'Called when a option is selected', |
| 66 | + }, |
| 67 | + onSearch: { |
| 68 | + description: 'Called when searching items', |
| 69 | + }, |
| 70 | + onChange: { |
| 71 | + description: 'Called when selecting an option or changing an input value', |
| 72 | + }, |
| 73 | + onDropdownVisibleChange: { |
| 74 | + description: 'Called when dropdown opened/closed', |
| 75 | + }, |
| 76 | + onClear: { |
| 77 | + description: 'Called when clear', |
| 78 | + }, |
| 79 | + dropdownRender: { |
| 80 | + description: 'Customize dropdown content', |
| 81 | + }, |
| 82 | + dropdownAlign: { |
| 83 | + description: "Adjust how the autocomplete's dropdown should be aligned", |
| 84 | + }, |
| 85 | + style: { |
| 86 | + description: 'Additional styles for the wrapper of the children', |
| 87 | + }, |
| 88 | + dropdownStyle: { |
| 89 | + description: 'Additional styles for the dropdown', |
| 90 | + }, |
| 91 | + dropdownMatchSelectWidth: { |
| 92 | + description: |
| 93 | + 'Determine whether the dropdown menu and the select input are the same width.' + |
| 94 | + 'Default set min-width same as input. Will ignore when value less than select width.', |
| 95 | + }, |
| 96 | + }, |
| 97 | + |
| 98 | + // Define defaults |
| 99 | + args: { |
| 100 | + options: [ |
| 101 | + { label: 'test', value: 'test' }, |
| 102 | + { label: 'test2', value: 'test2' }, |
| 103 | + ], |
| 104 | + }, |
| 105 | +} satisfies Meta<typeof AutoComplete>; |
| 106 | + |
| 107 | +export default meta; |
| 108 | + |
| 109 | +// Stories |
| 110 | + |
| 111 | +type Story = StoryObj<typeof meta>; |
| 112 | + |
| 113 | +// Basic story is what is displayed 1st in storybook & is used as the code sandbox |
| 114 | +// Pass props to this so that it can be customized via the UI props panel |
| 115 | +export const sandbox: Story = { |
| 116 | + tags: ['dev'], |
| 117 | + render: (props) => ( |
| 118 | + <AutoComplete {...props}> |
| 119 | + <input /> |
| 120 | + </AutoComplete> |
| 121 | + ), |
| 122 | +}; |
0 commit comments