@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,226 @@
|
|
|
1
|
+
kind: component
|
|
2
|
+
id: toaster
|
|
3
|
+
name: Toaster
|
|
4
|
+
description: >-
|
|
5
|
+
Short messages that float up in a screen corner, report the result of an
|
|
6
|
+
action, then go away by themselves (`toast()`). Built on `sonner`, but it reads
|
|
7
|
+
dark mode from the `dark` class on `<html>` instead of using `next-themes` as
|
|
8
|
+
shadcn does.
|
|
9
|
+
metadata:
|
|
10
|
+
status: {status: stable}
|
|
11
|
+
since: 1.0.0
|
|
12
|
+
tags: [feedback]
|
|
13
|
+
|
|
14
|
+
sections:
|
|
15
|
+
- kind: guidelines
|
|
16
|
+
for: all
|
|
17
|
+
framing: when-to-use
|
|
18
|
+
items:
|
|
19
|
+
- level: should
|
|
20
|
+
statement: >-
|
|
21
|
+
Use to confirm the result of something the user just did, such as saved
|
|
22
|
+
or request sent.
|
|
23
|
+
- level: should
|
|
24
|
+
statement: >-
|
|
25
|
+
For an action that can be undone: do it at once, then show a toast with
|
|
26
|
+
an "เลิกทำ" (undo) button instead of asking first in a Dialog.
|
|
27
|
+
- level: must-not
|
|
28
|
+
statement: >-
|
|
29
|
+
Don't use for information that has to stay visible until it's fixed, or
|
|
30
|
+
that the user must not miss. A toast disappears. Use <dsds:alert>.
|
|
31
|
+
alternatives:
|
|
32
|
+
- to: alert
|
|
33
|
+
checkedBy: manual
|
|
34
|
+
- level: must-not
|
|
35
|
+
statement: >-
|
|
36
|
+
Don't use for an error on a form field. Use `FieldError` from
|
|
37
|
+
<dsds:field>.
|
|
38
|
+
alternatives:
|
|
39
|
+
- to: field
|
|
40
|
+
checkedBy: manual
|
|
41
|
+
- level: must-not
|
|
42
|
+
statement: >-
|
|
43
|
+
Don't use when the user has to decide something. Use <dsds:dialog> or
|
|
44
|
+
<dsds:alert-dialog>.
|
|
45
|
+
alternatives:
|
|
46
|
+
- to: dialog
|
|
47
|
+
- to: alert-dialog
|
|
48
|
+
checkedBy: manual
|
|
49
|
+
|
|
50
|
+
- kind: guidelines
|
|
51
|
+
for: all
|
|
52
|
+
items:
|
|
53
|
+
- id: mount-once
|
|
54
|
+
level: must
|
|
55
|
+
statement: >-
|
|
56
|
+
Mount `<Toaster />` once for the whole app in the root layout, and call
|
|
57
|
+
`toast()` from `"use client"` files. More than one Toaster shows each
|
|
58
|
+
toast more than once.
|
|
59
|
+
refs:
|
|
60
|
+
- to: labdsnov#mount-providers-once
|
|
61
|
+
rel: relates-to
|
|
62
|
+
checkedBy: manual
|
|
63
|
+
- id: type-matches-result
|
|
64
|
+
level: must
|
|
65
|
+
statement: >-
|
|
66
|
+
Pick the type from the result: `toast.success` succeeded, `toast.error`
|
|
67
|
+
failed, `toast.warning` succeeded with a caveat, `toast.info`
|
|
68
|
+
information, plain `toast()` otherwise (such as deleted + undo). For work
|
|
69
|
+
still running, use `toast.promise(promise, { loading, success, error })`.
|
|
70
|
+
checkedBy: manual
|
|
71
|
+
- id: past-tense-title
|
|
72
|
+
level: should
|
|
73
|
+
statement: >-
|
|
74
|
+
The title states the result briefly ("เปลี่ยนแผนการลงทุนแล้ว",
|
|
75
|
+
"investment plan changed") and `description` gives the consequence
|
|
76
|
+
("มีผลกับเงินสมทบงวดถัดไป", "applies from the next contribution").
|
|
77
|
+
example:
|
|
78
|
+
ref:
|
|
79
|
+
href: ./Toaster.stories.tsx#ShowToast
|
|
80
|
+
rel: demo
|
|
81
|
+
checkedBy: manual
|
|
82
|
+
- id: error-says-next
|
|
83
|
+
level: should
|
|
84
|
+
statement: >-
|
|
85
|
+
A `toast.error` says what to do next ("ไม่สามารถบันทึกได้
|
|
86
|
+
กรุณาลองอีกครั้ง", "couldn't save, please try again"). Errors that need
|
|
87
|
+
the user to fix data go in an Alert or FieldError instead.
|
|
88
|
+
checkedBy: manual
|
|
89
|
+
- id: one-action
|
|
90
|
+
level: should
|
|
91
|
+
statement: >-
|
|
92
|
+
`action` holds one button with a short label ("เลิกทำ"). A toast with an
|
|
93
|
+
undo button should get a longer `duration` so there's time to press it.
|
|
94
|
+
checkedBy: manual
|
|
95
|
+
- id: no-rich-colors
|
|
96
|
+
level: should-not
|
|
97
|
+
statement: >-
|
|
98
|
+
Don't turn on `richColors`. It uses sonner's own colours, not the
|
|
99
|
+
system's tokens, so `tokens:check` never sees them.
|
|
100
|
+
refs:
|
|
101
|
+
- to: shared-a11y#app-colours-same-bar
|
|
102
|
+
rel: relates-to
|
|
103
|
+
|
|
104
|
+
- kind: guidelines
|
|
105
|
+
for: all
|
|
106
|
+
title: Accessibility
|
|
107
|
+
tags: [accessibility]
|
|
108
|
+
items:
|
|
109
|
+
- id: announced
|
|
110
|
+
level: must
|
|
111
|
+
statement: >-
|
|
112
|
+
Toasts are announced to screen readers by sonner's live region, so the
|
|
113
|
+
text must make sense without seeing the icon.
|
|
114
|
+
evidence:
|
|
115
|
+
- href: https://www.w3.org/WAI/WCAG22/Understanding/status-messages.html
|
|
116
|
+
role: WCAG 2.2 SC 4.1.3 (AA)
|
|
117
|
+
checks:
|
|
118
|
+
- href: ./Toaster.stories.tsx#ShowToast
|
|
119
|
+
role: test
|
|
120
|
+
note: play function opens a toast and checks its title and description
|
|
121
|
+
checkedBy: assisted
|
|
122
|
+
- id: enough-time
|
|
123
|
+
level: must
|
|
124
|
+
statement: >-
|
|
125
|
+
A toast with a button stays long enough to reach by keyboard, and the
|
|
126
|
+
same action must also be possible elsewhere (such as restoring from the
|
|
127
|
+
list page), because the toast goes away by itself.
|
|
128
|
+
evidence:
|
|
129
|
+
- href: https://www.w3.org/WAI/WCAG22/Understanding/timing-adjustable.html
|
|
130
|
+
role: WCAG 2.2 SC 2.2.1 (A)
|
|
131
|
+
checkedBy: manual
|
|
132
|
+
|
|
133
|
+
- kind: guidelines
|
|
134
|
+
for: agent
|
|
135
|
+
items:
|
|
136
|
+
- refs:
|
|
137
|
+
- to: shared-testing#assert-by-state
|
|
138
|
+
rel: same-as
|
|
139
|
+
- refs:
|
|
140
|
+
- to: shared-testing#query-portal-with-screen
|
|
141
|
+
rel: same-as
|
|
142
|
+
|
|
143
|
+
- kind: definitions
|
|
144
|
+
for: all
|
|
145
|
+
context: anatomy
|
|
146
|
+
items:
|
|
147
|
+
- term: Toaster
|
|
148
|
+
definition: >-
|
|
149
|
+
The container, mounted once. Takes `position` (default `bottom-right`),
|
|
150
|
+
`richColors`, `closeButton`, `theme` (follows `.dark` by default).
|
|
151
|
+
- term: toast()
|
|
152
|
+
definition: >-
|
|
153
|
+
The function that shows a toast. Options used most: `description`,
|
|
154
|
+
`action: { label, onClick }`, `duration` (ms).
|
|
155
|
+
|
|
156
|
+
- kind: section
|
|
157
|
+
for: all
|
|
158
|
+
title: Open decisions
|
|
159
|
+
freeform:
|
|
160
|
+
- title: TODO
|
|
161
|
+
body: >-
|
|
162
|
+
The app's `position` isn't decided yet, and every type's icon uses the
|
|
163
|
+
text colour. Whether to use `--success` / `--warning` / `--destructive`
|
|
164
|
+
for them isn't decided.
|
|
165
|
+
|
|
166
|
+
sourceFiles:
|
|
167
|
+
- platform: react
|
|
168
|
+
file: ./Toaster.tsx
|
|
169
|
+
|
|
170
|
+
imports:
|
|
171
|
+
- platform: react
|
|
172
|
+
code: >-
|
|
173
|
+
import { Toaster, toast } from "@designil/labdsnov"
|
|
174
|
+
package: "@designil/labdsnov"
|
|
175
|
+
|
|
176
|
+
traits:
|
|
177
|
+
- traitType: variant
|
|
178
|
+
kind: enum
|
|
179
|
+
id: type
|
|
180
|
+
name: toast type
|
|
181
|
+
description: >-
|
|
182
|
+
Which function is called. It sets the icon.
|
|
183
|
+
values:
|
|
184
|
+
- id: default
|
|
185
|
+
description: >-
|
|
186
|
+
`toast()`, no icon.
|
|
187
|
+
- id: success
|
|
188
|
+
description: >-
|
|
189
|
+
`toast.success()`, a tick in a circle.
|
|
190
|
+
- id: info
|
|
191
|
+
description: >-
|
|
192
|
+
`toast.info()`, an i in a circle.
|
|
193
|
+
- id: warning
|
|
194
|
+
description: >-
|
|
195
|
+
`toast.warning()`, a warning triangle.
|
|
196
|
+
- id: error
|
|
197
|
+
description: >-
|
|
198
|
+
`toast.error()`, a cross in a circle.
|
|
199
|
+
- id: promise
|
|
200
|
+
description: >-
|
|
201
|
+
`toast.promise()`, a spinner while waiting, then the result's icon.
|
|
202
|
+
- traitType: variant
|
|
203
|
+
kind: boolean
|
|
204
|
+
id: closeButton
|
|
205
|
+
description: >-
|
|
206
|
+
Shows a close button on each toast (set on `Toaster`).
|
|
207
|
+
- traitType: variant
|
|
208
|
+
kind: boolean
|
|
209
|
+
id: richColors
|
|
210
|
+
description: >-
|
|
211
|
+
Background colour by type from sonner, not from the system's tokens.
|
|
212
|
+
|
|
213
|
+
alternatives:
|
|
214
|
+
- to: alert
|
|
215
|
+
- to: alert-dialog
|
|
216
|
+
|
|
217
|
+
refs:
|
|
218
|
+
- href: ./Toaster.md
|
|
219
|
+
rel: relates-to
|
|
220
|
+
role: usage doc (Thai)
|
|
221
|
+
- href: ./Toaster.stories.tsx
|
|
222
|
+
rel: demo
|
|
223
|
+
role: CSF stories
|
|
224
|
+
- href: https://sonner.emilkowal.ski
|
|
225
|
+
rel: relates-to
|
|
226
|
+
role: sonner docs
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Toaster (ข้อความแจ้งชั่วคราว)
|
|
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
|
+
ใช้ไลบรารี `sonner` (ติดตั้งมากับ `@designil/labdsnov` แล้ว)
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
// app/layout.tsx: วาง Toaster ครั้งเดียวทั้งแอป
|
|
19
|
+
import { Toaster } from "@designil/labdsnov"
|
|
20
|
+
|
|
21
|
+
;<body>
|
|
22
|
+
{children}
|
|
23
|
+
<Toaster />
|
|
24
|
+
</body>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
// ในไฟล์ที่มี "use client"
|
|
29
|
+
import { toast } from "@designil/labdsnov"
|
|
30
|
+
|
|
31
|
+
toast.success("เปลี่ยนแผนการลงทุนแล้ว", { description: "มีผลกับเงินสมทบงวดถัดไป" })
|
|
32
|
+
toast.error("ไม่สามารถบันทึกได้ กรุณาลองอีกครั้ง")
|
|
33
|
+
toast("ลบผู้รับผลประโยชน์แล้ว", { action: { label: "เลิกทำ", onClick: undo } })
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
- โหมดมืดตาม class `dark` ที่ `<html>` อัตโนมัติ
|
|
37
|
+
|
|
38
|
+
## When to use
|
|
39
|
+
|
|
40
|
+
- ยืนยันผลของการกระทำที่ผู้ใช้เพิ่งทำ เช่น บันทึกแล้ว ส่งคำขอแล้ว
|
|
41
|
+
- การกระทำที่ย้อนกลับได้: แสดงพร้อมปุ่ม "เลิกทำ" แทนการถามยืนยันด้วย `Dialog`
|
|
42
|
+
|
|
43
|
+
## When not to use
|
|
44
|
+
|
|
45
|
+
| สถานการณ์ | ใช้แทน |
|
|
46
|
+
| ------------------------ | ------------------------------------------- |
|
|
47
|
+
| ข้อมูลที่ต้องอยู่ให้เห็นจนกว่าจะแก้ | `Alert` |
|
|
48
|
+
| ข้อผิดพลาดของช่องในฟอร์ม | `FieldError` (ดู [Field](../Field/Field.md)) |
|
|
49
|
+
| ต้องให้ผู้ใช้ตัดสินใจ | `Dialog` |
|
|
50
|
+
| ข้อมูลสำคัญที่ผู้ใช้ห้ามพลาด | `Alert` หรือ `Dialog` เพราะ toast หายไปเอง |
|
|
51
|
+
|
|
52
|
+
## Props and variants
|
|
53
|
+
|
|
54
|
+
### toast()
|
|
55
|
+
|
|
56
|
+
| เรียกใช้ | ไอคอน |
|
|
57
|
+
| ----------------------------------------------------- | ------------------------------ |
|
|
58
|
+
| `toast(ข้อความ)` | ไม่มี |
|
|
59
|
+
| `toast.success(ข้อความ)` | เครื่องหมายถูกในวงกลม |
|
|
60
|
+
| `toast.info(ข้อความ)` | ตัว i ในวงกลม |
|
|
61
|
+
| `toast.warning(ข้อความ)` | สามเหลี่ยมเตือน |
|
|
62
|
+
| `toast.error(ข้อความ)` | กากบาทในวงกลม |
|
|
63
|
+
| `toast.promise(promise, { loading, success, error })` | ไอคอนหมุนระหว่างรอ แล้วเปลี่ยนตามผล |
|
|
64
|
+
|
|
65
|
+
ตัวเลือกที่ใช้บ่อย: `description` (ข้อความรอง), `action: { label, onClick }` (ปุ่ม), `duration` (มิลลิวินาที)
|
|
66
|
+
|
|
67
|
+
### Toaster
|
|
68
|
+
|
|
69
|
+
| Prop | ค่า | ค่าเริ่มต้น | ความหมาย |
|
|
70
|
+
| ------------- | -------------------------------------- | -------------- | ------------------------------------------------------------ |
|
|
71
|
+
| `position` | `top-left` … `bottom-right` (6 ตำแหน่ง) | `bottom-right` | มุมที่แสดง TODO: ยังไม่ได้กำหนดตำแหน่งสำหรับแอป |
|
|
72
|
+
| `richColors` | `boolean` | `false` | พื้นสีตามประเภท (เขียว แดง ฯลฯ) ของ sonner เอง ไม่ใช่ token ของเรา |
|
|
73
|
+
| `closeButton` | `boolean` | `false` | แสดงปุ่มปิด |
|
|
74
|
+
| `theme` | `light`, `dark`, `system` | ตาม `.dark` | บังคับโหมดสี |
|
|
75
|
+
|
|
76
|
+
TODO: ไอคอนทุกประเภทเป็นสีเดียวกับข้อความ (ไม่มีสีตามประเภท) ยังไม่ได้ตัดสินใจว่าจะใช้ `--success` / `--warning` / `--destructive` หรือไม่
|
|
77
|
+
|
|
78
|
+
## Tokens used
|
|
79
|
+
|
|
80
|
+
ค่าทั้งหมดมาจาก `src/styles/theme.css`
|
|
81
|
+
|
|
82
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
83
|
+
| ---------------------- | -------------------------- | -------------------------- | ------------ |
|
|
84
|
+
| `--popover` | `oklch(1 0 0)` | `oklch(0.228 0.013 107.4)` | พื้น toast |
|
|
85
|
+
| `--popover-foreground` | `oklch(0.153 0.006 107.1)` | `oklch(0.988 0.003 106.5)` | ตัวอักษร |
|
|
86
|
+
| `--border` | `oklch(0.93 0.007 106.5)` | `oklch(1 0 0 / 10%)` | เส้นขอบ |
|
|
87
|
+
| `--radius` | `0.625rem` | – | มุมโค้ง (10px) |
|
|
88
|
+
|
|
89
|
+
## Example
|
|
90
|
+
|
|
91
|
+
จาก story `ShowToast` ใน `Toaster.stories.tsx`:
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
<>
|
|
95
|
+
<Toaster />
|
|
96
|
+
<Button
|
|
97
|
+
variant="outline"
|
|
98
|
+
onClick={() =>
|
|
99
|
+
toast.success("เปลี่ยนแผนการลงทุนแล้ว", {
|
|
100
|
+
description: "มีผลกับเงินสมทบงวดถัดไป",
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
>
|
|
104
|
+
สำเร็จ
|
|
105
|
+
</Button>
|
|
106
|
+
</>
|
|
107
|
+
```
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
kind: component
|
|
2
|
+
id: toggle
|
|
3
|
+
name: Toggle
|
|
4
|
+
description: >-
|
|
5
|
+
A button that stays pressed, showing whether one option is on or off, such as
|
|
6
|
+
showing one series on a chart. Wraps Base UI's `Toggle` and exposes
|
|
7
|
+
`aria-pressed`.
|
|
8
|
+
metadata:
|
|
9
|
+
status: {status: stable}
|
|
10
|
+
since: 1.0.0
|
|
11
|
+
tags: [action, selection]
|
|
12
|
+
|
|
13
|
+
sections:
|
|
14
|
+
- kind: guidelines
|
|
15
|
+
for: all
|
|
16
|
+
framing: when-to-use
|
|
17
|
+
items:
|
|
18
|
+
- level: should
|
|
19
|
+
statement: >-
|
|
20
|
+
Use to turn a display option on or off with an immediate visible
|
|
21
|
+
effect, such as a chart series or a filter.
|
|
22
|
+
- level: may
|
|
23
|
+
statement: >-
|
|
24
|
+
Use for formatting buttons such as bold.
|
|
25
|
+
- level: must-not
|
|
26
|
+
statement: >-
|
|
27
|
+
Don't use for a setting that is saved permanently (such as turning on
|
|
28
|
+
notifications). Use <dsds:switch>.
|
|
29
|
+
alternatives:
|
|
30
|
+
- to: switch
|
|
31
|
+
checkedBy: manual
|
|
32
|
+
- level: must-not
|
|
33
|
+
statement: >-
|
|
34
|
+
Don't use for confirming something in a form before submitting. Use
|
|
35
|
+
<dsds:checkbox>.
|
|
36
|
+
alternatives:
|
|
37
|
+
- to: checkbox
|
|
38
|
+
checkedBy: manual
|
|
39
|
+
- level: must-not
|
|
40
|
+
statement: >-
|
|
41
|
+
Don't use for a one-off action. Use <dsds:button>.
|
|
42
|
+
alternatives:
|
|
43
|
+
- to: button
|
|
44
|
+
checkedBy: manual
|
|
45
|
+
- level: should-not
|
|
46
|
+
statement: >-
|
|
47
|
+
Don't place several Toggles side by side to pick one of several options.
|
|
48
|
+
Use <dsds:toggle-group>.
|
|
49
|
+
alternatives:
|
|
50
|
+
- to: toggle-group
|
|
51
|
+
|
|
52
|
+
- kind: guidelines
|
|
53
|
+
for: all
|
|
54
|
+
items:
|
|
55
|
+
- id: label-names-thing
|
|
56
|
+
level: must
|
|
57
|
+
statement: >-
|
|
58
|
+
The label names what is turned on or off ("แสดงเงินสมทบจากนายจ้าง",
|
|
59
|
+
"show employer contributions"), never the state ("เปิดอยู่", "on"). The
|
|
60
|
+
pressed look and `aria-pressed` show the state, and the label doesn't
|
|
61
|
+
change.
|
|
62
|
+
checkedBy: manual
|
|
63
|
+
- id: immediate-effect
|
|
64
|
+
level: should
|
|
65
|
+
statement: >-
|
|
66
|
+
Apply the change in `onPressedChange` straight away. A Toggle that only
|
|
67
|
+
takes effect after a later "save" belongs in a form as a Checkbox.
|
|
68
|
+
checks:
|
|
69
|
+
- href: ./Toggle.stories.tsx#Pressing
|
|
70
|
+
role: test
|
|
71
|
+
note: play function checks aria-pressed flips and onPressedChange is called
|
|
72
|
+
checkedBy: automated
|
|
73
|
+
- id: outline-standalone
|
|
74
|
+
level: should
|
|
75
|
+
statement: >-
|
|
76
|
+
Use `variant="outline"` for a Toggle standing on its own on the page,
|
|
77
|
+
so it reads as a control before it's pressed. `default` (no border until
|
|
78
|
+
pressed) suits toolbars.
|
|
79
|
+
example:
|
|
80
|
+
ref:
|
|
81
|
+
href: ./Toggle.stories.tsx#Variants
|
|
82
|
+
rel: demo
|
|
83
|
+
checkedBy: manual
|
|
84
|
+
- id: size-matches-row
|
|
85
|
+
level: should
|
|
86
|
+
statement: >-
|
|
87
|
+
Match `size` to the buttons beside it: `sm` 32px, `default` 36px, `lg`
|
|
88
|
+
40px.
|
|
89
|
+
checkedBy: manual
|
|
90
|
+
|
|
91
|
+
- kind: guidelines
|
|
92
|
+
for: all
|
|
93
|
+
title: Accessibility
|
|
94
|
+
tags: [accessibility]
|
|
95
|
+
items:
|
|
96
|
+
- id: icon-only-label
|
|
97
|
+
level: must
|
|
98
|
+
statement: >-
|
|
99
|
+
An icon-only Toggle has a Thai `aria-label` naming the option, such as
|
|
100
|
+
"ตัวหนา" (bold).
|
|
101
|
+
refines:
|
|
102
|
+
- to: shared-a11y#icon-only-label
|
|
103
|
+
checks:
|
|
104
|
+
- href: ./Toggle.stories.tsx#IconOnly
|
|
105
|
+
role: test
|
|
106
|
+
checkedBy: automated
|
|
107
|
+
- id: keyboard-toggle
|
|
108
|
+
level: must
|
|
109
|
+
statement: >-
|
|
110
|
+
Tab reaches the Toggle and Space or Enter flips `aria-pressed`.
|
|
111
|
+
evidence:
|
|
112
|
+
- href: https://www.w3.org/WAI/ARIA/apg/patterns/button/
|
|
113
|
+
role: WAI-ARIA APG Button pattern (toggle button)
|
|
114
|
+
checks:
|
|
115
|
+
- href: ./Toggle.stories.tsx#Keyboard
|
|
116
|
+
role: test
|
|
117
|
+
checkedBy: automated
|
|
118
|
+
- id: toggle-contrast
|
|
119
|
+
level: must
|
|
120
|
+
statement: >-
|
|
121
|
+
Unpressed text is 5.97:1 light / 8.43:1 dark, hover text 17.76:1 /
|
|
122
|
+
13.79:1, pressed text 17.76:1 / 13.79:1, and the pressed edge 3.93:1 /
|
|
123
|
+
4.05:1. The pressed state relies on that edge, so don't remove it with
|
|
124
|
+
`className`.
|
|
125
|
+
refines:
|
|
126
|
+
- to: shared-a11y#non-text-contrast
|
|
127
|
+
checks:
|
|
128
|
+
- href: ../../../scripts/tokens.mjs
|
|
129
|
+
role: test
|
|
130
|
+
note: CONTRAST_PAIRS "Toggle …"
|
|
131
|
+
checkedBy: automated
|
|
132
|
+
- refs:
|
|
133
|
+
- to: shared-a11y#focus-ring
|
|
134
|
+
rel: same-as
|
|
135
|
+
|
|
136
|
+
- kind: guidelines
|
|
137
|
+
for: agent
|
|
138
|
+
items:
|
|
139
|
+
- refs:
|
|
140
|
+
- to: shared-testing#disabled-check-by-attribute
|
|
141
|
+
rel: same-as
|
|
142
|
+
|
|
143
|
+
- kind: definitions
|
|
144
|
+
for: all
|
|
145
|
+
title: States
|
|
146
|
+
context: labdsnov.states
|
|
147
|
+
items:
|
|
148
|
+
- term: Not pressed
|
|
149
|
+
definition: >-
|
|
150
|
+
Secondary text colour.
|
|
151
|
+
- term: Hover
|
|
152
|
+
definition: >-
|
|
153
|
+
Faint background, darker text. Check by hand (can't be forced in a story).
|
|
154
|
+
- term: Pressed
|
|
155
|
+
definition: >-
|
|
156
|
+
Faint background, dark edge (3:1), dark text, `aria-pressed="true"`.
|
|
157
|
+
- term: Keyboard focus
|
|
158
|
+
definition: >-
|
|
159
|
+
Solid `--focus-ring` ring.
|
|
160
|
+
- term: Disabled
|
|
161
|
+
definition: >-
|
|
162
|
+
Dimmed to 50%.
|
|
163
|
+
|
|
164
|
+
sourceFiles:
|
|
165
|
+
- platform: react
|
|
166
|
+
file: ./Toggle.tsx
|
|
167
|
+
|
|
168
|
+
imports:
|
|
169
|
+
- platform: react
|
|
170
|
+
code: >-
|
|
171
|
+
import { Toggle, toggleVariants } from "@designil/labdsnov"
|
|
172
|
+
package: "@designil/labdsnov"
|
|
173
|
+
|
|
174
|
+
traits:
|
|
175
|
+
- traitType: variant
|
|
176
|
+
kind: enum
|
|
177
|
+
id: variant
|
|
178
|
+
description: >-
|
|
179
|
+
How the Toggle looks before and after it's pressed.
|
|
180
|
+
values:
|
|
181
|
+
- id: default
|
|
182
|
+
description: >-
|
|
183
|
+
No border until pressed. For toolbars.
|
|
184
|
+
- id: outline
|
|
185
|
+
description: >-
|
|
186
|
+
A faint border at all times. For a Toggle on its own.
|
|
187
|
+
- traitType: variant
|
|
188
|
+
kind: enum
|
|
189
|
+
id: size
|
|
190
|
+
description: >-
|
|
191
|
+
Height and padding.
|
|
192
|
+
values:
|
|
193
|
+
- id: default
|
|
194
|
+
description: >-
|
|
195
|
+
36px.
|
|
196
|
+
- id: sm
|
|
197
|
+
description: >-
|
|
198
|
+
32px.
|
|
199
|
+
- id: lg
|
|
200
|
+
description: >-
|
|
201
|
+
40px.
|
|
202
|
+
- traitType: state
|
|
203
|
+
kind: boolean
|
|
204
|
+
id: pressed
|
|
205
|
+
description: >-
|
|
206
|
+
On (`pressed` / `defaultPressed`), shown with `aria-pressed="true"`.
|
|
207
|
+
- traitType: state
|
|
208
|
+
kind: boolean
|
|
209
|
+
id: disabled
|
|
210
|
+
description: >-
|
|
211
|
+
Disabled, dimmed to 50%.
|
|
212
|
+
|
|
213
|
+
alternatives:
|
|
214
|
+
- to: switch
|
|
215
|
+
- to: toggle-group
|
|
216
|
+
- to: checkbox
|
|
217
|
+
|
|
218
|
+
refs:
|
|
219
|
+
- href: ./Toggle.md
|
|
220
|
+
rel: relates-to
|
|
221
|
+
role: usage doc (Thai)
|
|
222
|
+
- href: ./Toggle.stories.tsx
|
|
223
|
+
rel: demo
|
|
224
|
+
role: CSF stories
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Toggle (ปุ่มเปิด/ปิด)
|
|
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 { Toggle } from "@designil/labdsnov"
|
|
17
|
+
|
|
18
|
+
;<Toggle variant="outline" onPressedChange={setShowEmployer}>
|
|
19
|
+
แสดงเงินสมทบจากนายจ้าง
|
|
20
|
+
</Toggle>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
- ข้อความบนปุ่มบอก "สิ่งที่เปิด/ปิด" ไม่ใช่สถานะ (ไม่เขียนว่า "เปิดอยู่") สถานะบอกด้วยหน้าตาและ `aria-pressed`
|
|
24
|
+
- ปุ่มที่มีแต่ไอคอนต้องมี `aria-label`
|
|
25
|
+
|
|
26
|
+
## When to use
|
|
27
|
+
|
|
28
|
+
- เปิด/ปิดการแสดงผลที่เห็นผลทันที เช่น เส้นกราฟ ตัวกรอง
|
|
29
|
+
- ปุ่มจัดรูปแบบ เช่น ตัวหนา
|
|
30
|
+
|
|
31
|
+
## When not to use
|
|
32
|
+
|
|
33
|
+
| สถานการณ์ | ใช้แทน |
|
|
34
|
+
| ----------------------------- | ------------- |
|
|
35
|
+
| ตั้งค่าที่บันทึกถาวร (เปิดการแจ้งเตือน) | `Switch` |
|
|
36
|
+
| เลือกหนึ่งจากหลายตัวเลือกที่อยู่ด้วยกัน | `ToggleGroup` |
|
|
37
|
+
| ยืนยันในฟอร์มก่อนส่ง | `Checkbox` |
|
|
38
|
+
| สั่งการกระทำครั้งเดียว | `Button` |
|
|
39
|
+
|
|
40
|
+
## Props and variants
|
|
41
|
+
|
|
42
|
+
| Prop | ค่า | ค่าเริ่มต้น | ความหมาย |
|
|
43
|
+
| ----------------------------- | --------------------- | --------- | ---------------------- |
|
|
44
|
+
| `variant` | `default`, `outline` | `default` | หน้าตา (ดูตารางด้านล่าง) |
|
|
45
|
+
| `size` | `default`, `sm`, `lg` | `default` | สูง 36 / 32 / 40px |
|
|
46
|
+
| `pressed` / `onPressedChange` | `boolean` / ฟังก์ชัน | – | ควบคุมสถานะจากภายนอก |
|
|
47
|
+
| `defaultPressed` | `boolean` | `false` | กดไว้ตั้งแต่แรก |
|
|
48
|
+
| `disabled` | `boolean` | `false` | ปิดใช้งาน จางลง 50% |
|
|
49
|
+
| `className` | class | – | ปรับหน้าตาเฉพาะจุดครั้งเดียว |
|
|
50
|
+
|
|
51
|
+
| Variant | หน้าตา |
|
|
52
|
+
| --------- | ------------------ |
|
|
53
|
+
| `default` | ไม่มีเส้นขอบจนกว่าจะกด |
|
|
54
|
+
| `outline` | มีเส้นขอบจางตลอด |
|
|
55
|
+
|
|
56
|
+
### States
|
|
57
|
+
|
|
58
|
+
- **ไม่ได้กด**: ตัวอักษรสีรอง
|
|
59
|
+
- **Hover**: พื้นจาง ตัวอักษรเข้ม
|
|
60
|
+
- **กดอยู่**: พื้นจาง เส้นขอบเข้ม (contrast 3:1) ตัวอักษรเข้ม
|
|
61
|
+
- **Focus จากคีย์บอร์ด**: วงแหวนทึบสี `--focus-ring` กด Space หรือ Enter เพื่อสลับ
|
|
62
|
+
|
|
63
|
+
## Tokens used
|
|
64
|
+
|
|
65
|
+
ค่าทั้งหมดมาจาก `src/styles/theme.css`
|
|
66
|
+
|
|
67
|
+
### Component tokens
|
|
68
|
+
|
|
69
|
+
token เฉพาะของคอมโพเนนต์นี้ ชี้ไปที่ semantic token ด้านล่าง เปลี่ยนที่นี่เพื่อปรับเฉพาะคอมโพเนนต์นี้ (โหมดมืด "–" = ใช้ค่าเดียวกับโหมดสว่าง)
|
|
70
|
+
|
|
71
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
72
|
+
| ------------------------- | -------------------- | ------------------- | ----------------------------------------------- |
|
|
73
|
+
| `--toggle-fg` | `--muted-foreground` | – | ตัวอักษร/ไอคอนตอนไม่ได้กด |
|
|
74
|
+
| `--toggle-hover-bg` | `--muted` | – | พื้นตอน hover |
|
|
75
|
+
| `--toggle-hover-fg` | `--foreground` | – | ตัวอักษรตอน hover |
|
|
76
|
+
| `--toggle-outline-border` | `--border` | – | ขอบ variant `outline` ตอนไม่ได้กด |
|
|
77
|
+
| `--toggle-pressed-border` | `--control-border` | – | ขอบตอนกดอยู่ (contrast 3:1) |
|
|
78
|
+
| `--toggle-pressed-bg` | `--muted` | – | พื้นตอนกดอยู่ / เลือกอยู่ |
|
|
79
|
+
| `--toggle-pressed-fg` | `--foreground` | – | ตัวอักษรตอนกดอยู่ / เลือกอยู่ |
|
|
80
|
+
| `--focus-ring` | `--ring` | – | วงแหวน focus จากคีย์บอร์ดของทุกคอมโพเนนต์ (ทึบ 2px) |
|
|
81
|
+
| `--invalid-border` | `--destructive` | – | เส้นขอบเมื่อข้อมูลไม่ถูกต้อง และวงแหวน focus ขณะไม่ถูกต้อง |
|
|
82
|
+
| `--invalid-ring` | `--destructive` 20% | `--destructive` 40% | วงแหวนจางรอบช่องที่ไม่ถูกต้อง (ตกแต่ง) |
|
|
83
|
+
|
|
84
|
+
### Semantic tokens
|
|
85
|
+
|
|
86
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
87
|
+
| -------------------- | -------------------------- | -------------------------- | --------------------------- |
|
|
88
|
+
| `--muted-foreground` | `oklch(0.5 0.027 107.3)` | `oklch(0.737 0.021 106.9)` | ตัวอักษรตอนไม่ได้กด |
|
|
89
|
+
| `--ring` | `oklch(0.45 0.03 106.9)` | `oklch(0.8 0.02 106.9)` | วงแหวน focus |
|
|
90
|
+
| `--destructive` | `oklch(0.505 0.2 27.325)` | `oklch(0.75 0.16 22.216)` | สถานะไม่ถูกต้อง |
|
|
91
|
+
| `--border` | `oklch(0.93 0.007 106.5)` | `oklch(1 0 0 / 10%)` | ผ่าน token ของคอมโพเนนต์ด้านบน |
|
|
92
|
+
| `--control-border` | `oklch(0.6 0.02 106.9)` | `oklch(0.55 0.015 106.9)` | ผ่าน token ของคอมโพเนนต์ด้านบน |
|
|
93
|
+
| `--foreground` | `oklch(0.153 0.006 107.1)` | `oklch(0.988 0.003 106.5)` | ผ่าน token ของคอมโพเนนต์ด้านบน |
|
|
94
|
+
| `--muted` | `oklch(0.966 0.005 106.5)` | `oklch(0.286 0.016 107.4)` | ผ่าน token ของคอมโพเนนต์ด้านบน |
|
|
95
|
+
|
|
96
|
+
## Example
|
|
97
|
+
|
|
98
|
+
จาก story `Variants` ใน `Toggle.stories.tsx`:
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
<Toggle variant="outline">outline</Toggle>
|
|
102
|
+
<Toggle variant="outline" defaultPressed>outline (กดอยู่)</Toggle>
|
|
103
|
+
```
|