-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathMultiSelector.doc.mjs
More file actions
478 lines (474 loc) · 18.3 KB
/
Copy pathMultiSelector.doc.mjs
File metadata and controls
478 lines (474 loc) · 18.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
// Copyright (c) Meta Platforms, Inc. and affiliates.
/** @type {import('@astryxdesign/cli/authoring').ComponentDoc} */
export const docs = {
name: 'MultiSelector',
displayName: 'Multi Selector',
group: 'Selector',
category: 'Data Input',
keywords: [
'multiselect',
'checkbox',
'dropdown',
'multi',
'picker',
'checklist',
'facet',
'filter',
'select',
],
theming: {
targets: [
{
className: 'astryx-multi-selector',
visualProps: ['variant', 'size', 'status'],
states: ['disabled'],
},
{
className: 'astryx-multi-selector-clear-icon',
deprecatedFor: 'input-clear-icon',
},
{className: 'astryx-multi-selector-empty-state'},
{className: 'astryx-multi-selector-search'},
{className: 'astryx-multi-selector-section-heading'},
{
className: 'astryx-multi-selector-indicator-icon',
states: ['state'],
},
{
className: 'astryx-multi-selector-option',
visualProps: ['size'],
states: ['select-all', 'selected', 'disabled'],
},
{className: 'astryx-multi-selector-popup'},
],
},
components: [
{
name: 'MultiSelector',
displayName: 'Multi Selector',
description:
'Multi-select dropdown with checkboxes for choosing multiple items.',
props: [
{
name: 'label',
type: 'string',
description: 'Label text for accessibility.',
required: true,
},
{
name: 'options',
type: 'MultiSelectorOptionType[]',
description:
'Array of items: strings, objects with value/label/icon/disabled, dividers, or sections.',
required: true,
},
{
name: 'value',
type: 'string[]',
description: 'Currently selected values.',
required: true,
},
{
name: 'onChange',
type: '(value: string[]) => void',
description: 'Callback fired when the selection changes.',
required: true,
},
{
name: 'changeAction',
type: '(value: string[]) => void | Promise<void>',
description: 'Async action on change. Fires after onChange.',
},
{
name: 'placeholder',
type: 'string',
description: 'Placeholder text shown when no value is selected.',
default: "'Select...'",
},
{
name: 'size',
type: "'sm' | 'md' | 'lg'",
description: 'Size variant for the selector.',
default: "'md'",
},
{
name: 'variant',
type: "'input' | 'ghost'",
description:
'Visual trigger style. input is the bordered input treatment for forms; ghost is borderless and matches ghost buttons for toolbar usage.',
default: "'input'",
},
{
name: 'triggerDisplay',
type: "'count' | 'labels' | 'badges'",
description: 'How to display selected items in the trigger.',
default: "'count'",
},
{
name: 'maxBadges',
type: 'number',
description:
'Maximum badges to show before "+N". Only for triggerDisplay="badges".',
default: '3',
},
{
name: 'hasSelectAll',
type: 'boolean',
description: 'Whether to show a select-all checkbox.',
},
{
name: 'selectAllLabel',
type: 'string',
description: 'Label for the select-all checkbox.',
default: "'Select all'",
},
{
name: 'hasSearch',
type: 'boolean',
description:
'Whether to show a search input for filtering options. As the user types, the match count (or "No results found") is announced to screen readers via a polite live region. The search field has built-in affordances: a leading magnifier icon and, once a query is typed, a trailing clear (✕) button that resets the query and returns focus to the input.',
},
{
name: 'hasChevron',
type: 'boolean',
description:
'Shows the chevron at the end of the trigger. Set false to let the clear button stand alone in that slot — with hasClear, a selector that has values otherwise shows both a × and a chevron. Only the chevron is dropped: a status glyph shares the slot and still appears, and since the chevron is decorative (aria-hidden) and sits outside the trigger button, the accessible name, focus order, and keyboard behaviour are unchanged.',
default: 'true',
},
{
name: 'searchPlaceholder',
type: 'string',
description: 'Placeholder text for the search input.',
default: "'Search...'",
},
{
name: 'isDisabled',
type: 'boolean',
description: 'Disables the selector.',
},
{
name: 'htmlName',
type: 'string',
description:
'The HTML name attribute for form submissions. Renders one hidden input per selected value, like a native multi-select.',
},
{
name: 'disabledMessage',
type: 'string',
description:
'Explains why the selector is disabled. With isDisabled, shows a tooltip on hover/keyboard focus and keeps the trigger focusable via aria-disabled (activation stays blocked). Use this instead of wrapping a disabled MultiSelector in Tooltip. Disabled controls swallow the hover events an external Tooltip needs.',
},
{
name: 'isLabelHidden',
type: 'boolean',
description: 'Visually hides the label while keeping it accessible.',
},
{
name: 'description',
type: 'string',
description: 'Helper text displayed below the label.',
},
{
name: 'isOptional',
type: 'boolean',
description: 'Marks the field as optional.',
},
{
name: 'isRequired',
type: 'boolean',
description: 'Marks the field as required.',
},
{
name: 'isLoading',
type: 'boolean',
description: 'Shows a loading spinner in the trigger.',
},
{
name: 'status',
type: "{type: 'error' | 'warning' | 'success', message?: string}",
description: 'Validation status with an optional message.',
},
{
name: 'statusVariant',
type: "'attached' | 'detached' | 'tooltip'",
description:
'How the status message is placed relative to the input. attached overlaps directly below the bordered input and is only valid for the input variant; ghost selectors detach attached status messages by default. Use tooltip for compact toolbar controls.',
default:
"'attached' for input selectors; 'detached' for ghost selectors",
},
{
name: 'renderOption',
type: '(option: MultiSelectorOptionData) => ReactNode',
description:
'Custom render function for each selectable option in the dropdown. Not called for dividers, sections, or the select-all row.',
},
{
name: 'indicatorPosition',
type: "'start' | 'end'",
description:
'Which edge of the option row carries the checkbox. end pushes it to the far edge of the row, including on the select-all row.',
default: "'start'",
},
{
name: 'width',
type: 'SizeValue',
description:
'Width of the field (number = pixels, string used as-is, e.g. "100%"). Sizes the whole field (label, control, and status) so they stay aligned.',
},
{
name: 'xstyle',
type: 'StyleXStyles',
description:
'StyleX styles for layout customization. Must be a stylex.create() value.',
},
],
},
],
usage: {
description:
'A checkbox dropdown for selecting multiple values from a list. Selected items can display as a count, labels, or badges. Use it for filtering or when presenting a finite set of options where multiple choices are needed.',
bestPractices: [
{
guidance: true,
description:
'Use for a moderate, finite set of options where multiple choices are needed.',
},
{
guidance: true,
description:
'Enable search filtering when the list exceeds ~15 options.',
},
{
guidance: true,
description:
'Use renderOption for custom option rows; the checkbox affordance remains owned by MultiSelector.',
},
{
guidance: true,
description:
'Enable select-all when most users will want all or nearly all options selected.',
},
{
guidance: true,
description:
'Use inside InputGroup only when the control needs a short prefix or suffix addon as part of one decorated input surface; prefer count or labels trigger display so the group stays single-line.',
},
{
guidance: true,
description:
'Use variant="ghost" when a multi-selector sits in a toolbar with ghost buttons. If validation status is needed there, prefer statusVariant="tooltip" so the toolbar height stays compact.',
},
{
guidance: false,
description: 'Use for single-value selection; use Selector instead.',
},
{
guidance: false,
description: 'Show more than ~20 options without enabling search.',
},
{
guidance: false,
description:
'Wrap a disabled MultiSelector in Tooltip to explain why it is disabled; disabled triggers swallow the hover events the wrapper needs. Use the disabledMessage prop instead.',
},
],
},
examples: [
{
label: 'Let the clear button replace the chevron',
code: `
// With hasClear alone, a selector that has values shows both a × and a
// chevron in the end slot. hasChevron={false} leaves the × on its own, so
// the one affordance in that slot is the one the user can act on.
<MultiSelector
label="Tags"
options={tags}
value={selectedTags}
onChange={setSelectedTags}
hasClear
hasChevron={false}
/>
`,
},
],
};
/** @type {import('@astryxdesign/cli/authoring').ComponentTranslationDoc} */
export const docsZh = {
components: [
{
name: 'MultiSelector',
displayName: 'Multi Selector',
description: '带复选框的多选下拉框,用于从列表中选择多项。',
propDescriptions: {
label: '无障碍标签文本。',
options:
'项目数组——字符串、带 value/label/icon/disabled 的对象、分隔线或分组。',
value: '当前选中的值。',
onChange: '选择变化时触发的回调。',
changeAction: '变化时的异步操作,在 onChange 之后触发。',
placeholder: '未选择值时显示的占位文本。',
size: '选择器的尺寸变体。',
triggerDisplay: '在触发器中显示选中项的方式。',
maxBadges:
'显示"+N"之前的最大徽章数。仅适用于 triggerDisplay="badges"。',
hasSelectAll: '是否显示全选复选框。',
selectAllLabel: '全选复选框的标签。',
hasSearch: '是否显示用于过滤选项的搜索输入。',
hasChevron:
'是否在触发器末尾显示折叠箭头。设为 false 可让清除按钮独占该位置——配合 hasClear 时,已有选中值的选择器否则会同时显示 × 和箭头。仅去掉箭头:状态图标共用该位置且不受影响;箭头是装饰性的(aria-hidden)且位于触发按钮之外,因此无障碍名称、焦点顺序与键盘行为均不变。',
searchPlaceholder: '搜索输入的占位文本。',
isDisabled: '禁用选择器。',
htmlName:
'用于表单提交的 HTML name 属性。为每个已选值渲染一个隐藏输入,类似原生多选。',
disabledMessage:
'解释选择器被禁用的原因。与 isDisabled 一起使用时,悬停/键盘聚焦时显示工具提示,并通过 aria-disabled 保持触发器可聚焦(仍无法激活)。请使用此属性,而不是用 Tooltip 包裹被禁用的选择器。',
isLabelHidden: '视觉上隐藏标签同时保持其可访问性。',
description: '标签下方显示的辅助文本。',
isOptional: '将字段标记为可选。',
isRequired: '将字段标记为必填。',
isLoading: '在触发器中显示加载旋转器。',
status: '带可选消息的验证状态。',
statusVariant:
'状态消息的放置方式:attached 直接叠加在输入框下方;detached 作为独立元素浮于下方并留有间距。',
renderOption:
'每个可选选项的自定义渲染函数。不会用于分隔线、分组或全选行。',
xstyle: '布局自定义的 StyleX 样式,必须是 stylex.create() 值。',
},
},
],
usage: {
description:
'A checkbox dropdown for selecting multiple values from a list. Selected items can display as a count, labels, or badges. Use it for filtering or when presenting a finite set of options where multiple choices are needed.',
bestPractices: [
{
guidance: true,
description:
'Use for a moderate, finite set of options where multiple choices are needed.',
},
{
guidance: true,
description:
'Enable search filtering when the list exceeds ~15 options.',
},
{
guidance: true,
description:
'Use renderOption for custom option rows; the checkbox affordance remains owned by MultiSelector.',
},
{
guidance: true,
description:
'Enable select-all when most users will want all or nearly all options selected.',
},
{
guidance: false,
description: 'Use for single-value selection; use Selector instead.',
},
{
guidance: false,
description: 'Show more than ~20 options without enabling search.',
},
{
guidance: false,
description:
'Wrap a disabled MultiSelector in Tooltip to explain why it is disabled; disabled triggers swallow the hover events the wrapper needs. Use the disabledMessage prop instead.',
},
],
},
};
/** @type {import('@astryxdesign/cli/authoring').ComponentTranslationDoc} */
export const docsDense = {
description:
'checkbox multi-select dropdown for finite sets like column toggles or filter facets',
usage: {
description:
'A checkbox dropdown for selecting multiple values from a list. Selected items can display as a count, labels, or badges. Use it for filtering or when presenting a finite set of options where multiple choices are needed.',
bestPractices: [
{
guidance: true,
description:
'Use for a moderate, finite set of options where multiple choices are needed.',
},
{
guidance: true,
description:
'Enable search filtering when the list exceeds ~15 options.',
},
{
guidance: true,
description:
'renderOption for custom rows; checkbox affordance stays owned by MultiSelector.',
},
{
guidance: true,
description:
'Enable select-all when most users will want all or nearly all options selected.',
},
{
guidance: true,
description:
'Use inside InputGroup only for a short prefix or suffix addon; prefer count or labels trigger display so the group stays single-line.',
},
{
guidance: true,
description:
'Use variant="ghost" in toolbars with ghost buttons; prefer statusVariant="tooltip" for compact validation status.',
},
{
guidance: false,
description: 'Use for single-value selection; use Selector instead.',
},
{
guidance: false,
description: 'Show more than ~20 options without enabling search.',
},
{
guidance: false,
description:
'Wrap a disabled MultiSelector in Tooltip to explain why it is disabled; disabled triggers swallow the hover events the wrapper needs. Use the disabledMessage prop instead.',
},
],
},
components: [
{
name: 'MultiSelector',
displayName: 'Multi Selector',
description: 'checkbox multi-select dropdown',
propDescriptions: {
label: 'a11y label',
options:
'items: strings, objects w/ value/label/icon/disabled, dividers, sections',
value: 'selected values',
onChange: 'callback on selection change',
changeAction: 'async; fires after onChange',
placeholder: 'text when nothing selected',
size: 'size variant',
variant:
'visual trigger style: input bordered control or ghost toolbar control',
triggerDisplay: 'how to show selected in trigger',
maxBadges: 'max badges before "+N"; badges mode only',
hasSelectAll: 'show select-all checkbox',
selectAllLabel: 'select-all label',
hasSearch: 'show search input',
hasChevron:
"false => drop the trigger chevron so hasClear's × owns the end slot alone. Status glyph unaffected; chevron is aria-hidden and outside the button, so name/focus/keyboard are unchanged. Defaults to true.",
searchPlaceholder: 'search placeholder',
isDisabled: 'disables selector',
htmlName: 'HTML name attr; one hidden input per selected value.',
disabledMessage:
'why disabled; w/ isDisabled shows tooltip on hover/focus, trigger stays focusable via aria-disabled; use instead of Tooltip wrapper',
isLabelHidden: 'visually hides label',
description: 'helper text below label',
isOptional: 'marks optional',
isRequired: 'marks required',
isLoading: 'spinner in trigger',
status: 'validation status w/ optional message',
statusVariant:
'status message placement; ghost detaches attached by default; use tooltip for compact toolbars.',
renderOption:
'custom render fn per selectable option; not dividers/sections/select-all',
xstyle: 'StyleX layout styles; stylex.create() only',
},
},
],
};