@designil/labdsnov 0.0.0-stage → 1.0.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 +133 -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 +96 -0
- package/docs/ComponentTokens.md +191 -0
- package/docs/Contributing.md +97 -0
- package/docs/GettingStarted.md +106 -0
- package/docs/Radius.md +25 -0
- package/docs/Typography.md +38 -0
- package/package.json +79 -3
- package/src/components/Accordion/Accordion.md +102 -0
- package/src/components/Alert/Alert.md +90 -0
- package/src/components/AlertDialog/AlertDialog.md +131 -0
- package/src/components/Avatar/Avatar.md +77 -0
- package/src/components/Badge/Badge.md +124 -0
- package/src/components/Breadcrumb/Breadcrumb.md +110 -0
- package/src/components/Button/Button.md +165 -0
- package/src/components/ButtonGroup/ButtonGroup.md +96 -0
- package/src/components/Calendar/Calendar.md +111 -0
- package/src/components/Card/Card.md +99 -0
- package/src/components/Chart/Chart.md +112 -0
- package/src/components/Checkbox/Checkbox.md +105 -0
- package/src/components/Collapsible/Collapsible.md +86 -0
- package/src/components/Combobox/Combobox.md +143 -0
- package/src/components/DatePicker/DatePicker.md +82 -0
- package/src/components/Dialog/Dialog.md +193 -0
- package/src/components/Drawer/Drawer.md +125 -0
- package/src/components/DropdownMenu/DropdownMenu.md +151 -0
- package/src/components/Empty/Empty.md +90 -0
- package/src/components/Field/Field.md +139 -0
- package/src/components/FundCard/FundCard.md +93 -0
- package/src/components/HoverCard/HoverCard.md +100 -0
- package/src/components/Input/Input.md +115 -0
- package/src/components/InputGroup/InputGroup.md +115 -0
- package/src/components/InputOTP/InputOTP.md +105 -0
- package/src/components/Kbd/Kbd.md +85 -0
- package/src/components/Label/Label.md +75 -0
- package/src/components/NavigationMenu/NavigationMenu.md +128 -0
- package/src/components/Pagination/Pagination.md +115 -0
- package/src/components/Popover/Popover.md +111 -0
- package/src/components/Progress/Progress.md +83 -0
- package/src/components/RadioGroup/RadioGroup.md +123 -0
- package/src/components/ScrollArea/ScrollArea.md +88 -0
- package/src/components/Select/Select.md +170 -0
- package/src/components/Separator/Separator.md +68 -0
- package/src/components/Skeleton/Skeleton.md +68 -0
- package/src/components/Slider/Slider.md +107 -0
- package/src/components/Spinner/Spinner.md +64 -0
- package/src/components/Switch/Switch.md +101 -0
- package/src/components/Table/Table.md +117 -0
- package/src/components/Tabs/Tabs.md +173 -0
- package/src/components/Textarea/Textarea.md +89 -0
- package/src/components/Toaster/Toaster.md +107 -0
- package/src/components/Toggle/Toggle.md +103 -0
- package/src/components/ToggleGroup/ToggleGroup.md +95 -0
- package/src/components/Tooltip/Tooltip.md +104 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# Select (รายการให้เลือก)
|
|
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
|
+
Label,
|
|
18
|
+
Select,
|
|
19
|
+
SelectContent,
|
|
20
|
+
SelectItem,
|
|
21
|
+
SelectTrigger,
|
|
22
|
+
SelectValue,
|
|
23
|
+
} from "@designil/labdsnov"
|
|
24
|
+
|
|
25
|
+
const states = { nsw: "นิวเซาท์เวลส์", vic: "วิกตอเรีย", qld: "ควีนส์แลนด์" }
|
|
26
|
+
|
|
27
|
+
<Label htmlFor="state">รัฐที่อยู่อาศัย</Label>
|
|
28
|
+
<Select items={states}>
|
|
29
|
+
<SelectTrigger id="state" className="w-full">
|
|
30
|
+
<SelectValue placeholder="เลือกรัฐ" />
|
|
31
|
+
</SelectTrigger>
|
|
32
|
+
<SelectContent>
|
|
33
|
+
{Object.entries(states).map(([value, label]) => (
|
|
34
|
+
<SelectItem key={value} value={value}>{label}</SelectItem>
|
|
35
|
+
))}
|
|
36
|
+
</SelectContent>
|
|
37
|
+
</Select>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
- **ส่ง `items` ให้ `Select` เสมอ** (object `{ value: label }` หรือ array `{ value, label }`) ไม่อย่างนั้นปุ่มจะแสดง `value` ดิบ เช่น "nsw" แทนชื่อ
|
|
41
|
+
- ปุ่มกว้างเท่าเนื้อหา ใส่ `className="w-full"` เมื่ออยู่ในฟอร์ม
|
|
42
|
+
- ควบคุมค่าเอง ใช้ `value` กับ `onValueChange` ในไฟล์ที่มี `"use client"`
|
|
43
|
+
|
|
44
|
+
## When to use
|
|
45
|
+
|
|
46
|
+
- เลือกหนึ่งค่าจากรายการยาว (ประมาณ 6 ตัวเลือกขึ้นไป) เช่น รัฐ ประเทศ สินทรัพย์
|
|
47
|
+
|
|
48
|
+
## When not to use
|
|
49
|
+
|
|
50
|
+
| สถานการณ์ | ใช้แทน |
|
|
51
|
+
| ---------------------------- | -------------------------------------------------- |
|
|
52
|
+
| ตัวเลือกน้อย (2–5) ที่ควรเห็นทั้งหมด | `RadioGroup` |
|
|
53
|
+
| รายการยาวมากที่ต้องพิมพ์ค้นหา | `Combobox` (ดู [Combobox](../Combobox/Combobox.md)) |
|
|
54
|
+
| เมนูคำสั่ง เช่น แก้ไข / ลบ | `DropdownMenu` |
|
|
55
|
+
| เลือกวันที่ | `DatePicker` |
|
|
56
|
+
|
|
57
|
+
## Anatomy
|
|
58
|
+
|
|
59
|
+
- **Select**: ตัวครอบ เก็บค่าที่เลือก
|
|
60
|
+
- **SelectTrigger** → **SelectValue**: ปุ่มที่แสดงค่าที่เลือก (หรือ placeholder)
|
|
61
|
+
- **SelectContent**: รายการที่เปิดขึ้น
|
|
62
|
+
- **SelectGroup** → **SelectLabel** + **SelectItem**: จัดกลุ่มตัวเลือกพร้อมหัวข้อ
|
|
63
|
+
- **SelectSeparator**: เส้นคั่นระหว่างกลุ่ม
|
|
64
|
+
|
|
65
|
+
## Props and variants
|
|
66
|
+
|
|
67
|
+
### Select
|
|
68
|
+
|
|
69
|
+
| Prop | ค่า | ค่าเริ่มต้น | ความหมาย |
|
|
70
|
+
| ------------------------- | ---------------- | ------- | ------------------------------------------------ |
|
|
71
|
+
| `items` | object หรือ array | – | ชื่อที่แสดงของแต่ละค่า |
|
|
72
|
+
| `defaultValue` | value | – | ค่าที่เลือกไว้ตอนแรก |
|
|
73
|
+
| `value` / `onValueChange` | value / ฟังก์ชัน | – | ควบคุมจากภายนอก |
|
|
74
|
+
| `multiple` | `boolean` | `false` | เลือกได้หลายค่า TODO: ยังไม่มีตัวอย่างและยังไม่ได้ตรวจหน้าตา |
|
|
75
|
+
| `disabled` | `boolean` | `false` | ปิดใช้งาน จางลง 50% |
|
|
76
|
+
| `required` / `name` | – | – | สำหรับส่งฟอร์ม |
|
|
77
|
+
|
|
78
|
+
### SelectTrigger
|
|
79
|
+
|
|
80
|
+
| Prop | ค่า | ค่าเริ่มต้น | ความหมาย |
|
|
81
|
+
| -------------- | --------------- | --------- | ------------------------------------- |
|
|
82
|
+
| `size` | `default`, `sm` | `default` | ความสูง 36px / 32px |
|
|
83
|
+
| `aria-invalid` | `boolean` | – | ข้อมูลไม่ถูกต้อง เส้นขอบสีแดงและวงแหวนแดงจาง |
|
|
84
|
+
| `className` | class | – | เช่น `w-full` |
|
|
85
|
+
|
|
86
|
+
### SelectValue / SelectItem
|
|
87
|
+
|
|
88
|
+
| Prop | ใช้กับ | ความหมาย |
|
|
89
|
+
| ------------- | ------------- | -------------------------------- |
|
|
90
|
+
| `placeholder` | `SelectValue` | ข้อความเมื่อยังไม่ได้เลือก เช่น "เลือกรัฐ" |
|
|
91
|
+
| `value` | `SelectItem` | **บังคับ** ค่าของตัวเลือก |
|
|
92
|
+
| `disabled` | `SelectItem` | ตัวเลือกที่เลือกไม่ได้ จางลง 50% |
|
|
93
|
+
|
|
94
|
+
`SelectContent` รับ `side`, `align` และ `alignItemWithTrigger` (ค่าเริ่มต้น `true`: รายการเปิดทับปุ่มให้ตัวเลือกปัจจุบันอยู่ตรงปุ่ม)
|
|
95
|
+
|
|
96
|
+
### พฤติกรรมที่มีให้แล้ว
|
|
97
|
+
|
|
98
|
+
- หน้าตาปุ่มเหมือน `Input` แบบ `filled` และสูงเท่ากัน วางคู่กันในฟอร์มได้
|
|
99
|
+
- ตัวเลือกที่เลือกมีเครื่องหมายถูกด้านขวา รายการยาวเลื่อนได้และมีลูกศรเลื่อนขึ้น/ลง
|
|
100
|
+
|
|
101
|
+
## Tokens used
|
|
102
|
+
|
|
103
|
+
ค่าทั้งหมดมาจาก `src/styles/theme.css`
|
|
104
|
+
|
|
105
|
+
### Component tokens
|
|
106
|
+
|
|
107
|
+
token เฉพาะของคอมโพเนนต์นี้ ชี้ไปที่ semantic token ด้านล่าง เปลี่ยนที่นี่เพื่อปรับเฉพาะคอมโพเนนต์นี้ (โหมดมืด "–" = ใช้ค่าเดียวกับโหมดสว่าง)
|
|
108
|
+
|
|
109
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
110
|
+
| -------------------------- | --------------------- | ------------------- | ----------------------------------------------- |
|
|
111
|
+
| `--field-border` | `--control-border` | – | เส้นขอบช่องกรอก |
|
|
112
|
+
| `--field-bg` | `--input` 50% | – | พื้นช่องกรอก |
|
|
113
|
+
| `--field-placeholder` | `--muted-foreground` | – | placeholder |
|
|
114
|
+
| `--field-icon` | `--muted-foreground` | – | ไอคอนในช่อง เช่น ลูกศร |
|
|
115
|
+
| `--menu-label-fg` | `--muted-foreground` | – | หัวข้อกลุ่ม, ปุ่มลัด |
|
|
116
|
+
| `--menu-item-highlight-bg` | `--accent` | – | พื้นรายการที่ไฮไลต์ |
|
|
117
|
+
| `--menu-item-highlight-fg` | `--accent-foreground` | – | ตัวอักษรรายการที่ไฮไลต์ |
|
|
118
|
+
| `--focus-ring` | `--ring` | – | วงแหวน focus จากคีย์บอร์ดของทุกคอมโพเนนต์ (ทึบ 2px) |
|
|
119
|
+
| `--invalid-border` | `--destructive` | – | เส้นขอบเมื่อข้อมูลไม่ถูกต้อง และวงแหวน focus ขณะไม่ถูกต้อง |
|
|
120
|
+
| `--invalid-ring` | `--destructive` 20% | `--destructive` 40% | วงแหวนจางรอบช่องที่ไม่ถูกต้อง (ตกแต่ง) |
|
|
121
|
+
|
|
122
|
+
### Semantic tokens
|
|
123
|
+
|
|
124
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
125
|
+
| ---------------------- | -------------------------- | -------------------------- | --------------------------------------- |
|
|
126
|
+
| `--input` | `oklch(0.93 0.007 106.5)` | `oklch(1 0 0 / 15%)` | พื้นปุ่ม (50%) |
|
|
127
|
+
| `--muted-foreground` | `oklch(0.5 0.027 107.3)` | `oklch(0.737 0.021 106.9)` | placeholder, ไอคอนลูกศร, หัวข้อกลุ่ม |
|
|
128
|
+
| `--popover` | `oklch(1 0 0)` | `oklch(0.228 0.013 107.4)` | พื้นรายการ |
|
|
129
|
+
| `--popover-foreground` | `oklch(0.153 0.006 107.1)` | `oklch(0.988 0.003 106.5)` | ตัวอักษรในรายการ |
|
|
130
|
+
| `--accent` | `oklch(0.966 0.005 106.5)` | `oklch(0.286 0.016 107.4)` | พื้นตัวเลือกที่โฟกัส |
|
|
131
|
+
| `--accent-foreground` | `oklch(0.228 0.013 107.4)` | `oklch(0.988 0.003 106.5)` | ตัวอักษรตัวเลือกที่โฟกัส |
|
|
132
|
+
| `--border` | `oklch(0.93 0.007 106.5)` | `oklch(1 0 0 / 10%)` | เส้นคั่นกลุ่ม |
|
|
133
|
+
| `--foreground` | `oklch(0.153 0.006 107.1)` | `oklch(0.988 0.003 106.5)` | เส้นขอบบาง ๆ รอบรายการ (5% สว่าง, 10% มืด) |
|
|
134
|
+
| `--ring` | `oklch(0.45 0.03 106.9)` | `oklch(0.8 0.02 106.9)` | วงแหวน focus |
|
|
135
|
+
| `--destructive` | `oklch(0.505 0.2 27.325)` | `oklch(0.75 0.16 22.216)` | สถานะไม่ถูกต้อง |
|
|
136
|
+
| `--control-border` | `oklch(0.6 0.02 106.9)` | `oklch(0.55 0.015 106.9)` | ผ่าน token ของคอมโพเนนต์ด้านบน |
|
|
137
|
+
|
|
138
|
+
## Example
|
|
139
|
+
|
|
140
|
+
จาก story `Groups` ใน `Select.stories.tsx`:
|
|
141
|
+
|
|
142
|
+
```tsx
|
|
143
|
+
<Select
|
|
144
|
+
items={{
|
|
145
|
+
cash: "เงินสด",
|
|
146
|
+
bonds: "ตราสารหนี้",
|
|
147
|
+
shares: "หุ้นออสเตรเลีย",
|
|
148
|
+
global: "หุ้นต่างประเทศ",
|
|
149
|
+
}}
|
|
150
|
+
>
|
|
151
|
+
<SelectTrigger className="w-64" aria-label="สินทรัพย์">
|
|
152
|
+
<SelectValue placeholder="เลือกสินทรัพย์" />
|
|
153
|
+
</SelectTrigger>
|
|
154
|
+
<SelectContent>
|
|
155
|
+
<SelectGroup>
|
|
156
|
+
<SelectLabel>ความเสี่ยงต่ำ</SelectLabel>
|
|
157
|
+
<SelectItem value="cash">เงินสด</SelectItem>
|
|
158
|
+
<SelectItem value="bonds">ตราสารหนี้</SelectItem>
|
|
159
|
+
</SelectGroup>
|
|
160
|
+
<SelectSeparator />
|
|
161
|
+
<SelectGroup>
|
|
162
|
+
<SelectLabel>ความเสี่ยงสูง</SelectLabel>
|
|
163
|
+
<SelectItem value="shares">หุ้นออสเตรเลีย</SelectItem>
|
|
164
|
+
<SelectItem value="global" disabled>
|
|
165
|
+
หุ้นต่างประเทศ
|
|
166
|
+
</SelectItem>
|
|
167
|
+
</SelectGroup>
|
|
168
|
+
</SelectContent>
|
|
169
|
+
</Select>
|
|
170
|
+
```
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Separator (เส้นคั่น)
|
|
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 { Separator } from "@designil/labdsnov"
|
|
17
|
+
|
|
18
|
+
<Separator className="my-4" />
|
|
19
|
+
|
|
20
|
+
// แนวตั้ง: วางใน flex แถวที่มีความสูง
|
|
21
|
+
<div className="flex h-5 items-center gap-4">
|
|
22
|
+
<span>ภาพรวม</span>
|
|
23
|
+
<Separator orientation="vertical" />
|
|
24
|
+
<span>ธุรกรรม</span>
|
|
25
|
+
</div>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## When to use
|
|
29
|
+
|
|
30
|
+
- แบ่งส่วนเนื้อหาในการ์ดหรือในเมนู ที่ระยะห่างอย่างเดียวไม่พอ
|
|
31
|
+
- คั่นลิงก์หรือข้อมูลสั้น ๆ ที่อยู่แถวเดียวกัน (แนวตั้ง)
|
|
32
|
+
|
|
33
|
+
## When not to use
|
|
34
|
+
|
|
35
|
+
- **แบ่งส่วนใหญ่ของหน้า**: ใช้หัวข้อและระยะห่าง
|
|
36
|
+
- **ในฟอร์ม** (เช่น "หรือ" ระหว่างทางเลือก): ใช้ `FieldSeparator` (ดู [Field](../Field/Field.md))
|
|
37
|
+
- **ในรายการ `Select` / `DropdownMenu`**: ใช้ `SelectSeparator` / `DropdownMenuSeparator`
|
|
38
|
+
|
|
39
|
+
## Props and variants
|
|
40
|
+
|
|
41
|
+
| Prop | ค่า | ค่าเริ่มต้น | ความหมาย |
|
|
42
|
+
| ------------- | ------------------------ | ------------ | ------------------------------------------------ |
|
|
43
|
+
| `orientation` | `horizontal`, `vertical` | `horizontal` | แนวนอน: หนา 1px กว้างเต็ม แนวตั้ง: กว้าง 1px สูงเท่าแถว |
|
|
44
|
+
| `className` | class | – | ระยะห่างรอบเส้น เช่น `my-4` |
|
|
45
|
+
|
|
46
|
+
เส้นคั่นเป็นแค่การตกแต่ง โปรแกรมอ่านหน้าจออ่านว่าเป็นเส้นคั่น TODO: ยังไม่ได้ตัดสินใจว่าเส้นคั่นเพื่อความสวยงามควรซ่อนจากโปรแกรมอ่านหน้าจอหรือไม่
|
|
47
|
+
|
|
48
|
+
## Tokens used
|
|
49
|
+
|
|
50
|
+
ค่าทั้งหมดมาจาก `src/styles/theme.css`
|
|
51
|
+
|
|
52
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
53
|
+
| ---------- | ------------------------- | -------------------- | ---- |
|
|
54
|
+
| `--border` | `oklch(0.93 0.007 106.5)` | `oklch(1 0 0 / 10%)` | สีเส้น |
|
|
55
|
+
|
|
56
|
+
## Example
|
|
57
|
+
|
|
58
|
+
จาก story `Vertical` ใน `Separator.stories.tsx`:
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
<div className="flex h-5 items-center gap-4 text-sm">
|
|
62
|
+
<span>ภาพรวม</span>
|
|
63
|
+
<Separator orientation="vertical" />
|
|
64
|
+
<span>ธุรกรรม</span>
|
|
65
|
+
<Separator orientation="vertical" />
|
|
66
|
+
<span>เอกสาร</span>
|
|
67
|
+
</div>
|
|
68
|
+
```
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Skeleton (โครงร่างระหว่างโหลด)
|
|
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 { Skeleton } from "@designil/labdsnov"
|
|
17
|
+
|
|
18
|
+
;<div role="status" aria-label="กำลังโหลดยอดเงิน">
|
|
19
|
+
<Skeleton className="h-4 w-48" />
|
|
20
|
+
</div>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
- กำหนดขนาดด้วย `className` ให้เท่ากับเนื้อหาจริง หน้าจะไม่กระโดดเมื่อข้อมูลมาถึง
|
|
24
|
+
- ครอบกลุ่ม skeleton ด้วย `role="status"` และ `aria-label` ที่บอกว่ากำลังโหลดอะไร เพราะ Skeleton ไม่มีข้อความให้โปรแกรมอ่านหน้าจออ่าน
|
|
25
|
+
|
|
26
|
+
## When to use
|
|
27
|
+
|
|
28
|
+
- เนื้อหาที่รู้รูปร่างล่วงหน้ากำลังโหลด เช่น การ์ดกองทุน ยอดเงิน ตารางธุรกรรม
|
|
29
|
+
|
|
30
|
+
## When not to use
|
|
31
|
+
|
|
32
|
+
- **การทำงานที่รู้ความคืบหน้า** (อัปโหลดไฟล์): ใช้ `Progress`
|
|
33
|
+
- **การกระทำของผู้ใช้ที่รอผล** (กดบันทึก): ปิดปุ่มและใส่ `Spinner` (ดู [Spinner](../Spinner/Spinner.md))
|
|
34
|
+
- **โหลดเร็วมาก** (ต่ำกว่าประมาณ 300ms): skeleton กะพริบแวบเดียวดูรบกวน TODO: ยังไม่ได้กำหนดเวลาหน่วงก่อนแสดง
|
|
35
|
+
|
|
36
|
+
## Props and variants
|
|
37
|
+
|
|
38
|
+
ไม่มี variant หรือ size มุมโค้ง 18px ปรับรูปร่างด้วย `className` เช่น `rounded-full` สำหรับรูปโปรไฟล์
|
|
39
|
+
|
|
40
|
+
| Prop | ค่า | ความหมาย |
|
|
41
|
+
| ----------- | ----- | ----------------------------- |
|
|
42
|
+
| `className` | class | **ต้องใส่** ขนาด เช่น `h-4 w-48` |
|
|
43
|
+
|
|
44
|
+
## Tokens used
|
|
45
|
+
|
|
46
|
+
ค่าทั้งหมดมาจาก `src/styles/theme.css`
|
|
47
|
+
|
|
48
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
49
|
+
| ---------- | -------------------------- | -------------------------- | ------------------------------- |
|
|
50
|
+
| `--muted` | `oklch(0.966 0.005 106.5)` | `oklch(0.286 0.016 107.4)` | สีกล่อง |
|
|
51
|
+
| `--radius` | `0.625rem` | – | มุมโค้ง (`--radius × 1.8` = 18px) |
|
|
52
|
+
|
|
53
|
+
## Example
|
|
54
|
+
|
|
55
|
+
จาก story `FundCardLoading` ใน `Skeleton.stories.tsx`:
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
<div
|
|
59
|
+
className="flex w-64 flex-col gap-3"
|
|
60
|
+
role="status"
|
|
61
|
+
aria-label="กำลังโหลดตัวเลือกการลงทุน"
|
|
62
|
+
>
|
|
63
|
+
<Skeleton className="aspect-square w-full rounded-3xl" />
|
|
64
|
+
<Skeleton className="h-3 w-32" />
|
|
65
|
+
<Skeleton className="h-4 w-48" />
|
|
66
|
+
<Skeleton className="h-5 w-24" />
|
|
67
|
+
</div>
|
|
68
|
+
```
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Slider (แถบเลื่อนเลือกค่า)
|
|
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, Slider } from "@designil/labdsnov"
|
|
17
|
+
|
|
18
|
+
<Label id="rate-label">อัตราเงินสมทบเพิ่มเติม {rate}%</Label>
|
|
19
|
+
<Slider
|
|
20
|
+
value={rate}
|
|
21
|
+
onValueChange={(v) => setRate(v as number)}
|
|
22
|
+
min={0}
|
|
23
|
+
max={15}
|
|
24
|
+
step={0.5}
|
|
25
|
+
getAriaLabel={() => "อัตราเงินสมทบเพิ่มเติม"}
|
|
26
|
+
getAriaValueText={(formatted) => `${formatted}% ของเงินเดือน`}
|
|
27
|
+
/>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
- **ตั้งชื่อเสมอ** ด้วย `getAriaLabel` และใส่ `getAriaValueText` ให้มีหน่วย (%, บาท, ปี)
|
|
31
|
+
- **แสดงค่าที่เลือกเป็นตัวเลข** ข้าง ๆ เสมอ ตำแหน่งปุ่มอย่างเดียวอ่านค่าแม่นไม่ได้
|
|
32
|
+
- ตัวเลขจัดรูปแบบภาษาไทย (`locale="th-TH"`) เปลี่ยนได้ด้วย `locale` และ `format`
|
|
33
|
+
|
|
34
|
+
## When to use
|
|
35
|
+
|
|
36
|
+
- ค่าที่ไม่ต้องแม่นยำมากและอยากเห็นผลทันที เช่น อัตราเงินสมทบ 0–15% ในเครื่องคำนวณ
|
|
37
|
+
- ช่วงค่า เช่น อายุ 30–60 ปี (`value` สองค่า)
|
|
38
|
+
|
|
39
|
+
## When not to use
|
|
40
|
+
|
|
41
|
+
| สถานการณ์ | ใช้แทน |
|
|
42
|
+
| ---------------------- | -------------------------------------- |
|
|
43
|
+
| จำนวนเงินที่ต้องพิมพ์แม่นยำ | `Input type="number"` หรือ `InputGroup` |
|
|
44
|
+
| ตัวเลือกไม่กี่ค่าที่มีชื่อ | `RadioGroup` หรือ `ToggleGroup` |
|
|
45
|
+
| แสดงความคืบหน้า (กดไม่ได้) | `Progress` |
|
|
46
|
+
|
|
47
|
+
TODO: ยังไม่ได้ตัดสินใจว่าเครื่องคำนวณควรมีช่องพิมพ์ค่าคู่กับ Slider หรือไม่
|
|
48
|
+
|
|
49
|
+
## Props and variants
|
|
50
|
+
|
|
51
|
+
| Prop | ค่า | ค่าเริ่มต้น | ความหมาย |
|
|
52
|
+
| ------------------------- | -------------------------------------- | ------------ | ----------------------------------------- |
|
|
53
|
+
| `value` / `onValueChange` | ตัวเลข หรือ array สองค่า / ฟังก์ชัน | – | ควบคุมค่าจากภายนอก |
|
|
54
|
+
| `defaultValue` | ตัวเลข หรือ array สองค่า | `min` | ค่าเริ่มต้น array = มีสองปุ่ม (ช่วง) |
|
|
55
|
+
| `min` / `max` | ตัวเลข | `0` / `100` | ขอบเขต |
|
|
56
|
+
| `step` / `largeStep` | ตัวเลข | `1` / `10` | ระยะต่อการกดลูกศร / Page Up-Down |
|
|
57
|
+
| `orientation` | `horizontal`, `vertical` | `horizontal` | แนวนอนเต็มความกว้าง หรือแนวตั้งสูงอย่างน้อย 160px |
|
|
58
|
+
| `getAriaLabel` | `(index) => ข้อความ` | – | ชื่อของแต่ละปุ่ม |
|
|
59
|
+
| `getAriaValueText` | `(formatted, value, index) => ข้อความ` | – | ข้อความที่อ่านออกเสียงสำหรับค่า |
|
|
60
|
+
| `format` / `locale` | ตัวเลือกของ `Intl.NumberFormat` / locale | – / `th-TH` | รูปแบบตัวเลข |
|
|
61
|
+
| `disabled` | `boolean` | `false` | ปิดใช้งาน จางลง 50% |
|
|
62
|
+
|
|
63
|
+
หน้าตา: รางสูง 8px มีขอบ (contrast 3:1) ช่วงที่เลือกสีหลัก ปุ่มเลื่อน 24×16px พื้นขาวขอบสีหลัก
|
|
64
|
+
|
|
65
|
+
- **คีย์บอร์ด**: ลูกศรเลื่อนทีละ `step`, Page Up/Down ทีละ `largeStep`, Home/End ไปสุดขอบ
|
|
66
|
+
- **Focus**: วงแหวนทึบสี `--focus-ring` รอบปุ่มเลื่อน เว้นระยะ 2px
|
|
67
|
+
|
|
68
|
+
## Tokens used
|
|
69
|
+
|
|
70
|
+
ค่าทั้งหมดมาจาก `src/styles/theme.css`
|
|
71
|
+
|
|
72
|
+
### Component tokens
|
|
73
|
+
|
|
74
|
+
token เฉพาะของคอมโพเนนต์นี้ ชี้ไปที่ semantic token ด้านล่าง เปลี่ยนที่นี่เพื่อปรับเฉพาะคอมโพเนนต์นี้ (โหมดมืด "–" = ใช้ค่าเดียวกับโหมดสว่าง)
|
|
75
|
+
|
|
76
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
77
|
+
| ----------------------- | ------------------ | ------ | --------------------------------------------- |
|
|
78
|
+
| `--slider-track-border` | `--control-border` | – | ขอบราง (contrast 3:1) |
|
|
79
|
+
| `--slider-track` | `--muted` | – | ราง |
|
|
80
|
+
| `--slider-range` | `--primary` | – | ช่วงที่เลือก |
|
|
81
|
+
| `--slider-thumb-border` | `--primary` | – | ขอบปุ่มเลื่อน |
|
|
82
|
+
| `--slider-thumb-bg` | `--background` | – | พื้นปุ่มเลื่อน |
|
|
83
|
+
| `--focus-ring` | `--ring` | – | วงแหวน focus จากคีย์บอร์ดของทุกคอมโพเนนต์ (ทึบ 2px) |
|
|
84
|
+
|
|
85
|
+
### Semantic tokens
|
|
86
|
+
|
|
87
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
88
|
+
| ------------------ | --------------------------- | --------------------------- | --------------------------- |
|
|
89
|
+
| `--ring` | `oklch(0.45 0.03 106.9)` | `oklch(0.8 0.02 106.9)` | วงแหวน focus |
|
|
90
|
+
| `--background` | `oklch(1 0 0)` | `oklch(0.153 0.006 107.1)` | ระยะเว้นรอบวงแหวน focus |
|
|
91
|
+
| `--control-border` | `oklch(0.6 0.02 106.9)` | `oklch(0.55 0.015 106.9)` | ผ่าน token ของคอมโพเนนต์ด้านบน |
|
|
92
|
+
| `--muted` | `oklch(0.966 0.005 106.5)` | `oklch(0.286 0.016 107.4)` | ผ่าน token ของคอมโพเนนต์ด้านบน |
|
|
93
|
+
| `--primary` | `oklch(0.553 0.195 38.402)` | `oklch(0.705 0.187 47.604)` | ผ่าน token ของคอมโพเนนต์ด้านบน |
|
|
94
|
+
|
|
95
|
+
## Example
|
|
96
|
+
|
|
97
|
+
จาก story `Range` ใน `Slider.stories.tsx`:
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
<Slider
|
|
101
|
+
defaultValue={[30, 60]}
|
|
102
|
+
min={18}
|
|
103
|
+
max={75}
|
|
104
|
+
getAriaLabel={(index) => (index === 0 ? "อายุต่ำสุด" : "อายุสูงสุด")}
|
|
105
|
+
getAriaValueText={(formatted) => `${formatted} ปี`}
|
|
106
|
+
/>
|
|
107
|
+
```
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Spinner (ไอคอนกำลังโหลด)
|
|
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 { Button, Spinner } from "@designil/labdsnov"
|
|
17
|
+
|
|
18
|
+
;<Button disabled>
|
|
19
|
+
<Spinner data-icon="inline-start" />
|
|
20
|
+
กำลังบันทึก…
|
|
21
|
+
</Button>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
- โปรแกรมอ่านหน้าจออ่านว่า "กำลังโหลด" เปลี่ยนได้ด้วย `aria-label`
|
|
25
|
+
- สีและขนาดตามข้อความรอบ ๆ ปรับขนาดด้วย `className` เช่น `size-6`
|
|
26
|
+
|
|
27
|
+
## When to use
|
|
28
|
+
|
|
29
|
+
- ปุ่มที่กดแล้วต้องรอผล เช่น บันทึก ส่งคำขอ: ปิดปุ่ม (`disabled`) ใส่ Spinner และเปลี่ยนข้อความเป็น "กำลัง…"
|
|
30
|
+
- พื้นที่เล็ก ๆ ที่กำลังโหลด เช่น ในป้ายสถานะ
|
|
31
|
+
|
|
32
|
+
## When not to use
|
|
33
|
+
|
|
34
|
+
| สถานการณ์ | ใช้แทน |
|
|
35
|
+
| --------------------------------- | ----------------------- |
|
|
36
|
+
| เนื้อหาที่รู้รูปร่างกำลังโหลด (การ์ด ตาราง) | `Skeleton` |
|
|
37
|
+
| งานที่รู้ความคืบหน้า (อัปโหลด) | `Progress` |
|
|
38
|
+
| Spinner อย่างเดียวกลางหน้า ไม่มีข้อความ | ใส่ข้อความบอกว่ากำลังทำอะไร |
|
|
39
|
+
|
|
40
|
+
## Props and variants
|
|
41
|
+
|
|
42
|
+
ไม่มี variant หรือ size ขนาดเริ่มต้น 16px หมุนตลอด
|
|
43
|
+
|
|
44
|
+
| Prop | ค่า | ความหมาย |
|
|
45
|
+
| ------------ | ------ | ---------------------------------- |
|
|
46
|
+
| `aria-label` | ข้อความ | ค่าเริ่มต้น "กำลังโหลด" |
|
|
47
|
+
| `className` | class | ขนาดหรือสี เช่น `size-6 text-primary` |
|
|
48
|
+
|
|
49
|
+
TODO: ปุ่มยังไม่มี prop `loading` ที่ใส่ Spinner และปิดปุ่มให้อัตโนมัติ ต้องประกอบเองตามตัวอย่าง
|
|
50
|
+
|
|
51
|
+
## Tokens used
|
|
52
|
+
|
|
53
|
+
ไม่ใช้ token โดยตรง สีตามข้อความ (`currentColor`)
|
|
54
|
+
|
|
55
|
+
## Example
|
|
56
|
+
|
|
57
|
+
จาก story `InButton` ใน `Spinner.stories.tsx` (บางส่วน):
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
<Button disabled>
|
|
61
|
+
<Spinner data-icon="inline-start" />
|
|
62
|
+
กำลังบันทึก…
|
|
63
|
+
</Button>
|
|
64
|
+
```
|
|
@@ -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
|
+
```
|