@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,105 @@
|
|
|
1
|
+
# InputOTP (ช่องกรอกรหัสยืนยัน)
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
ช่องกรอกรหัสยืนยันแบบใช้ครั้งเดียว (OTP) แยกกล่องละหนึ่งตัวอักษร เช่น รหัส 6 หลักทาง SMS
|
|
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
|
+
ใช้ไลบรารี `input-otp` (ติดตั้งมากับ `@designil/labdsnov` แล้ว)
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, Label } from "@designil/labdsnov"
|
|
19
|
+
|
|
20
|
+
<Label htmlFor="otp">รหัสยืนยัน 6 หลัก</Label>
|
|
21
|
+
<InputOTP id="otp" maxLength={6} onComplete={verify}>
|
|
22
|
+
<InputOTPGroup>
|
|
23
|
+
<InputOTPSlot index={0} />
|
|
24
|
+
<InputOTPSlot index={1} />
|
|
25
|
+
<InputOTPSlot index={2} />
|
|
26
|
+
</InputOTPGroup>
|
|
27
|
+
<InputOTPSeparator />
|
|
28
|
+
<InputOTPGroup>
|
|
29
|
+
<InputOTPSlot index={3} />
|
|
30
|
+
<InputOTPSlot index={4} />
|
|
31
|
+
<InputOTPSlot index={5} />
|
|
32
|
+
</InputOTPGroup>
|
|
33
|
+
</InputOTP>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
- มีช่องกรอกจริงหนึ่งช่องซ้อนอยู่ใต้กล่อง จึงวาง (paste) รหัสทั้งชุด และกรอกอัตโนมัติจาก SMS บนมือถือได้
|
|
37
|
+
- ใส่ `InputOTPSlot` ให้ครบตาม `maxLength` โดย `index` เริ่มที่ 0
|
|
38
|
+
|
|
39
|
+
## When to use
|
|
40
|
+
|
|
41
|
+
- รหัสยืนยันตัวตนแบบใช้ครั้งเดียว เมื่อเข้าสู่ระบบหรือยืนยันการถอนเงิน
|
|
42
|
+
|
|
43
|
+
## When not to use
|
|
44
|
+
|
|
45
|
+
- **รหัสผ่าน หรือตัวเลขยาวอื่น ๆ** (เลขบัญชี, TFN): ใช้ `Input`
|
|
46
|
+
- **PIN ที่ต้องซ่อนตัวเลข**: TODO: ยังไม่มีตัวเลือกซ่อนตัวเลขในกล่อง
|
|
47
|
+
|
|
48
|
+
## Props and variants
|
|
49
|
+
|
|
50
|
+
ไม่มี variant หรือ size กล่องละ 36px หน้าตาเหมือน `Input` แบบ `filled` กล่องในกลุ่มเดียวกันต่อกันเป็นแคปซูล
|
|
51
|
+
|
|
52
|
+
| ส่วน / Prop | ความหมาย |
|
|
53
|
+
| ------------------------------- | ---------------------------------------------------- |
|
|
54
|
+
| `InputOTP` `maxLength` | **บังคับ** จำนวนตัวอักษร |
|
|
55
|
+
| `InputOTP` `value` / `onChange` | ควบคุมค่าจากภายนอก |
|
|
56
|
+
| `InputOTP` `onComplete` | เรียกเมื่อกรอกครบ ใช้ส่งรหัสไปตรวจได้ทันที |
|
|
57
|
+
| `InputOTP` `pattern` | จำกัดตัวอักษรที่กรอกได้ TODO: ยังไม่มีตัวอย่าง (เช่น ตัวเลขเท่านั้น) |
|
|
58
|
+
| `InputOTP` `disabled` | ปิดใช้งาน จางลง 50% |
|
|
59
|
+
| `InputOTPGroup` | กลุ่มกล่องที่ต่อกัน |
|
|
60
|
+
| `InputOTPSlot` `index` | **บังคับ** ตำแหน่งของกล่อง |
|
|
61
|
+
| `InputOTPSlot` `aria-invalid` | รหัสไม่ถูกต้อง เส้นขอบสีแดง |
|
|
62
|
+
| `InputOTPSeparator` | ขีดคั่นระหว่างกลุ่ม |
|
|
63
|
+
|
|
64
|
+
กล่องที่กำลังกรอกมีวงแหวนทึบสี `--focus-ring` (สีแดงเมื่อข้อมูลไม่ถูกต้อง) และเคอร์เซอร์กะพริบ
|
|
65
|
+
|
|
66
|
+
## Tokens used
|
|
67
|
+
|
|
68
|
+
ค่าทั้งหมดมาจาก `src/styles/theme.css`
|
|
69
|
+
|
|
70
|
+
### Component tokens
|
|
71
|
+
|
|
72
|
+
token เฉพาะของคอมโพเนนต์นี้ ชี้ไปที่ semantic token ด้านล่าง เปลี่ยนที่นี่เพื่อปรับเฉพาะคอมโพเนนต์นี้ (โหมดมืด "–" = ใช้ค่าเดียวกับโหมดสว่าง)
|
|
73
|
+
|
|
74
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
75
|
+
| ------------------ | ------------------- | ------------------- | ----------------------------------------------- |
|
|
76
|
+
| `--invalid-border` | `--destructive` | – | เส้นขอบเมื่อข้อมูลไม่ถูกต้อง และวงแหวน focus ขณะไม่ถูกต้อง |
|
|
77
|
+
| `--invalid-ring` | `--destructive` 20% | `--destructive` 40% | วงแหวนจางรอบช่องที่ไม่ถูกต้อง (ตกแต่ง) |
|
|
78
|
+
| `--field-border` | `--control-border` | – | เส้นขอบช่องกรอก |
|
|
79
|
+
| `--field-bg` | `--input` 50% | – | พื้นช่องกรอก |
|
|
80
|
+
| `--focus-ring` | `--ring` | – | วงแหวน focus จากคีย์บอร์ดของทุกคอมโพเนนต์ (ทึบ 2px) |
|
|
81
|
+
|
|
82
|
+
### Semantic tokens
|
|
83
|
+
|
|
84
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
85
|
+
| ------------------ | -------------------------- | -------------------------- | --------------------------- |
|
|
86
|
+
| `--input` | `oklch(0.93 0.007 106.5)` | `oklch(1 0 0 / 15%)` | พื้นกล่อง (50%) และเส้นขอบ |
|
|
87
|
+
| `--ring` | `oklch(0.45 0.03 106.9)` | `oklch(0.8 0.02 106.9)` | กล่องที่กำลังกรอก |
|
|
88
|
+
| `--foreground` | `oklch(0.153 0.006 107.1)` | `oklch(0.988 0.003 106.5)` | เคอร์เซอร์ |
|
|
89
|
+
| `--destructive` | `oklch(0.505 0.2 27.325)` | `oklch(0.75 0.16 22.216)` | สถานะไม่ถูกต้อง |
|
|
90
|
+
| `--control-border` | `oklch(0.6 0.02 106.9)` | `oklch(0.55 0.015 106.9)` | ผ่าน token ของคอมโพเนนต์ด้านบน |
|
|
91
|
+
|
|
92
|
+
## Example
|
|
93
|
+
|
|
94
|
+
จาก story `Invalid` ใน `InputOTP.stories.tsx`:
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
<InputOTP id="otp-invalid" maxLength={6} defaultValue="123456">
|
|
98
|
+
<InputOTPGroup>
|
|
99
|
+
{[0, 1, 2, 3, 4, 5].map((index) => (
|
|
100
|
+
<InputOTPSlot key={index} index={index} aria-invalid />
|
|
101
|
+
))}
|
|
102
|
+
</InputOTPGroup>
|
|
103
|
+
</InputOTP>
|
|
104
|
+
<p className="text-sm text-destructive">รหัสไม่ถูกต้อง กรุณาลองอีกครั้ง</p>
|
|
105
|
+
```
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
kind: component
|
|
2
|
+
id: kbd
|
|
3
|
+
name: Kbd
|
|
4
|
+
description: >-
|
|
5
|
+
Shows a keyboard key or shortcut, such as ⌘ K, in text, a menu or a Tooltip. A
|
|
6
|
+
`<kbd>`, 22px high, 12px text, 10px radius.
|
|
7
|
+
metadata:
|
|
8
|
+
status: {status: stable}
|
|
9
|
+
since: 1.0.0
|
|
10
|
+
tags: [display]
|
|
11
|
+
|
|
12
|
+
sections:
|
|
13
|
+
- kind: guidelines
|
|
14
|
+
for: all
|
|
15
|
+
framing: when-to-use
|
|
16
|
+
items:
|
|
17
|
+
- level: should
|
|
18
|
+
statement: >-
|
|
19
|
+
Use to show shortcuts in a <dsds:tooltip>, a menu or help text.
|
|
20
|
+
- level: may
|
|
21
|
+
statement: >-
|
|
22
|
+
Use as a hint inside a search field in <dsds:input-group>; its background follows
|
|
23
|
+
the field.
|
|
24
|
+
example:
|
|
25
|
+
ref:
|
|
26
|
+
href: ./Kbd.stories.tsx#InInputGroup
|
|
27
|
+
rel: demo
|
|
28
|
+
- level: must-not
|
|
29
|
+
statement: >-
|
|
30
|
+
Don't use it as something to click. Kbd isn't interactive; use <dsds:button>.
|
|
31
|
+
alternatives:
|
|
32
|
+
- to: button
|
|
33
|
+
checkedBy: manual
|
|
34
|
+
- level: should-not
|
|
35
|
+
statement: >-
|
|
36
|
+
Don't use for code or values the user must type, such as a member number; use
|
|
37
|
+
`<code>` or plain text.
|
|
38
|
+
|
|
39
|
+
- kind: guidelines
|
|
40
|
+
for: all
|
|
41
|
+
items:
|
|
42
|
+
- id: group-simultaneous
|
|
43
|
+
level: must
|
|
44
|
+
statement: >-
|
|
45
|
+
Keys pressed together go in a `KbdGroup`
|
|
46
|
+
(`<KbdGroup><Kbd>⌘</Kbd><Kbd>K</Kbd></KbdGroup>`). Don't write "+" between them.
|
|
47
|
+
checkedBy: manual
|
|
48
|
+
- id: key-names-as-printed
|
|
49
|
+
level: must
|
|
50
|
+
statement: >-
|
|
51
|
+
Write key names as printed on the keyboard (`Enter`, `Esc`, `⌘`, `Ctrl`), not
|
|
52
|
+
translated into Thai. The surrounding sentence is Thai, e.g. "กด … เพื่อค้นหากองทุน"
|
|
53
|
+
(press … to search funds).
|
|
54
|
+
checkedBy: manual
|
|
55
|
+
- id: real-shortcut-only
|
|
56
|
+
level: must
|
|
57
|
+
statement: >-
|
|
58
|
+
Only show shortcuts the app actually binds. Kbd doesn't bind any key.
|
|
59
|
+
checkedBy: manual
|
|
60
|
+
- id: tooltip-auto-colour
|
|
61
|
+
level: may
|
|
62
|
+
statement: >-
|
|
63
|
+
Inside a Tooltip, don't set colours: Kbd inverts with the Tooltip on its own
|
|
64
|
+
(`--kbd-tooltip-*`).
|
|
65
|
+
example:
|
|
66
|
+
ref:
|
|
67
|
+
href: ./Kbd.stories.tsx#InTooltip
|
|
68
|
+
rel: demo
|
|
69
|
+
|
|
70
|
+
- kind: guidelines
|
|
71
|
+
for: all
|
|
72
|
+
title: Accessibility
|
|
73
|
+
tags: [accessibility]
|
|
74
|
+
items:
|
|
75
|
+
- id: kbd-contrast
|
|
76
|
+
level: must
|
|
77
|
+
statement: >-
|
|
78
|
+
Kbd text passes 5.41:1 light / 6.14:1 dark, and inside a Tooltip 10.96:1 / 14.60:1.
|
|
79
|
+
checks:
|
|
80
|
+
- href: ../../../scripts/tokens.mjs
|
|
81
|
+
role: test
|
|
82
|
+
note: CONTRAST_PAIRS "Kbd …"
|
|
83
|
+
checkedBy: automated
|
|
84
|
+
- id: symbol-name
|
|
85
|
+
level: should
|
|
86
|
+
statement: >-
|
|
87
|
+
Symbols like ⌘ ⇧ ⌥ aren't always read out as key names. Add an `aria-label` to the
|
|
88
|
+
`Kbd` (e.g. `aria-label="Command"`) when the shortcut matters.
|
|
89
|
+
checkedBy: manual
|
|
90
|
+
|
|
91
|
+
- kind: section
|
|
92
|
+
for: all
|
|
93
|
+
title: Open decisions
|
|
94
|
+
freeform:
|
|
95
|
+
- title: TODO
|
|
96
|
+
body: >-
|
|
97
|
+
Not yet decided how to show ⌘ (macOS) or Ctrl (Windows) depending on the user's
|
|
98
|
+
device.
|
|
99
|
+
|
|
100
|
+
sourceFiles:
|
|
101
|
+
- platform: react
|
|
102
|
+
file: ./Kbd.tsx
|
|
103
|
+
|
|
104
|
+
imports:
|
|
105
|
+
- platform: react
|
|
106
|
+
code: >-
|
|
107
|
+
import { Kbd, KbdGroup } from "@designil/labdsnov"
|
|
108
|
+
package: "@designil/labdsnov"
|
|
109
|
+
|
|
110
|
+
alternatives:
|
|
111
|
+
- to: button
|
|
112
|
+
|
|
113
|
+
refs:
|
|
114
|
+
- href: ./Kbd.md
|
|
115
|
+
rel: relates-to
|
|
116
|
+
role: Thai usage doc
|
|
117
|
+
- href: ./Kbd.stories.tsx
|
|
118
|
+
rel: demo
|
|
119
|
+
role: CSF stories
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Kbd (ปุ่มคีย์บอร์ด)
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
แสดงปุ่มบนคีย์บอร์ดหรือคีย์ลัด เช่น ⌘ K ในข้อความ เมนู หรือ Tooltip
|
|
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 { Kbd, KbdGroup } from "@designil/labdsnov"
|
|
17
|
+
|
|
18
|
+
;<p>
|
|
19
|
+
กด{" "}
|
|
20
|
+
<KbdGroup>
|
|
21
|
+
<Kbd>⌘</Kbd>
|
|
22
|
+
<Kbd>K</Kbd>
|
|
23
|
+
</KbdGroup>{" "}
|
|
24
|
+
เพื่อค้นหากองทุน
|
|
25
|
+
</p>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- ปุ่มที่กดพร้อมกันใส่ใน `KbdGroup`
|
|
29
|
+
- เขียนชื่อปุ่มตามที่พิมพ์บนคีย์บอร์ด (`Enter`, `Esc`, `⌘`) ไม่แปลเป็นภาษาไทย
|
|
30
|
+
- TODO: ยังไม่ได้กำหนดว่าจะแสดง ⌘ (macOS) หรือ Ctrl (Windows) ตามเครื่องของผู้ใช้อย่างไร
|
|
31
|
+
|
|
32
|
+
## When to use
|
|
33
|
+
|
|
34
|
+
- บอกคีย์ลัดใน Tooltip, เมนู หรือข้อความช่วยเหลือ
|
|
35
|
+
- คำใบ้ในช่องค้นหา (ใน `InputGroup`)
|
|
36
|
+
|
|
37
|
+
## When not to use
|
|
38
|
+
|
|
39
|
+
- **เป็นปุ่มให้กด**: ใช้ `Button` (Kbd กดไม่ได้)
|
|
40
|
+
- **โค้ดหรือค่าที่ผู้ใช้ต้องพิมพ์ตาม เช่น เลขสมาชิก**: ใช้ `<code>` หรือข้อความปกติ
|
|
41
|
+
|
|
42
|
+
## Props and variants
|
|
43
|
+
|
|
44
|
+
ไม่มี variant หรือ size สูง 22px ตัวอักษร 12px มุมโค้ง 10px
|
|
45
|
+
|
|
46
|
+
- **ใน Tooltip**: สีกลับตาม Tooltip อัตโนมัติ
|
|
47
|
+
- **ใน InputGroup**: พื้นเปลี่ยนตามช่องกรอก
|
|
48
|
+
- `Kbd` และ `KbdGroup` เป็น `<kbd>` ใส่ `className` ได้
|
|
49
|
+
|
|
50
|
+
## Tokens used
|
|
51
|
+
|
|
52
|
+
ค่าทั้งหมดมาจาก `src/styles/theme.css`
|
|
53
|
+
|
|
54
|
+
### Component tokens
|
|
55
|
+
|
|
56
|
+
token เฉพาะของคอมโพเนนต์นี้ ชี้ไปที่ semantic token ด้านล่าง เปลี่ยนที่นี่เพื่อปรับเฉพาะคอมโพเนนต์นี้ (โหมดมืด "–" = ใช้ค่าเดียวกับโหมดสว่าง)
|
|
57
|
+
|
|
58
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
59
|
+
| ------------------ | -------------------- | ------------------ | ------------------------ |
|
|
60
|
+
| `--kbd-bg` | `--muted` | – | พื้นปุ่มคีย์บอร์ด |
|
|
61
|
+
| `--kbd-fg` | `--muted-foreground` | – | ตัวอักษรปุ่มคีย์บอร์ด |
|
|
62
|
+
| `--kbd-tooltip-bg` | `--tooltip-fg` 20% | `--tooltip-fg` 12% | พื้นปุ่มคีย์บอร์ดใน Tooltip |
|
|
63
|
+
| `--kbd-tooltip-fg` | `--tooltip-fg` | – | ตัวอักษรปุ่มคีย์บอร์ดใน Tooltip |
|
|
64
|
+
|
|
65
|
+
### Semantic tokens
|
|
66
|
+
|
|
67
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
68
|
+
| -------------------- | -------------------------- | -------------------------- | --------------------------- |
|
|
69
|
+
| `--muted` | `oklch(0.966 0.005 106.5)` | `oklch(0.286 0.016 107.4)` | ผ่าน token ของคอมโพเนนต์ด้านบน |
|
|
70
|
+
| `--muted-foreground` | `oklch(0.5 0.027 107.3)` | `oklch(0.737 0.021 106.9)` | ผ่าน token ของคอมโพเนนต์ด้านบน |
|
|
71
|
+
|
|
72
|
+
## Example
|
|
73
|
+
|
|
74
|
+
จาก story `Shortcut` ใน `Kbd.stories.tsx`:
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
<p className="text-sm">
|
|
78
|
+
กด{" "}
|
|
79
|
+
<KbdGroup>
|
|
80
|
+
<Kbd>⌘</Kbd>
|
|
81
|
+
<Kbd>K</Kbd>
|
|
82
|
+
</KbdGroup>{" "}
|
|
83
|
+
เพื่อค้นหากองทุน
|
|
84
|
+
</p>
|
|
85
|
+
```
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
kind: component
|
|
2
|
+
id: label
|
|
3
|
+
name: Label
|
|
4
|
+
description: >-
|
|
5
|
+
The name of a form field: says what to enter, and whether it's required (red
|
|
6
|
+
asterisk). 14px, medium weight, rendered as a `<label>`.
|
|
7
|
+
metadata:
|
|
8
|
+
status: {status: stable}
|
|
9
|
+
since: 1.0.0
|
|
10
|
+
tags: [form]
|
|
11
|
+
|
|
12
|
+
sections:
|
|
13
|
+
- kind: guidelines
|
|
14
|
+
for: all
|
|
15
|
+
framing: when-to-use
|
|
16
|
+
items:
|
|
17
|
+
- level: must
|
|
18
|
+
statement: >-
|
|
19
|
+
Every <dsds:input> has a Label tied to it (or a `FieldLabel` inside <dsds:field>).
|
|
20
|
+
checkedBy: manual
|
|
21
|
+
- level: must-not
|
|
22
|
+
statement: >-
|
|
23
|
+
Don't use it as a section or page heading; use `h2`/`h3`.
|
|
24
|
+
checkedBy: manual
|
|
25
|
+
- level: must-not
|
|
26
|
+
statement: >-
|
|
27
|
+
Don't use it for help text or error messages under a field; use
|
|
28
|
+
`FieldDescription` / `FieldError` in <dsds:field>.
|
|
29
|
+
alternatives:
|
|
30
|
+
- to: field
|
|
31
|
+
checkedBy: manual
|
|
32
|
+
- level: should-not
|
|
33
|
+
statement: >-
|
|
34
|
+
Don't use a Label with no field to point at. Without `htmlFor` it does nothing; use
|
|
35
|
+
plain text.
|
|
36
|
+
|
|
37
|
+
- kind: guidelines
|
|
38
|
+
for: all
|
|
39
|
+
items:
|
|
40
|
+
- id: htmlfor-matches-id
|
|
41
|
+
level: must
|
|
42
|
+
statement: >-
|
|
43
|
+
`htmlFor` always matches the field's `id`. Clicking the label focuses the field,
|
|
44
|
+
and screen readers read the label as the field's name.
|
|
45
|
+
evidence:
|
|
46
|
+
- href: https://www.w3.org/WAI/WCAG22/Understanding/info-and-relationships.html
|
|
47
|
+
role: WCAG 2.2 SC 1.3.1 (A)
|
|
48
|
+
checks:
|
|
49
|
+
- href: ./Label.stories.tsx#WithInput
|
|
50
|
+
role: test
|
|
51
|
+
note: play function clicks the "อีเมล" (email) label, then checks the field has focus and that name
|
|
52
|
+
checkedBy: automated
|
|
53
|
+
- id: required-both
|
|
54
|
+
level: must
|
|
55
|
+
statement: >-
|
|
56
|
+
`required` on Label only draws the red asterisk. Put `required` on the field too.
|
|
57
|
+
refines:
|
|
58
|
+
- to: field#required-two-places
|
|
59
|
+
checks:
|
|
60
|
+
- href: ./Label.stories.tsx#Required
|
|
61
|
+
role: test
|
|
62
|
+
note: play function checks for "*" in ::after
|
|
63
|
+
checkedBy: assisted
|
|
64
|
+
- id: above-8px
|
|
65
|
+
level: should
|
|
66
|
+
statement: >-
|
|
67
|
+
Place the label above the field, 8px apart (`grid gap-2`), with short text such as
|
|
68
|
+
"อีเมล" (email) or "ชื่อ-นามสกุล" (full name).
|
|
69
|
+
checkedBy: manual
|
|
70
|
+
- id: disabled-structure
|
|
71
|
+
level: should
|
|
72
|
+
statement: >-
|
|
73
|
+
The label dims to 50% when its field is disabled only in two structures: the field
|
|
74
|
+
has class `peer` and comes before the label (`.peer:disabled ~ label`), or the
|
|
75
|
+
label sits in an element with class `group` and `data-disabled="true"`. A label
|
|
76
|
+
placed above the field in the usual way does not dim on its own.
|
|
77
|
+
example:
|
|
78
|
+
ref:
|
|
79
|
+
href: ./Label.stories.tsx#DisabledGroup
|
|
80
|
+
rel: demo
|
|
81
|
+
checks:
|
|
82
|
+
- href: ./Label.stories.tsx#DisabledPeer
|
|
83
|
+
role: test
|
|
84
|
+
- href: ./Label.stories.tsx#DisabledGroup
|
|
85
|
+
role: test
|
|
86
|
+
checkedBy: automated
|
|
87
|
+
- id: no-colon
|
|
88
|
+
level: should-not
|
|
89
|
+
statement: >-
|
|
90
|
+
Don't end a label with ":" (every story writes "อีเมล", not "อีเมล:").
|
|
91
|
+
|
|
92
|
+
- kind: section
|
|
93
|
+
for: all
|
|
94
|
+
title: Open decisions
|
|
95
|
+
freeform:
|
|
96
|
+
- title: TODO
|
|
97
|
+
body: >-
|
|
98
|
+
Not yet checked whether screen readers read out the `required` asterisk.
|
|
99
|
+
|
|
100
|
+
sourceFiles:
|
|
101
|
+
- platform: react
|
|
102
|
+
file: ./Label.tsx
|
|
103
|
+
|
|
104
|
+
imports:
|
|
105
|
+
- platform: react
|
|
106
|
+
code: >-
|
|
107
|
+
import { Label } from "@designil/labdsnov"
|
|
108
|
+
package: "@designil/labdsnov"
|
|
109
|
+
|
|
110
|
+
traits:
|
|
111
|
+
- traitType: variant
|
|
112
|
+
kind: boolean
|
|
113
|
+
id: required
|
|
114
|
+
description: >-
|
|
115
|
+
A red asterisk after the text (visual only).
|
|
116
|
+
- traitType: state
|
|
117
|
+
kind: boolean
|
|
118
|
+
id: disabled
|
|
119
|
+
description: >-
|
|
120
|
+
Dimmed to 50% when its field is disabled (through `peer` or `group`).
|
|
121
|
+
|
|
122
|
+
alternatives:
|
|
123
|
+
- to: field
|
|
124
|
+
|
|
125
|
+
refs:
|
|
126
|
+
- href: ./Label.md
|
|
127
|
+
rel: relates-to
|
|
128
|
+
role: Thai usage doc
|
|
129
|
+
- href: ./Label.stories.tsx
|
|
130
|
+
rel: demo
|
|
131
|
+
role: CSF stories
|
|
132
|
+
- href: https://www.figma.com/design/QsKWb3A53lIh4QBDnAkGHh/labdsnov?node-id=10-142
|
|
133
|
+
rel: design
|
|
134
|
+
role: Label in Figma
|
|
135
|
+
- href: ../../../figma/Label.figma.ts
|
|
136
|
+
rel: source
|
|
137
|
+
role: Code Connect template
|
|
138
|
+
|
|
139
|
+
$extensions:
|
|
140
|
+
com.figma:
|
|
141
|
+
nodeId: "10:142"
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Label (ป้ายชื่อช่องกรอก)
|
|
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 { Input, Label } from "@designil/labdsnov"
|
|
17
|
+
|
|
18
|
+
;<div className="grid gap-2">
|
|
19
|
+
<Label htmlFor="full-name" required>
|
|
20
|
+
ชื่อ-นามสกุล
|
|
21
|
+
</Label>
|
|
22
|
+
<Input id="full-name" required />
|
|
23
|
+
</div>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`htmlFor` ของ Label ต้องตรงกับ `id` ของช่องกรอก
|
|
27
|
+
|
|
28
|
+
## When to use
|
|
29
|
+
|
|
30
|
+
- ทุกช่อง `Input` ต้องมี Label ผูกไว้ คลิกที่ Label แล้วโฟกัสจะไปที่ช่อง และโปรแกรมอ่านหน้าจออ่านชื่อนี้เป็นชื่อของช่อง
|
|
31
|
+
- วางไว้เหนือช่อง ห่างกัน 8px ตาม stories
|
|
32
|
+
- ช่องที่บังคับกรอก ใส่ `required` ให้มีดอกจันสีแดงต่อท้าย
|
|
33
|
+
|
|
34
|
+
## When not to use
|
|
35
|
+
|
|
36
|
+
- **หัวข้อของส่วนหรือของหน้า**: ใช้หัวข้อ (heading) แทน
|
|
37
|
+
- **ข้อความช่วยเหลือหรือข้อความผิดพลาดใต้ช่อง**: ใช้ `FieldDescription` / `FieldError` ผูกด้วย `aria-describedby` (ดู [Field](../Field/Field.md)) ในฟอร์มใช้ `FieldLabel` แทน Label ได้
|
|
38
|
+
- **ป้ายที่ไม่ได้ผูกกับช่องใด**: ถ้าไม่มี `htmlFor` ป้ายจะไม่ทำหน้าที่ใด ๆ
|
|
39
|
+
|
|
40
|
+
## Props and variants
|
|
41
|
+
|
|
42
|
+
ไม่มี variant หรือ size ตัวอักษร 14px น้ำหนัก medium
|
|
43
|
+
|
|
44
|
+
| Prop | ค่า | ค่าเริ่มต้น | ความหมาย |
|
|
45
|
+
| ----------- | --------- | ------- | ------------------------------------------- |
|
|
46
|
+
| `htmlFor` | id ของช่อง | – | ผูกป้ายกับช่องกรอก **ต้องใส่เสมอ** |
|
|
47
|
+
| `required` | `boolean` | `false` | แสดงดอกจันสีแดงต่อท้ายข้อความ |
|
|
48
|
+
| `children` | ข้อความ | – | ชื่อช่อง เป็นภาษาไทย สั้น เช่น "อีเมล", "ชื่อ-นามสกุล" |
|
|
49
|
+
| `className` | class | – | ปรับหน้าตาเฉพาะจุดครั้งเดียว ชนะสไตล์ของป้ายเสมอ |
|
|
50
|
+
|
|
51
|
+
- `required` เป็นแค่เครื่องหมายที่มองเห็น ไม่ได้ทำให้ช่องบังคับกรอก ต้องใส่ `required` ที่ `Input` ด้วย TODO: ยังไม่ได้ตรวจว่าโปรแกรมอ่านหน้าจออ่านดอกจันออกมาหรือไม่
|
|
52
|
+
- **สถานะปิดใช้งาน**: ป้ายจางลง 50% เมื่อช่องที่ผูกไว้ถูกปิดใช้งาน แต่ **ไม่เกิดขึ้นเอง** ต้องจัดโครงสร้างตาม story `DisabledPeer` หรือ `DisabledGroup` ถ้าวางป้ายเหนือช่องแบบปกติ ป้ายจะไม่จาง
|
|
53
|
+
|
|
54
|
+
## Tokens used
|
|
55
|
+
|
|
56
|
+
ค่าทั้งหมดมาจาก `src/styles/theme.css`
|
|
57
|
+
|
|
58
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
59
|
+
| --------------- | -------------------------- | -------------------------- | -------------------- |
|
|
60
|
+
| `--foreground` | `oklch(0.153 0.006 107.1)` | `oklch(0.988 0.003 106.5)` | ข้อความ (สืบทอดจากหน้า) |
|
|
61
|
+
| `--destructive` | `oklch(0.505 0.2 27.325)` | `oklch(0.75 0.16 22.216)` | ดอกจันของ `required` |
|
|
62
|
+
| `--font-sans` | system font stack | – | ข้อความ |
|
|
63
|
+
|
|
64
|
+
## Example
|
|
65
|
+
|
|
66
|
+
จาก story `WithInput` ใน `Label.stories.tsx`:
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
<div className="grid w-80 gap-2">
|
|
70
|
+
<Label htmlFor="label-email" required>
|
|
71
|
+
อีเมล
|
|
72
|
+
</Label>
|
|
73
|
+
<Input id="label-email" type="email" placeholder="you@example.com" />
|
|
74
|
+
</div>
|
|
75
|
+
```
|