@maxio-com/react-ui-components 9.15.0 → 9.16.1
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/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/skills/maxio-react/SKILL.md +68 -0
- package/dist/skills/maxio-react/agents/openai.yaml +4 -0
- package/dist/skills/maxio-react/references/components-action-list.md +92 -0
- package/dist/skills/maxio-react/references/components-action-menu.md +162 -0
- package/dist/skills/maxio-react/references/components-avatar.md +66 -0
- package/dist/skills/maxio-react/references/components-breadcrumbs.md +86 -0
- package/dist/skills/maxio-react/references/components-buttons-button.md +170 -0
- package/dist/skills/maxio-react/references/components-buttons-iconbutton.md +102 -0
- package/dist/skills/maxio-react/references/components-card.md +175 -0
- package/dist/skills/maxio-react/references/components-chip.md +151 -0
- package/dist/skills/maxio-react/references/components-data-table.md +344 -0
- package/dist/skills/maxio-react/references/components-drawer.md +293 -0
- package/dist/skills/maxio-react/references/components-flex.md +185 -0
- package/dist/skills/maxio-react/references/components-forms-checkbox.md +257 -0
- package/dist/skills/maxio-react/references/components-forms-combobox.md +250 -0
- package/dist/skills/maxio-react/references/components-forms-radio-group.md +202 -0
- package/dist/skills/maxio-react/references/components-forms-select.md +295 -0
- package/dist/skills/maxio-react/references/components-forms-textfield.md +253 -0
- package/dist/skills/maxio-react/references/components-grid.md +140 -0
- package/dist/skills/maxio-react/references/components-icon.md +169 -0
- package/dist/skills/maxio-react/references/components-link.md +180 -0
- package/dist/skills/maxio-react/references/components-listbox.md +205 -0
- package/dist/skills/maxio-react/references/components-loading-spinner.md +123 -0
- package/dist/skills/maxio-react/references/components-logo.md +91 -0
- package/dist/skills/maxio-react/references/components-notifications-alert.md +103 -0
- package/dist/skills/maxio-react/references/components-notifications-banner.md +173 -0
- package/dist/skills/maxio-react/references/components-notifications-toast.md +155 -0
- package/dist/skills/maxio-react/references/components-pagination.md +115 -0
- package/dist/skills/maxio-react/references/components-popover.md +176 -0
- package/dist/skills/maxio-react/references/components-progressbar.md +98 -0
- package/dist/skills/maxio-react/references/components-segmentedcontrol.md +292 -0
- package/dist/skills/maxio-react/references/components-tabs.md +193 -0
- package/dist/skills/maxio-react/references/components-tag.md +117 -0
- package/dist/skills/maxio-react/references/components-tile.md +114 -0
- package/dist/skills/maxio-react/references/components-toggle.md +218 -0
- package/dist/skills/maxio-react/references/components-tooltip.md +178 -0
- package/dist/skills/maxio-react/references/components-typography-body.md +101 -0
- package/dist/skills/maxio-react/references/components-typography-code.md +72 -0
- package/dist/skills/maxio-react/references/components-typography-display.md +91 -0
- package/dist/skills/maxio-react/references/components-typography-heading.md +88 -0
- package/dist/skills/maxio-react/references/components-typography-label.md +82 -0
- package/dist/skills/maxio-react/references/deprecated-textinput.md +250 -0
- package/dist/skills/maxio-react/references/foundations-dark-mode.md +85 -0
- package/dist/skills/maxio-react/references/foundations-design-tokens-about.md +108 -0
- package/dist/skills/maxio-react/references/foundations-design-tokens-colors-primitive-colors.md +33 -0
- package/dist/skills/maxio-react/references/foundations-design-tokens-colors-semantic-colors.md +11 -0
- package/dist/skills/maxio-react/references/foundations-start-here.md +128 -0
- package/dist/skills/maxio-react/references/patterns-auth-layout.md +318 -0
- package/dist/skills/maxio-react/references/patterns-side-nav.md +182 -0
- package/dist/skills/maxio-react/references/patterns-top-bar.md +214 -0
- package/package.json +2 -2
- package/typings/index.d.ts +24 -4
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
# Checkbox
|
|
2
|
+
|
|
3
|
+
## Usage Guidelines
|
|
4
|
+
|
|
5
|
+
### Overview
|
|
6
|
+
|
|
7
|
+
Checkbox is a form control for single and multiple selections.
|
|
8
|
+
|
|
9
|
+
#### When to Use
|
|
10
|
+
|
|
11
|
+
- Use Checkbox for independent yes/no choices or optional form settings.
|
|
12
|
+
- Use CheckboxGroup when users can choose any number of related options from a set.
|
|
13
|
+
- Use an indeterminate checkbox for a parent option that summarizes a partially selected child list.
|
|
14
|
+
- Use helper text when the consequences of selecting options are not obvious from the labels alone.
|
|
15
|
+
|
|
16
|
+
#### When Not to Use
|
|
17
|
+
|
|
18
|
+
- Do not use Checkbox when users must choose exactly one option. Use RadioGroup instead.
|
|
19
|
+
- Do not use Checkbox as an immediate action trigger. Use Button, IconButton, or ActionMenu instead.
|
|
20
|
+
- Do not use Checkbox for on/off settings that apply immediately without form submission. Use Toggle instead.
|
|
21
|
+
- Do not use placeholder or helper text as the accessible label. Provide a visible label or another accessible name.
|
|
22
|
+
|
|
23
|
+
### Variants
|
|
24
|
+
|
|
25
|
+
| Variants | Purpose | Usage notes |
|
|
26
|
+
| :-------------- | :----------------------------------------- | :-------------------------------------------------------------------------- |
|
|
27
|
+
| `default` | Unselected option. | Use for available options that are not currently selected. |
|
|
28
|
+
| `checked` | Selected option. | Use `checked` for controlled state or `defaultChecked` for uncontrolled UI. |
|
|
29
|
+
| `indeterminate` | Mixed parent state. | Use only when the checkbox summarizes a partially selected collection. |
|
|
30
|
+
| `error` | Invalid option or invalid selection group. | Pair with visible validation text and `aria-invalid`. |
|
|
31
|
+
| `disabled` | Option or group cannot be changed. | Use when users cannot act on the option in the current context. |
|
|
32
|
+
| `skeleton` | Placeholder while checkbox content loads. | Use only as a noninteractive loading placeholder. |
|
|
33
|
+
|
|
34
|
+
### Behavior
|
|
35
|
+
|
|
36
|
+
- **Mouse and touch**: clicking or tapping the label or control toggles the selected state unless disabled.
|
|
37
|
+
- **Keyboard**: native checkboxes receive focus with Tab and toggle with Space.
|
|
38
|
+
- **Focus management**: focus lands on the native checkbox input. Keep the visible Maxio focus treatment intact.
|
|
39
|
+
- **Controlled state**: use `checked` and `onChange` for a single controlled checkbox. Use `value` and `onChange` on CheckboxGroup when product state owns the selected value array.
|
|
40
|
+
- **Validation**: show validation after users submit, blur the group, or otherwise finish interacting. Use group-level validation when the requirement applies to the collection.
|
|
41
|
+
|
|
42
|
+
### Accessibility
|
|
43
|
+
|
|
44
|
+
- Use a native `input type="checkbox"` for each option.
|
|
45
|
+
- Give every checkbox an accessible name with visible `label`, `aria-label`, or `aria-labelledby`.
|
|
46
|
+
- Wrap related checkboxes in CheckboxGroup with a group label when they are part of one question.
|
|
47
|
+
- Associate helper text and error text with the group or input through `aria-describedby`.
|
|
48
|
+
- Use `aria-invalid="true"` for invalid checkboxes or invalid group options.
|
|
49
|
+
- Use `aria-checked="mixed"` for indeterminate checkboxes when composing static HTML.
|
|
50
|
+
- Do not rely on color alone to communicate selected, mixed, disabled, or invalid state.
|
|
51
|
+
|
|
52
|
+
### Content
|
|
53
|
+
|
|
54
|
+
- Write checkbox labels as specific options, such as "Send invoice receipt" or "Customer portal".
|
|
55
|
+
- Keep group labels short and question-like enough to frame the option set.
|
|
56
|
+
- Use helper text to explain consequences, limits, or selection requirements before validation fails.
|
|
57
|
+
- Write error messages that name the recovery step, such as "Select at least one delivery method."
|
|
58
|
+
- Avoid labels that describe the control gesture, such as "Check this box".
|
|
59
|
+
|
|
60
|
+
### Related
|
|
61
|
+
|
|
62
|
+
- **[Radio](components-forms-radio-group.md)**: use when users must choose exactly one option from a set.
|
|
63
|
+
- **[Toggle](components-toggle.md)**: use for immediate on/off settings.
|
|
64
|
+
- **[TextField](components-forms-textfield.md)**: use when users need to enter a custom value.
|
|
65
|
+
|
|
66
|
+
## React
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
import { Checkbox, CheckboxGroup } from '@maxio-com/react-ui-components';
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## State Management
|
|
73
|
+
|
|
74
|
+
Use controlled state when product logic needs to validate, save, or share the current selection. Use uncontrolled state when the selected value can be read from a form submit or ref.
|
|
75
|
+
|
|
76
|
+
### Controlled Checkbox
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
const [selected, setSelected] = React.useState(false);
|
|
80
|
+
|
|
81
|
+
<Checkbox
|
|
82
|
+
label="Send invoice receipt"
|
|
83
|
+
value="receipt"
|
|
84
|
+
checked={selected}
|
|
85
|
+
onChange={setSelected}
|
|
86
|
+
/>;
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Uncontrolled Checkbox
|
|
90
|
+
|
|
91
|
+
```tsx
|
|
92
|
+
<Checkbox label="Auto-collect payments" value="auto-collect" defaultChecked />
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Controlled Group
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
const [deliveryMethods, setDeliveryMethods] = React.useState(['email']);
|
|
99
|
+
|
|
100
|
+
<CheckboxGroup
|
|
101
|
+
name="invoice-delivery-methods"
|
|
102
|
+
label="Invoice delivery methods"
|
|
103
|
+
value={deliveryMethods}
|
|
104
|
+
onChange={setDeliveryMethods}
|
|
105
|
+
>
|
|
106
|
+
<Checkbox value="email" label="Email" />
|
|
107
|
+
<Checkbox value="postal-mail" label="Postal mail" />
|
|
108
|
+
<Checkbox value="customer-portal" label="Customer portal" />
|
|
109
|
+
</CheckboxGroup>;
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Imports
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
import { Checkbox, CheckboxGroup } from "@maxio-com/react-ui-components";
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Prop Types
|
|
119
|
+
|
|
120
|
+
### Checkbox
|
|
121
|
+
|
|
122
|
+
| Prop | Type | Required | Default | Description | Source |
|
|
123
|
+
| --- | --- | --- | --- | --- | --- |
|
|
124
|
+
| `disabled` | `boolean` | no | - | - | CheckboxProps |
|
|
125
|
+
| `error` | `boolean` | no | `false` | - | CheckboxProps |
|
|
126
|
+
| `indeterminate` | `boolean` | no | - | - | CheckboxProps |
|
|
127
|
+
| `label` | `string` | no | - | - | CheckboxProps |
|
|
128
|
+
| `onChange` | `((selected: boolean) => void)` | no | - | - | CheckboxProps |
|
|
129
|
+
| `value` | `string` | no | - | - | CheckboxProps |
|
|
130
|
+
|
|
131
|
+
## Stories
|
|
132
|
+
|
|
133
|
+
### Default
|
|
134
|
+
|
|
135
|
+
Use Checkbox for an independent yes/no choice. Provide a visible label that describes the option being selected, and use value when the checkbox belongs to a submitted form or group.
|
|
136
|
+
|
|
137
|
+
```tsx
|
|
138
|
+
const Default = () => <Checkbox
|
|
139
|
+
label="Send invoice receipt"
|
|
140
|
+
onChange={action('onChange')}
|
|
141
|
+
value="receipt" />;
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Checked
|
|
145
|
+
|
|
146
|
+
Use a checked checkbox when the option is already selected. Use defaultChecked for uncontrolled forms, or checked with onChange when product state owns the selected value.
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
const Checked = () => <Checkbox
|
|
150
|
+
defaultChecked
|
|
151
|
+
label="Auto-collect payments"
|
|
152
|
+
onChange={() => {}}
|
|
153
|
+
value="auto-collect" />;
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Error
|
|
157
|
+
|
|
158
|
+
Use error state when a required acknowledgement or group selection fails validation. Pair the invalid control with visible error text in the surrounding form.
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
const Error = () => <Checkbox
|
|
162
|
+
label="I confirm these billing changes are approved"
|
|
163
|
+
error
|
|
164
|
+
value="approval-confirmed" />;
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Indeterminate
|
|
168
|
+
|
|
169
|
+
Use indeterminate for parent options that summarize a partially selected child list, such as selecting all visible subscriptions.
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
const Indeterminate = () => <Checkbox indeterminate label="Select all subscriptions" value="all-subscriptions" />;
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Disabled
|
|
176
|
+
|
|
177
|
+
Use disabled state for options that cannot be changed in the current context. Keep the label visible so users can understand what is unavailable.
|
|
178
|
+
|
|
179
|
+
```tsx
|
|
180
|
+
const Disabled = () => <Checkbox label="Apply expired coupon" disabled value="expired-coupon" />;
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Default Group
|
|
184
|
+
|
|
185
|
+
Use CheckboxGroup when multiple related options share one group label, helper text, validation message, and selected value array.
|
|
186
|
+
|
|
187
|
+
```tsx
|
|
188
|
+
const DefaultGroup = (
|
|
189
|
+
args // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
190
|
+
) => (
|
|
191
|
+
<CheckboxGroup name="invoice-notifications" label="Invoice notifications">
|
|
192
|
+
<Checkbox value="customer" label="Customer receipt" />
|
|
193
|
+
<Checkbox value="accounting" label="Accounting copy" />
|
|
194
|
+
<Checkbox value="collections" label="Collections alert" />
|
|
195
|
+
</CheckboxGroup>
|
|
196
|
+
);
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Disabled Group
|
|
200
|
+
|
|
201
|
+
Use a disabled group when the whole set of related choices is unavailable. The disabled state should apply consistently to every option in the group.
|
|
202
|
+
|
|
203
|
+
```tsx
|
|
204
|
+
const DisabledGroup = (
|
|
205
|
+
args // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
206
|
+
) => (
|
|
207
|
+
<CheckboxGroup
|
|
208
|
+
name="disabled-checkbox-group"
|
|
209
|
+
label="Legacy notification settings"
|
|
210
|
+
disabled
|
|
211
|
+
>
|
|
212
|
+
<Checkbox value="email" label="Email" />
|
|
213
|
+
<Checkbox value="sms" label="SMS" />
|
|
214
|
+
<Checkbox value="webhook" label="Webhook" />
|
|
215
|
+
</CheckboxGroup>
|
|
216
|
+
);
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Helper Text Group
|
|
220
|
+
|
|
221
|
+
Use helper text to explain how the selected options affect a workflow before users make a choice.
|
|
222
|
+
|
|
223
|
+
```tsx
|
|
224
|
+
const HelperTextGroup = (
|
|
225
|
+
args // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
226
|
+
) => (
|
|
227
|
+
<CheckboxGroup
|
|
228
|
+
name="helper-checkbox-group"
|
|
229
|
+
label="Renewal reminders"
|
|
230
|
+
helperText="Choose every reminder channel your team wants to receive."
|
|
231
|
+
>
|
|
232
|
+
<Checkbox value="30-days" label="30 days before renewal" />
|
|
233
|
+
<Checkbox value="7-days" label="7 days before renewal" />
|
|
234
|
+
<Checkbox value="day-of" label="On the renewal date" />
|
|
235
|
+
</CheckboxGroup>
|
|
236
|
+
);
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Error Group
|
|
240
|
+
|
|
241
|
+
Use group-level error messaging when validation depends on the set of selected options. Reference the error from the group so assistive technology announces the problem once for the collection.
|
|
242
|
+
|
|
243
|
+
```tsx
|
|
244
|
+
const ErrorGroup = (
|
|
245
|
+
args // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
246
|
+
) => (
|
|
247
|
+
<CheckboxGroup
|
|
248
|
+
name="error-checkbox-group"
|
|
249
|
+
label="Invoice delivery methods"
|
|
250
|
+
errorMessage="Select at least one delivery method."
|
|
251
|
+
>
|
|
252
|
+
<Checkbox value="email" label="Email" />
|
|
253
|
+
<Checkbox value="postal-mail" label="Postal mail" />
|
|
254
|
+
<Checkbox value="customer-portal" label="Customer portal" />
|
|
255
|
+
</CheckboxGroup>
|
|
256
|
+
);
|
|
257
|
+
```
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# ComboBox
|
|
2
|
+
|
|
3
|
+
## Usage Guidelines
|
|
4
|
+
|
|
5
|
+
### Overview
|
|
6
|
+
|
|
7
|
+
#### When to Use
|
|
8
|
+
|
|
9
|
+
- Use when users choose from a known set of values and typing helps them find the right option.
|
|
10
|
+
- Use when the option list is long, customer-generated, or easier to search than scan.
|
|
11
|
+
- Use when options can be grouped into sections or rendered from dynamic product data.
|
|
12
|
+
- Use with `allowsCustomValue` only when values outside the provided options are valid.
|
|
13
|
+
|
|
14
|
+
#### When Not to Use
|
|
15
|
+
|
|
16
|
+
- Do not use for short, predictable lists. Use Select or RadioGroup instead.
|
|
17
|
+
- Do not use for command menus or action lists. Use ActionMenu or ActionList instead.
|
|
18
|
+
- Do not use when users need to browse a static list without text filtering. Use ListBox instead.
|
|
19
|
+
- Do not rely on placeholder text as the only label.
|
|
20
|
+
|
|
21
|
+
### Variants
|
|
22
|
+
|
|
23
|
+
| Variants | Purpose | Usage notes |
|
|
24
|
+
| :------------------ | :-------------------------------------------- | :------------------------------------------------------------------------------ |
|
|
25
|
+
| `sm` | Compact field for dense interfaces. | Use where form density is high and labels remain readable. |
|
|
26
|
+
| `md` | Default field size. | Use for most forms. |
|
|
27
|
+
| `lg` | Larger field for prominent form rows. | Use sparingly when the field needs more visual emphasis. |
|
|
28
|
+
| `xl` | Field with integrated label and helper/error. | Use when the field needs a stronger contained treatment. |
|
|
29
|
+
| `selectionMode` | Single or multiple value selection. | Use multiple selection only when users can choose several values for one field. |
|
|
30
|
+
| `allowsCustomValue` | Free-form text entry. | Use only when typed values outside the list can be saved. |
|
|
31
|
+
|
|
32
|
+
### Behavior
|
|
33
|
+
|
|
34
|
+
- **Mouse and touch**: Users type in the input, open the listbox with the trigger, and select an option from the popup.
|
|
35
|
+
- **Keyboard**: Users tab to the input, type to filter, use arrow keys to move through options, press `Enter` to select, and press `Escape` to close the listbox.
|
|
36
|
+
- **Focus management**: Focus remains on the input while users filter and move through the listbox.
|
|
37
|
+
- **Controlled state**: Use `value` and `onChange` when product state owns the selected value. Use `defaultValue` for uncontrolled form fields.
|
|
38
|
+
- **Filtering**: Keep visible options aligned with the current query. Use dynamic item rendering when options come from product data.
|
|
39
|
+
|
|
40
|
+
### Accessibility
|
|
41
|
+
|
|
42
|
+
- Provide a visible `label` whenever possible. Use `aria-label` or `aria-labelledby` only when a visible label is not available.
|
|
43
|
+
- Use `description` for helper text and `errorMessage` for validation feedback.
|
|
44
|
+
- Pair invalid values with `isInvalid` and an actionable `errorMessage`.
|
|
45
|
+
- Keep focus indicators visible on the input and options.
|
|
46
|
+
- Keep disabled options in the list only when seeing the unavailable value helps users understand the choice set.
|
|
47
|
+
- Do not rely on color alone to communicate validation, disabled, read-only, or selected state.
|
|
48
|
+
|
|
49
|
+
### Content
|
|
50
|
+
|
|
51
|
+
- Write labels as short nouns, such as "Account", "Customer", or "Plan".
|
|
52
|
+
- Use placeholder text for examples, not instructions that replace the label.
|
|
53
|
+
- Keep option names concise and unique enough to scan after filtering.
|
|
54
|
+
- Group options with clear section headers when the list mixes statuses or categories.
|
|
55
|
+
- Write error messages that name the problem and recovery step, such as "Account is required."
|
|
56
|
+
|
|
57
|
+
### Related
|
|
58
|
+
|
|
59
|
+
- **[Select](components-forms-select.md)**: use when users choose from a shorter closed list.
|
|
60
|
+
- **[ListBox](components-listbox.md)**: use when the option list should remain visible on the page.
|
|
61
|
+
- **[RadioGroup](components-forms-radio-group.md)**: use when all choices should be visible and only one option can be selected.
|
|
62
|
+
- **[ActionMenu](components-action-menu.md)**: use when the choices are actions instead of form values.
|
|
63
|
+
|
|
64
|
+
## React
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
import { ComboBox } from '@maxio-com/react-ui-components';
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## State Management
|
|
71
|
+
|
|
72
|
+
Use controlled state when product logic needs to validate, transform, save, or share the selected value. Use `onInputChange` when product logic also needs the typed query.
|
|
73
|
+
|
|
74
|
+
### Controlled
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
const [account, setAccount] = React.useState('acme');
|
|
78
|
+
|
|
79
|
+
<ComboBox label="Account" value={account} onChange={setAccount}>
|
|
80
|
+
<ComboBox.Item id="acme">Acme Co.</ComboBox.Item>
|
|
81
|
+
<ComboBox.Item id="globex">Globex</ComboBox.Item>
|
|
82
|
+
</ComboBox>;
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Uncontrolled
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
<ComboBox label="Account" defaultValue="acme">
|
|
89
|
+
<ComboBox.Item id="acme">Acme Co.</ComboBox.Item>
|
|
90
|
+
<ComboBox.Item id="globex">Globex</ComboBox.Item>
|
|
91
|
+
</ComboBox>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Imports
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
import { ComboBox, Grid, Icon } from "@maxio-com/react-ui-components";
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Stories
|
|
101
|
+
|
|
102
|
+
### Default
|
|
103
|
+
|
|
104
|
+
Use ComboBox when users choose from a known set of values and typing helps them find the right option. Provide a visible label and use placeholder text only as an example of the expected value.
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
const Default = () => <ComboBox
|
|
108
|
+
label="Account"
|
|
109
|
+
placeholder="Select account"
|
|
110
|
+
onChange={action('onChange')}
|
|
111
|
+
menuTrigger="focus">
|
|
112
|
+
<ComboBox.Item id="acme">Acme Co.</ComboBox.Item>
|
|
113
|
+
<ComboBox.Item id="globex">Globex</ComboBox.Item>
|
|
114
|
+
<ComboBox.Item id="initech">Initech</ComboBox.Item>
|
|
115
|
+
</ComboBox>;
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Dynamic Items
|
|
119
|
+
|
|
120
|
+
Use dynamic items when options are loaded from typed product data. Keep each item id stable so selection state remains consistent after filtering or data refreshes.
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
const DynamicItems = (args) => (
|
|
124
|
+
<ComboBox<Account> {...(args as ComboBoxProps<Account>)}>
|
|
125
|
+
{(item) => <ComboBox.Item id={item.id}>{item.name}</ComboBox.Item>}
|
|
126
|
+
</ComboBox>
|
|
127
|
+
);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### With Sections
|
|
131
|
+
|
|
132
|
+
Use sections when the option set mixes statuses, categories, or other groups that help users scan the list after filtering.
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
const WithSections = () => <ComboBox label="Account" placeholder="Select account">
|
|
136
|
+
<ComboBox.Section>
|
|
137
|
+
<ComboBox.Header>Active</ComboBox.Header>
|
|
138
|
+
<ComboBox.Item id="acme">Acme Co.</ComboBox.Item>
|
|
139
|
+
<ComboBox.Item id="globex">Globex</ComboBox.Item>
|
|
140
|
+
</ComboBox.Section>
|
|
141
|
+
<ComboBox.Section>
|
|
142
|
+
<ComboBox.Header>Archived</ComboBox.Header>
|
|
143
|
+
<ComboBox.Item id="initech">Initech</ComboBox.Item>
|
|
144
|
+
</ComboBox.Section>
|
|
145
|
+
</ComboBox>;
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### With Disabled Option
|
|
149
|
+
|
|
150
|
+
Use disabled options when seeing an unavailable value helps users understand the full choice set. Omit unavailable options when they add noise.
|
|
151
|
+
|
|
152
|
+
```tsx
|
|
153
|
+
const WithDisabledOption = () => <ComboBox label="Account" placeholder="Select account">
|
|
154
|
+
<ComboBox.Item id="acme">Acme Co.</ComboBox.Item>
|
|
155
|
+
<ComboBox.Item id="globex" isDisabled>Globex
|
|
156
|
+
</ComboBox.Item>
|
|
157
|
+
<ComboBox.Item id="initech">Initech</ComboBox.Item>
|
|
158
|
+
</ComboBox>;
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Custom Value
|
|
162
|
+
|
|
163
|
+
Use custom values only when typed values outside the provided options are accepted by the product flow. Validate custom text before saving it.
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
const CustomValue = () => <ComboBox
|
|
167
|
+
label="Account"
|
|
168
|
+
placeholder="Type an account"
|
|
169
|
+
allowsCustomValue
|
|
170
|
+
onInputChange={action('onInputChange')}>
|
|
171
|
+
<ComboBox.Item id="acme">Acme Co.</ComboBox.Item>
|
|
172
|
+
<ComboBox.Item id="globex">Globex</ComboBox.Item>
|
|
173
|
+
<ComboBox.Item id="initech">Initech</ComboBox.Item>
|
|
174
|
+
</ComboBox>;
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Multiple Selection
|
|
178
|
+
|
|
179
|
+
Use multiple selection when users can assign more than one value to the same field. Provide surrounding UI that makes selected values easy to review.
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
const MultipleSelection = () => <ComboBox
|
|
183
|
+
label="Accounts"
|
|
184
|
+
placeholder="Add accounts"
|
|
185
|
+
selectionMode="multiple"
|
|
186
|
+
defaultValue={['acme']}>
|
|
187
|
+
<ComboBox.Item id="acme">Acme Co.</ComboBox.Item>
|
|
188
|
+
<ComboBox.Item id="globex">Globex</ComboBox.Item>
|
|
189
|
+
<ComboBox.Item id="initech">Initech</ComboBox.Item>
|
|
190
|
+
</ComboBox>;
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### With Icon
|
|
194
|
+
|
|
195
|
+
Use a leading icon when the field benefits from compact visual context, such as search. Keep decorative icons hidden from the accessible name.
|
|
196
|
+
|
|
197
|
+
```tsx
|
|
198
|
+
const WithIcon = () => <ComboBox
|
|
199
|
+
label="Account"
|
|
200
|
+
placeholder="Search accounts"
|
|
201
|
+
leadingElement={<Icon variant="search" />}>
|
|
202
|
+
<ComboBox.Item id="acme">Acme Co.</ComboBox.Item>
|
|
203
|
+
<ComboBox.Item id="globex">Globex</ComboBox.Item>
|
|
204
|
+
<ComboBox.Item id="initech">Initech</ComboBox.Item>
|
|
205
|
+
</ComboBox>;
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Validation
|
|
209
|
+
|
|
210
|
+
Use errorMessage with isInvalid so assistive technology receives invalid state and users get actionable validation feedback.
|
|
211
|
+
|
|
212
|
+
```tsx
|
|
213
|
+
const Validation = () => <ComboBox
|
|
214
|
+
label="Account"
|
|
215
|
+
placeholder="Select account"
|
|
216
|
+
isInvalid
|
|
217
|
+
errorMessage="Account is required.">
|
|
218
|
+
<ComboBox.Item id="acme">Acme Co.</ComboBox.Item>
|
|
219
|
+
<ComboBox.Item id="globex">Globex</ComboBox.Item>
|
|
220
|
+
<ComboBox.Item id="initech">Initech</ComboBox.Item>
|
|
221
|
+
</ComboBox>;
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Sizes
|
|
225
|
+
|
|
226
|
+
Use size to match the density and prominence of the surrounding form. Use md for most forms, sm in dense interfaces, and lg or xl only when the form row needs more emphasis.
|
|
227
|
+
|
|
228
|
+
```tsx
|
|
229
|
+
const Sizes = (args) => (
|
|
230
|
+
<Grid gap={4}>
|
|
231
|
+
{(['sm', 'md', 'lg', 'xl'] as const).map((size) => (
|
|
232
|
+
<ComboBox key={size} size={size} {...args}>
|
|
233
|
+
<ComboBox.Item id="acme">Acme Co.</ComboBox.Item>
|
|
234
|
+
<ComboBox.Item id="globex">Globex</ComboBox.Item>
|
|
235
|
+
</ComboBox>
|
|
236
|
+
))}
|
|
237
|
+
</Grid>
|
|
238
|
+
);
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Disabled
|
|
242
|
+
|
|
243
|
+
Use disabled ComboBoxes when the value is unavailable and users cannot act on it in the current context.
|
|
244
|
+
|
|
245
|
+
```tsx
|
|
246
|
+
const Disabled = () => <ComboBox label="Account" placeholder="Select account" isDisabled>
|
|
247
|
+
<ComboBox.Item id="acme">Acme Co.</ComboBox.Item>
|
|
248
|
+
<ComboBox.Item id="globex">Globex</ComboBox.Item>
|
|
249
|
+
</ComboBox>;
|
|
250
|
+
```
|