@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,198 @@
|
|
|
1
|
+
kind: component
|
|
2
|
+
id: switch
|
|
3
|
+
name: Switch
|
|
4
|
+
description: >-
|
|
5
|
+
An on/off switch for a setting that takes effect immediately. Dark grey track when
|
|
6
|
+
off, primary (orange) when on. Wraps Base UI `Switch`.
|
|
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 for settings that take effect as soon as they're switched, with no save
|
|
20
|
+
button, e.g. notifications, receiving documents by email.
|
|
21
|
+
- level: must-not
|
|
22
|
+
statement: >-
|
|
23
|
+
Never use for a form value that applies on submit (e.g. accepting terms). Use
|
|
24
|
+
<dsds:checkbox>.
|
|
25
|
+
alternatives:
|
|
26
|
+
- to: checkbox
|
|
27
|
+
checkedBy: manual
|
|
28
|
+
- level: must-not
|
|
29
|
+
statement: >-
|
|
30
|
+
Never use to pick one of several options. Use <dsds:radio-group>.
|
|
31
|
+
alternatives:
|
|
32
|
+
- to: radio-group
|
|
33
|
+
checkedBy: manual
|
|
34
|
+
- level: should-not
|
|
35
|
+
statement: >-
|
|
36
|
+
Don't use as an on/off display option in a toolbar (e.g. bold). Use
|
|
37
|
+
<dsds:toggle>.
|
|
38
|
+
alternatives:
|
|
39
|
+
- to: toggle
|
|
40
|
+
|
|
41
|
+
- kind: guidelines
|
|
42
|
+
for: all
|
|
43
|
+
items:
|
|
44
|
+
- id: label-describes-on
|
|
45
|
+
level: must
|
|
46
|
+
statement: >-
|
|
47
|
+
The label says what is on when the switch is on ("รับใบแจ้งยอดทางอีเมล"
|
|
48
|
+
(receive statements by email)). The label doesn't change with the state and
|
|
49
|
+
doesn't say "on/off".
|
|
50
|
+
checkedBy: manual
|
|
51
|
+
- id: label-bound
|
|
52
|
+
level: must
|
|
53
|
+
statement: >-
|
|
54
|
+
Tie a <dsds:label> with `id` / `htmlFor` so clicking the text toggles it. In
|
|
55
|
+
settings forms use `Field orientation="horizontal"` or `responsive`.
|
|
56
|
+
checks:
|
|
57
|
+
- href: ./Switch.stories.tsx#Toggle
|
|
58
|
+
role: test
|
|
59
|
+
note: play function clicks the switch and the label text and checks it toggles
|
|
60
|
+
uses:
|
|
61
|
+
- to: label
|
|
62
|
+
- to: field
|
|
63
|
+
checkedBy: automated
|
|
64
|
+
- id: save-immediately
|
|
65
|
+
level: must
|
|
66
|
+
statement: >-
|
|
67
|
+
Save immediately in `onCheckedChange`. If saving fails, put the switch back and
|
|
68
|
+
tell the user (how isn't defined yet, see Open decisions).
|
|
69
|
+
checkedBy: manual
|
|
70
|
+
- id: size-default
|
|
71
|
+
level: should
|
|
72
|
+
statement: >-
|
|
73
|
+
Use `size="default"` (44×20px track). `sm` (28×16px) has no defined use yet.
|
|
74
|
+
checkedBy: manual
|
|
75
|
+
|
|
76
|
+
- kind: guidelines
|
|
77
|
+
for: all
|
|
78
|
+
title: Accessibility
|
|
79
|
+
tags: [accessibility]
|
|
80
|
+
items:
|
|
81
|
+
- id: space-toggles
|
|
82
|
+
level: must
|
|
83
|
+
statement: >-
|
|
84
|
+
Tab to the switch and press Space to toggle (`role="switch"`, `aria-checked`).
|
|
85
|
+
evidence:
|
|
86
|
+
- href: https://www.w3.org/WAI/ARIA/apg/patterns/switch/
|
|
87
|
+
role: WAI-ARIA APG Switch pattern
|
|
88
|
+
checks:
|
|
89
|
+
- href: ./Switch.stories.tsx#Toggle
|
|
90
|
+
role: test
|
|
91
|
+
checkedBy: automated
|
|
92
|
+
- id: track-contrast
|
|
93
|
+
level: must
|
|
94
|
+
statement: >-
|
|
95
|
+
The off track (`--switch-track`) passes 3.93:1 / 4.05:1, the off thumb
|
|
96
|
+
3.93:1 / 4.68:1 and the on thumb 4.93:1 / 6.46:1 (light / dark). Never change the
|
|
97
|
+
off track to a light grey (`--muted`).
|
|
98
|
+
refines:
|
|
99
|
+
- to: shared-a11y#non-text-contrast
|
|
100
|
+
checks:
|
|
101
|
+
- href: ../../../scripts/tokens.mjs
|
|
102
|
+
role: test
|
|
103
|
+
note: CONTRAST_PAIRS "ราง Switch …" and "ปุ่มเลื่อน Switch …"
|
|
104
|
+
checkedBy: automated
|
|
105
|
+
- refs:
|
|
106
|
+
- to: shared-a11y#target-size
|
|
107
|
+
rel: same-as
|
|
108
|
+
|
|
109
|
+
- kind: definitions
|
|
110
|
+
for: all
|
|
111
|
+
title: States
|
|
112
|
+
context: labdsnov.states
|
|
113
|
+
items:
|
|
114
|
+
- term: Off
|
|
115
|
+
definition: >-
|
|
116
|
+
Dark grey track, thumb on the left.
|
|
117
|
+
- term: On
|
|
118
|
+
definition: >-
|
|
119
|
+
Primary-colour track, thumb moved to the right.
|
|
120
|
+
- term: aria-invalid
|
|
121
|
+
definition: >-
|
|
122
|
+
Red border and faint red ring.
|
|
123
|
+
- term: Disabled
|
|
124
|
+
definition: >-
|
|
125
|
+
50% opacity.
|
|
126
|
+
|
|
127
|
+
- kind: section
|
|
128
|
+
for: all
|
|
129
|
+
title: Open decisions
|
|
130
|
+
freeform:
|
|
131
|
+
- title: TODO
|
|
132
|
+
body: >-
|
|
133
|
+
Not defined how to tell the user a setting saved or failed to save (e.g. a
|
|
134
|
+
toast), and no defined use for size `sm`.
|
|
135
|
+
|
|
136
|
+
sourceFiles:
|
|
137
|
+
- platform: react
|
|
138
|
+
file: ./Switch.tsx
|
|
139
|
+
|
|
140
|
+
imports:
|
|
141
|
+
- platform: react
|
|
142
|
+
code: >-
|
|
143
|
+
import { Switch } from "@designil/labdsnov"
|
|
144
|
+
package: "@designil/labdsnov"
|
|
145
|
+
|
|
146
|
+
traits:
|
|
147
|
+
- traitType: variant
|
|
148
|
+
kind: enum
|
|
149
|
+
id: size
|
|
150
|
+
description: >-
|
|
151
|
+
Track size.
|
|
152
|
+
values:
|
|
153
|
+
- id: default
|
|
154
|
+
description: >-
|
|
155
|
+
44×20px.
|
|
156
|
+
- id: sm
|
|
157
|
+
description: >-
|
|
158
|
+
28×16px, no defined use yet.
|
|
159
|
+
- traitType: state
|
|
160
|
+
kind: boolean
|
|
161
|
+
id: checked
|
|
162
|
+
description: >-
|
|
163
|
+
Switched on.
|
|
164
|
+
- traitType: state
|
|
165
|
+
kind: boolean
|
|
166
|
+
id: disabled
|
|
167
|
+
description: >-
|
|
168
|
+
Disabled.
|
|
169
|
+
- traitType: state
|
|
170
|
+
kind: boolean
|
|
171
|
+
id: aria-invalid
|
|
172
|
+
name: Invalid
|
|
173
|
+
description: >-
|
|
174
|
+
Invalid value.
|
|
175
|
+
|
|
176
|
+
uses:
|
|
177
|
+
- to: label
|
|
178
|
+
alternatives:
|
|
179
|
+
- to: checkbox
|
|
180
|
+
- to: toggle
|
|
181
|
+
|
|
182
|
+
refs:
|
|
183
|
+
- href: ./Switch.md
|
|
184
|
+
rel: relates-to
|
|
185
|
+
role: Thai usage doc
|
|
186
|
+
- href: ./Switch.stories.tsx
|
|
187
|
+
rel: demo
|
|
188
|
+
role: CSF stories
|
|
189
|
+
- href: https://www.figma.com/design/QsKWb3A53lIh4QBDnAkGHh/labdsnov?node-id=12-89
|
|
190
|
+
rel: design
|
|
191
|
+
role: Switch in Figma
|
|
192
|
+
- href: ../../../figma/Switch.figma.ts
|
|
193
|
+
rel: source
|
|
194
|
+
role: Code Connect template
|
|
195
|
+
|
|
196
|
+
$extensions:
|
|
197
|
+
com.figma:
|
|
198
|
+
nodeId: "12:89"
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Switch (สวิตช์เปิด/ปิด)
|
|
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 { Label, Switch } from "@designil/labdsnov"
|
|
17
|
+
|
|
18
|
+
;<div className="flex items-center gap-2">
|
|
19
|
+
<Switch id="email-statements" />
|
|
20
|
+
<Label htmlFor="email-statements">รับใบแจ้งยอดทางอีเมล</Label>
|
|
21
|
+
</div>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## When to use
|
|
25
|
+
|
|
26
|
+
- การตั้งค่าที่เปิด/ปิดแล้วมีผลทันที ไม่ต้องกดบันทึก เช่น การแจ้งเตือน การรับเอกสารทางอีเมล
|
|
27
|
+
|
|
28
|
+
## When not to use
|
|
29
|
+
|
|
30
|
+
- **ค่าในฟอร์มที่มีผลเมื่อกดส่ง** (เช่น ยอมรับเงื่อนไข): ใช้ `Checkbox`
|
|
31
|
+
- **เลือกหนึ่งจากหลายตัวเลือก**: ใช้ `RadioGroup`
|
|
32
|
+
- TODO: ยังไม่ได้กำหนดว่าจะแจ้งผู้ใช้อย่างไรเมื่อบันทึกการตั้งค่าสำเร็จหรือไม่สำเร็จ (เช่น ใช้ `toast`)
|
|
33
|
+
|
|
34
|
+
## Props and variants
|
|
35
|
+
|
|
36
|
+
| Prop | ค่า | ค่าเริ่มต้น | ความหมาย |
|
|
37
|
+
| ----------------------------- | ----------------- | --------- | ------------------------------------- |
|
|
38
|
+
| `size` | `default`, `sm` | `default` | ขนาด (ดูตารางด้านล่าง) |
|
|
39
|
+
| `checked` / `onCheckedChange` | `boolean` / ฟังก์ชัน | – | ควบคุมจากภายนอก |
|
|
40
|
+
| `defaultChecked` | `boolean` | `false` | เปิดไว้ตั้งแต่แรก |
|
|
41
|
+
| `disabled` | `boolean` | `false` | ปิดใช้งาน จางลง 50% |
|
|
42
|
+
| `aria-invalid` | `boolean` | – | ข้อมูลไม่ถูกต้อง เส้นขอบสีแดงและวงแหวนแดงจาง |
|
|
43
|
+
| `className` | class | – | ปรับหน้าตาเฉพาะจุดครั้งเดียว |
|
|
44
|
+
|
|
45
|
+
| Size | ขนาดราง | ใช้เมื่อ |
|
|
46
|
+
| --------- | ------- | ------------------------- |
|
|
47
|
+
| `default` | 44×20px | ค่าเริ่มต้น |
|
|
48
|
+
| `sm` | 28×16px | TODO: ยังไม่ได้กำหนดการใช้งาน |
|
|
49
|
+
|
|
50
|
+
### States
|
|
51
|
+
|
|
52
|
+
- **ปิด**: รางสีเทาเข้ม (contrast 3:1) ปุ่มกลมอยู่ซ้าย
|
|
53
|
+
- **เปิด**: รางสีหลัก (ส้ม) ปุ่มกลมเลื่อนไปขวา
|
|
54
|
+
- **Focus จากคีย์บอร์ด**: วงแหวนทึบสี `--focus-ring` กด Space เพื่อสลับ
|
|
55
|
+
|
|
56
|
+
## Tokens used
|
|
57
|
+
|
|
58
|
+
ค่าทั้งหมดมาจาก `src/styles/theme.css`
|
|
59
|
+
|
|
60
|
+
### Component tokens
|
|
61
|
+
|
|
62
|
+
token เฉพาะของคอมโพเนนต์นี้ ชี้ไปที่ semantic token ด้านล่าง เปลี่ยนที่นี่เพื่อปรับเฉพาะคอมโพเนนต์นี้ (โหมดมืด "–" = ใช้ค่าเดียวกับโหมดสว่าง)
|
|
63
|
+
|
|
64
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
65
|
+
| ------------------------ | ---------------------- | ------------------- | ----------------------------------------------- |
|
|
66
|
+
| `--control-checked-bg` | `--primary` | – | พื้นและเส้นขอบตอนเลือก |
|
|
67
|
+
| `--switch-track` | `--control-border` | – | ราง Switch ตอนปิด |
|
|
68
|
+
| `--switch-thumb` | `--background` | `--foreground` | ปุ่มเลื่อน Switch ตอนปิด |
|
|
69
|
+
| `--switch-thumb-checked` | `--primary-foreground` | – | ปุ่มเลื่อน Switch ตอนเปิด |
|
|
70
|
+
| `--focus-ring` | `--ring` | – | วงแหวน focus จากคีย์บอร์ดของทุกคอมโพเนนต์ (ทึบ 2px) |
|
|
71
|
+
| `--invalid-border` | `--destructive` | – | เส้นขอบเมื่อข้อมูลไม่ถูกต้อง และวงแหวน focus ขณะไม่ถูกต้อง |
|
|
72
|
+
| `--invalid-ring` | `--destructive` 20% | `--destructive` 40% | วงแหวนจางรอบช่องที่ไม่ถูกต้อง (ตกแต่ง) |
|
|
73
|
+
|
|
74
|
+
### Semantic tokens
|
|
75
|
+
|
|
76
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
77
|
+
| ---------------------- | --------------------------- | --------------------------- | --------------------------- |
|
|
78
|
+
| `--primary` | `oklch(0.553 0.195 38.402)` | `oklch(0.705 0.187 47.604)` | รางเมื่อเปิด |
|
|
79
|
+
| `--background` | `oklch(1 0 0)` | `oklch(0.153 0.006 107.1)` | ปุ่มกลม (โหมดสว่าง) |
|
|
80
|
+
| `--primary-foreground` | `oklch(0.98 0.016 73.684)` | `oklch(0.205 0.05 40)` | ปุ่มกลมเมื่อเปิด (โหมดมืด) |
|
|
81
|
+
| `--foreground` | `oklch(0.153 0.006 107.1)` | `oklch(0.988 0.003 106.5)` | ปุ่มกลมเมื่อปิด (โหมดมืด) |
|
|
82
|
+
| `--ring` | `oklch(0.45 0.03 106.9)` | `oklch(0.8 0.02 106.9)` | วงแหวน focus |
|
|
83
|
+
| `--destructive` | `oklch(0.505 0.2 27.325)` | `oklch(0.75 0.16 22.216)` | สถานะไม่ถูกต้อง |
|
|
84
|
+
| `--control-border` | `oklch(0.6 0.02 106.9)` | `oklch(0.55 0.015 106.9)` | ผ่าน token ของคอมโพเนนต์ด้านบน |
|
|
85
|
+
|
|
86
|
+
## Example
|
|
87
|
+
|
|
88
|
+
จาก story `States` ใน `Switch.stories.tsx` (บางส่วน):
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
<div className="grid gap-3">
|
|
92
|
+
<div className="flex items-center gap-2">
|
|
93
|
+
<Switch id="sw-on" defaultChecked />
|
|
94
|
+
<Label htmlFor="sw-on">เปิด</Label>
|
|
95
|
+
</div>
|
|
96
|
+
<div className="flex items-center gap-2">
|
|
97
|
+
<Switch id="sw-disabled" disabled defaultChecked />
|
|
98
|
+
<Label htmlFor="sw-disabled">ปิดใช้งาน</Label>
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
```
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
kind: component
|
|
2
|
+
id: table
|
|
3
|
+
name: Table
|
|
4
|
+
description: >-
|
|
5
|
+
A data table in rows and columns that is easy to read and compare, e.g. a
|
|
6
|
+
transaction list. Has a wrapper that scrolls horizontally. Structure only: no
|
|
7
|
+
sorting, filtering or pagination.
|
|
8
|
+
metadata:
|
|
9
|
+
status: {status: stable}
|
|
10
|
+
since: 1.0.0
|
|
11
|
+
tags: [data-display]
|
|
12
|
+
|
|
13
|
+
sections:
|
|
14
|
+
- kind: guidelines
|
|
15
|
+
for: all
|
|
16
|
+
framing: when-to-use
|
|
17
|
+
items:
|
|
18
|
+
- level: should
|
|
19
|
+
statement: >-
|
|
20
|
+
Use for many rows with the same columns that must be compared across rows, e.g.
|
|
21
|
+
transactions, monthly contributions.
|
|
22
|
+
- level: should-not
|
|
23
|
+
statement: >-
|
|
24
|
+
Don't use for a few values about one thing. Use <dsds:card>.
|
|
25
|
+
alternatives:
|
|
26
|
+
- to: card
|
|
27
|
+
- level: should-not
|
|
28
|
+
statement: >-
|
|
29
|
+
Don't use to list investment options. Use <dsds:fund-card> (except for tables
|
|
30
|
+
that compare numbers).
|
|
31
|
+
alternatives:
|
|
32
|
+
- to: fund-card
|
|
33
|
+
- level: must-not
|
|
34
|
+
statement: >-
|
|
35
|
+
Never use a table for page layout. Use CSS grid / flex.
|
|
36
|
+
checkedBy: manual
|
|
37
|
+
|
|
38
|
+
- kind: guidelines
|
|
39
|
+
for: all
|
|
40
|
+
items:
|
|
41
|
+
- id: money-right-tabular
|
|
42
|
+
level: must
|
|
43
|
+
statement: >-
|
|
44
|
+
Money columns are right-aligned (`text-right`) and use `tabular-nums` on both
|
|
45
|
+
`TableHead` and `TableCell`, so decimal points line up. Write "AU$1,245.00"
|
|
46
|
+
(2 decimals).
|
|
47
|
+
checkedBy: manual
|
|
48
|
+
- id: thai-dates
|
|
49
|
+
level: must
|
|
50
|
+
statement: >-
|
|
51
|
+
Date columns use the format "13 พ.ย. 2569" (`Intl` `th-TH`, short month,
|
|
52
|
+
Buddhist year).
|
|
53
|
+
refines:
|
|
54
|
+
- to: shared-content#buddhist-year
|
|
55
|
+
checkedBy: manual
|
|
56
|
+
- id: status-as-badge
|
|
57
|
+
level: should
|
|
58
|
+
statement: >-
|
|
59
|
+
Status columns use <dsds:badge> (`success` / `warning` / `destructive`)
|
|
60
|
+
following Badge's rules.
|
|
61
|
+
uses:
|
|
62
|
+
- to: badge
|
|
63
|
+
refs:
|
|
64
|
+
- to: badge#status-mapping
|
|
65
|
+
rel: relates-to
|
|
66
|
+
checkedBy: manual
|
|
67
|
+
- id: footer-totals
|
|
68
|
+
level: should
|
|
69
|
+
statement: >-
|
|
70
|
+
Put totals in `TableFooter` (faint grey background, medium weight). Use
|
|
71
|
+
`colSpan` for the "รวม" (total) label cell.
|
|
72
|
+
checkedBy: manual
|
|
73
|
+
- id: row-actions-menu
|
|
74
|
+
level: should
|
|
75
|
+
statement: >-
|
|
76
|
+
Per-row actions use a "…" button opening a <dsds:dropdown-menu> in the last
|
|
77
|
+
column, not several buttons per row.
|
|
78
|
+
uses:
|
|
79
|
+
- to: dropdown-menu
|
|
80
|
+
checkedBy: manual
|
|
81
|
+
- id: selected-row
|
|
82
|
+
level: may
|
|
83
|
+
statement: >-
|
|
84
|
+
Highlight a selected row with `data-state="selected"` on `TableRow`.
|
|
85
|
+
- id: long-list-pagination
|
|
86
|
+
level: should
|
|
87
|
+
statement: >-
|
|
88
|
+
Tables longer than about 25 rows use <dsds:pagination> below the table.
|
|
89
|
+
uses:
|
|
90
|
+
- to: pagination
|
|
91
|
+
checkedBy: manual
|
|
92
|
+
- id: no-wrap-awareness
|
|
93
|
+
level: should-not
|
|
94
|
+
statement: >-
|
|
95
|
+
Don't put long text in cells. Cell text doesn't wrap, so the table gets wide and
|
|
96
|
+
must scroll sideways on mobile.
|
|
97
|
+
|
|
98
|
+
- kind: guidelines
|
|
99
|
+
for: all
|
|
100
|
+
title: Accessibility
|
|
101
|
+
tags: [accessibility]
|
|
102
|
+
items:
|
|
103
|
+
- id: caption-required
|
|
104
|
+
level: must
|
|
105
|
+
statement: >-
|
|
106
|
+
Always add a `TableCaption`. It is the table's name for screen readers (shown
|
|
107
|
+
below the table).
|
|
108
|
+
evidence:
|
|
109
|
+
- href: https://www.w3.org/WAI/tutorials/tables/caption-summary/
|
|
110
|
+
role: W3C WAI Tables Tutorial, Caption & Summary
|
|
111
|
+
checkedBy: manual
|
|
112
|
+
- id: header-cells
|
|
113
|
+
level: must
|
|
114
|
+
statement: >-
|
|
115
|
+
Column headers use `TableHead` (`<th>`) inside `TableHeader`, not a bold
|
|
116
|
+
`TableCell`.
|
|
117
|
+
evidence:
|
|
118
|
+
- href: https://www.w3.org/WAI/WCAG22/Understanding/info-and-relationships.html
|
|
119
|
+
role: WCAG 2.2 SC 1.3.1 (A)
|
|
120
|
+
checks:
|
|
121
|
+
- href: ./Table.stories.tsx#Playground
|
|
122
|
+
role: test
|
|
123
|
+
note: play function checks 4 columnheaders and 6 rows
|
|
124
|
+
checkedBy: automated
|
|
125
|
+
- id: reflow
|
|
126
|
+
level: should
|
|
127
|
+
statement: >-
|
|
128
|
+
A wide table scrolls horizontally inside its wrapper and doesn't make the whole
|
|
129
|
+
page scroll sideways (see story `NarrowScreen`). Switching to a card list on
|
|
130
|
+
narrow screens is undecided.
|
|
131
|
+
evidence:
|
|
132
|
+
- href: https://www.w3.org/WAI/WCAG22/Understanding/reflow.html
|
|
133
|
+
role: WCAG 2.2 SC 1.4.10 (AA)
|
|
134
|
+
checkedBy: manual
|
|
135
|
+
|
|
136
|
+
- kind: definitions
|
|
137
|
+
for: all
|
|
138
|
+
context: anatomy
|
|
139
|
+
items:
|
|
140
|
+
- term: Table
|
|
141
|
+
definition: >-
|
|
142
|
+
`<table>` in a horizontally scrolling wrapper, full width.
|
|
143
|
+
- term: TableCaption
|
|
144
|
+
definition: >-
|
|
145
|
+
The table name, shown below the table.
|
|
146
|
+
- term: TableHeader / TableHead
|
|
147
|
+
definition: >-
|
|
148
|
+
`<thead>` / `<th>`, column headers 48px tall.
|
|
149
|
+
- term: TableBody / TableRow / TableCell
|
|
150
|
+
definition: >-
|
|
151
|
+
Rows get a faint background on hover; cells have 12px padding.
|
|
152
|
+
- term: TableFooter
|
|
153
|
+
definition: >-
|
|
154
|
+
Summary row, faint grey background, medium weight.
|
|
155
|
+
|
|
156
|
+
- kind: section
|
|
157
|
+
for: all
|
|
158
|
+
title: Open decisions
|
|
159
|
+
freeform:
|
|
160
|
+
- title: TODO
|
|
161
|
+
body: >-
|
|
162
|
+
No data table with sorting, filtering and pagination yet, and not decided
|
|
163
|
+
whether to switch to a card list on narrow screens.
|
|
164
|
+
|
|
165
|
+
sourceFiles:
|
|
166
|
+
- platform: react
|
|
167
|
+
file: ./Table.tsx
|
|
168
|
+
|
|
169
|
+
imports:
|
|
170
|
+
- platform: react
|
|
171
|
+
code: >-
|
|
172
|
+
import { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow } from "@designil/labdsnov"
|
|
173
|
+
package: "@designil/labdsnov"
|
|
174
|
+
|
|
175
|
+
traits:
|
|
176
|
+
- traitType: state
|
|
177
|
+
kind: boolean
|
|
178
|
+
id: selected
|
|
179
|
+
description: >-
|
|
180
|
+
A `TableRow` with `data-state="selected"` gets a highlighted background.
|
|
181
|
+
|
|
182
|
+
uses:
|
|
183
|
+
- to: badge
|
|
184
|
+
alternatives:
|
|
185
|
+
- to: card
|
|
186
|
+
- to: fund-card
|
|
187
|
+
- to: chart
|
|
188
|
+
|
|
189
|
+
refs:
|
|
190
|
+
- href: ./Table.md
|
|
191
|
+
rel: relates-to
|
|
192
|
+
role: Thai usage doc
|
|
193
|
+
- href: ./Table.stories.tsx
|
|
194
|
+
rel: demo
|
|
195
|
+
role: CSF stories
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Table (ตาราง)
|
|
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
|
+
Table,
|
|
18
|
+
TableBody,
|
|
19
|
+
TableCaption,
|
|
20
|
+
TableCell,
|
|
21
|
+
TableHead,
|
|
22
|
+
TableHeader,
|
|
23
|
+
TableRow,
|
|
24
|
+
} from "@designil/labdsnov"
|
|
25
|
+
|
|
26
|
+
;<Table>
|
|
27
|
+
<TableCaption>ธุรกรรมล่าสุดในบัญชีของคุณ</TableCaption>
|
|
28
|
+
<TableHeader>
|
|
29
|
+
<TableRow>
|
|
30
|
+
<TableHead>วันที่</TableHead>
|
|
31
|
+
<TableHead className="text-right">จำนวนเงิน</TableHead>
|
|
32
|
+
</TableRow>
|
|
33
|
+
</TableHeader>
|
|
34
|
+
<TableBody>
|
|
35
|
+
<TableRow>
|
|
36
|
+
<TableCell>13 พ.ย. 2569</TableCell>
|
|
37
|
+
<TableCell className="text-right tabular-nums">AU$1,245.00</TableCell>
|
|
38
|
+
</TableRow>
|
|
39
|
+
</TableBody>
|
|
40
|
+
</Table>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
- ใส่ `TableCaption` เสมอ เป็นชื่อของตารางสำหรับโปรแกรมอ่านหน้าจอ (แสดงใต้ตาราง)
|
|
44
|
+
- ตัวเลขเงิน: ชิดขวา (`text-right`) และใช้ตัวเลขความกว้างเท่ากัน (`tabular-nums`) ทั้งหัวคอลัมน์และเซลล์
|
|
45
|
+
|
|
46
|
+
## When to use
|
|
47
|
+
|
|
48
|
+
- ข้อมูลหลายแถวที่มีคอลัมน์เหมือนกัน และต้องเปรียบเทียบระหว่างแถว เช่น ธุรกรรม เงินสมทบรายเดือน
|
|
49
|
+
|
|
50
|
+
## When not to use
|
|
51
|
+
|
|
52
|
+
- **ข้อมูลเรื่องเดียวไม่กี่ค่า**: ใช้ `Card`
|
|
53
|
+
- **ตัวเลือกการลงทุน**: ใช้ `FundCard`
|
|
54
|
+
- **จัดหน้า (layout)**: ใช้ CSS grid / flex ไม่ใช่ตาราง
|
|
55
|
+
- **เรียงลำดับ กรอง แบ่งหน้า**: TODO: Table เป็นแค่โครงตาราง ยังไม่มีคอมโพเนนต์ data table ที่ทำสิ่งเหล่านี้
|
|
56
|
+
|
|
57
|
+
## Anatomy
|
|
58
|
+
|
|
59
|
+
- **Table** (มีกล่องครอบที่เลื่อนแนวนอนได้)
|
|
60
|
+
- **TableCaption**: ชื่อตาราง
|
|
61
|
+
- **TableHeader** → **TableRow** → **TableHead**: หัวคอลัมน์
|
|
62
|
+
- **TableBody** → **TableRow** → **TableCell**
|
|
63
|
+
- **TableFooter**: แถวสรุป เช่น ยอดรวม (พื้นสีเทาจาง ตัวอักษร medium)
|
|
64
|
+
|
|
65
|
+
## Props and variants
|
|
66
|
+
|
|
67
|
+
ไม่มี variant หรือ size ทุกส่วนรับ props ของ element ตารางปกติ (เช่น `colSpan`) และ `className`
|
|
68
|
+
|
|
69
|
+
- ตารางกว้างเต็มพื้นที่ ข้อความในเซลล์ไม่ขึ้นบรรทัดใหม่ ถ้าตารางกว้างกว่าจอ ผู้ใช้เลื่อนตารางไปด้านข้างได้
|
|
70
|
+
- แถวมีพื้นจางเมื่อ hover ใส่ `data-state="selected"` ที่ `TableRow` เพื่อไฮไลต์แถวที่เลือก
|
|
71
|
+
- หัวคอลัมน์สูง 48px เซลล์มีระยะขอบใน 12px
|
|
72
|
+
- TODO: บนมือถือ ตารางกว้างต้องเลื่อนด้านข้าง ยังไม่ได้ตัดสินใจว่าจะเปลี่ยนเป็นรายการการ์ดบนจอแคบหรือไม่
|
|
73
|
+
|
|
74
|
+
## Tokens used
|
|
75
|
+
|
|
76
|
+
ค่าทั้งหมดมาจาก `src/styles/theme.css`
|
|
77
|
+
|
|
78
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
79
|
+
| -------------------- | -------------------------- | -------------------------- | -------------------------------------------- |
|
|
80
|
+
| `--border` | `oklch(0.93 0.007 106.5)` | `oklch(1 0 0 / 10%)` | เส้นคั่นแถว |
|
|
81
|
+
| `--muted` | `oklch(0.966 0.005 106.5)` | `oklch(0.286 0.016 107.4)` | พื้นแถวตอน hover (50%), แถวที่เลือก, แถวสรุป (50%) |
|
|
82
|
+
| `--foreground` | `oklch(0.153 0.006 107.1)` | `oklch(0.988 0.003 106.5)` | หัวคอลัมน์ |
|
|
83
|
+
| `--muted-foreground` | `oklch(0.5 0.027 107.3)` | `oklch(0.737 0.021 106.9)` | ชื่อตาราง (caption) |
|
|
84
|
+
|
|
85
|
+
## Example
|
|
86
|
+
|
|
87
|
+
จาก story `Playground` ใน `Table.stories.tsx` (แถวเดียว):
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
<Table>
|
|
91
|
+
<TableCaption>ธุรกรรมล่าสุดในบัญชีของคุณ</TableCaption>
|
|
92
|
+
<TableHeader>
|
|
93
|
+
<TableRow>
|
|
94
|
+
<TableHead>วันที่</TableHead>
|
|
95
|
+
<TableHead>รายการ</TableHead>
|
|
96
|
+
<TableHead>สถานะ</TableHead>
|
|
97
|
+
<TableHead className="text-right">จำนวนเงิน</TableHead>
|
|
98
|
+
</TableRow>
|
|
99
|
+
</TableHeader>
|
|
100
|
+
<TableBody>
|
|
101
|
+
<TableRow>
|
|
102
|
+
<TableCell>13 พ.ย. 2569</TableCell>
|
|
103
|
+
<TableCell>เงินสมทบจากนายจ้าง</TableCell>
|
|
104
|
+
<TableCell>
|
|
105
|
+
<Badge variant="success">สำเร็จ</Badge>
|
|
106
|
+
</TableCell>
|
|
107
|
+
<TableCell className="text-right tabular-nums">AU$1,245.00</TableCell>
|
|
108
|
+
</TableRow>
|
|
109
|
+
</TableBody>
|
|
110
|
+
<TableFooter>
|
|
111
|
+
<TableRow>
|
|
112
|
+
<TableCell colSpan={3}>รวม</TableCell>
|
|
113
|
+
<TableCell className="text-right tabular-nums">AU$1,245.00</TableCell>
|
|
114
|
+
</TableRow>
|
|
115
|
+
</TableFooter>
|
|
116
|
+
</Table>
|
|
117
|
+
```
|