@designil/labdsnov 0.0.0-stage → 1.1.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/LICENSE +21 -0
- package/README.md +150 -2
- package/dist/components/Accordion/Accordion.d.ts +8 -0
- package/dist/components/Accordion/Accordion.js +82 -0
- package/dist/components/Accordion/Accordion.module.css.js +23 -0
- package/dist/components/Accordion/index.d.ts +1 -0
- package/dist/components/Alert/Alert.d.ts +17 -0
- package/dist/components/Alert/Alert.js +58 -0
- package/dist/components/Alert/Alert.module.css.js +17 -0
- package/dist/components/Alert/index.d.ts +1 -0
- package/dist/components/AlertDialog/AlertDialog.d.ts +29 -0
- package/dist/components/AlertDialog/AlertDialog.js +150 -0
- package/dist/components/AlertDialog/AlertDialog.module.css.js +23 -0
- package/dist/components/AlertDialog/index.d.ts +1 -0
- package/dist/components/Avatar/Avatar.d.ts +23 -0
- package/dist/components/Avatar/Avatar.js +84 -0
- package/dist/components/Avatar/Avatar.module.css.js +23 -0
- package/dist/components/Avatar/index.d.ts +1 -0
- package/dist/components/Badge/Badge.d.ts +17 -0
- package/dist/components/Badge/Badge.js +37 -0
- package/dist/components/Badge/Badge.module.css.js +19 -0
- package/dist/components/Badge/index.d.ts +1 -0
- package/dist/components/Breadcrumb/Breadcrumb.d.ts +15 -0
- package/dist/components/Breadcrumb/Breadcrumb.js +111 -0
- package/dist/components/Breadcrumb/Breadcrumb.module.css.js +19 -0
- package/dist/components/Breadcrumb/index.d.ts +1 -0
- package/dist/components/Button/Button.d.ts +39 -0
- package/dist/components/Button/Button.js +62 -0
- package/dist/components/Button/Button.module.css.js +37 -0
- package/dist/components/Button/index.d.ts +1 -0
- package/dist/components/ButtonGroup/ButtonGroup.d.ts +21 -0
- package/dist/components/ButtonGroup/ButtonGroup.js +59 -0
- package/dist/components/ButtonGroup/ButtonGroup.module.css.js +15 -0
- package/dist/components/ButtonGroup/index.d.ts +1 -0
- package/dist/components/Calendar/Calendar.d.ts +17 -0
- package/dist/components/Calendar/Calendar.js +154 -0
- package/dist/components/Calendar/Calendar.module.css.js +67 -0
- package/dist/components/Calendar/index.d.ts +1 -0
- package/dist/components/Card/Card.d.ts +20 -0
- package/dist/components/Card/Card.js +87 -0
- package/dist/components/Card/Card.module.css.js +23 -0
- package/dist/components/Card/index.d.ts +1 -0
- package/dist/components/Chart/Chart.d.ts +59 -0
- package/dist/components/Chart/Chart.js +199 -0
- package/dist/components/Chart/Chart.module.css.js +47 -0
- package/dist/components/Chart/index.d.ts +1 -0
- package/dist/components/Checkbox/Checkbox.d.ts +4 -0
- package/dist/components/Checkbox/Checkbox.js +44 -0
- package/dist/components/Checkbox/Checkbox.module.css.js +13 -0
- package/dist/components/Checkbox/index.d.ts +1 -0
- package/dist/components/Collapsible/Collapsible.d.ts +8 -0
- package/dist/components/Collapsible/Collapsible.js +28 -0
- package/dist/components/Collapsible/Collapsible.module.css.js +7 -0
- package/dist/components/Collapsible/index.d.ts +1 -0
- package/dist/components/Combobox/Combobox.d.ts +36 -0
- package/dist/components/Combobox/Combobox.js +296 -0
- package/dist/components/Combobox/Combobox.module.css.js +39 -0
- package/dist/components/Combobox/index.d.ts +1 -0
- package/dist/components/DatePicker/DatePicker.d.ts +28 -0
- package/dist/components/DatePicker/DatePicker.js +73 -0
- package/dist/components/DatePicker/DatePicker.module.css.js +9 -0
- package/dist/components/DatePicker/index.d.ts +1 -0
- package/dist/components/Dialog/Dialog.d.ts +27 -0
- package/dist/components/Dialog/Dialog.js +144 -0
- package/dist/components/Dialog/Dialog.module.css.js +29 -0
- package/dist/components/Dialog/index.d.ts +1 -0
- package/dist/components/Drawer/Drawer.d.ts +22 -0
- package/dist/components/Drawer/Drawer.js +166 -0
- package/dist/components/Drawer/Drawer.module.css.js +23 -0
- package/dist/components/Drawer/index.d.ts +1 -0
- package/dist/components/DropdownMenu/DropdownMenu.d.ts +32 -0
- package/dist/components/DropdownMenu/DropdownMenu.js +245 -0
- package/dist/components/DropdownMenu/DropdownMenu.module.css.js +33 -0
- package/dist/components/DropdownMenu/index.d.ts +1 -0
- package/dist/components/Empty/Empty.d.ts +18 -0
- package/dist/components/Empty/Empty.js +76 -0
- package/dist/components/Empty/Empty.module.css.js +21 -0
- package/dist/components/Empty/index.d.ts +1 -0
- package/dist/components/Field/Field.d.ts +53 -0
- package/dist/components/Field/Field.js +172 -0
- package/dist/components/Field/Field.module.css.js +41 -0
- package/dist/components/Field/index.d.ts +1 -0
- package/dist/components/FundCard/FundCard.d.ts +18 -0
- package/dist/components/FundCard/FundCard.js +66 -0
- package/dist/components/FundCard/FundCard.module.css.js +25 -0
- package/dist/components/FundCard/index.d.ts +1 -0
- package/dist/components/HoverCard/HoverCard.d.ts +8 -0
- package/dist/components/HoverCard/HoverCard.js +42 -0
- package/dist/components/HoverCard/HoverCard.module.css.js +9 -0
- package/dist/components/HoverCard/index.d.ts +1 -0
- package/dist/components/Input/Input.d.ts +12 -0
- package/dist/components/Input/Input.js +23 -0
- package/dist/components/Input/Input.module.css.js +11 -0
- package/dist/components/Input/index.d.ts +1 -0
- package/dist/components/InputGroup/InputGroup.d.ts +39 -0
- package/dist/components/InputGroup/InputGroup.js +103 -0
- package/dist/components/InputGroup/InputGroup.module.css.js +31 -0
- package/dist/components/InputGroup/index.d.ts +1 -0
- package/dist/components/InputOTP/InputOTP.d.ts +18 -0
- package/dist/components/InputOTP/InputOTP.js +72 -0
- package/dist/components/InputOTP/InputOTP.module.css.js +19 -0
- package/dist/components/InputOTP/index.d.ts +1 -0
- package/dist/components/Kbd/Kbd.d.ts +5 -0
- package/dist/components/Kbd/Kbd.js +20 -0
- package/dist/components/Kbd/Kbd.module.css.js +9 -0
- package/dist/components/Kbd/index.d.ts +1 -0
- package/dist/components/Label/Label.d.ts +7 -0
- package/dist/components/Label/Label.js +17 -0
- package/dist/components/Label/Label.module.css.js +9 -0
- package/dist/components/Label/index.d.ts +1 -0
- package/dist/components/NavigationMenu/NavigationMenu.d.ts +20 -0
- package/dist/components/NavigationMenu/NavigationMenu.js +153 -0
- package/dist/components/NavigationMenu/NavigationMenu.module.css.js +29 -0
- package/dist/components/NavigationMenu/index.d.ts +1 -0
- package/dist/components/Pagination/Pagination.d.ts +29 -0
- package/dist/components/Pagination/Pagination.js +133 -0
- package/dist/components/Pagination/Pagination.module.css.js +19 -0
- package/dist/components/Pagination/index.d.ts +1 -0
- package/dist/components/Popover/Popover.d.ts +10 -0
- package/dist/components/Popover/Popover.js +78 -0
- package/dist/components/Popover/Popover.module.css.js +15 -0
- package/dist/components/Popover/index.d.ts +1 -0
- package/dist/components/Progress/Progress.d.ts +12 -0
- package/dist/components/Progress/Progress.js +74 -0
- package/dist/components/Progress/Progress.module.css.js +15 -0
- package/dist/components/Progress/index.d.ts +1 -0
- package/dist/components/RadioGroup/RadioGroup.d.ts +6 -0
- package/dist/components/RadioGroup/RadioGroup.js +37 -0
- package/dist/components/RadioGroup/RadioGroup.module.css.js +13 -0
- package/dist/components/RadioGroup/index.d.ts +1 -0
- package/dist/components/ScrollArea/ScrollArea.d.ts +9 -0
- package/dist/components/ScrollArea/ScrollArea.js +60 -0
- package/dist/components/ScrollArea/ScrollArea.module.css.js +17 -0
- package/dist/components/ScrollArea/index.d.ts +1 -0
- package/dist/components/Select/Select.d.ts +23 -0
- package/dist/components/Select/Select.js +188 -0
- package/dist/components/Select/Select.module.css.js +37 -0
- package/dist/components/Select/index.d.ts +1 -0
- package/dist/components/Separator/Separator.d.ts +4 -0
- package/dist/components/Separator/Separator.js +22 -0
- package/dist/components/Separator/Separator.module.css.js +7 -0
- package/dist/components/Separator/index.d.ts +1 -0
- package/dist/components/Skeleton/Skeleton.d.ts +4 -0
- package/dist/components/Skeleton/Skeleton.js +16 -0
- package/dist/components/Skeleton/Skeleton.module.css.js +7 -0
- package/dist/components/Skeleton/index.d.ts +1 -0
- package/dist/components/Slider/Slider.d.ts +13 -0
- package/dist/components/Slider/Slider.js +61 -0
- package/dist/components/Slider/Slider.module.css.js +15 -0
- package/dist/components/Slider/index.d.ts +1 -0
- package/dist/components/Spinner/Spinner.d.ts +6 -0
- package/dist/components/Spinner/Spinner.js +22 -0
- package/dist/components/Spinner/Spinner.module.css.js +7 -0
- package/dist/components/Spinner/index.d.ts +1 -0
- package/dist/components/Switch/Switch.d.ts +13 -0
- package/dist/components/Switch/Switch.js +29 -0
- package/dist/components/Switch/Switch.module.css.js +13 -0
- package/dist/components/Switch/index.d.ts +1 -0
- package/dist/components/Table/Table.d.ts +12 -0
- package/dist/components/Table/Table.js +96 -0
- package/dist/components/Table/Table.module.css.js +23 -0
- package/dist/components/Table/index.d.ts +1 -0
- package/dist/components/Tabs/Tabs.d.ts +16 -0
- package/dist/components/Tabs/Tabs.js +55 -0
- package/dist/components/Tabs/Tabs.module.css.js +17 -0
- package/dist/components/Tabs/index.d.ts +1 -0
- package/dist/components/Textarea/Textarea.d.ts +4 -0
- package/dist/components/Textarea/Textarea.js +16 -0
- package/dist/components/Textarea/Textarea.module.css.js +7 -0
- package/dist/components/Textarea/index.d.ts +1 -0
- package/dist/components/Toaster/Toaster.d.ts +8 -0
- package/dist/components/Toaster/Toaster.js +85 -0
- package/dist/components/Toaster/Toaster.module.css.js +11 -0
- package/dist/components/Toaster/index.d.ts +1 -0
- package/dist/components/Toggle/Toggle.d.ts +26 -0
- package/dist/components/Toggle/Toggle.js +35 -0
- package/dist/components/Toggle/Toggle.module.css.js +17 -0
- package/dist/components/Toggle/index.d.ts +1 -0
- package/dist/components/ToggleGroup/ToggleGroup.d.ts +20 -0
- package/dist/components/ToggleGroup/ToggleGroup.js +64 -0
- package/dist/components/ToggleGroup/ToggleGroup.module.css.js +11 -0
- package/dist/components/ToggleGroup/index.d.ts +1 -0
- package/dist/components/Tooltip/Tooltip.d.ts +8 -0
- package/dist/components/Tooltip/Tooltip.js +61 -0
- package/dist/components/Tooltip/Tooltip.module.css.js +11 -0
- package/dist/components/Tooltip/index.d.ts +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +265 -0
- package/dist/styles.css +1 -0
- package/docs/Accessibility.md +129 -0
- package/docs/Colors.md +149 -0
- package/docs/ComponentTokens.md +191 -0
- package/docs/Contributing.md +104 -0
- package/docs/GettingStarted.md +106 -0
- package/docs/Radius.md +25 -0
- package/docs/Typography.md +38 -0
- package/package.json +88 -4
- package/src/components/Accordion/Accordion.dsds.yaml +195 -0
- package/src/components/Accordion/Accordion.md +102 -0
- package/src/components/Alert/Alert.dsds.yaml +206 -0
- package/src/components/Alert/Alert.md +90 -0
- package/src/components/AlertDialog/AlertDialog.dsds.yaml +243 -0
- package/src/components/AlertDialog/AlertDialog.md +131 -0
- package/src/components/Avatar/Avatar.dsds.yaml +172 -0
- package/src/components/Avatar/Avatar.md +77 -0
- package/src/components/Badge/Badge.dsds.yaml +191 -0
- package/src/components/Badge/Badge.md +124 -0
- package/src/components/Breadcrumb/Breadcrumb.dsds.yaml +162 -0
- package/src/components/Breadcrumb/Breadcrumb.md +110 -0
- package/src/components/Button/Button.dsds.yaml +350 -0
- package/src/components/Button/Button.md +165 -0
- package/src/components/ButtonGroup/ButtonGroup.dsds.yaml +193 -0
- package/src/components/ButtonGroup/ButtonGroup.md +96 -0
- package/src/components/Calendar/Calendar.dsds.yaml +236 -0
- package/src/components/Calendar/Calendar.md +111 -0
- package/src/components/Card/Card.dsds.yaml +199 -0
- package/src/components/Card/Card.md +99 -0
- package/src/components/Chart/Chart.dsds.yaml +216 -0
- package/src/components/Chart/Chart.md +112 -0
- package/src/components/Checkbox/Checkbox.dsds.yaml +215 -0
- package/src/components/Checkbox/Checkbox.md +105 -0
- package/src/components/Collapsible/Collapsible.dsds.yaml +146 -0
- package/src/components/Collapsible/Collapsible.md +86 -0
- package/src/components/Combobox/Combobox.dsds.yaml +241 -0
- package/src/components/Combobox/Combobox.md +143 -0
- package/src/components/DatePicker/DatePicker.dsds.yaml +179 -0
- package/src/components/DatePicker/DatePicker.md +82 -0
- package/src/components/Dialog/Dialog.dsds.yaml +300 -0
- package/src/components/Dialog/Dialog.md +193 -0
- package/src/components/Drawer/Drawer.dsds.yaml +207 -0
- package/src/components/Drawer/Drawer.md +125 -0
- package/src/components/DropdownMenu/DropdownMenu.dsds.yaml +265 -0
- package/src/components/DropdownMenu/DropdownMenu.md +151 -0
- package/src/components/Empty/Empty.dsds.yaml +171 -0
- package/src/components/Empty/Empty.md +90 -0
- package/src/components/Field/Field.dsds.yaml +285 -0
- package/src/components/Field/Field.md +139 -0
- package/src/components/FundCard/FundCard.dsds.yaml +195 -0
- package/src/components/FundCard/FundCard.md +93 -0
- package/src/components/HoverCard/HoverCard.dsds.yaml +157 -0
- package/src/components/HoverCard/HoverCard.md +100 -0
- package/src/components/Input/Input.dsds.yaml +235 -0
- package/src/components/Input/Input.md +115 -0
- package/src/components/InputGroup/InputGroup.dsds.yaml +234 -0
- package/src/components/InputGroup/InputGroup.md +115 -0
- package/src/components/InputOTP/InputOTP.dsds.yaml +184 -0
- package/src/components/InputOTP/InputOTP.md +105 -0
- package/src/components/Kbd/Kbd.dsds.yaml +119 -0
- package/src/components/Kbd/Kbd.md +85 -0
- package/src/components/Label/Label.dsds.yaml +141 -0
- package/src/components/Label/Label.md +75 -0
- package/src/components/NavigationMenu/NavigationMenu.dsds.yaml +196 -0
- package/src/components/NavigationMenu/NavigationMenu.md +128 -0
- package/src/components/Pagination/Pagination.dsds.yaml +172 -0
- package/src/components/Pagination/Pagination.md +115 -0
- package/src/components/Popover/Popover.dsds.yaml +168 -0
- package/src/components/Popover/Popover.md +111 -0
- package/src/components/Progress/Progress.dsds.yaml +169 -0
- package/src/components/Progress/Progress.md +83 -0
- package/src/components/RadioGroup/RadioGroup.dsds.yaml +215 -0
- package/src/components/RadioGroup/RadioGroup.md +123 -0
- package/src/components/ScrollArea/ScrollArea.dsds.yaml +153 -0
- package/src/components/ScrollArea/ScrollArea.md +88 -0
- package/src/components/Select/Select.dsds.yaml +239 -0
- package/src/components/Select/Select.md +170 -0
- package/src/components/Separator/Separator.dsds.yaml +121 -0
- package/src/components/Separator/Separator.md +68 -0
- package/src/components/Skeleton/Skeleton.dsds.yaml +124 -0
- package/src/components/Skeleton/Skeleton.md +68 -0
- package/src/components/Slider/Slider.dsds.yaml +194 -0
- package/src/components/Slider/Slider.md +107 -0
- package/src/components/Spinner/Spinner.dsds.yaml +126 -0
- package/src/components/Spinner/Spinner.md +64 -0
- package/src/components/Switch/Switch.dsds.yaml +198 -0
- package/src/components/Switch/Switch.md +101 -0
- package/src/components/Table/Table.dsds.yaml +195 -0
- package/src/components/Table/Table.md +117 -0
- package/src/components/Tabs/Tabs.dsds.yaml +239 -0
- package/src/components/Tabs/Tabs.md +173 -0
- package/src/components/Textarea/Textarea.dsds.yaml +167 -0
- package/src/components/Textarea/Textarea.md +89 -0
- package/src/components/Toaster/Toaster.dsds.yaml +226 -0
- package/src/components/Toaster/Toaster.md +107 -0
- package/src/components/Toggle/Toggle.dsds.yaml +224 -0
- package/src/components/Toggle/Toggle.md +103 -0
- package/src/components/ToggleGroup/ToggleGroup.dsds.yaml +230 -0
- package/src/components/ToggleGroup/ToggleGroup.md +95 -0
- package/src/components/Tooltip/Tooltip.dsds.yaml +202 -0
- package/src/components/Tooltip/Tooltip.md +104 -0
- package/src/index.dsds.yaml +467 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
kind: component
|
|
2
|
+
id: collapsible
|
|
3
|
+
name: Collapsible
|
|
4
|
+
description: >-
|
|
5
|
+
Hides and shows a single section of content with a button, e.g. fee details. It has
|
|
6
|
+
no look of its own. Wraps Base UI's `Collapsible`.
|
|
7
|
+
metadata:
|
|
8
|
+
status: {status: stable}
|
|
9
|
+
since: 1.0.0
|
|
10
|
+
tags: [disclosure]
|
|
11
|
+
|
|
12
|
+
sections:
|
|
13
|
+
- kind: guidelines
|
|
14
|
+
for: all
|
|
15
|
+
framing: when-to-use
|
|
16
|
+
items:
|
|
17
|
+
- level: should
|
|
18
|
+
statement: >-
|
|
19
|
+
Use for supporting detail most people don't need to read, e.g. how fees are
|
|
20
|
+
calculated.
|
|
21
|
+
- level: should
|
|
22
|
+
statement: >-
|
|
23
|
+
Use to hide advanced options in a form.
|
|
24
|
+
- level: must-not
|
|
25
|
+
statement: >-
|
|
26
|
+
Don't hide information users need to decide (e.g. the total fee). Show it on the
|
|
27
|
+
page. Collapsible may only hide the breakdown of a figure that's already shown.
|
|
28
|
+
checkedBy: manual
|
|
29
|
+
- level: should-not
|
|
30
|
+
statement: >-
|
|
31
|
+
Don't use for several stacked sections such as an FAQ. Use <dsds:accordion>.
|
|
32
|
+
alternatives:
|
|
33
|
+
- to: accordion
|
|
34
|
+
- level: should-not
|
|
35
|
+
statement: >-
|
|
36
|
+
Don't use for content that floats over the page. Use <dsds:popover>.
|
|
37
|
+
alternatives:
|
|
38
|
+
- to: popover
|
|
39
|
+
|
|
40
|
+
- kind: guidelines
|
|
41
|
+
for: all
|
|
42
|
+
items:
|
|
43
|
+
- id: trigger-is-button
|
|
44
|
+
level: must
|
|
45
|
+
statement: >-
|
|
46
|
+
The trigger has no look of its own. Write it as
|
|
47
|
+
`<CollapsibleTrigger render={<Button variant="ghost" size="sm" />}>`.
|
|
48
|
+
refs:
|
|
49
|
+
- to: shared-composition#render-prop
|
|
50
|
+
rel: relates-to
|
|
51
|
+
uses:
|
|
52
|
+
- to: button
|
|
53
|
+
checkedBy: assisted
|
|
54
|
+
- id: trigger-says-what
|
|
55
|
+
level: should
|
|
56
|
+
statement: >-
|
|
57
|
+
The button text says what will be shown ("ดูรายละเอียด", see details). Don't
|
|
58
|
+
change it to "ซ่อน" (hide) when open: `aria-expanded` and the rotated chevron
|
|
59
|
+
convey the state.
|
|
60
|
+
checkedBy: manual
|
|
61
|
+
- id: rotate-chevron
|
|
62
|
+
level: may
|
|
63
|
+
statement: >-
|
|
64
|
+
Rotate the chevron with `className="[&[data-panel-open]_svg]:rotate-180"` on the
|
|
65
|
+
trigger.
|
|
66
|
+
- id: find-in-page
|
|
67
|
+
level: may
|
|
68
|
+
statement: >-
|
|
69
|
+
For content users may search with Ctrl+F, use `keepMounted` together with
|
|
70
|
+
`hiddenUntilFound` on `CollapsibleContent`.
|
|
71
|
+
|
|
72
|
+
- kind: guidelines
|
|
73
|
+
for: all
|
|
74
|
+
title: Accessibility
|
|
75
|
+
tags: [accessibility]
|
|
76
|
+
items:
|
|
77
|
+
- id: aria-expanded
|
|
78
|
+
level: must
|
|
79
|
+
statement: >-
|
|
80
|
+
The trigger has `aria-expanded` matching the state, and Enter or Space opens and
|
|
81
|
+
closes it.
|
|
82
|
+
evidence:
|
|
83
|
+
- href: https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/
|
|
84
|
+
role: WAI-ARIA APG Disclosure pattern
|
|
85
|
+
checks:
|
|
86
|
+
- href: ./Collapsible.stories.tsx#OpenAndClose
|
|
87
|
+
role: test
|
|
88
|
+
- href: ./Collapsible.stories.tsx#Keyboard
|
|
89
|
+
role: test
|
|
90
|
+
checkedBy: automated
|
|
91
|
+
- id: content-after-trigger
|
|
92
|
+
level: should
|
|
93
|
+
statement: >-
|
|
94
|
+
Place `CollapsibleContent` right after the trigger in DOM order, so the next Tab
|
|
95
|
+
goes into the content just opened.
|
|
96
|
+
checkedBy: manual
|
|
97
|
+
|
|
98
|
+
- kind: definitions
|
|
99
|
+
for: all
|
|
100
|
+
context: anatomy
|
|
101
|
+
items:
|
|
102
|
+
- term: Collapsible
|
|
103
|
+
definition: >-
|
|
104
|
+
Root; takes `open` / `onOpenChange`, `defaultOpen`, `disabled`
|
|
105
|
+
- term: CollapsibleTrigger
|
|
106
|
+
definition: >-
|
|
107
|
+
The open/close button; use `render` with Button
|
|
108
|
+
- term: CollapsibleContent
|
|
109
|
+
definition: >-
|
|
110
|
+
The content; its height animates open/closed in 200ms. Takes `keepMounted`.
|
|
111
|
+
|
|
112
|
+
sourceFiles:
|
|
113
|
+
- platform: react
|
|
114
|
+
file: ./Collapsible.tsx
|
|
115
|
+
|
|
116
|
+
imports:
|
|
117
|
+
- platform: react
|
|
118
|
+
code: >-
|
|
119
|
+
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@designil/labdsnov"
|
|
120
|
+
package: "@designil/labdsnov"
|
|
121
|
+
|
|
122
|
+
traits:
|
|
123
|
+
- traitType: state
|
|
124
|
+
kind: boolean
|
|
125
|
+
id: open
|
|
126
|
+
description: >-
|
|
127
|
+
Content is open; the trigger has `data-panel-open` and `aria-expanded="true"`
|
|
128
|
+
- traitType: state
|
|
129
|
+
kind: boolean
|
|
130
|
+
id: disabled
|
|
131
|
+
description: >-
|
|
132
|
+
The trigger can't open or close
|
|
133
|
+
|
|
134
|
+
uses:
|
|
135
|
+
- to: button
|
|
136
|
+
alternatives:
|
|
137
|
+
- to: accordion
|
|
138
|
+
- to: popover
|
|
139
|
+
|
|
140
|
+
refs:
|
|
141
|
+
- href: ./Collapsible.md
|
|
142
|
+
rel: relates-to
|
|
143
|
+
role: Thai usage doc
|
|
144
|
+
- href: ./Collapsible.stories.tsx
|
|
145
|
+
rel: demo
|
|
146
|
+
role: CSF stories
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Collapsible (ส่วนพับได้)
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
ซ่อนและแสดงเนื้อหาส่วนเดียวด้วยปุ่ม เช่น รายละเอียดค่าธรรมเนียม
|
|
6
|
+
|
|
7
|
+
## Import and usage
|
|
8
|
+
|
|
9
|
+
**ตั้งค่าครั้งเดียวในแอป** (ใช้ร่วมกันทุกคอมโพเนนต์):
|
|
10
|
+
|
|
11
|
+
1. ติดตั้ง `@designil/labdsnov` (`pnpm add @designil/labdsnov`) พร้อม `react` และ `react-dom` 19
|
|
12
|
+
2. import สไตล์ครั้งเดียวที่ root layout: `import "@designil/labdsnov/styles.css"`
|
|
13
|
+
3. กำหนดตัวแปร `--font-heading` (แอปใช้ IBM Plex Sans Thai) และใส่ class `dark` ที่ `<html>` เมื่อต้องการโหมดมืด
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import {
|
|
17
|
+
Button,
|
|
18
|
+
Collapsible,
|
|
19
|
+
CollapsibleContent,
|
|
20
|
+
CollapsibleTrigger,
|
|
21
|
+
} from "@designil/labdsnov"
|
|
22
|
+
|
|
23
|
+
;<Collapsible>
|
|
24
|
+
<CollapsibleTrigger render={<Button variant="ghost" size="sm" />}>
|
|
25
|
+
ดูรายละเอียด
|
|
26
|
+
</CollapsibleTrigger>
|
|
27
|
+
<CollapsibleContent>…</CollapsibleContent>
|
|
28
|
+
</Collapsible>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
- ปุ่มไม่มีหน้าตาของตัวเอง ใช้ `render={<Button … />}`
|
|
32
|
+
- ข้อความบนปุ่มบอกว่าจะเห็นอะไร เช่น "ดูรายละเอียด" ปุ่มบอกสถานะเปิด/ปิดผ่าน `aria-expanded` เอง
|
|
33
|
+
- ไอคอนลูกศรหมุนได้ด้วย `[&[data-panel-open]_svg]:rotate-180` บนปุ่ม (ดู story)
|
|
34
|
+
|
|
35
|
+
## When to use
|
|
36
|
+
|
|
37
|
+
- รายละเอียดเสริมที่คนส่วนใหญ่ไม่ต้องอ่าน เช่น การคำนวณค่าธรรมเนียม
|
|
38
|
+
- ตัวเลือกขั้นสูงในฟอร์ม
|
|
39
|
+
|
|
40
|
+
## When not to use
|
|
41
|
+
|
|
42
|
+
| สถานการณ์ | ใช้แทน |
|
|
43
|
+
| ----------------------------- | ------------ |
|
|
44
|
+
| หลายส่วนเรียงกัน เช่น คำถามที่พบบ่อย | `Accordion` |
|
|
45
|
+
| ข้อมูลที่ผู้ใช้ต้องเห็นเพื่อตัดสินใจ | แสดงในหน้าเลย |
|
|
46
|
+
| เนื้อหาลอยทับหน้า | `Popover` |
|
|
47
|
+
|
|
48
|
+
## Props and variants
|
|
49
|
+
|
|
50
|
+
ไม่มี variant หรือ size
|
|
51
|
+
|
|
52
|
+
| Prop | ใช้กับ | ความหมาย |
|
|
53
|
+
| ----------------------- | -------------------- | ------------------------------------------------------------------- |
|
|
54
|
+
| `open` / `onOpenChange` | `Collapsible` | ควบคุมการเปิดจากภายนอก |
|
|
55
|
+
| `defaultOpen` | `Collapsible` | เปิดไว้ตั้งแต่แรก |
|
|
56
|
+
| `disabled` | `Collapsible` | ปิดใช้งานปุ่ม |
|
|
57
|
+
| `keepMounted` | `CollapsibleContent` | เก็บเนื้อหาไว้ในหน้าตอนปิด (ค้นหาด้วย Ctrl+F ได้เมื่อใช้คู่กับ `hiddenUntilFound`) |
|
|
58
|
+
|
|
59
|
+
- ความสูงของเนื้อหาเลื่อนเปิด/ปิดใน 200ms
|
|
60
|
+
- **คีย์บอร์ด**: Tab ไปที่ปุ่ม Enter หรือ Space เพื่อเปิด/ปิด
|
|
61
|
+
|
|
62
|
+
## Tokens used
|
|
63
|
+
|
|
64
|
+
ไม่มีสีของตัวเอง สีมาจาก `Button` ที่ใช้เป็นปุ่ม และเนื้อหาที่ใส่
|
|
65
|
+
|
|
66
|
+
## Example
|
|
67
|
+
|
|
68
|
+
จาก story `Playground` ใน `Collapsible.stories.tsx`:
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
<Collapsible className="w-80">
|
|
72
|
+
<div className="flex items-center justify-between gap-2">
|
|
73
|
+
<p className="text-sm font-medium">ค่าธรรมเนียมรายปี 0.85%</p>
|
|
74
|
+
<CollapsibleTrigger render={<Button variant="ghost" size="sm" />}>
|
|
75
|
+
ดูรายละเอียด
|
|
76
|
+
</CollapsibleTrigger>
|
|
77
|
+
</div>
|
|
78
|
+
<CollapsibleContent>
|
|
79
|
+
<ul className="mt-2 grid gap-1 rounded-2xl bg-muted p-3 text-sm">
|
|
80
|
+
<li>ค่าบริหารกองทุน 0.60%</li>
|
|
81
|
+
<li>ค่าดูแลบัญชี 0.20%</li>
|
|
82
|
+
<li>ค่าประกันภัย 0.05%</li>
|
|
83
|
+
</ul>
|
|
84
|
+
</CollapsibleContent>
|
|
85
|
+
</Collapsible>
|
|
86
|
+
```
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
kind: component
|
|
2
|
+
id: combobox
|
|
3
|
+
name: Combobox
|
|
4
|
+
description: >-
|
|
5
|
+
A field where users type to filter a long list, then pick a value (or several, as
|
|
6
|
+
chips). Looks like InputGroup. Wraps Base UI's `Combobox`.
|
|
7
|
+
metadata:
|
|
8
|
+
status: {status: stable}
|
|
9
|
+
since: 1.0.0
|
|
10
|
+
tags: [form, selection]
|
|
11
|
+
|
|
12
|
+
sections:
|
|
13
|
+
- kind: guidelines
|
|
14
|
+
for: all
|
|
15
|
+
framing: when-to-use
|
|
16
|
+
items:
|
|
17
|
+
- level: should
|
|
18
|
+
statement: >-
|
|
19
|
+
Use to pick one value from a very long list whose names users already know, e.g.
|
|
20
|
+
country, bank.
|
|
21
|
+
- level: should
|
|
22
|
+
statement: >-
|
|
23
|
+
Use `multiple` with chips when several values can be picked, e.g. countries worked
|
|
24
|
+
in.
|
|
25
|
+
- level: should-not
|
|
26
|
+
statement: >-
|
|
27
|
+
Don't use for short lists (under about 15 options). Use <dsds:select>.
|
|
28
|
+
alternatives:
|
|
29
|
+
- to: select
|
|
30
|
+
- level: should-not
|
|
31
|
+
statement: >-
|
|
32
|
+
Don't use for 2–5 options that should all be visible. Use <dsds:radio-group>.
|
|
33
|
+
alternatives:
|
|
34
|
+
- to: radio-group
|
|
35
|
+
- level: must-not
|
|
36
|
+
statement: >-
|
|
37
|
+
Don't use for free text that doesn't have to match the list. Use <dsds:input>.
|
|
38
|
+
alternatives:
|
|
39
|
+
- to: input
|
|
40
|
+
checkedBy: manual
|
|
41
|
+
|
|
42
|
+
- kind: guidelines
|
|
43
|
+
for: all
|
|
44
|
+
items:
|
|
45
|
+
- id: items-and-render-fn
|
|
46
|
+
level: must
|
|
47
|
+
statement: >-
|
|
48
|
+
Pass the whole list as `items` on `Combobox` and give `ComboboxList` a function
|
|
49
|
+
`(item) => <ComboboxItem key value>`. The component filters for you: never
|
|
50
|
+
`.filter()` the list yourself and map it into children.
|
|
51
|
+
checks:
|
|
52
|
+
- href: ./Combobox.stories.tsx#FilterAndChoose
|
|
53
|
+
role: test
|
|
54
|
+
note: play function types "สห" and expects 2 options left
|
|
55
|
+
checkedBy: automated
|
|
56
|
+
- id: always-empty
|
|
57
|
+
level: must
|
|
58
|
+
statement: >-
|
|
59
|
+
Always include `ComboboxEmpty` saying nothing was found, e.g. "ไม่พบประเทศที่ค้นหา"
|
|
60
|
+
(no matching country). Otherwise an empty list has no explanation.
|
|
61
|
+
checks:
|
|
62
|
+
- href: ./Combobox.stories.tsx#NoMatch
|
|
63
|
+
role: test
|
|
64
|
+
checkedBy: automated
|
|
65
|
+
- id: object-items-label
|
|
66
|
+
level: must
|
|
67
|
+
statement: >-
|
|
68
|
+
Object items need `itemToStringLabel` on `Combobox` to say which text is searched
|
|
69
|
+
and shown in the field; otherwise the field shows "[object Object]".
|
|
70
|
+
checkedBy: manual
|
|
71
|
+
- id: chips-anchor
|
|
72
|
+
level: must
|
|
73
|
+
statement: >-
|
|
74
|
+
Multiple mode uses `ComboboxChips` + `ComboboxValue` + `ComboboxChip` +
|
|
75
|
+
`ComboboxChipsInput` instead of `ComboboxInput`, and passes the `anchor` from
|
|
76
|
+
`useComboboxAnchor()` both to `ComboboxChips` (`ref`) and to `ComboboxContent`;
|
|
77
|
+
otherwise the list is positioned in the wrong place.
|
|
78
|
+
example:
|
|
79
|
+
ref:
|
|
80
|
+
href: ./Combobox.stories.tsx#MultipleChips
|
|
81
|
+
rel: demo
|
|
82
|
+
checkedBy: manual
|
|
83
|
+
- id: full-width-in-form
|
|
84
|
+
level: should
|
|
85
|
+
statement: >-
|
|
86
|
+
The field is as wide as its content. In forms add `className="w-full"` to match
|
|
87
|
+
other fields.
|
|
88
|
+
checkedBy: manual
|
|
89
|
+
- id: placeholder-hint
|
|
90
|
+
level: should
|
|
91
|
+
statement: >-
|
|
92
|
+
`placeholder` explains how to use it ("พิมพ์เพื่อค้นหา", type to search;
|
|
93
|
+
"เพิ่มประเทศ", add a country). It isn't the field's label; that's the <dsds:label>.
|
|
94
|
+
checkedBy: manual
|
|
95
|
+
- id: clear-or-trigger
|
|
96
|
+
level: may
|
|
97
|
+
statement: >-
|
|
98
|
+
`showClear` shows an "×" clear button (hiding the chevron while a value is set).
|
|
99
|
+
Suits optional fields.
|
|
100
|
+
- id: no-userevent-type
|
|
101
|
+
level: must-not
|
|
102
|
+
statement: >-
|
|
103
|
+
In play functions don't test filtering with `userEvent.type`. Use
|
|
104
|
+
`fireEvent.change`.
|
|
105
|
+
refs:
|
|
106
|
+
- to: shared-testing#fire-change-for-typing
|
|
107
|
+
rel: relates-to
|
|
108
|
+
checkedBy: manual
|
|
109
|
+
|
|
110
|
+
- kind: guidelines
|
|
111
|
+
for: all
|
|
112
|
+
title: Accessibility
|
|
113
|
+
tags: [accessibility]
|
|
114
|
+
items:
|
|
115
|
+
- id: input-label
|
|
116
|
+
level: must
|
|
117
|
+
statement: >-
|
|
118
|
+
`ComboboxInput` (or `ComboboxChipsInput`) has an `id` bound to a <dsds:label>
|
|
119
|
+
`htmlFor`. The placeholder isn't the field's name.
|
|
120
|
+
evidence:
|
|
121
|
+
- href: https://www.w3.org/WAI/WCAG22/Understanding/labels-or-instructions.html
|
|
122
|
+
role: WCAG 2.2 SC 3.3.2 (A)
|
|
123
|
+
checkedBy: manual
|
|
124
|
+
- id: chip-remove-label
|
|
125
|
+
level: must
|
|
126
|
+
statement: >-
|
|
127
|
+
The "×" on each chip is already named "นำออก" (remove). In multiple mode don't hide
|
|
128
|
+
it with `showRemove={false}` unless there's another keyboard way to remove values.
|
|
129
|
+
checks:
|
|
130
|
+
- href: ./Combobox.stories.tsx#MultipleChips
|
|
131
|
+
role: test
|
|
132
|
+
note: play function presses "นำออก" and the chip disappears
|
|
133
|
+
checkedBy: automated
|
|
134
|
+
- refs:
|
|
135
|
+
- to: shared-a11y#focus-ring
|
|
136
|
+
rel: same-as
|
|
137
|
+
|
|
138
|
+
- kind: definitions
|
|
139
|
+
for: all
|
|
140
|
+
context: anatomy
|
|
141
|
+
items:
|
|
142
|
+
- term: Combobox
|
|
143
|
+
definition: >-
|
|
144
|
+
Root; takes `items`, `value` / `onValueChange`, `defaultValue`, `multiple`,
|
|
145
|
+
`itemToStringLabel`
|
|
146
|
+
- term: ComboboxInput
|
|
147
|
+
definition: >-
|
|
148
|
+
The text field; takes `showTrigger` (default `true`), `showClear`, `disabled`
|
|
149
|
+
- term: ComboboxContent
|
|
150
|
+
definition: >-
|
|
151
|
+
The list popup (portalled); takes `anchor`
|
|
152
|
+
- term: ComboboxList / ComboboxItem
|
|
153
|
+
definition: >-
|
|
154
|
+
The options; the selected one has a tick on the right, `disabled` can't be picked
|
|
155
|
+
- term: ComboboxEmpty
|
|
156
|
+
definition: >-
|
|
157
|
+
Message shown when nothing matches
|
|
158
|
+
- term: ComboboxGroup / ComboboxLabel / ComboboxSeparator
|
|
159
|
+
definition: >-
|
|
160
|
+
Group the options
|
|
161
|
+
- term: ComboboxChips / ComboboxChip / ComboboxChipsInput
|
|
162
|
+
definition: >-
|
|
163
|
+
Multiple mode; each chip has a "นำออก" (remove) button
|
|
164
|
+
|
|
165
|
+
- kind: definitions
|
|
166
|
+
for: all
|
|
167
|
+
context: keyboard
|
|
168
|
+
items:
|
|
169
|
+
- term: Typing
|
|
170
|
+
definition: >-
|
|
171
|
+
Filters the list
|
|
172
|
+
- term: Up / Down arrow
|
|
173
|
+
definition: >-
|
|
174
|
+
Highlight the previous / next option
|
|
175
|
+
- term: Enter
|
|
176
|
+
definition: >-
|
|
177
|
+
Pick the highlighted option
|
|
178
|
+
- term: Escape
|
|
179
|
+
definition: >-
|
|
180
|
+
Close the list
|
|
181
|
+
|
|
182
|
+
- kind: section
|
|
183
|
+
for: all
|
|
184
|
+
title: Open decisions
|
|
185
|
+
freeform:
|
|
186
|
+
- title: TODO
|
|
187
|
+
body: >-
|
|
188
|
+
The number of options at which to switch from Select to Combobox isn't decided
|
|
189
|
+
("about 15" is an estimate).
|
|
190
|
+
|
|
191
|
+
sourceFiles:
|
|
192
|
+
- platform: react
|
|
193
|
+
file: ./Combobox.tsx
|
|
194
|
+
|
|
195
|
+
imports:
|
|
196
|
+
- platform: react
|
|
197
|
+
code: >-
|
|
198
|
+
import { Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList } from "@designil/labdsnov"
|
|
199
|
+
package: "@designil/labdsnov"
|
|
200
|
+
|
|
201
|
+
traits:
|
|
202
|
+
- traitType: variant
|
|
203
|
+
kind: boolean
|
|
204
|
+
id: multiple
|
|
205
|
+
description: >-
|
|
206
|
+
Several values can be picked; used with chips
|
|
207
|
+
- traitType: variant
|
|
208
|
+
kind: boolean
|
|
209
|
+
id: showTrigger
|
|
210
|
+
description: >-
|
|
211
|
+
Chevron button that opens the list (default `true`)
|
|
212
|
+
- traitType: variant
|
|
213
|
+
kind: boolean
|
|
214
|
+
id: showClear
|
|
215
|
+
description: >-
|
|
216
|
+
"×" button that clears the value
|
|
217
|
+
- traitType: state
|
|
218
|
+
kind: boolean
|
|
219
|
+
id: disabled
|
|
220
|
+
description: >-
|
|
221
|
+
Disabled
|
|
222
|
+
- traitType: state
|
|
223
|
+
kind: boolean
|
|
224
|
+
id: open
|
|
225
|
+
description: >-
|
|
226
|
+
The list is open
|
|
227
|
+
|
|
228
|
+
uses:
|
|
229
|
+
- to: input-group
|
|
230
|
+
- to: label
|
|
231
|
+
alternatives:
|
|
232
|
+
- to: select
|
|
233
|
+
- to: radio-group
|
|
234
|
+
|
|
235
|
+
refs:
|
|
236
|
+
- href: ./Combobox.md
|
|
237
|
+
rel: relates-to
|
|
238
|
+
role: Thai usage doc
|
|
239
|
+
- href: ./Combobox.stories.tsx
|
|
240
|
+
rel: demo
|
|
241
|
+
role: CSF stories
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Combobox (ช่องค้นหาและเลือก)
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
ช่องที่พิมพ์เพื่อกรองรายการยาว แล้วเลือกค่า (หรือหลายค่า) จากรายการนั้น
|
|
6
|
+
|
|
7
|
+
## Import and usage
|
|
8
|
+
|
|
9
|
+
**ตั้งค่าครั้งเดียวในแอป** (ใช้ร่วมกันทุกคอมโพเนนต์):
|
|
10
|
+
|
|
11
|
+
1. ติดตั้ง `@designil/labdsnov` (`pnpm add @designil/labdsnov`) พร้อม `react` และ `react-dom` 19
|
|
12
|
+
2. import สไตล์ครั้งเดียวที่ root layout: `import "@designil/labdsnov/styles.css"`
|
|
13
|
+
3. กำหนดตัวแปร `--font-heading` (แอปใช้ IBM Plex Sans Thai) และใส่ class `dark` ที่ `<html>` เมื่อต้องการโหมดมืด
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import {
|
|
17
|
+
Combobox,
|
|
18
|
+
ComboboxContent,
|
|
19
|
+
ComboboxEmpty,
|
|
20
|
+
ComboboxInput,
|
|
21
|
+
ComboboxItem,
|
|
22
|
+
ComboboxList,
|
|
23
|
+
Label,
|
|
24
|
+
} from "@designil/labdsnov"
|
|
25
|
+
|
|
26
|
+
<Label htmlFor="country">ประเทศที่พำนักทางภาษี</Label>
|
|
27
|
+
<Combobox items={countries}>
|
|
28
|
+
<ComboboxInput id="country" placeholder="พิมพ์เพื่อค้นหา" />
|
|
29
|
+
<ComboboxContent>
|
|
30
|
+
<ComboboxEmpty>ไม่พบประเทศที่ค้นหา</ComboboxEmpty>
|
|
31
|
+
<ComboboxList>
|
|
32
|
+
{(item: string) => <ComboboxItem key={item} value={item}>{item}</ComboboxItem>}
|
|
33
|
+
</ComboboxList>
|
|
34
|
+
</ComboboxContent>
|
|
35
|
+
</Combobox>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
- ส่งรายการทั้งหมดเป็น `items` แล้วใช้ฟังก์ชันใน `ComboboxList` เพื่อแสดงเฉพาะที่ตรงกับคำค้น
|
|
39
|
+
- ใส่ `ComboboxEmpty` เสมอ แสดงเมื่อไม่มีรายการตรงกับคำค้น
|
|
40
|
+
- รายการที่เป็น object ใช้ `itemToStringLabel` ของ `Combobox` บอกว่าข้อความไหนใช้ค้นหาและแสดง
|
|
41
|
+
|
|
42
|
+
## When to use
|
|
43
|
+
|
|
44
|
+
- เลือกหนึ่งค่าจากรายการยาวมากที่ผู้ใช้รู้ชื่ออยู่แล้ว เช่น ประเทศ ธนาคาร
|
|
45
|
+
- เลือกหลายค่า (`multiple`) แสดงเป็นชิป เช่น ประเทศที่เคยทำงาน
|
|
46
|
+
|
|
47
|
+
## When not to use
|
|
48
|
+
|
|
49
|
+
| สถานการณ์ | ใช้แทน |
|
|
50
|
+
| ---------------------------------- | ------------ |
|
|
51
|
+
| รายการไม่ยาว (ไม่ถึงประมาณ 15 ตัวเลือก) | `Select` |
|
|
52
|
+
| 2–5 ตัวเลือกที่ควรเห็นทั้งหมด | `RadioGroup` |
|
|
53
|
+
| ข้อความอิสระที่ไม่ต้องตรงกับรายการ | `Input` |
|
|
54
|
+
|
|
55
|
+
TODO: ยังไม่ได้กำหนดจำนวนตัวเลือกที่ควรเปลี่ยนจาก `Select` เป็น Combobox
|
|
56
|
+
|
|
57
|
+
## Props and variants
|
|
58
|
+
|
|
59
|
+
### ComboboxInput
|
|
60
|
+
|
|
61
|
+
| Prop | ค่าเริ่มต้น | ความหมาย |
|
|
62
|
+
| ------------- | ------- | ----------------------------- |
|
|
63
|
+
| `showTrigger` | `true` | ปุ่มลูกศรเปิดรายการ |
|
|
64
|
+
| `showClear` | `false` | ปุ่ม "×" ล้างค่า (ซ่อนลูกศรเมื่อมีปุ่มนี้) |
|
|
65
|
+
| `disabled` | `false` | ปิดใช้งาน |
|
|
66
|
+
| `placeholder` | – | เช่น "พิมพ์เพื่อค้นหา" |
|
|
67
|
+
|
|
68
|
+
หน้าตาเหมือน `InputGroup` (และ `Input` แบบ `filled`) กว้างตามเนื้อหา ใส่ `className="w-full"` ในฟอร์ม
|
|
69
|
+
|
|
70
|
+
### Combobox
|
|
71
|
+
|
|
72
|
+
| Prop | ความหมาย |
|
|
73
|
+
| ------------------------- | ----------------------------------- |
|
|
74
|
+
| `items` | รายการทั้งหมด |
|
|
75
|
+
| `value` / `onValueChange` | ควบคุมค่าที่เลือกจากภายนอก |
|
|
76
|
+
| `defaultValue` | ค่าที่เลือกไว้ตอนแรก |
|
|
77
|
+
| `multiple` | เลือกได้หลายค่า (ใช้กับ `ComboboxChips`) |
|
|
78
|
+
|
|
79
|
+
### เลือกหลายค่า (ชิป)
|
|
80
|
+
|
|
81
|
+
ใช้ `ComboboxChips` + `ComboboxValue` + `ComboboxChip` + `ComboboxChipsInput` แทน `ComboboxInput` และส่ง `anchor` จาก `useComboboxAnchor()` ให้ `ComboboxContent` (ดู story `MultipleChips`) ชิปแต่ละอันมีปุ่ม "นำออก"
|
|
82
|
+
|
|
83
|
+
### ส่วนอื่น ๆ
|
|
84
|
+
|
|
85
|
+
`ComboboxGroup` + `ComboboxLabel` จัดกลุ่มรายการ, `ComboboxSeparator` เส้นคั่น, `ComboboxItem` `disabled` รายการที่เลือกไม่ได้ รายการที่เลือกแล้วมีเครื่องหมายถูกด้านขวา
|
|
86
|
+
|
|
87
|
+
## Tokens used
|
|
88
|
+
|
|
89
|
+
ค่าทั้งหมดมาจาก `src/styles/theme.css`
|
|
90
|
+
|
|
91
|
+
### Component tokens
|
|
92
|
+
|
|
93
|
+
token เฉพาะของคอมโพเนนต์นี้ ชี้ไปที่ semantic token ด้านล่าง เปลี่ยนที่นี่เพื่อปรับเฉพาะคอมโพเนนต์นี้ (โหมดมืด "–" = ใช้ค่าเดียวกับโหมดสว่าง)
|
|
94
|
+
|
|
95
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
96
|
+
| -------------------------- | --------------------- | ------------------- | ----------------------------------------------- |
|
|
97
|
+
| `--field-icon` | `--muted-foreground` | – | ไอคอนในช่อง เช่น ลูกศร |
|
|
98
|
+
| `--field-border` | `--control-border` | – | เส้นขอบช่องกรอก |
|
|
99
|
+
| `--field-bg` | `--input` 50% | – | พื้นช่องกรอก |
|
|
100
|
+
| `--menu-item-highlight-bg` | `--accent` | – | พื้นรายการที่ไฮไลต์ |
|
|
101
|
+
| `--menu-item-highlight-fg` | `--accent-foreground` | – | ตัวอักษรรายการที่ไฮไลต์ |
|
|
102
|
+
| `--menu-label-fg` | `--muted-foreground` | – | หัวข้อกลุ่ม, ปุ่มลัด |
|
|
103
|
+
| `--focus-ring` | `--ring` | – | วงแหวน focus จากคีย์บอร์ดของทุกคอมโพเนนต์ (ทึบ 2px) |
|
|
104
|
+
| `--invalid-border` | `--destructive` | – | เส้นขอบเมื่อข้อมูลไม่ถูกต้อง และวงแหวน focus ขณะไม่ถูกต้อง |
|
|
105
|
+
| `--invalid-ring` | `--destructive` 20% | `--destructive` 40% | วงแหวนจางรอบช่องที่ไม่ถูกต้อง (ตกแต่ง) |
|
|
106
|
+
|
|
107
|
+
### Semantic tokens
|
|
108
|
+
|
|
109
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
110
|
+
| ---------------------- | -------------------------- | -------------------------- | --------------------------- |
|
|
111
|
+
| `--input` | `oklch(0.93 0.007 106.5)` | `oklch(1 0 0 / 15%)` | พื้นช่องกรอกและชิป |
|
|
112
|
+
| `--popover` | `oklch(1 0 0)` | `oklch(0.228 0.013 107.4)` | พื้นรายการ |
|
|
113
|
+
| `--popover-foreground` | `oklch(0.153 0.006 107.1)` | `oklch(0.988 0.003 106.5)` | ตัวอักษรในรายการ |
|
|
114
|
+
| `--accent` | `oklch(0.966 0.005 106.5)` | `oklch(0.286 0.016 107.4)` | พื้นรายการที่ไฮไลต์ |
|
|
115
|
+
| `--accent-foreground` | `oklch(0.228 0.013 107.4)` | `oklch(0.988 0.003 106.5)` | ตัวอักษรรายการที่ไฮไลต์ |
|
|
116
|
+
| `--muted-foreground` | `oklch(0.5 0.027 107.3)` | `oklch(0.737 0.021 106.9)` | ลูกศร, หัวข้อกลุ่ม, ข้อความไม่พบ |
|
|
117
|
+
| `--border` | `oklch(0.93 0.007 106.5)` | `oklch(1 0 0 / 10%)` | เส้นคั่น |
|
|
118
|
+
| `--ring` | `oklch(0.45 0.03 106.9)` | `oklch(0.8 0.02 106.9)` | วงแหวน focus |
|
|
119
|
+
| `--destructive` | `oklch(0.505 0.2 27.325)` | `oklch(0.75 0.16 22.216)` | สถานะไม่ถูกต้อง |
|
|
120
|
+
| `--control-border` | `oklch(0.6 0.02 106.9)` | `oklch(0.55 0.015 106.9)` | ผ่าน token ของคอมโพเนนต์ด้านบน |
|
|
121
|
+
|
|
122
|
+
## Example
|
|
123
|
+
|
|
124
|
+
จาก story `MultipleChips` ใน `Combobox.stories.tsx`:
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
const anchor = useComboboxAnchor()
|
|
128
|
+
|
|
129
|
+
<Combobox items={countries} multiple defaultValue={["ไทย", "ออสเตรเลีย"]}>
|
|
130
|
+
<ComboboxChips ref={anchor}>
|
|
131
|
+
<ComboboxValue>
|
|
132
|
+
{(values: string[]) => values.map((value) => <ComboboxChip key={value}>{value}</ComboboxChip>)}
|
|
133
|
+
</ComboboxValue>
|
|
134
|
+
<ComboboxChipsInput id="cb-chips" placeholder="เพิ่มประเทศ" />
|
|
135
|
+
</ComboboxChips>
|
|
136
|
+
<ComboboxContent anchor={anchor}>
|
|
137
|
+
<ComboboxEmpty>ไม่พบประเทศที่ค้นหา</ComboboxEmpty>
|
|
138
|
+
<ComboboxList>
|
|
139
|
+
{(item: string) => <ComboboxItem key={item} value={item}>{item}</ComboboxItem>}
|
|
140
|
+
</ComboboxList>
|
|
141
|
+
</ComboboxContent>
|
|
142
|
+
</Combobox>
|
|
143
|
+
```
|