@ceed/cds 1.34.0 → 1.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Accordions/Accordions.d.ts +1 -0
- package/dist/components/Alert/Alert.d.ts +5 -5
- package/dist/components/Autocomplete/Autocomplete.d.ts +2 -2
- package/dist/components/Avatar/Avatar.d.ts +7 -17
- package/dist/components/Box/Box.d.ts +1 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +6 -5
- package/dist/components/Button/Button.d.ts +3 -2
- package/dist/components/Calendar/Calendar.d.ts +1 -0
- package/dist/components/Card/Card.d.ts +1 -0
- package/dist/components/Checkbox/Checkbox.d.ts +1 -0
- package/dist/components/Chip/Chip.d.ts +1 -0
- package/dist/components/Container/Container.d.ts +6 -1
- package/dist/components/CurrencyInput/CurrencyInput.d.ts +1 -1
- package/dist/components/DialogActions/DialogActions.d.ts +1 -0
- package/dist/components/DialogContent/DialogContent.d.ts +1 -0
- package/dist/components/DialogFrame/DialogFrame.d.ts +1 -1
- package/dist/components/DialogTitle/DialogTitle.d.ts +1 -0
- package/dist/components/Divider/Divider.d.ts +1 -0
- package/dist/components/Drawer/Drawer.d.ts +1 -0
- package/dist/components/Dropdown/Dropdown.d.ts +28 -1
- package/dist/components/FormControl/FormControl.d.ts +1 -0
- package/dist/components/FormHelperText/FormHelperText.d.ts +1 -0
- package/dist/components/FormLabel/FormLabel.d.ts +1 -0
- package/dist/components/Grid/Grid.d.ts +1 -0
- package/dist/components/IconButton/IconButton.d.ts +3 -2
- package/dist/components/IconMenuButton/IconMenuButton.d.ts +7 -6
- package/dist/components/InfoSign/InfoSign.d.ts +3 -2
- package/dist/components/Input/Input.d.ts +8 -22
- package/dist/components/InsetDrawer/InsetDrawer.d.ts +1 -0
- package/dist/components/Markdown/Markdown.d.ts +9 -24
- package/dist/components/Menu/Menu.d.ts +2 -1
- package/dist/components/MenuButton/MenuButton.d.ts +10 -8
- package/dist/components/Modal/Modal.d.ts +4 -2
- package/dist/components/NavigationGroup/NavigationGroup.d.ts +3 -2
- package/dist/components/NavigationItem/NavigationItem.d.ts +3 -2
- package/dist/components/Navigator/Navigator.d.ts +5 -4
- package/dist/components/Pagination/Pagination.d.ts +1 -1
- package/dist/components/Radio/Radio.d.ts +1 -0
- package/dist/components/RadioList/RadioList.d.ts +3 -2
- package/dist/components/SearchBar/SearchBar.d.ts +6 -5
- package/dist/components/SearchBar/index.d.ts +3 -2
- package/dist/components/Select/Select.d.ts +12 -10
- package/dist/components/Sheet/Sheet.d.ts +1 -0
- package/dist/components/Stack/Stack.d.ts +1 -0
- package/dist/components/Stepper/Stepper.d.ts +2 -1
- package/dist/components/Switch/Switch.d.ts +1 -0
- package/dist/components/Table/Table.d.ts +7 -5
- package/dist/components/Tabs/Tabs.d.ts +1 -0
- package/dist/components/Textarea/Textarea.d.ts +8 -20
- package/dist/components/Tooltip/Tooltip.d.ts +1 -0
- package/dist/components/Typography/Typography.d.ts +1 -0
- package/dist/components/Uploader/Uploader.d.ts +18 -17
- package/dist/components/data-display/Avatar.md +60 -72
- package/dist/components/data-display/Badge.md +197 -181
- package/dist/components/data-display/Chip.md +164 -142
- package/dist/components/data-display/DataTable.md +843 -338
- package/dist/components/data-display/InfoSign.md +1 -3
- package/dist/components/data-display/Markdown.md +93 -125
- package/dist/components/data-display/Table.md +1453 -1007
- package/dist/components/data-display/Typography.md +113 -116
- package/dist/components/feedback/Alert.md +80 -86
- package/dist/components/feedback/CircularProgress.md +32 -36
- package/dist/components/feedback/Dialog.md +25 -17
- package/dist/components/feedback/Modal.md +296 -264
- package/dist/components/feedback/Skeleton.md +125 -89
- package/dist/components/index.d.ts +63 -4
- package/dist/components/inputs/Autocomplete.md +191 -95
- package/dist/components/inputs/Button.md +83 -83
- package/dist/components/inputs/ButtonGroup.md +195 -185
- package/dist/components/inputs/Calendar.md +25 -28
- package/dist/components/inputs/Checkbox.md +11 -29
- package/dist/components/inputs/CurrencyInput.md +4 -4
- package/dist/components/inputs/DatePicker.md +229 -110
- package/dist/components/inputs/DateRangePicker.md +248 -137
- package/dist/components/inputs/FilterableCheckboxGroup.md +115 -55
- package/dist/components/inputs/FormControl.md +75 -69
- package/dist/components/inputs/IconButton.md +229 -205
- package/dist/components/inputs/Input.md +131 -98
- package/dist/components/inputs/MonthPicker.md +186 -84
- package/dist/components/inputs/MonthRangePicker.md +73 -49
- package/dist/components/inputs/PercentageInput.md +15 -31
- package/dist/components/inputs/RadioButton.md +320 -256
- package/dist/components/inputs/RadioList.md +66 -50
- package/dist/components/inputs/RadioTileGroup.md +287 -170
- package/dist/components/inputs/SearchBar.md +154 -55
- package/dist/components/inputs/Select.md +106 -95
- package/dist/components/inputs/Slider.md +153 -102
- package/dist/components/inputs/Switch.md +193 -138
- package/dist/components/inputs/Textarea.md +15 -20
- package/dist/components/inputs/Uploader/Uploader.md +68 -39
- package/dist/components/layout/Box.md +841 -662
- package/dist/components/layout/Container.md +3 -11
- package/dist/components/layout/Grid.md +480 -394
- package/dist/components/layout/Stack.md +739 -566
- package/dist/components/navigation/Breadcrumbs.md +4 -4
- package/dist/components/navigation/Drawer.md +34 -25
- package/dist/components/navigation/Dropdown.md +745 -408
- package/dist/components/navigation/IconMenuButton.md +14 -6
- package/dist/components/navigation/InsetDrawer.md +8 -13
- package/dist/components/navigation/Link.md +1 -2
- package/dist/components/navigation/Menu.md +623 -502
- package/dist/components/navigation/MenuButton.md +18 -10
- package/dist/components/navigation/NavigationGroup.md +19 -50
- package/dist/components/navigation/NavigationItem.md +6 -6
- package/dist/components/navigation/Navigator.md +26 -28
- package/dist/components/navigation/Pagination.md +86 -75
- package/dist/components/navigation/Stepper.md +2 -12
- package/dist/components/navigation/Tabs.md +48 -36
- package/dist/components/surfaces/Accordions.md +89 -172
- package/dist/components/surfaces/Card.md +1094 -709
- package/dist/components/surfaces/Divider.md +562 -412
- package/dist/components/surfaces/Sheet.md +700 -518
- package/dist/guides/ThemeProvider.md +8 -8
- package/dist/index.browser.js +4 -4
- package/dist/index.browser.js.map +4 -4
- package/dist/index.cjs +1079 -1052
- package/dist/index.d.ts +2 -1
- package/dist/index.js +725 -690
- package/framer/index.js +1 -1
- package/package.json +32 -35
|
@@ -2,102 +2,201 @@
|
|
|
2
2
|
|
|
3
3
|
## Introduction
|
|
4
4
|
|
|
5
|
-
A search input component
|
|
6
|
-
|
|
7
|
-
> 💡 **Placeholder guidance**
|
|
8
|
-
>
|
|
9
|
-
> When `options` are provided, each option can include a `placeholder` field to hint at the expected input format for that category. This helps users understand what value to enter.
|
|
10
|
-
>
|
|
11
|
-
> - Account #: `e.g. 1234567`
|
|
12
|
-
> - Jira Issue #: `e.g. PROC-1234`
|
|
5
|
+
A search input component combining a text field and a search button. Optionally includes a category Select that lets users narrow results by keyword type. Hovering over the input while it has a value reveals a clear (✕) button to reset the field. Sizes to its content by default (`inline-flex`) and accepts all `Box` props for layout control.
|
|
13
6
|
|
|
14
7
|
```tsx
|
|
15
|
-
<SearchBar
|
|
8
|
+
<SearchBar value={value} onChange={setValue} />
|
|
16
9
|
```
|
|
17
10
|
|
|
18
|
-
| Field
|
|
19
|
-
|
|
|
20
|
-
|
|
|
21
|
-
| options
|
|
22
|
-
|
|
|
23
|
-
|
|
|
24
|
-
|
|
|
11
|
+
| Field | Description | Default |
|
|
12
|
+
| ----------- | ----------- | ------- |
|
|
13
|
+
| showSelect | — | — |
|
|
14
|
+
| options | — | — |
|
|
15
|
+
| placeholder | — | — |
|
|
16
|
+
| value | — | — |
|
|
17
|
+
| onChange | — | — |
|
|
18
|
+
| onSearch | — | — |
|
|
25
19
|
|
|
26
20
|
## Usage
|
|
27
21
|
|
|
28
22
|
```tsx
|
|
29
23
|
import { SearchBar } from '@ceed/cds';
|
|
30
24
|
|
|
25
|
+
// Basic
|
|
26
|
+
<SearchBar value={query} onChange={setQuery} onSearch={({ inputValue }) => fetch(inputValue)} />
|
|
27
|
+
|
|
28
|
+
// With category Select
|
|
31
29
|
<SearchBar
|
|
32
|
-
|
|
33
|
-
onChange={setQuery}
|
|
30
|
+
showSelect
|
|
34
31
|
options={[
|
|
35
32
|
{ label: 'Account #', value: 'account', placeholder: 'e.g. 1234567' },
|
|
36
33
|
{ label: 'Jira Issue #', value: 'jira', placeholder: 'e.g. PROC-1234' },
|
|
37
34
|
]}
|
|
38
|
-
|
|
35
|
+
value={query}
|
|
36
|
+
onChange={setQuery}
|
|
37
|
+
onSearch={({ selectValue, inputValue }) => fetch(selectValue, inputValue)}
|
|
39
38
|
/>
|
|
40
39
|
```
|
|
41
40
|
|
|
42
|
-
##
|
|
41
|
+
## With Select
|
|
43
42
|
|
|
44
|
-
Use `
|
|
43
|
+
Use `showSelect` together with `options` to display a category Select to the left of the text input. The selected category is passed as `selectValue` in the `onSearch` callback.
|
|
45
44
|
|
|
46
45
|
```tsx
|
|
47
|
-
<SearchBar
|
|
46
|
+
<SearchBar showSelect options={SAMPLE_OPTIONS} value={value} onChange={setValue} />
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Clearable Input
|
|
50
|
+
|
|
51
|
+
When the input has a value, hovering over the component reveals a clear (✕) button at the right of the text field. Clicking it calls `onChange('')` without triggering `onSearch`.
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
<Stack alignItems="flex-start" gap={2}>
|
|
55
|
+
<Typography level="body-sm">Hover over the input to reveal the clear (✕) button.</Typography>
|
|
56
|
+
<SearchBar value={value} onChange={setValue} />
|
|
57
|
+
</Stack>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Placeholder
|
|
61
|
+
|
|
62
|
+
Each `SearchBarOption` can include a `placeholder` field that is shown in the text input while that category is selected. Pass a `placeholder` prop directly to override the option-level placeholder for all categories.
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
<Stack alignItems="flex-start" gap={3}>
|
|
66
|
+
<Stack alignItems="flex-start" gap={1}>
|
|
67
|
+
<Typography level="body-xs" fontWeight="md">
|
|
68
|
+
No placeholder prop — uses the active option's placeholder
|
|
69
|
+
</Typography>
|
|
70
|
+
<SearchBar showSelect options={SAMPLE_OPTIONS} value={value} onChange={setValue} />
|
|
71
|
+
</Stack>
|
|
72
|
+
<Stack alignItems="flex-start" gap={1}>
|
|
73
|
+
<Typography level="body-xs" fontWeight="md">
|
|
74
|
+
placeholder="Search by keyword" — overrides option-level placeholder
|
|
75
|
+
</Typography>
|
|
76
|
+
<SearchBar
|
|
77
|
+
showSelect
|
|
78
|
+
options={SAMPLE_OPTIONS}
|
|
79
|
+
placeholder="Search by keyword"
|
|
80
|
+
value={value}
|
|
81
|
+
onChange={setValue}
|
|
82
|
+
/>
|
|
83
|
+
</Stack>
|
|
84
|
+
</Stack>
|
|
48
85
|
```
|
|
49
86
|
|
|
50
87
|
## onSearch
|
|
51
88
|
|
|
52
|
-
`onSearch` fires when the search button is clicked or the Enter key is pressed. It receives
|
|
89
|
+
`onSearch` fires when the search button is clicked or the Enter key is pressed. It receives `inputValue` (always present) and `selectValue` (only present when `showSelect` is `true`).
|
|
53
90
|
|
|
54
91
|
```tsx
|
|
55
|
-
<Stack gap={2}>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
92
|
+
<Stack alignItems="flex-start" gap={2}>
|
|
93
|
+
<SearchBar
|
|
94
|
+
showSelect
|
|
95
|
+
options={SAMPLE_OPTIONS}
|
|
96
|
+
value={value}
|
|
97
|
+
onChange={setValue}
|
|
98
|
+
onSearch={setLastSearch}
|
|
99
|
+
/>
|
|
100
|
+
<Typography level="body-sm">value: "{value}"</Typography>
|
|
101
|
+
{lastSearch && (
|
|
102
|
+
<Typography level="body-sm">
|
|
103
|
+
onSearch: [{lastSearch.selectValue}] "{lastSearch.inputValue}"
|
|
104
|
+
</Typography>
|
|
105
|
+
)}
|
|
106
|
+
</Stack>
|
|
62
107
|
```
|
|
63
108
|
|
|
64
|
-
|
|
109
|
+
When `showSelect` is `false`, `selectValue` is omitted from the payload entirely — not `undefined` as a key, but absent.
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
<Stack alignItems="flex-start" gap={2}>
|
|
113
|
+
<Typography level="body-sm">
|
|
114
|
+
When <code>showSelect</code> is <code>false</code>, <code>selectValue</code> is omitted from
|
|
115
|
+
the <code>onSearch</code> payload.
|
|
116
|
+
</Typography>
|
|
117
|
+
<SearchBar value={value} onChange={setValue} onSearch={setLastSearch} />
|
|
118
|
+
{lastSearch && (
|
|
119
|
+
<Stack alignItems="flex-start" gap={0.5}>
|
|
120
|
+
<Typography level="body-sm">inputValue: "{lastSearch.inputValue}"</Typography>
|
|
121
|
+
<Typography
|
|
122
|
+
level="body-sm"
|
|
123
|
+
sx={{
|
|
124
|
+
color: lastSearch.selectValue === undefined ? "success.500" : "danger.500"
|
|
125
|
+
}}
|
|
126
|
+
>
|
|
127
|
+
selectValue:{" "}
|
|
128
|
+
{lastSearch.selectValue === undefined ? "undefined ✅" : `"${lastSearch.selectValue}" ❌`}
|
|
129
|
+
</Typography>
|
|
130
|
+
</Stack>
|
|
131
|
+
)}
|
|
132
|
+
</Stack>
|
|
133
|
+
```
|
|
65
134
|
|
|
66
|
-
|
|
67
|
-
| ------------ | ---------------------------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
68
|
-
| `value` | `string` | — | Current text input value |
|
|
69
|
-
| `onChange` | `(value: string) => void` | — | Called when the text input value changes |
|
|
70
|
-
| `onSearch` | `(params: { selectValue?: string; inputValue: string }) => void` | — | Called on search button click or Enter key |
|
|
71
|
-
| `hideSelect` | `boolean` | `false` | Hide the category Select and show a narrower input-only layout |
|
|
72
|
-
| `options` | `SearchBarOption[]` | — | List of selectable categories rendered in the category Select. Each item may include a `placeholder` hint shown in the text input when that category is active. Required when `hideSelect` is `false`. |
|
|
135
|
+
## Width
|
|
73
136
|
|
|
74
|
-
|
|
137
|
+
SearchBar sizes to its content by default. Pass any `Box` width prop to constrain or stretch it.
|
|
75
138
|
|
|
76
|
-
|
|
139
|
+
```tsx
|
|
140
|
+
<Stack alignItems="flex-start" gap={3}>
|
|
141
|
+
<Stack alignItems="flex-start" gap={1}>
|
|
142
|
+
<Typography level="body-xs" fontWeight="md">
|
|
143
|
+
width="100%" — stretches to parent width
|
|
144
|
+
</Typography>
|
|
145
|
+
<Box
|
|
146
|
+
sx={{
|
|
147
|
+
border: "1px dashed",
|
|
148
|
+
borderColor: "neutral.300",
|
|
149
|
+
padding: 1
|
|
150
|
+
}}
|
|
151
|
+
>
|
|
152
|
+
<SearchBar width="100%" value={value} onChange={setValue} />
|
|
153
|
+
</Box>
|
|
154
|
+
</Stack>
|
|
155
|
+
<Stack alignItems="flex-start" gap={1}>
|
|
156
|
+
<Typography level="body-xs" fontWeight="md">
|
|
157
|
+
width={400} — fixed 400px
|
|
158
|
+
</Typography>
|
|
159
|
+
<SearchBar width={400} value={value} onChange={setValue} />
|
|
160
|
+
</Stack>
|
|
161
|
+
<Stack alignItems="flex-start" gap={1}>
|
|
162
|
+
<Typography level="body-xs" fontWeight="md">
|
|
163
|
+
No width prop — sizes to content (inline-flex default)
|
|
164
|
+
</Typography>
|
|
165
|
+
<SearchBar value={value} onChange={setValue} />
|
|
166
|
+
</Stack>
|
|
167
|
+
</Stack>
|
|
168
|
+
```
|
|
77
169
|
|
|
78
|
-
|
|
170
|
+
## Props and Customization
|
|
79
171
|
|
|
80
|
-
|
|
|
81
|
-
| ------------- |
|
|
82
|
-
| `
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
172
|
+
| Prop | Type | Default | Description |
|
|
173
|
+
| ------------- | ---------------------------------------------------------------- | ------- | ----------------------------------------------------------------------------------- |
|
|
174
|
+
| `value` | `string` | — | Current value of the text input. Required. |
|
|
175
|
+
| `onChange` | `(value: string) => void` | — | Called when the text input value changes. Required. |
|
|
176
|
+
| `onSearch` | `(params: { selectValue?: string; inputValue: string }) => void` | — | Called on search button click or Enter key. |
|
|
177
|
+
| `showSelect` | `boolean` | `false` | Show the category Select alongside the input. |
|
|
178
|
+
| `options` | `SearchBarOption[]` | — | Category options for the Select. Required when `showSelect` is `true`. |
|
|
179
|
+
| `placeholder` | `string` | — | Placeholder text for the input. Takes priority over the option-level `placeholder`. |
|
|
85
180
|
|
|
86
|
-
|
|
181
|
+
> **Note**: Also accepts all `Box` props (`width`, `sx`, `className`, `style`, etc.).
|
|
87
182
|
|
|
88
|
-
|
|
89
|
-
| ------------------------ | ------------------------------------- | ----------------------------------------------- |
|
|
90
|
-
| `--ceed-SearchBar-width` | `300px` / `220px` (when `hideSelect`) | Component width; override per instance via `sx` |
|
|
183
|
+
### SearchBarOption
|
|
91
184
|
|
|
92
|
-
|
|
185
|
+
| Field | Type | Required | Description |
|
|
186
|
+
| ------------- | -------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------- |
|
|
187
|
+
| `label` | `string` | ✓ | Display text shown in the Select dropdown. |
|
|
188
|
+
| `value` | `string` | ✓ | Identifier passed as `selectValue` in the `onSearch` callback. |
|
|
189
|
+
| `placeholder` | `string` | — | Hint text shown in the input while this category is selected (e.g. `"e.g. PROC-1234"`). Overridden by the top-level `placeholder` prop. |
|
|
93
190
|
|
|
94
191
|
## Best Practices
|
|
95
192
|
|
|
96
|
-
- Always provide
|
|
97
|
-
-
|
|
98
|
-
-
|
|
193
|
+
- Always provide `options` when `showSelect` is `true` — the Select renders nothing if `options` is omitted.
|
|
194
|
+
- Add a `placeholder` to each option to show the expected input format for that category.
|
|
195
|
+
- Use the top-level `placeholder` prop only when a single hint applies regardless of category.
|
|
196
|
+
- Prefer handling `onSearch` over `onChange` for server-side queries — fire the request once on explicit submission rather than on every keystroke.
|
|
99
197
|
|
|
100
198
|
## Accessibility
|
|
101
199
|
|
|
102
200
|
- The search button has `aria-label="Search"` and the clear button has `aria-label="Clear"`.
|
|
103
|
-
- The text input is a native `<input>` element
|
|
201
|
+
- The text input is a native `<input>` element; pressing Enter triggers `onSearch`.
|
|
202
|
+
- The clear button uses `onMouseDown` with `e.preventDefault()` to prevent the input from losing focus when clicked.
|
|
@@ -54,13 +54,7 @@ const options = [
|
|
|
54
54
|
];
|
|
55
55
|
|
|
56
56
|
function MyComponent() {
|
|
57
|
-
return
|
|
58
|
-
<Select
|
|
59
|
-
label="Choose a pet"
|
|
60
|
-
options={options}
|
|
61
|
-
defaultValue="dog"
|
|
62
|
-
/>
|
|
63
|
-
);
|
|
57
|
+
return <Select label="Choose a pet" options={options} defaultValue="dog" />;
|
|
64
58
|
}
|
|
65
59
|
```
|
|
66
60
|
|
|
@@ -70,11 +64,11 @@ Select supports four visual styles: `outlined` (default), `plain`, `soft`, and `
|
|
|
70
64
|
|
|
71
65
|
```tsx
|
|
72
66
|
<Stack spacing={4}>
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
</Stack>
|
|
67
|
+
<Select defaultValue="dog" options={options} />
|
|
68
|
+
<Select defaultValue="dog" variant="plain" options={options} />
|
|
69
|
+
<Select defaultValue="dog" variant="soft" options={options} />
|
|
70
|
+
<Select defaultValue="dog" variant="solid" options={options} />
|
|
71
|
+
</Stack>
|
|
78
72
|
```
|
|
79
73
|
|
|
80
74
|
```tsx
|
|
@@ -90,10 +84,10 @@ Three sizes are available: `sm`, `md` (default), and `lg`.
|
|
|
90
84
|
|
|
91
85
|
```tsx
|
|
92
86
|
<Stack spacing={4}>
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
</Stack>
|
|
87
|
+
<Select defaultValue="dog" size="sm" options={options} />
|
|
88
|
+
<Select defaultValue="dog" size="md" options={options} />
|
|
89
|
+
<Select defaultValue="dog" size="lg" options={options} />
|
|
90
|
+
</Stack>
|
|
97
91
|
```
|
|
98
92
|
|
|
99
93
|
```tsx
|
|
@@ -108,12 +102,12 @@ Apply semantic colors to communicate intent or state.
|
|
|
108
102
|
|
|
109
103
|
```tsx
|
|
110
104
|
<Stack spacing={4}>
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
</Stack>
|
|
105
|
+
<Select defaultValue="dog" color="primary" options={options} />
|
|
106
|
+
<Select defaultValue="dog" color="neutral" options={options} />
|
|
107
|
+
<Select defaultValue="dog" color="success" options={options} />
|
|
108
|
+
<Select defaultValue="dog" color="danger" options={options} />
|
|
109
|
+
<Select defaultValue="dog" color="warning" options={options} />
|
|
110
|
+
</Stack>
|
|
117
111
|
```
|
|
118
112
|
|
|
119
113
|
```tsx
|
|
@@ -129,11 +123,19 @@ Apply semantic colors to communicate intent or state.
|
|
|
129
123
|
Use `startDecorator` and `endDecorator` to add icons, badges, or other elements beside the select trigger.
|
|
130
124
|
|
|
131
125
|
```tsx
|
|
132
|
-
<Select
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
126
|
+
<Select
|
|
127
|
+
placeholder="Select a pet…"
|
|
128
|
+
startDecorator={<FavoriteBorder />}
|
|
129
|
+
endDecorator={
|
|
130
|
+
<Chip size="sm" color="danger" variant="soft">
|
|
131
|
+
+5
|
|
132
|
+
</Chip>
|
|
133
|
+
}
|
|
134
|
+
sx={{
|
|
135
|
+
width: 240
|
|
136
|
+
}}
|
|
137
|
+
options={options}
|
|
138
|
+
/>
|
|
137
139
|
```
|
|
138
140
|
|
|
139
141
|
```tsx
|
|
@@ -144,11 +146,13 @@ import { Chip } from '@ceed/cds';
|
|
|
144
146
|
placeholder="Select a pet..."
|
|
145
147
|
startDecorator={<FavoriteBorder />}
|
|
146
148
|
endDecorator={
|
|
147
|
-
<Chip size="sm" color="danger" variant="soft"
|
|
149
|
+
<Chip size="sm" color="danger" variant="soft">
|
|
150
|
+
+5
|
|
151
|
+
</Chip>
|
|
148
152
|
}
|
|
149
153
|
options={options}
|
|
150
154
|
sx={{ width: 240 }}
|
|
151
|
-
|
|
155
|
+
/>;
|
|
152
156
|
```
|
|
153
157
|
|
|
154
158
|
## Label and Helper Text
|
|
@@ -157,14 +161,14 @@ The `label` prop renders a form label above the select. The `helperText` prop re
|
|
|
157
161
|
|
|
158
162
|
```tsx
|
|
159
163
|
<>
|
|
160
|
-
|
|
161
|
-
</>
|
|
164
|
+
<Select label="Label" defaultValue="dog" options={options} />
|
|
165
|
+
</>
|
|
162
166
|
```
|
|
163
167
|
|
|
164
168
|
```tsx
|
|
165
169
|
<>
|
|
166
|
-
|
|
167
|
-
</>
|
|
170
|
+
<Select label="Select" helperText="I'm helper text" defaultValue="dog" options={options} />
|
|
171
|
+
</>
|
|
168
172
|
```
|
|
169
173
|
|
|
170
174
|
```tsx
|
|
@@ -184,17 +188,12 @@ Set `error` to `true` to visually indicate a validation error. Combine with `hel
|
|
|
184
188
|
|
|
185
189
|
```tsx
|
|
186
190
|
<>
|
|
187
|
-
|
|
188
|
-
</>
|
|
191
|
+
<Select label="label" error defaultValue="dog" options={options} />
|
|
192
|
+
</>
|
|
189
193
|
```
|
|
190
194
|
|
|
191
195
|
```tsx
|
|
192
|
-
<Select
|
|
193
|
-
label="Pet"
|
|
194
|
-
error
|
|
195
|
-
helperText="This field is required"
|
|
196
|
-
options={options}
|
|
197
|
-
/>
|
|
196
|
+
<Select label="Pet" error helperText="This field is required" options={options} />
|
|
198
197
|
```
|
|
199
198
|
|
|
200
199
|
## Form Control
|
|
@@ -203,9 +202,9 @@ Combining `label`, `helperText`, and `error` produces a complete form field. Her
|
|
|
203
202
|
|
|
204
203
|
```tsx
|
|
205
204
|
<>
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
</>
|
|
205
|
+
<Select label="Label" helperText="I'm helper text" defaultValue="dog" options={options} />
|
|
206
|
+
<Select label="Label" helperText="I'm helper text" defaultValue="dog" error options={options} />
|
|
207
|
+
</>
|
|
209
208
|
```
|
|
210
209
|
|
|
211
210
|
## Required Field
|
|
@@ -222,12 +221,7 @@ Set `required` to mark the field as required. An asterisk is added to the label
|
|
|
222
221
|
```
|
|
223
222
|
|
|
224
223
|
```tsx
|
|
225
|
-
<Select
|
|
226
|
-
label="Pet"
|
|
227
|
-
helperText="This field is required"
|
|
228
|
-
required
|
|
229
|
-
options={options}
|
|
230
|
-
/>
|
|
224
|
+
<Select label="Pet" helperText="This field is required" required options={options} />
|
|
231
225
|
```
|
|
232
226
|
|
|
233
227
|
## Multiple Selection
|
|
@@ -245,12 +239,7 @@ Set `multiple` to allow selecting more than one option. The value becomes an arr
|
|
|
245
239
|
```
|
|
246
240
|
|
|
247
241
|
```tsx
|
|
248
|
-
<Select
|
|
249
|
-
label="Pets"
|
|
250
|
-
multiple
|
|
251
|
-
defaultValue={['dog']}
|
|
252
|
-
options={options}
|
|
253
|
-
/>
|
|
242
|
+
<Select label="Pets" multiple defaultValue={['dog']} options={options} />
|
|
254
243
|
```
|
|
255
244
|
|
|
256
245
|
## Controlled Select
|
|
@@ -259,30 +248,41 @@ Use the `value` and `onChange` props for controlled behavior when you need to sy
|
|
|
259
248
|
|
|
260
249
|
```tsx
|
|
261
250
|
<div>
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
251
|
+
<Select
|
|
252
|
+
{...args}
|
|
253
|
+
options={options}
|
|
254
|
+
value={value}
|
|
255
|
+
onChange={(event, newValue) => {
|
|
256
|
+
setValue(newValue);
|
|
257
|
+
args.onChange?.(event, newValue);
|
|
258
|
+
}}
|
|
259
|
+
/>
|
|
260
|
+
<Select
|
|
261
|
+
{...args}
|
|
262
|
+
options={["dog", "cat", "fish", "bird"] as string[]}
|
|
263
|
+
value={value}
|
|
264
|
+
onChange={(event, newValue) => {
|
|
265
|
+
setValue(newValue);
|
|
266
|
+
args.onChange?.(event, newValue);
|
|
267
|
+
}}
|
|
268
|
+
/>
|
|
269
|
+
<Select
|
|
270
|
+
{...args}
|
|
271
|
+
options={["dog", "cat", "fish", "bird"] as string[]}
|
|
272
|
+
value={[value]}
|
|
273
|
+
onChange={(event, newValue) => {
|
|
274
|
+
setValue(newValue);
|
|
275
|
+
args.onChange?.(event, newValue);
|
|
276
|
+
}}
|
|
277
|
+
multiple
|
|
278
|
+
/>
|
|
279
|
+
</div>
|
|
275
280
|
```
|
|
276
281
|
|
|
277
282
|
```tsx
|
|
278
283
|
const [value, setValue] = useState('dog');
|
|
279
284
|
|
|
280
|
-
<Select
|
|
281
|
-
label="Pet"
|
|
282
|
-
value={value}
|
|
283
|
-
onChange={(event, newValue) => setValue(newValue)}
|
|
284
|
-
options={options}
|
|
285
|
-
/>
|
|
285
|
+
<Select label="Pet" value={value} onChange={(event, newValue) => setValue(newValue)} options={options} />;
|
|
286
286
|
```
|
|
287
287
|
|
|
288
288
|
## Disabled Options
|
|
@@ -308,7 +308,7 @@ const options = [
|
|
|
308
308
|
{ value: 'bird', label: 'Bird' },
|
|
309
309
|
];
|
|
310
310
|
|
|
311
|
-
<Select label="Pet" options={options} defaultValue="dog"
|
|
311
|
+
<Select label="Pet" options={options} defaultValue="dog" />;
|
|
312
312
|
```
|
|
313
313
|
|
|
314
314
|
## Options with Secondary Text
|
|
@@ -317,16 +317,27 @@ Add a `secondaryText` field to display supplementary information below each opti
|
|
|
317
317
|
|
|
318
318
|
```tsx
|
|
319
319
|
<Stack spacing={4} direction="row" alignItems="flex-start">
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
</
|
|
320
|
+
{sizes.map((size) => (
|
|
321
|
+
<Stack key={size} spacing={1}>
|
|
322
|
+
<span
|
|
323
|
+
style={{
|
|
324
|
+
color: "#6366f1",
|
|
325
|
+
fontSize: 12
|
|
326
|
+
}}
|
|
327
|
+
>
|
|
328
|
+
{size}
|
|
329
|
+
</span>
|
|
330
|
+
<Select
|
|
331
|
+
placeholder="Placeholder"
|
|
332
|
+
options={optionsWithSecondaryText}
|
|
333
|
+
sx={{
|
|
334
|
+
minWidth: 200
|
|
335
|
+
}}
|
|
336
|
+
size={size}
|
|
337
|
+
/>
|
|
338
|
+
</Stack>
|
|
339
|
+
))}
|
|
340
|
+
</Stack>
|
|
330
341
|
```
|
|
331
342
|
|
|
332
343
|
```tsx
|
|
@@ -336,7 +347,7 @@ const userOptions = [
|
|
|
336
347
|
{ value: 'sophia', label: 'Sophia Martinez', secondaryText: '(646) 555-0734' },
|
|
337
348
|
];
|
|
338
349
|
|
|
339
|
-
<Select placeholder="Select a contact" options={userOptions}
|
|
350
|
+
<Select placeholder="Select a contact" options={userOptions} />;
|
|
340
351
|
```
|
|
341
352
|
|
|
342
353
|
## Numeric Values
|
|
@@ -345,11 +356,11 @@ Select supports both string and numeric option values. When using numeric values
|
|
|
345
356
|
|
|
346
357
|
```tsx
|
|
347
358
|
<Stack spacing={4}>
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
</Stack>
|
|
359
|
+
<Select defaultValue={1} options={numericOptions} />
|
|
360
|
+
<Select defaultValue={1} variant="plain" options={numericOptions} />
|
|
361
|
+
<Select defaultValue={1} variant="soft" options={numericOptions} />
|
|
362
|
+
<Select defaultValue={1} variant="solid" options={numericOptions} />
|
|
363
|
+
</Stack>
|
|
353
364
|
```
|
|
354
365
|
|
|
355
366
|
```tsx
|
|
@@ -359,7 +370,7 @@ const numericOptions = [
|
|
|
359
370
|
{ value: 3, label: 'Option 3' },
|
|
360
371
|
];
|
|
361
372
|
|
|
362
|
-
<Select options={numericOptions} defaultValue={1}
|
|
373
|
+
<Select options={numericOptions} defaultValue={1} />;
|
|
363
374
|
```
|
|
364
375
|
|
|
365
376
|
## Common Use Cases
|
|
@@ -590,12 +601,12 @@ const options = [
|
|
|
590
601
|
{ value: 2, label: 'Option 2' },
|
|
591
602
|
] as const;
|
|
592
603
|
|
|
593
|
-
<Select<typeof options[number], false>
|
|
604
|
+
<Select<(typeof options)[number], false>
|
|
594
605
|
options={options}
|
|
595
606
|
onChange={(e, val) => {
|
|
596
607
|
// val is typed as number
|
|
597
608
|
}}
|
|
598
|
-
|
|
609
|
+
/>;
|
|
599
610
|
```
|
|
600
611
|
|
|
601
612
|
> **Note**: Select also accepts all Joy UI Select props.
|