|
| 1 | +import { |
| 2 | + Meta, |
| 3 | + Story, |
| 4 | + Props, |
| 5 | + Status, |
| 6 | +} from '../../../../../.storybook/components'; |
| 7 | + |
| 8 | +import * as Stories from './Select.stories'; |
| 9 | + |
| 10 | +<Meta of={Stories} /> |
| 11 | + |
| 12 | +# Select |
| 13 | + |
| 14 | +<Status variant="experimental" /> |
| 15 | + |
| 16 | +A select displays a collapsible list of options and allows a user to select one of them. |
| 17 | + |
| 18 | +```tsx |
| 19 | +import { |
| 20 | + Select, |
| 21 | + ListItem, |
| 22 | + ListSection, |
| 23 | + ListItemText, |
| 24 | +} from '@koobiq/react-components'; |
| 25 | +``` |
| 26 | + |
| 27 | +<Story of={Stories.Base} /> |
| 28 | + |
| 29 | +## Props |
| 30 | + |
| 31 | +<Props /> |
| 32 | + |
| 33 | +## Content |
| 34 | + |
| 35 | +Select accepts static and dynamic collections.The examples above show static collections, |
| 36 | +which can be used when the full list of options is known ahead of time. |
| 37 | +Dynamic collections, as shown below, can be used when the options come from an external |
| 38 | +data source such as an API call, or update over time. |
| 39 | + |
| 40 | +As seen below, an iterable list of options is passed to the `Select` using the `items` prop. |
| 41 | +Each item accepts an `key` prop, which is passed to the `onSelectionChange` handler to identify |
| 42 | +the selected item. Alternatively, if the item objects contain an key property, as shown |
| 43 | +in the example below, then this is used automatically and an `key` prop is not required. |
| 44 | + |
| 45 | +<Story of={Stories.Content} /> |
| 46 | + |
| 47 | +## Selection |
| 48 | + |
| 49 | +Setting a selected option can be done by using the `defaultSelectedKey` or `selectedKey` prop. |
| 50 | +The selected key corresponds to the `key` prop of an item. |
| 51 | + |
| 52 | +<Story of={Stories.Selection} /> |
| 53 | + |
| 54 | +## Error |
| 55 | + |
| 56 | +The `error` prop toggles the error state. The `errorMessage` shows a message to explain the error to the user. |
| 57 | + |
| 58 | +<Story of={Stories.Error} /> |
| 59 | + |
| 60 | +## Disabled |
| 61 | + |
| 62 | +When the select component is disabled, it cannot be interacted with. |
| 63 | + |
| 64 | +<Story of={Stories.Disabled} /> |
| 65 | + |
| 66 | +## Disabled options |
| 67 | + |
| 68 | +Select supports marking items as disabled using the `disabledKeys` prop. |
| 69 | +Each key in this list corresponds with the `key` prop passed to the `ListItem` component. |
| 70 | + |
| 71 | +<Story of={Stories.DisabledOptions} /> |
| 72 | + |
| 73 | +## Required |
| 74 | + |
| 75 | +To make a select required, add the `required` prop. |
| 76 | +If the field has a label, a required indicator will appear next to it. |
| 77 | + |
| 78 | +<Story of={Stories.Required} /> |
| 79 | + |
| 80 | +## Full width |
| 81 | + |
| 82 | +The `fullWidth` prop will make a select fit to its parent width. |
| 83 | + |
| 84 | +<Story of={Stories.FullWidth} /> |
| 85 | + |
| 86 | +## Open |
| 87 | + |
| 88 | +### Default open |
| 89 | + |
| 90 | +Select isn't opened by default. The `defaultOpen` prop can be used to set the default state. |
| 91 | + |
| 92 | +### Controlled open |
| 93 | + |
| 94 | +The `open` prop can be used to make the opened state controlled. The `onOpenChange` event is fired when the select's open state changes. |
| 95 | + |
| 96 | +<Story of={Stories.Open} /> |
| 97 | + |
| 98 | +## Section |
| 99 | + |
| 100 | +A select component can display items grouped together in sections. |
| 101 | + |
| 102 | +<Story of={Stories.Section} /> |
| 103 | + |
| 104 | +## With icons |
| 105 | + |
| 106 | +See example below how to use [icons](?path=/docs/icons--docs) in items of component. |
| 107 | + |
| 108 | +<Story of={Stories.WithIcons} /> |
| 109 | + |
| 110 | +## With item details |
| 111 | + |
| 112 | +See example below for using details in items of component. |
| 113 | + |
| 114 | +<Story of={Stories.WithItemDetails} /> |
0 commit comments