@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,115 @@
|
|
|
1
|
+
# Input (ช่องกรอกข้อมูล)
|
|
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="email" required>
|
|
20
|
+
อีเมล
|
|
21
|
+
</Label>
|
|
22
|
+
<Input id="email" type="email" required placeholder="you@example.com" />
|
|
23
|
+
</div>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## When to use
|
|
27
|
+
|
|
28
|
+
- ข้อมูลสั้นบรรทัดเดียวในฟอร์ม เช่น ฟอร์มแก้ไขข้อมูลบัญชี เข้าสู่ระบบ
|
|
29
|
+
- ใช้คู่กับ `Label` เสมอ (ดู [Label](../Label/Label.md))
|
|
30
|
+
- เลือก `type` ให้ตรงกับข้อมูล (`email`, `password`, `tel`, `number`, `search`, `file`) เพื่อให้มือถือแสดงแป้นพิมพ์ที่เหมาะสม
|
|
31
|
+
|
|
32
|
+
## When not to use
|
|
33
|
+
|
|
34
|
+
- **ข้อความหลายบรรทัด**: ใช้ `Textarea`
|
|
35
|
+
- **เลือกจากรายการ หรือเปิด/ปิด**: ใช้ `Select`, `RadioGroup`, `Checkbox` หรือ `Switch`
|
|
36
|
+
- **เลือกวันที่**: ใช้ `DatePicker`
|
|
37
|
+
- **ใช้ placeholder แทนป้ายชื่อ**: placeholder หายไปเมื่อเริ่มพิมพ์ ใช้แค่ยกตัวอย่างรูปแบบ เช่น "04xx xxx xxx"
|
|
38
|
+
|
|
39
|
+
## Props and variants
|
|
40
|
+
|
|
41
|
+
| Prop | ค่า | ค่าเริ่มต้น | ความหมาย |
|
|
42
|
+
| -------------------- | ------------------- | -------- | ----------------------------------------------------------- |
|
|
43
|
+
| `variant` | `filled`, `outline` | `filled` | หน้าตาของช่อง (ดูตารางด้านล่าง) |
|
|
44
|
+
| `type` | ชนิดของ input | `text` | ชนิดข้อมูล |
|
|
45
|
+
| `id` | ข้อความ | – | ใช้ผูกกับ `Label` ผ่าน `htmlFor` |
|
|
46
|
+
| `placeholder` | ข้อความ | – | ตัวอย่างรูปแบบ เป็นภาษาไทยหรือรูปแบบข้อมูล |
|
|
47
|
+
| `value` / `onChange` | ข้อความ / ฟังก์ชัน | – | ควบคุมค่าจากภายนอก (หรือใช้ `defaultValue`) |
|
|
48
|
+
| `disabled` | `boolean` | `false` | ปิดใช้งาน จางลง 50% โฟกัสไม่ได้ |
|
|
49
|
+
| `aria-invalid` | `boolean` | – | ข้อมูลไม่ถูกต้อง แสดงเส้นขอบสีแดงและวงแหวนแดงจาง |
|
|
50
|
+
| `aria-describedby` | id ของข้อความ | – | ผูกข้อความช่วยเหลือหรือข้อความผิดพลาดใต้ช่อง ให้โปรแกรมอ่านหน้าจออ่านด้วย |
|
|
51
|
+
| `required` | `boolean` | `false` | บังคับกรอก ต้องใส่เองแม้ `Label` จะมี `required` แล้ว |
|
|
52
|
+
| `className` | class | – | ปรับหน้าตาเฉพาะจุดครั้งเดียว ชนะสไตล์ของช่องเสมอ |
|
|
53
|
+
|
|
54
|
+
### Variants
|
|
55
|
+
|
|
56
|
+
| Variant | หน้าตา | ใช้เมื่อ |
|
|
57
|
+
| --------- | ---------------- | ------------------------- |
|
|
58
|
+
| `filled` | พื้นทึบอ่อน มีเส้นขอบ | ค่าเริ่มต้น ใช้ในฟอร์มทั่วไป |
|
|
59
|
+
| `outline` | พื้นโปร่งใส มีเส้นขอบ | TODO: ยังไม่ได้กำหนดว่าใช้ที่ไหน |
|
|
60
|
+
|
|
61
|
+
ช่องสูง 36px กว้างเต็มพื้นที่ ทรงแคปซูล ตัวอักษร 16px บนจอแคบ และ 14px บนจอ 768px ขึ้นไป
|
|
62
|
+
|
|
63
|
+
### States
|
|
64
|
+
|
|
65
|
+
- **Focus จากคีย์บอร์ด**: เส้นขอบและวงแหวนทึบสี `--focus-ring`
|
|
66
|
+
- **ปิดใช้งาน**: จางลง 50%
|
|
67
|
+
- **ข้อมูลไม่ถูกต้อง** (`aria-invalid`): เส้นขอบสีแดงและวงแหวนแดงจาง เมื่อโฟกัสวงแหวนเป็นสีแดงทึบ ต้องมีข้อความบอกว่าผิดอย่างไรใต้ช่องเสมอ ใช้ `FieldError` (ดู [Field](../Field/Field.md))
|
|
68
|
+
|
|
69
|
+
## Tokens used
|
|
70
|
+
|
|
71
|
+
ค่าทั้งหมดมาจาก `src/styles/theme.css`
|
|
72
|
+
|
|
73
|
+
### Component tokens
|
|
74
|
+
|
|
75
|
+
token เฉพาะของคอมโพเนนต์นี้ ชี้ไปที่ semantic token ด้านล่าง เปลี่ยนที่นี่เพื่อปรับเฉพาะคอมโพเนนต์นี้ (โหมดมืด "–" = ใช้ค่าเดียวกับโหมดสว่าง)
|
|
76
|
+
|
|
77
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
78
|
+
| --------------------- | -------------------- | ------------------- | ----------------------------------------------- |
|
|
79
|
+
| `--field-placeholder` | `--muted-foreground` | – | placeholder |
|
|
80
|
+
| `--field-border` | `--control-border` | – | เส้นขอบช่องกรอก |
|
|
81
|
+
| `--field-bg` | `--input` 50% | – | พื้นช่องกรอก |
|
|
82
|
+
| `--focus-ring` | `--ring` | – | วงแหวน focus จากคีย์บอร์ดของทุกคอมโพเนนต์ (ทึบ 2px) |
|
|
83
|
+
| `--invalid-border` | `--destructive` | – | เส้นขอบเมื่อข้อมูลไม่ถูกต้อง และวงแหวน focus ขณะไม่ถูกต้อง |
|
|
84
|
+
| `--invalid-ring` | `--destructive` 20% | `--destructive` 40% | วงแหวนจางรอบช่องที่ไม่ถูกต้อง (ตกแต่ง) |
|
|
85
|
+
|
|
86
|
+
### Semantic tokens
|
|
87
|
+
|
|
88
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
89
|
+
| -------------------- | -------------------------- | -------------------------- | ----------------------------------- |
|
|
90
|
+
| `--input` | `oklch(0.93 0.007 106.5)` | `oklch(1 0 0 / 15%)` | พื้น `filled` (50%), เส้นขอบ `outline` |
|
|
91
|
+
| `--muted-foreground` | `oklch(0.5 0.027 107.3)` | `oklch(0.737 0.021 106.9)` | placeholder |
|
|
92
|
+
| `--foreground` | `oklch(0.153 0.006 107.1)` | `oklch(0.988 0.003 106.5)` | ตัวอักษรที่พิมพ์ (สืบทอด), ปุ่มเลือกไฟล์ |
|
|
93
|
+
| `--ring` | `oklch(0.45 0.03 106.9)` | `oklch(0.8 0.02 106.9)` | เส้นขอบและวงแหวน focus |
|
|
94
|
+
| `--destructive` | `oklch(0.505 0.2 27.325)` | `oklch(0.75 0.16 22.216)` | สถานะไม่ถูกต้อง |
|
|
95
|
+
| `--radius` | `0.625rem` | – | มุมโค้ง (`--radius × 2.2` = 22px) |
|
|
96
|
+
| `--control-border` | `oklch(0.6 0.02 106.9)` | `oklch(0.55 0.015 106.9)` | ผ่าน token ของคอมโพเนนต์ด้านบน |
|
|
97
|
+
|
|
98
|
+
## Example
|
|
99
|
+
|
|
100
|
+
จาก story `Invalid` ใน `Input.stories.tsx`:
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
<div className="grid gap-2">
|
|
104
|
+
<Label htmlFor="input-tfn">เลขประจำตัวผู้เสียภาษี (TFN)</Label>
|
|
105
|
+
<Input
|
|
106
|
+
id="input-tfn"
|
|
107
|
+
aria-invalid
|
|
108
|
+
defaultValue="123-456"
|
|
109
|
+
aria-describedby="input-tfn-hint"
|
|
110
|
+
/>
|
|
111
|
+
<p id="input-tfn-hint" className="text-xs text-destructive">
|
|
112
|
+
เลขประจำตัวผู้เสียภาษี (TFN) ต้องมี 9 หลัก
|
|
113
|
+
</p>
|
|
114
|
+
</div>
|
|
115
|
+
```
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
kind: component
|
|
2
|
+
id: input-group
|
|
3
|
+
name: InputGroup
|
|
4
|
+
description: >-
|
|
5
|
+
A text field with an icon, text or button inside the same frame, such as "AU$" before
|
|
6
|
+
an amount or a copy button. Looks like a `filled` Input, 36px high.
|
|
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: should
|
|
18
|
+
statement: >-
|
|
19
|
+
Use for a unit or currency attached to the value, such as "AU$" or "%".
|
|
20
|
+
- level: should
|
|
21
|
+
statement: >-
|
|
22
|
+
Use for a search icon in a search field, and for buttons that act on the field's
|
|
23
|
+
value, such as show/hide password or copy.
|
|
24
|
+
- level: should
|
|
25
|
+
statement: >-
|
|
26
|
+
Use `InputGroupTextarea` for a text area with a row below it, such as a character
|
|
27
|
+
counter.
|
|
28
|
+
example:
|
|
29
|
+
ref:
|
|
30
|
+
href: ./InputGroup.stories.tsx#TextareaWithFooter
|
|
31
|
+
rel: demo
|
|
32
|
+
- level: must-not
|
|
33
|
+
statement: >-
|
|
34
|
+
Don't put the form's submit button in the group. Place a <dsds:button> outside the
|
|
35
|
+
field (or use <dsds:button-group> when the button really is part of the field).
|
|
36
|
+
alternatives:
|
|
37
|
+
- to: button
|
|
38
|
+
- to: button-group
|
|
39
|
+
checkedBy: manual
|
|
40
|
+
- level: must-not
|
|
41
|
+
statement: >-
|
|
42
|
+
Don't use `InputGroupText` as the field's label. Use <dsds:label> / `FieldLabel`.
|
|
43
|
+
alternatives:
|
|
44
|
+
- to: label
|
|
45
|
+
checkedBy: manual
|
|
46
|
+
- level: should-not
|
|
47
|
+
statement: >-
|
|
48
|
+
Don't use it to choose from a list. Use <dsds:select> or <dsds:combobox>.
|
|
49
|
+
alternatives:
|
|
50
|
+
- to: select
|
|
51
|
+
- to: combobox
|
|
52
|
+
|
|
53
|
+
- kind: guidelines
|
|
54
|
+
for: all
|
|
55
|
+
items:
|
|
56
|
+
- id: group-parts
|
|
57
|
+
level: must
|
|
58
|
+
statement: >-
|
|
59
|
+
Use `InputGroupInput` / `InputGroupTextarea` instead of `Input` / `Textarea` inside
|
|
60
|
+
the group (they have no background or frame of their own). A plain `Input` in the
|
|
61
|
+
group gives a frame inside a frame.
|
|
62
|
+
checkedBy: manual
|
|
63
|
+
- id: addon-after-in-code
|
|
64
|
+
level: should
|
|
65
|
+
statement: >-
|
|
66
|
+
Always place `InputGroupAddon` after the input in code and set where it shows with
|
|
67
|
+
`align` (default `inline-start`). The DOM order is then field first, addon second.
|
|
68
|
+
checkedBy: manual
|
|
69
|
+
- id: button-ghost-xs
|
|
70
|
+
level: should
|
|
71
|
+
statement: >-
|
|
72
|
+
Buttons in the group use `InputGroupButton` (`ghost`, default `size="xs"`, or
|
|
73
|
+
`icon-xs` for icons), not a regular-size `Button`, which is as tall as the field.
|
|
74
|
+
checkedBy: manual
|
|
75
|
+
- id: disabled-manual
|
|
76
|
+
level: must
|
|
77
|
+
statement: >-
|
|
78
|
+
To disable the whole group, set `data-disabled="true"` on `InputGroup` yourself and
|
|
79
|
+
`disabled` on the input. The group doesn't set this state automatically.
|
|
80
|
+
checkedBy: manual
|
|
81
|
+
- id: readonly-copy
|
|
82
|
+
level: should
|
|
83
|
+
statement: >-
|
|
84
|
+
A value offered for copying (e.g. a member number) uses `readOnly`, not
|
|
85
|
+
`disabled`, so it can still be focused and selected.
|
|
86
|
+
example:
|
|
87
|
+
ref:
|
|
88
|
+
href: ./InputGroup.stories.tsx#WithButtons
|
|
89
|
+
rel: demo
|
|
90
|
+
checkedBy: manual
|
|
91
|
+
|
|
92
|
+
- kind: guidelines
|
|
93
|
+
for: all
|
|
94
|
+
title: Accessibility
|
|
95
|
+
tags: [accessibility]
|
|
96
|
+
items:
|
|
97
|
+
- id: button-label
|
|
98
|
+
level: must
|
|
99
|
+
statement: >-
|
|
100
|
+
An icon-only `InputGroupButton` has a Thai `aria-label`, such as "คัดลอก" (copy) or
|
|
101
|
+
"แสดง" (show).
|
|
102
|
+
refines:
|
|
103
|
+
- to: shared-a11y#icon-only-label
|
|
104
|
+
checks:
|
|
105
|
+
- href: ./InputGroup.stories.tsx#WithButtons
|
|
106
|
+
role: test
|
|
107
|
+
note: play function finds the button by the name "คัดลอก"
|
|
108
|
+
checkedBy: automated
|
|
109
|
+
- id: addon-click-focuses
|
|
110
|
+
level: must
|
|
111
|
+
statement: >-
|
|
112
|
+
Clicking an addon (outside its buttons) focuses the input. Don't stop click events
|
|
113
|
+
in the addon.
|
|
114
|
+
checks:
|
|
115
|
+
- href: ./InputGroup.stories.tsx#SearchIcon
|
|
116
|
+
role: test
|
|
117
|
+
checkedBy: automated
|
|
118
|
+
- id: group-focus-invalid
|
|
119
|
+
level: must
|
|
120
|
+
statement: >-
|
|
121
|
+
When the input is focused the whole group shows the ring, and when the input has
|
|
122
|
+
`aria-invalid` the whole group turns red. Put `aria-invalid` on `InputGroupInput`,
|
|
123
|
+
not on `InputGroup`.
|
|
124
|
+
refs:
|
|
125
|
+
- to: shared-a11y#invalid-has-message
|
|
126
|
+
rel: relates-to
|
|
127
|
+
checkedBy: manual
|
|
128
|
+
- id: unit-not-in-name
|
|
129
|
+
level: should
|
|
130
|
+
statement: >-
|
|
131
|
+
The unit in `InputGroupText` ("AU$") isn't part of the field's name. Put the unit
|
|
132
|
+
in the label too when it matters, e.g. "จำนวนเงิน (AUD)" (amount).
|
|
133
|
+
checkedBy: manual
|
|
134
|
+
|
|
135
|
+
- kind: guidelines
|
|
136
|
+
for: agent
|
|
137
|
+
items:
|
|
138
|
+
- refs:
|
|
139
|
+
- to: shared-testing#fire-change-for-typing
|
|
140
|
+
rel: same-as
|
|
141
|
+
|
|
142
|
+
- kind: definitions
|
|
143
|
+
for: all
|
|
144
|
+
context: anatomy
|
|
145
|
+
items:
|
|
146
|
+
- term: InputGroup
|
|
147
|
+
definition: >-
|
|
148
|
+
The frame. Gets the ring when an input inside it is focused.
|
|
149
|
+
- term: InputGroupInput / InputGroupTextarea
|
|
150
|
+
definition: >-
|
|
151
|
+
Text fields with no background or frame.
|
|
152
|
+
- term: InputGroupAddon
|
|
153
|
+
definition: >-
|
|
154
|
+
The addon. Takes `align`.
|
|
155
|
+
- term: InputGroupText
|
|
156
|
+
definition: >-
|
|
157
|
+
Muted text or icon.
|
|
158
|
+
- term: InputGroupButton
|
|
159
|
+
definition: >-
|
|
160
|
+
A `ghost` button. Takes `size`.
|
|
161
|
+
|
|
162
|
+
- kind: section
|
|
163
|
+
for: all
|
|
164
|
+
title: Open decisions
|
|
165
|
+
freeform:
|
|
166
|
+
- title: TODO
|
|
167
|
+
body: >-
|
|
168
|
+
There's no automatic disabled state for the whole group yet.
|
|
169
|
+
|
|
170
|
+
sourceFiles:
|
|
171
|
+
- platform: react
|
|
172
|
+
file: ./InputGroup.tsx
|
|
173
|
+
|
|
174
|
+
imports:
|
|
175
|
+
- platform: react
|
|
176
|
+
code: >-
|
|
177
|
+
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText } from "@designil/labdsnov"
|
|
178
|
+
package: "@designil/labdsnov"
|
|
179
|
+
|
|
180
|
+
traits:
|
|
181
|
+
- traitType: variant
|
|
182
|
+
kind: enum
|
|
183
|
+
id: addonAlign
|
|
184
|
+
name: InputGroupAddon align
|
|
185
|
+
description: >-
|
|
186
|
+
The `align` prop of `InputGroupAddon`.
|
|
187
|
+
values:
|
|
188
|
+
- id: inline-start
|
|
189
|
+
description: >-
|
|
190
|
+
Left of the input (default).
|
|
191
|
+
- id: inline-end
|
|
192
|
+
description: >-
|
|
193
|
+
Right of the input.
|
|
194
|
+
- id: block-start
|
|
195
|
+
description: >-
|
|
196
|
+
A row above; the group grows vertically.
|
|
197
|
+
- id: block-end
|
|
198
|
+
description: >-
|
|
199
|
+
A row below, e.g. a character counter.
|
|
200
|
+
- traitType: variant
|
|
201
|
+
kind: enum
|
|
202
|
+
id: buttonSize
|
|
203
|
+
name: InputGroupButton size
|
|
204
|
+
description: >-
|
|
205
|
+
The `size` prop of `InputGroupButton`.
|
|
206
|
+
values:
|
|
207
|
+
- id: xs
|
|
208
|
+
description: >-
|
|
209
|
+
24px high, with text (default).
|
|
210
|
+
- id: sm
|
|
211
|
+
description: >-
|
|
212
|
+
Button's `sm` size.
|
|
213
|
+
- id: icon-xs
|
|
214
|
+
description: >-
|
|
215
|
+
24×24px, icon only.
|
|
216
|
+
- id: icon-sm
|
|
217
|
+
description: >-
|
|
218
|
+
32×32px, icon only.
|
|
219
|
+
|
|
220
|
+
uses:
|
|
221
|
+
- to: input
|
|
222
|
+
- to: textarea
|
|
223
|
+
- to: button
|
|
224
|
+
alternatives:
|
|
225
|
+
- to: button-group
|
|
226
|
+
- to: combobox
|
|
227
|
+
|
|
228
|
+
refs:
|
|
229
|
+
- href: ./InputGroup.md
|
|
230
|
+
rel: relates-to
|
|
231
|
+
role: Thai usage doc
|
|
232
|
+
- href: ./InputGroup.stories.tsx
|
|
233
|
+
rel: demo
|
|
234
|
+
role: CSF stories
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# InputGroup (ช่องกรอกพร้อมส่วนเสริม)
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
ช่องกรอกที่มีไอคอน ข้อความ หรือปุ่มอยู่ในกรอบเดียวกัน เช่น "AU$" หน้าจำนวนเงิน หรือปุ่มคัดลอก
|
|
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 { InputGroup, InputGroupAddon, InputGroupInput, InputGroupText, Label } from "@designil/labdsnov"
|
|
17
|
+
|
|
18
|
+
<Label htmlFor="amount">จำนวนเงินสมทบเพิ่มเติม</Label>
|
|
19
|
+
<InputGroup>
|
|
20
|
+
<InputGroupInput id="amount" type="number" placeholder="0.00" />
|
|
21
|
+
<InputGroupAddon>
|
|
22
|
+
<InputGroupText>AU$</InputGroupText>
|
|
23
|
+
</InputGroupAddon>
|
|
24
|
+
</InputGroup>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
- ใช้ `InputGroupInput` / `InputGroupTextarea` แทน `Input` / `Textarea` ในกลุ่ม (ไม่มีพื้นและกรอบของตัวเอง)
|
|
28
|
+
- วาง `InputGroupAddon` ไว้หลังช่องกรอกใน code ได้เสมอ ตำแหน่งที่แสดงกำหนดด้วย `align`
|
|
29
|
+
|
|
30
|
+
## When to use
|
|
31
|
+
|
|
32
|
+
- หน่วยหรือสกุลเงินที่ติดกับค่า เช่น "AU$", "%"
|
|
33
|
+
- ไอคอนค้นหาในช่องค้นหา
|
|
34
|
+
- ปุ่มที่ทำงานกับค่าในช่อง เช่น แสดง/ซ่อนรหัสผ่าน คัดลอก
|
|
35
|
+
- ช่องข้อความที่มีแถวด้านล่าง เช่น ตัวนับตัวอักษร
|
|
36
|
+
|
|
37
|
+
## When not to use
|
|
38
|
+
|
|
39
|
+
- **ปุ่มส่งฟอร์ม**: วาง `Button` นอกช่อง
|
|
40
|
+
- **ป้ายชื่อของช่อง**: ใช้ `Label` / `FieldLabel` ไม่ใช่ข้อความในกลุ่ม
|
|
41
|
+
- **เลือกจากรายการ**: ใช้ `Select` หรือ `Combobox`
|
|
42
|
+
|
|
43
|
+
## Props and variants
|
|
44
|
+
|
|
45
|
+
หน้าตาเหมือน `Input` แบบ `filled` สูง 36px เมื่อช่องกรอกได้โฟกัส ทั้งกลุ่มมีวงแหวน เมื่อช่องกรอกมี `aria-invalid` ทั้งกลุ่มเป็นสีแดง
|
|
46
|
+
|
|
47
|
+
### InputGroupAddon `align`
|
|
48
|
+
|
|
49
|
+
| Align | ตำแหน่ง |
|
|
50
|
+
| -------------- | -------------------------- |
|
|
51
|
+
| `inline-start` | ซ้ายของช่องกรอก (ค่าเริ่มต้น) |
|
|
52
|
+
| `inline-end` | ขวาของช่องกรอก |
|
|
53
|
+
| `block-start` | แถวด้านบน (กลุ่มสูงขึ้นเป็นแนวตั้ง) |
|
|
54
|
+
| `block-end` | แถวด้านล่าง เช่น ตัวนับตัวอักษร |
|
|
55
|
+
|
|
56
|
+
คลิกที่ addon (นอกปุ่ม) แล้วโฟกัสไปที่ช่องกรอก
|
|
57
|
+
|
|
58
|
+
### InputGroupButton `size`
|
|
59
|
+
|
|
60
|
+
| Size | ขนาด |
|
|
61
|
+
| -------------- | ------------------------- |
|
|
62
|
+
| `xs` (ค่าเริ่มต้น) | สูง 24px มีข้อความ |
|
|
63
|
+
| `sm` | ตามขนาด `sm` ของ `Button` |
|
|
64
|
+
| `icon-xs` | 24×24px ไอคอนอย่างเดียว |
|
|
65
|
+
| `icon-sm` | 32×32px ไอคอนอย่างเดียว |
|
|
66
|
+
|
|
67
|
+
ปุ่มเป็น `ghost` โดยค่าเริ่มต้น ปุ่มไอคอนอย่างเดียวต้องมี `aria-label`
|
|
68
|
+
|
|
69
|
+
- **InputGroupText**: ข้อความหรือไอคอนสี muted เช่น "AU$"
|
|
70
|
+
- TODO: ยังไม่มีสถานะปิดใช้งานของทั้งกลุ่มที่ตั้งให้อัตโนมัติ ต้องใส่ `data-disabled="true"` ที่ `InputGroup` เอง
|
|
71
|
+
|
|
72
|
+
## Tokens used
|
|
73
|
+
|
|
74
|
+
ค่าทั้งหมดมาจาก `src/styles/theme.css`
|
|
75
|
+
|
|
76
|
+
### Component tokens
|
|
77
|
+
|
|
78
|
+
token เฉพาะของคอมโพเนนต์นี้ ชี้ไปที่ semantic token ด้านล่าง เปลี่ยนที่นี่เพื่อปรับเฉพาะคอมโพเนนต์นี้ (โหมดมืด "–" = ใช้ค่าเดียวกับโหมดสว่าง)
|
|
79
|
+
|
|
80
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
81
|
+
| ------------------ | ------------------- | ------------------- | ----------------------------------------------- |
|
|
82
|
+
| `--field-border` | `--control-border` | – | เส้นขอบช่องกรอก |
|
|
83
|
+
| `--field-bg` | `--input` 50% | – | พื้นช่องกรอก |
|
|
84
|
+
| `--focus-ring` | `--ring` | – | วงแหวน focus จากคีย์บอร์ดของทุกคอมโพเนนต์ (ทึบ 2px) |
|
|
85
|
+
| `--invalid-border` | `--destructive` | – | เส้นขอบเมื่อข้อมูลไม่ถูกต้อง และวงแหวน focus ขณะไม่ถูกต้อง |
|
|
86
|
+
| `--invalid-ring` | `--destructive` 20% | `--destructive` 40% | วงแหวนจางรอบช่องที่ไม่ถูกต้อง (ตกแต่ง) |
|
|
87
|
+
|
|
88
|
+
### Semantic tokens
|
|
89
|
+
|
|
90
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
91
|
+
| -------------------- | ------------------------- | -------------------------- | ------------------------------------------------- |
|
|
92
|
+
| `--input` | `oklch(0.93 0.007 106.5)` | `oklch(1 0 0 / 15%)` | พื้นกลุ่ม (50%) |
|
|
93
|
+
| `--muted-foreground` | `oklch(0.5 0.027 107.3)` | `oklch(0.737 0.021 106.9)` | ข้อความและไอคอนใน addon |
|
|
94
|
+
| `--ring` | `oklch(0.45 0.03 106.9)` | `oklch(0.8 0.02 106.9)` | วงแหวน focus ของทั้งกลุ่ม |
|
|
95
|
+
| `--destructive` | `oklch(0.505 0.2 27.325)` | `oklch(0.75 0.16 22.216)` | สถานะไม่ถูกต้อง |
|
|
96
|
+
| `--radius` | `0.625rem` | – | มุมโค้ง (`--radius × 2.6` = 26px, มี textarea: 18px) |
|
|
97
|
+
| `--control-border` | `oklch(0.6 0.02 106.9)` | `oklch(0.55 0.015 106.9)` | ผ่าน token ของคอมโพเนนต์ด้านบน |
|
|
98
|
+
|
|
99
|
+
## Example
|
|
100
|
+
|
|
101
|
+
จาก story `WithButtons` ใน `InputGroup.stories.tsx`:
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
<InputGroup className="w-80">
|
|
105
|
+
<InputGroupInput defaultValue="123 456 789" aria-label="เลขสมาชิก" readOnly />
|
|
106
|
+
<InputGroupAddon align="inline-end">
|
|
107
|
+
<InputGroupButton size="icon-xs" aria-label="แสดง">
|
|
108
|
+
<HugeiconsIcon icon={ViewIcon} strokeWidth={2} />
|
|
109
|
+
</InputGroupButton>
|
|
110
|
+
<InputGroupButton size="icon-xs" aria-label="คัดลอก">
|
|
111
|
+
<HugeiconsIcon icon={Copy01Icon} strokeWidth={2} />
|
|
112
|
+
</InputGroupButton>
|
|
113
|
+
</InputGroupAddon>
|
|
114
|
+
</InputGroup>
|
|
115
|
+
```
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
kind: component
|
|
2
|
+
id: input-otp
|
|
3
|
+
name: InputOTP
|
|
4
|
+
description: >-
|
|
5
|
+
A one-time passcode (OTP) field split into one box per character, e.g. a 6-digit
|
|
6
|
+
SMS code. A single real input sits under the boxes. Built on `input-otp`.
|
|
7
|
+
metadata:
|
|
8
|
+
status: {status: stable}
|
|
9
|
+
since: 1.0.0
|
|
10
|
+
tags: [form, authentication]
|
|
11
|
+
|
|
12
|
+
sections:
|
|
13
|
+
- kind: guidelines
|
|
14
|
+
for: all
|
|
15
|
+
framing: when-to-use
|
|
16
|
+
items:
|
|
17
|
+
- level: should
|
|
18
|
+
statement: >-
|
|
19
|
+
Use for one-time identity codes when signing in or confirming a withdrawal.
|
|
20
|
+
- level: must-not
|
|
21
|
+
statement: >-
|
|
22
|
+
Don't use for passwords or other long numbers (account number, TFN); use
|
|
23
|
+
<dsds:input>.
|
|
24
|
+
alternatives:
|
|
25
|
+
- to: input
|
|
26
|
+
checkedBy: manual
|
|
27
|
+
- level: must-not
|
|
28
|
+
statement: >-
|
|
29
|
+
Don't use for a PIN that must hide its digits: there is no option to mask the
|
|
30
|
+
boxes yet.
|
|
31
|
+
checkedBy: manual
|
|
32
|
+
|
|
33
|
+
- kind: guidelines
|
|
34
|
+
for: all
|
|
35
|
+
items:
|
|
36
|
+
- id: slots-match-length
|
|
37
|
+
level: must
|
|
38
|
+
statement: >-
|
|
39
|
+
Render one `InputOTPSlot` for every character of `maxLength` (required), with
|
|
40
|
+
`index` starting at 0 and no gaps. A missing box still accepts input, but its
|
|
41
|
+
character is invisible.
|
|
42
|
+
checkedBy: manual
|
|
43
|
+
- id: group-of-three
|
|
44
|
+
level: should
|
|
45
|
+
statement: >-
|
|
46
|
+
Split a 6-digit code into two groups of 3 boxes with an `InputOTPSeparator` between
|
|
47
|
+
them, so it's easy to read and compare against the SMS.
|
|
48
|
+
checkedBy: manual
|
|
49
|
+
- id: verify-on-complete
|
|
50
|
+
level: should
|
|
51
|
+
statement: >-
|
|
52
|
+
Send the code for checking in `onComplete` (called once every box is filled); no
|
|
53
|
+
separate "ยืนยัน" (confirm) button is needed. Show a checking state (e.g.
|
|
54
|
+
<dsds:spinner>) and set `disabled` while it runs.
|
|
55
|
+
checks:
|
|
56
|
+
- href: ./InputOTP.stories.tsx#Typing
|
|
57
|
+
role: test
|
|
58
|
+
note: play function checks that onComplete receives "482913"
|
|
59
|
+
uses:
|
|
60
|
+
- to: spinner
|
|
61
|
+
checkedBy: assisted
|
|
62
|
+
- id: paste-and-autofill
|
|
63
|
+
level: must-not
|
|
64
|
+
statement: >-
|
|
65
|
+
Don't replace it with 6 separate Inputs, and don't override `autoComplete`. This
|
|
66
|
+
component uses one real input, so pasting the whole code and SMS autofill on
|
|
67
|
+
mobile both work.
|
|
68
|
+
checkedBy: manual
|
|
69
|
+
|
|
70
|
+
- kind: guidelines
|
|
71
|
+
for: all
|
|
72
|
+
title: Accessibility
|
|
73
|
+
tags: [accessibility]
|
|
74
|
+
items:
|
|
75
|
+
- id: label-with-length
|
|
76
|
+
level: must
|
|
77
|
+
statement: >-
|
|
78
|
+
Tie a <dsds:label> to the `id` of `InputOTP` and state the length in it, e.g.
|
|
79
|
+
"รหัสยืนยัน 6 หลัก" (6-digit verification code).
|
|
80
|
+
uses:
|
|
81
|
+
- to: label
|
|
82
|
+
checkedBy: manual
|
|
83
|
+
- id: invalid-all-slots
|
|
84
|
+
level: must
|
|
85
|
+
statement: >-
|
|
86
|
+
For a wrong code, put `aria-invalid` on every `InputOTPSlot` (red border; the
|
|
87
|
+
active box gets a solid red ring) and add a message under the field saying what to
|
|
88
|
+
do next ("รหัสไม่ถูกต้อง กรุณาลองอีกครั้ง", wrong code, please try again).
|
|
89
|
+
refines:
|
|
90
|
+
- to: shared-a11y#invalid-has-message
|
|
91
|
+
example:
|
|
92
|
+
ref:
|
|
93
|
+
href: ./InputOTP.stories.tsx#Invalid
|
|
94
|
+
rel: demo
|
|
95
|
+
checkedBy: manual
|
|
96
|
+
- id: timing
|
|
97
|
+
level: should
|
|
98
|
+
statement: >-
|
|
99
|
+
If the code expires, show the remaining time as text and offer a
|
|
100
|
+
"ส่งรหัสอีกครั้ง" (resend code) button. Don't clear the field automatically when
|
|
101
|
+
time runs out.
|
|
102
|
+
evidence:
|
|
103
|
+
- href: https://www.w3.org/WAI/WCAG22/Understanding/timing-adjustable.html
|
|
104
|
+
role: WCAG 2.2 SC 2.2.1 (A)
|
|
105
|
+
checkedBy: manual
|
|
106
|
+
|
|
107
|
+
- kind: guidelines
|
|
108
|
+
for: agent
|
|
109
|
+
items:
|
|
110
|
+
- refs:
|
|
111
|
+
- to: shared-testing#fire-change-for-typing
|
|
112
|
+
rel: same-as
|
|
113
|
+
|
|
114
|
+
- kind: definitions
|
|
115
|
+
for: all
|
|
116
|
+
context: anatomy
|
|
117
|
+
items:
|
|
118
|
+
- term: InputOTP
|
|
119
|
+
definition: >-
|
|
120
|
+
The real input. Takes `maxLength` (required), `value` / `onChange`, `onComplete`,
|
|
121
|
+
`pattern`, `disabled`, `containerClassName`.
|
|
122
|
+
- term: InputOTPGroup
|
|
123
|
+
definition: >-
|
|
124
|
+
A run of boxes joined into one capsule.
|
|
125
|
+
- term: InputOTPSlot
|
|
126
|
+
definition: >-
|
|
127
|
+
One 36px box per character. Takes `index` (required) and `aria-invalid`. The active
|
|
128
|
+
box shows the `--focus-ring` ring and a blinking caret.
|
|
129
|
+
- term: InputOTPSeparator
|
|
130
|
+
definition: >-
|
|
131
|
+
A dash between groups.
|
|
132
|
+
|
|
133
|
+
- kind: section
|
|
134
|
+
for: all
|
|
135
|
+
title: Open decisions
|
|
136
|
+
freeform:
|
|
137
|
+
- title: TODO
|
|
138
|
+
body: >-
|
|
139
|
+
There is no option to mask digits (PIN) yet, and no example of `pattern` (e.g.
|
|
140
|
+
digits only).
|
|
141
|
+
|
|
142
|
+
sourceFiles:
|
|
143
|
+
- platform: react
|
|
144
|
+
file: ./InputOTP.tsx
|
|
145
|
+
|
|
146
|
+
imports:
|
|
147
|
+
- platform: react
|
|
148
|
+
code: >-
|
|
149
|
+
import { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot } from "@designil/labdsnov"
|
|
150
|
+
package: "@designil/labdsnov"
|
|
151
|
+
|
|
152
|
+
traits:
|
|
153
|
+
- traitType: state
|
|
154
|
+
kind: boolean
|
|
155
|
+
id: disabled
|
|
156
|
+
description: >-
|
|
157
|
+
Disabled, dimmed to 50%.
|
|
158
|
+
- traitType: state
|
|
159
|
+
kind: boolean
|
|
160
|
+
id: aria-invalid
|
|
161
|
+
name: Invalid
|
|
162
|
+
description: >-
|
|
163
|
+
On `InputOTPSlot`: the code is wrong. Red border.
|
|
164
|
+
- traitType: state
|
|
165
|
+
kind: boolean
|
|
166
|
+
id: active
|
|
167
|
+
description: >-
|
|
168
|
+
The box being filled. Solid ring and a blinking caret.
|
|
169
|
+
|
|
170
|
+
uses:
|
|
171
|
+
- to: label
|
|
172
|
+
alternatives:
|
|
173
|
+
- to: input
|
|
174
|
+
|
|
175
|
+
refs:
|
|
176
|
+
- href: ./InputOTP.md
|
|
177
|
+
rel: relates-to
|
|
178
|
+
role: Thai usage doc
|
|
179
|
+
- href: ./InputOTP.stories.tsx
|
|
180
|
+
rel: demo
|
|
181
|
+
role: CSF stories
|
|
182
|
+
- href: https://input-otp.rodz.dev
|
|
183
|
+
rel: relates-to
|
|
184
|
+
role: input-otp documentation
|