@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,193 @@
|
|
|
1
|
+
# Dialog (กล่องโต้ตอบ)
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
หน้าต่างแบบ modal ที่ลอยทับหน้า ให้ผู้ใช้ตัดสินใจหรือกรอกข้อมูลสั้น ๆ ให้เสร็จก่อนกลับไปทำงานต่อ
|
|
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
|
+
Button,
|
|
18
|
+
Dialog,
|
|
19
|
+
DialogClose,
|
|
20
|
+
DialogContent,
|
|
21
|
+
DialogDescription,
|
|
22
|
+
DialogFooter,
|
|
23
|
+
DialogHeader,
|
|
24
|
+
DialogTitle,
|
|
25
|
+
DialogTrigger,
|
|
26
|
+
} from "@designil/labdsnov"
|
|
27
|
+
|
|
28
|
+
;<Dialog>
|
|
29
|
+
<DialogTrigger render={<Button variant="outline" />}>
|
|
30
|
+
เปลี่ยนแผนการลงทุน
|
|
31
|
+
</DialogTrigger>
|
|
32
|
+
<DialogContent>
|
|
33
|
+
<DialogHeader>
|
|
34
|
+
<DialogTitle>เปลี่ยนแผนการลงทุน</DialogTitle>
|
|
35
|
+
<DialogDescription>การเปลี่ยนแผนจะมีผลกับเงินสมทบงวดถัดไป</DialogDescription>
|
|
36
|
+
</DialogHeader>
|
|
37
|
+
<DialogFooter>
|
|
38
|
+
<DialogClose render={<Button variant="outline" />}>ยกเลิก</DialogClose>
|
|
39
|
+
<DialogClose render={<Button />}>เปลี่ยนแผน</DialogClose>
|
|
40
|
+
</DialogFooter>
|
|
41
|
+
</DialogContent>
|
|
42
|
+
</Dialog>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
ควบคุมการเปิด/ปิดเอง (เช่น ปิดหลังบันทึกสำเร็จ) ใช้ `open` กับ `onOpenChange` ในไฟล์ที่มี `"use client"`:
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
"use client"
|
|
49
|
+
|
|
50
|
+
import { useState } from "react"
|
|
51
|
+
|
|
52
|
+
const [open, setOpen] = useState(false)
|
|
53
|
+
|
|
54
|
+
<Dialog open={open} onOpenChange={setOpen}>…</Dialog>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## When to use
|
|
58
|
+
|
|
59
|
+
- ยืนยันการตัดสินใจสำคัญที่ผู้ใช้เริ่มเอง เช่น เปลี่ยนแผนการลงทุน
|
|
60
|
+
- ยืนยันการกระทำที่ย้อนกลับไม่ได้: **ใช้ `AlertDialog`** (ดู [AlertDialog](../AlertDialog/AlertDialog.md)) ซึ่งประกาศเป็น `alertdialog` และปิดด้วยการคลิกนอกกล่องไม่ได้ ตัวอย่าง `ConfirmDelete` ด้านล่างเขียนไว้ก่อนมี AlertDialog
|
|
61
|
+
- ฟอร์มสั้น ๆ 1–3 ช่อง ที่ไม่ต้องออกจากหน้าเดิม เช่น แก้ไขข้อมูลบัญชี
|
|
62
|
+
|
|
63
|
+
ใช้เท่าที่จำเป็น ระบบดีไซน์หลัก (Carbon, Atlassian, Polaris) ถือว่า modal เป็นทางเลือกท้าย ๆ เพราะขัดจังหวะผู้ใช้
|
|
64
|
+
|
|
65
|
+
## When not to use
|
|
66
|
+
|
|
67
|
+
| สถานการณ์ | ใช้แทน |
|
|
68
|
+
| ---------------------------------- | -------------------------------------------- |
|
|
69
|
+
| ข้อความแจ้งที่ไม่ต้องตอบ (เช่น "บันทึกแล้ว") | `toast` (ดู [Toaster](../Toaster/Toaster.md)) |
|
|
70
|
+
| งานที่ผู้ใช้ทำบ่อย | ทำในหน้าโดยตรง |
|
|
71
|
+
| เนื้อหายาว ตารางใหญ่ หรือฟอร์มหลายขั้นตอน | หน้าใหม่ |
|
|
72
|
+
| การกระทำที่ย้อนกลับได้ (ลบแล้วกู้คืนได้) | ทำทันทีแล้วให้ "เลิกทำ" แทนการถามยืนยัน |
|
|
73
|
+
| เปิด dialog ซ้อนจาก dialog | รวมเป็น dialog เดียว หรือย้ายไปหน้าใหม่ |
|
|
74
|
+
| ตัวเลือกเล็ก ๆ ข้างปุ่ม | `Popover` หรือ `DropdownMenu` |
|
|
75
|
+
| แผงที่เลื่อนขึ้นจากขอบจอบนมือถือ | `Drawer` (ดู [Drawer](../Drawer/Drawer.md)) |
|
|
76
|
+
|
|
77
|
+
## Anatomy
|
|
78
|
+
|
|
79
|
+
ประกอบด้วยส่วนเหล่านี้ ซ้อนกันตามลำดับ:
|
|
80
|
+
|
|
81
|
+
- **Dialog**: ตัวครอบ ควบคุมการเปิด/ปิด
|
|
82
|
+
- **DialogTrigger**: ปุ่มที่เปิด dialog (ใช้ `Button` ผ่าน `render`)
|
|
83
|
+
- **DialogContent**: กล่องที่ลอยกลางจอ มีฉากหลังมืดและเบลอ และปุ่ม "ปิด" มุมขวาบน
|
|
84
|
+
- **DialogHeader** → **DialogTitle** (บังคับ) + **DialogDescription** (แนะนำ)
|
|
85
|
+
- เนื้อหา เช่น ช่องกรอกข้อมูล
|
|
86
|
+
- **DialogFooter** → ปุ่ม **DialogClose** (ใช้ `Button` ผ่าน `render`)
|
|
87
|
+
|
|
88
|
+
ชื่อเรื่องและคำอธิบายจะถูกอ่านโดยโปรแกรมอ่านหน้าจอเมื่อเปิด dialog จึงต้องมี `DialogTitle` เสมอ
|
|
89
|
+
|
|
90
|
+
## Props and variants
|
|
91
|
+
|
|
92
|
+
### Dialog
|
|
93
|
+
|
|
94
|
+
| Prop | ค่า | ค่าเริ่มต้น | ความหมาย |
|
|
95
|
+
| ------------------------- | ------------------------------- | ------- | ----------------------------------------------- |
|
|
96
|
+
| `open` / `onOpenChange` | `boolean` / ฟังก์ชัน | – | ควบคุมการเปิด/ปิดจากภายนอก |
|
|
97
|
+
| `defaultOpen` | `boolean` | `false` | เปิดไว้ตั้งแต่แรก |
|
|
98
|
+
| `modal` | `true`, `false`, `"trap-focus"` | `true` | `true` = ล็อกโฟกัส ล็อกการเลื่อนหน้า และกดนอกกล่องไม่ได้ |
|
|
99
|
+
| `disablePointerDismissal` | `boolean` | `false` | ปิดการปิด dialog เมื่อคลิกนอกกล่อง |
|
|
100
|
+
|
|
101
|
+
### DialogContent
|
|
102
|
+
|
|
103
|
+
| Prop | ค่า | ค่าเริ่มต้น | ความหมาย |
|
|
104
|
+
| ----------------- | --------------------------- | ------------- | --------------------------------------------- |
|
|
105
|
+
| `size` | `sm`, `default`, `lg`, `xl` | `default` | ความกว้างสูงสุด (ดูตารางด้านล่าง) |
|
|
106
|
+
| `showCloseButton` | `boolean` | `true` | แสดงปุ่มไอคอน "ปิด" มุมขวาบน |
|
|
107
|
+
| `initialFocus` | element | ช่องแรกที่โฟกัสได้ | element ที่ได้โฟกัสเมื่อเปิด |
|
|
108
|
+
| `finalFocus` | element | ปุ่มที่เปิด | element ที่ได้โฟกัสเมื่อปิด |
|
|
109
|
+
| `className` | class | – | ปรับหน้าตาเฉพาะจุดครั้งเดียว ชนะสไตล์ของ dialog เสมอ |
|
|
110
|
+
|
|
111
|
+
| Size | ความกว้างสูงสุด (จอ 640px ขึ้นไป) | ใช้กับ (จาก stories) |
|
|
112
|
+
| --------- | ---------------------------- | ------------------------- |
|
|
113
|
+
| `sm` | 384px | ยืนยันการลบ, ฟอร์มสั้น |
|
|
114
|
+
| `default` | 448px | ยืนยันการตัดสินใจทั่วไป |
|
|
115
|
+
| `lg` | 512px | TODO: ยังไม่มีตัวอย่างการใช้งาน |
|
|
116
|
+
| `xl` | 672px | TODO: ยังไม่มีตัวอย่างการใช้งาน |
|
|
117
|
+
|
|
118
|
+
บนจอแคบกว่า 640px ทุกขนาดกว้างเต็มจอ เว้นขอบซ้าย-ขวาข้างละ 16px
|
|
119
|
+
|
|
120
|
+
### DialogFooter
|
|
121
|
+
|
|
122
|
+
| Prop | ค่า | ค่าเริ่มต้น | ความหมาย |
|
|
123
|
+
| ----------------- | --------- | ------- | ------------------------------------------------------ |
|
|
124
|
+
| `showCloseButton` | `boolean` | `false` | เพิ่มปุ่ม outline "ปิด" ท้ายแถว ใช้กับ dialog ที่แจ้งข้อมูลอย่างเดียว |
|
|
125
|
+
|
|
126
|
+
### พฤติกรรมที่มีให้แล้ว
|
|
127
|
+
|
|
128
|
+
- กด **Escape**, ปุ่ม "ปิด", หรือคลิกนอกกล่อง (ค่าเริ่มต้น) เพื่อปิด
|
|
129
|
+
- เปิดแล้วโฟกัสย้ายเข้า dialog ไปที่ช่องแรกที่โฟกัสได้ และวนอยู่ภายใน dialog ปิดแล้วโฟกัสกลับไปที่ปุ่มที่เปิด
|
|
130
|
+
- หน้าด้านหลังเลื่อนและคลิกไม่ได้ขณะเปิด
|
|
131
|
+
- ปุ่มใน footer: จอกว้างเรียงเป็นแถวชิดขวา จอแคบซ้อนเป็นแนวตั้งโดยปุ่มสุดท้ายอยู่บนสุด ดังนั้น **ใส่ปุ่มยกเลิกก่อน แล้วปุ่มหลักทีหลัง** ปุ่มหลักจะอยู่ขวาสุด (จอกว้าง) หรือบนสุด (จอแคบ)
|
|
132
|
+
- เปิด/ปิดด้วยการจางและย่อ-ขยายเล็กน้อย 100ms
|
|
133
|
+
|
|
134
|
+
## Content rules
|
|
135
|
+
|
|
136
|
+
ตามแนวทางของ WAI-ARIA APG, Carbon, Atlassian, Polaris และ Apple HIG
|
|
137
|
+
|
|
138
|
+
- **ชื่อเรื่อง**: บอกสิ่งที่กำลังจะทำ ใช้คำเดียวกับปุ่มที่เปิด (เปิดจาก "แก้ไขข้อมูลบัญชี" → ชื่อ "แก้ไขข้อมูลบัญชี") สำหรับการยืนยัน เขียนเป็นคำถาม เช่น "ลบบัญชีผู้รับผลประโยชน์?"
|
|
139
|
+
- **คำอธิบาย**: บอกผลที่จะตามมา ถ้าย้อนกลับไม่ได้ต้องบอกตรง ๆ ไม่ต้องอธิบายว่าปุ่มทำอะไร
|
|
140
|
+
- **ปุ่ม**: ไม่เกิน 3 ปุ่ม มีปุ่มหลักปุ่มเดียว ใช้คำกริยาที่เจาะจง ("บันทึก", "ลบ", "เปลี่ยนแผน") หลีกเลี่ยง "ตกลง", "ใช่/ไม่", "ส่ง"
|
|
141
|
+
- **การกระทำอันตราย**: ปุ่มหลักใช้ `Button variant="destructive"` และต้องมีปุ่ม "ยกเลิก" เสมอ
|
|
142
|
+
- **ปุ่ม "ปิด" มุมขวาบน**: เก็บไว้เป็นค่าเริ่มต้น ซ่อนได้ (`showCloseButton={false}`) เฉพาะเมื่อ footer มีปุ่ม "ยกเลิก" ให้ออกได้แล้ว เช่น การยืนยันการลบ
|
|
143
|
+
- **เนื้อหายาว**: TODO: ตอนนี้ dialog ไม่จำกัดความสูงและไม่มีการเลื่อนเฉพาะเนื้อหา ถ้าเนื้อหาสูงกว่าจอให้ย้ายไปหน้าใหม่ จนกว่าจะตัดสินใจเรื่องนี้
|
|
144
|
+
|
|
145
|
+
## Tokens used
|
|
146
|
+
|
|
147
|
+
ค่าทั้งหมดมาจาก `src/styles/theme.css` ปุ่มใน dialog ใช้ token ของ `Button`
|
|
148
|
+
|
|
149
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
150
|
+
| ---------------------- | -------------------------------- | ---------------------------- | -------------------------------------- |
|
|
151
|
+
| `--popover` | `oklch(1 0 0)` | `oklch(0.228 0.013 107.4)` | พื้นของกล่อง |
|
|
152
|
+
| `--popover-foreground` | `oklch(0.153 0.006 107.1)` | `oklch(0.988 0.003 106.5)` | ตัวอักษรในกล่อง |
|
|
153
|
+
| `--foreground` | `oklch(0.153 0.006 107.1)` | `oklch(0.988 0.003 106.5)` | เส้นขอบบาง ๆ รอบกล่อง (5% สว่าง, 10% มืด) |
|
|
154
|
+
| `--muted-foreground` | `oklch(0.5 0.027 107.3)` | `oklch(0.737 0.021 106.9)` | ตัวอักษรคำอธิบาย |
|
|
155
|
+
| `--secondary` | `oklch(0.967 0.001 286.375)` | `oklch(0.274 0.006 286.033)` | พื้นปุ่ม "ปิด" มุมขวาบน |
|
|
156
|
+
| `--radius` | `0.625rem` | – | มุมโค้งของกล่อง (`--radius × 2.6` = 26px) |
|
|
157
|
+
| `--font-heading` | กำหนดโดยแอป (IBM Plex Sans Thai) | – | ชื่อเรื่อง (16px, medium) |
|
|
158
|
+
| `--font-sans` | system font stack | – | คำอธิบายและเนื้อหา (14px) |
|
|
159
|
+
|
|
160
|
+
ฉากหลังเป็นสีดำ 30% และเบลอ ซึ่งเป็นค่าตายตัว ไม่ใช่ token TODO: ตัดสินใจว่าควรเป็น token หรือไม่ ระยะห่างภายในกล่องคือ 24px
|
|
161
|
+
|
|
162
|
+
## Example
|
|
163
|
+
|
|
164
|
+
จาก story `ConfirmDelete` ใน `Dialog.stories.tsx`:
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
<Dialog>
|
|
168
|
+
<DialogTrigger render={<Button variant="destructive" />}>
|
|
169
|
+
ยืนยันการลบ
|
|
170
|
+
</DialogTrigger>
|
|
171
|
+
<DialogContent size="sm" showCloseButton={false}>
|
|
172
|
+
<DialogHeader>
|
|
173
|
+
<DialogTitle>ลบบัญชีผู้รับผลประโยชน์?</DialogTitle>
|
|
174
|
+
<DialogDescription>
|
|
175
|
+
การลบนี้ไม่สามารถย้อนกลับได้ ข้อมูลผู้รับผลประโยชน์จะถูกลบออกจากบัญชีของคุณ
|
|
176
|
+
</DialogDescription>
|
|
177
|
+
</DialogHeader>
|
|
178
|
+
<DialogFooter>
|
|
179
|
+
<DialogClose render={<Button variant="outline" />}>ยกเลิก</DialogClose>
|
|
180
|
+
<DialogClose render={<Button variant="destructive" />}>ลบ</DialogClose>
|
|
181
|
+
</DialogFooter>
|
|
182
|
+
</DialogContent>
|
|
183
|
+
</Dialog>
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Open questions (TODO)
|
|
187
|
+
|
|
188
|
+
ช่องว่างระหว่าง Dialog ปัจจุบันกับมาตรฐาน ยังไม่ได้แก้:
|
|
189
|
+
|
|
190
|
+
- **Alert dialog**: แก้แล้ว ใช้ `AlertDialog` สำหรับการยืนยัน TODO: ย้ายตัวอย่าง `ConfirmDelete` ไปใช้ AlertDialog
|
|
191
|
+
- **โฟกัสแรกในการยืนยันการลบ**: ใน `AlertDialog` โฟกัสไปที่ "ยกเลิก" ตามที่ APG แนะนำ (มี story `OpenAndCancel` ตรวจ)
|
|
192
|
+
- **คลิกนอกกล่อง**: Carbon ไม่ให้ปิดเมื่อ dialog มีปุ่มการกระทำ ส่วน Atlassian และ Base UI ให้ปิด ตอนนี้ปิดได้ (ค่าเริ่มต้น)
|
|
193
|
+
- **มือถือ**: มี `Drawer` แล้ว TODO: ยังไม่ได้ตัดสินใจว่าจะสลับ Dialog กับ Drawer ตามขนาดจออัตโนมัติหรือไม่
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
kind: component
|
|
2
|
+
id: drawer
|
|
3
|
+
name: Drawer
|
|
4
|
+
description: >-
|
|
5
|
+
A panel that slides in from a screen edge (usually the bottom) and can be swiped
|
|
6
|
+
closed. Suited to mobile. Sits 8px from the screen edge with a 26px corner radius.
|
|
7
|
+
Wraps Base UI's `Drawer`.
|
|
8
|
+
metadata:
|
|
9
|
+
status: {status: stable}
|
|
10
|
+
since: 1.0.0
|
|
11
|
+
tags: [overlay]
|
|
12
|
+
|
|
13
|
+
sections:
|
|
14
|
+
- kind: guidelines
|
|
15
|
+
for: all
|
|
16
|
+
framing: when-to-use
|
|
17
|
+
items:
|
|
18
|
+
- level: should
|
|
19
|
+
statement: >-
|
|
20
|
+
Use for short tasks on mobile, such as a short form, a choice or filters.
|
|
21
|
+
- level: should
|
|
22
|
+
statement: >-
|
|
23
|
+
Use `swipeDirection="right"` for a side panel, such as table filters.
|
|
24
|
+
example:
|
|
25
|
+
ref:
|
|
26
|
+
href: ./Drawer.stories.tsx#FromRight
|
|
27
|
+
rel: demo
|
|
28
|
+
- level: must-not
|
|
29
|
+
statement: >-
|
|
30
|
+
Don't use it to confirm an irreversible action: it's too easy to swipe away.
|
|
31
|
+
Use <dsds:alert-dialog>.
|
|
32
|
+
alternatives:
|
|
33
|
+
- to: alert-dialog
|
|
34
|
+
checkedBy: manual
|
|
35
|
+
- level: should-not
|
|
36
|
+
statement: >-
|
|
37
|
+
Don't use it on wide screens where a centred box fits better. Use <dsds:dialog>.
|
|
38
|
+
alternatives:
|
|
39
|
+
- to: dialog
|
|
40
|
+
- level: should-not
|
|
41
|
+
statement: >-
|
|
42
|
+
Don't use it as a command menu. Use <dsds:dropdown-menu>.
|
|
43
|
+
alternatives:
|
|
44
|
+
- to: dropdown-menu
|
|
45
|
+
|
|
46
|
+
- kind: guidelines
|
|
47
|
+
for: all
|
|
48
|
+
items:
|
|
49
|
+
- id: title-required
|
|
50
|
+
level: must
|
|
51
|
+
statement: >-
|
|
52
|
+
Always include `DrawerTitle`: it's the panel's name for screen readers. Add a
|
|
53
|
+
`DrawerDescription` that states the outcome or condition, e.g.
|
|
54
|
+
"เงินจะเข้าบัญชีภายใน 3 วันทำการ" (funds arrive within 3 business days).
|
|
55
|
+
checks:
|
|
56
|
+
- href: ./Drawer.stories.tsx#OpenAndClose
|
|
57
|
+
role: test
|
|
58
|
+
note: play function checks toHaveAccessibleDescription
|
|
59
|
+
checkedBy: automated
|
|
60
|
+
- id: footer-primary-first
|
|
61
|
+
level: must
|
|
62
|
+
statement: >-
|
|
63
|
+
`DrawerFooter` stacks buttons downward. The primary button goes on top, nearest
|
|
64
|
+
the thumb ("ยืนยัน", confirm), followed by
|
|
65
|
+
`DrawerClose render={<Button variant="outline" />}` ("ยกเลิก", cancel). This is
|
|
66
|
+
the reverse of Dialog, where cancel comes first.
|
|
67
|
+
checkedBy: manual
|
|
68
|
+
- id: swipe-handle-bottom
|
|
69
|
+
level: should
|
|
70
|
+
statement: >-
|
|
71
|
+
Bottom panels set `showSwipeHandle` so it's clear they can be swiped closed.
|
|
72
|
+
Side panels don't need one.
|
|
73
|
+
checkedBy: manual
|
|
74
|
+
- id: short-content
|
|
75
|
+
level: should
|
|
76
|
+
statement: >-
|
|
77
|
+
Keep content within the maximum height (screen height minus 96px). Move anything
|
|
78
|
+
longer to its own page.
|
|
79
|
+
checkedBy: manual
|
|
80
|
+
- id: trigger-render
|
|
81
|
+
level: must
|
|
82
|
+
statement: >-
|
|
83
|
+
Write the opening button as `<DrawerTrigger render={<Button variant="outline" />}>`.
|
|
84
|
+
refs:
|
|
85
|
+
- to: shared-composition#render-prop
|
|
86
|
+
rel: relates-to
|
|
87
|
+
checkedBy: assisted
|
|
88
|
+
|
|
89
|
+
- kind: guidelines
|
|
90
|
+
for: all
|
|
91
|
+
title: Accessibility
|
|
92
|
+
tags: [accessibility]
|
|
93
|
+
items:
|
|
94
|
+
- id: not-swipe-only
|
|
95
|
+
level: must
|
|
96
|
+
statement: >-
|
|
97
|
+
It must close without swiping: include a `DrawerClose` button in the footer, and
|
|
98
|
+
Escape closes it.
|
|
99
|
+
evidence:
|
|
100
|
+
- href: https://www.w3.org/WAI/WCAG22/Understanding/dragging-movements.html
|
|
101
|
+
role: WCAG 2.2 SC 2.5.7 (AA)
|
|
102
|
+
checks:
|
|
103
|
+
- href: ./Drawer.stories.tsx#OpenAndClose
|
|
104
|
+
role: test
|
|
105
|
+
note: play function closes with the "ยกเลิก" button, then checks aria-expanded="false"
|
|
106
|
+
checkedBy: automated
|
|
107
|
+
- id: modal-focus
|
|
108
|
+
level: must
|
|
109
|
+
statement: >-
|
|
110
|
+
`modal` (default `true`) adds a dark backdrop, traps focus in the panel and
|
|
111
|
+
blocks the page behind. Don't set `modal={false}` on a panel that holds a form.
|
|
112
|
+
checkedBy: manual
|
|
113
|
+
|
|
114
|
+
- kind: definitions
|
|
115
|
+
for: all
|
|
116
|
+
context: anatomy
|
|
117
|
+
items:
|
|
118
|
+
- term: Drawer
|
|
119
|
+
definition: >-
|
|
120
|
+
Root. Takes `swipeDirection`, `showSwipeHandle`, `open` / `onOpenChange`, `modal`,
|
|
121
|
+
`snapPoints`.
|
|
122
|
+
- term: DrawerTrigger
|
|
123
|
+
definition: >-
|
|
124
|
+
The opening button.
|
|
125
|
+
- term: DrawerContent
|
|
126
|
+
definition: >-
|
|
127
|
+
The panel. From the bottom/top it's full width and as tall as its content; from
|
|
128
|
+
a side it's 75% wide on mobile and 384px from 640px screens.
|
|
129
|
+
- term: DrawerHeader
|
|
130
|
+
definition: >-
|
|
131
|
+
Title + Description. Centred on mobile, left-aligned from 768px screens.
|
|
132
|
+
- term: DrawerFooter
|
|
133
|
+
definition: >-
|
|
134
|
+
Buttons, stacked downward.
|
|
135
|
+
- term: DrawerClose
|
|
136
|
+
definition: >-
|
|
137
|
+
Close button (`render={<Button />}`).
|
|
138
|
+
|
|
139
|
+
- kind: section
|
|
140
|
+
for: all
|
|
141
|
+
title: Open decisions
|
|
142
|
+
freeform:
|
|
143
|
+
- title: TODO
|
|
144
|
+
body: >-
|
|
145
|
+
Not yet decided whether to switch automatically between Dialog (wide screens) and
|
|
146
|
+
Drawer (mobile). There's no `snapPoints` example yet.
|
|
147
|
+
|
|
148
|
+
sourceFiles:
|
|
149
|
+
- platform: react
|
|
150
|
+
file: ./Drawer.tsx
|
|
151
|
+
|
|
152
|
+
imports:
|
|
153
|
+
- platform: react
|
|
154
|
+
code: >-
|
|
155
|
+
import { Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, DrawerTrigger } from "@designil/labdsnov"
|
|
156
|
+
package: "@designil/labdsnov"
|
|
157
|
+
|
|
158
|
+
traits:
|
|
159
|
+
- traitType: variant
|
|
160
|
+
kind: enum
|
|
161
|
+
id: swipeDirection
|
|
162
|
+
description: >-
|
|
163
|
+
The direction to swipe to close, and the edge the panel slides in from.
|
|
164
|
+
values:
|
|
165
|
+
- id: down
|
|
166
|
+
description: >-
|
|
167
|
+
From the bottom (default).
|
|
168
|
+
- id: up
|
|
169
|
+
description: >-
|
|
170
|
+
From the top.
|
|
171
|
+
- id: left
|
|
172
|
+
description: >-
|
|
173
|
+
From the left.
|
|
174
|
+
- id: right
|
|
175
|
+
description: >-
|
|
176
|
+
From the right, e.g. table filters.
|
|
177
|
+
- traitType: variant
|
|
178
|
+
kind: boolean
|
|
179
|
+
id: showSwipeHandle
|
|
180
|
+
description: >-
|
|
181
|
+
A grab bar for swiping.
|
|
182
|
+
- traitType: state
|
|
183
|
+
kind: boolean
|
|
184
|
+
id: open
|
|
185
|
+
description: >-
|
|
186
|
+
The panel is open.
|
|
187
|
+
|
|
188
|
+
combos:
|
|
189
|
+
- subject: showSwipeHandle
|
|
190
|
+
level: should-not
|
|
191
|
+
items: [swipeDirection.left, swipeDirection.right]
|
|
192
|
+
note: >-
|
|
193
|
+
The grab bar is designed for bottom/top panels.
|
|
194
|
+
|
|
195
|
+
uses:
|
|
196
|
+
- to: button
|
|
197
|
+
alternatives:
|
|
198
|
+
- to: dialog
|
|
199
|
+
- to: alert-dialog
|
|
200
|
+
|
|
201
|
+
refs:
|
|
202
|
+
- href: ./Drawer.md
|
|
203
|
+
rel: relates-to
|
|
204
|
+
role: Thai usage doc
|
|
205
|
+
- href: ./Drawer.stories.tsx
|
|
206
|
+
rel: demo
|
|
207
|
+
role: CSF stories
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Drawer (แผงเลื่อน)
|
|
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
|
+
Button,
|
|
18
|
+
Drawer,
|
|
19
|
+
DrawerClose,
|
|
20
|
+
DrawerContent,
|
|
21
|
+
DrawerDescription,
|
|
22
|
+
DrawerFooter,
|
|
23
|
+
DrawerHeader,
|
|
24
|
+
DrawerTitle,
|
|
25
|
+
DrawerTrigger,
|
|
26
|
+
} from "@designil/labdsnov"
|
|
27
|
+
|
|
28
|
+
;<Drawer showSwipeHandle>
|
|
29
|
+
<DrawerTrigger render={<Button variant="outline" />}>
|
|
30
|
+
เพิ่มเงินสมทบ
|
|
31
|
+
</DrawerTrigger>
|
|
32
|
+
<DrawerContent>
|
|
33
|
+
<DrawerHeader>
|
|
34
|
+
<DrawerTitle>เพิ่มเงินสมทบ</DrawerTitle>
|
|
35
|
+
<DrawerDescription>เงินจะเข้าบัญชีภายใน 3 วันทำการ</DrawerDescription>
|
|
36
|
+
</DrawerHeader>
|
|
37
|
+
…
|
|
38
|
+
<DrawerFooter>
|
|
39
|
+
<Button>ยืนยัน</Button>
|
|
40
|
+
<DrawerClose render={<Button variant="outline" />}>ยกเลิก</DrawerClose>
|
|
41
|
+
</DrawerFooter>
|
|
42
|
+
</DrawerContent>
|
|
43
|
+
</Drawer>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- ใส่ `DrawerTitle` เสมอ เป็นชื่อของแผงสำหรับโปรแกรมอ่านหน้าจอ
|
|
47
|
+
|
|
48
|
+
## When to use
|
|
49
|
+
|
|
50
|
+
- งานสั้น ๆ บนมือถือ เช่น ฟอร์มสั้น ตัวเลือก ตัวกรอง (ตอบ TODO "drawer" ใน `Dialog.md`)
|
|
51
|
+
- แผงด้านข้าง (`swipeDirection="right"`) เช่น ตัวกรองของตาราง
|
|
52
|
+
|
|
53
|
+
## When not to use
|
|
54
|
+
|
|
55
|
+
| สถานการณ์ | ใช้แทน |
|
|
56
|
+
| --------------------------- | -------------- |
|
|
57
|
+
| ยืนยันการกระทำที่ย้อนกลับไม่ได้ | `AlertDialog` |
|
|
58
|
+
| บนจอกว้างที่กล่องกลางจอเหมาะกว่า | `Dialog` |
|
|
59
|
+
| เมนูคำสั่ง | `DropdownMenu` |
|
|
60
|
+
|
|
61
|
+
TODO: ยังไม่ได้ตัดสินใจว่าจะสลับ Dialog (จอกว้าง) กับ Drawer (มือถือ) อัตโนมัติหรือไม่ (shadcn มีตัวอย่าง "Responsive")
|
|
62
|
+
|
|
63
|
+
## Props and variants
|
|
64
|
+
|
|
65
|
+
### Drawer
|
|
66
|
+
|
|
67
|
+
| Prop | ค่า | ค่าเริ่มต้น | ความหมาย |
|
|
68
|
+
| ----------------------- | ----------------------------- | ------- | --------------------------------------------------- |
|
|
69
|
+
| `swipeDirection` | `down`, `up`, `left`, `right` | `down` | ทิศที่ปัดเพื่อปิด และขอบที่แผงเลื่อนออกมา (`down` = จากด้านล่าง) |
|
|
70
|
+
| `showSwipeHandle` | `boolean` | `false` | แถบจับสำหรับปัด |
|
|
71
|
+
| `open` / `onOpenChange` | `boolean` / ฟังก์ชัน | – | ควบคุมการเปิด/ปิด |
|
|
72
|
+
| `modal` | `boolean` | `true` | มีฉากหลังมืด และหน้าด้านหลังกดไม่ได้ |
|
|
73
|
+
| `snapPoints` | รายการความสูง | – | จุดหยุดระหว่างปัด TODO: ยังไม่มีตัวอย่าง |
|
|
74
|
+
|
|
75
|
+
### ขนาด
|
|
76
|
+
|
|
77
|
+
- จากด้านล่าง/บน: กว้างเต็มจอ สูงตามเนื้อหา สูงสุดเท่าจอลบ 96px
|
|
78
|
+
- จากด้านข้าง: กว้าง 75% บนมือถือ และ 384px บนจอ 640px ขึ้นไป
|
|
79
|
+
- ห่างขอบจอ 8px มุมโค้ง 26px
|
|
80
|
+
|
|
81
|
+
### ส่วนอื่น ๆ
|
|
82
|
+
|
|
83
|
+
`DrawerHeader` (หัวข้อกึ่งกลางบนมือถือ ชิดซ้ายบนจอ 768px ขึ้นไป), `DrawerFooter` (ปุ่มเรียงลงมา), `DrawerClose` (ปิด ใช้ `render={<Button … />}`)
|
|
84
|
+
|
|
85
|
+
## Tokens used
|
|
86
|
+
|
|
87
|
+
ค่าทั้งหมดมาจาก `src/styles/theme.css`
|
|
88
|
+
|
|
89
|
+
| Token | โหมดสว่าง | โหมดมืด | ใช้ใน |
|
|
90
|
+
| ---------------------- | -------------------------------- | -------------------------- | ------------------------------- |
|
|
91
|
+
| `--popover` | `oklch(1 0 0)` | `oklch(0.228 0.013 107.4)` | พื้นแผง |
|
|
92
|
+
| `--popover-foreground` | `oklch(0.153 0.006 107.1)` | `oklch(0.988 0.003 106.5)` | ตัวอักษร |
|
|
93
|
+
| `--muted-foreground` | `oklch(0.5 0.027 107.3)` | `oklch(0.737 0.021 106.9)` | คำอธิบาย |
|
|
94
|
+
| `--muted` | `oklch(0.966 0.005 106.5)` | `oklch(0.286 0.016 107.4)` | แถบจับ |
|
|
95
|
+
| `--border` | `oklch(0.93 0.007 106.5)` | `oklch(1 0 0 / 10%)` | เส้นขอบ (โหมดมืด) |
|
|
96
|
+
| `--radius` | `0.625rem` | – | มุมโค้ง (`--radius × 2.6` = 26px) |
|
|
97
|
+
| `--font-heading` | กำหนดโดยแอป (IBM Plex Sans Thai) | – | หัวข้อ |
|
|
98
|
+
|
|
99
|
+
ฉากหลังสีดำ 30% และเบลอ จางลงตามระยะที่ปัด
|
|
100
|
+
|
|
101
|
+
## Example
|
|
102
|
+
|
|
103
|
+
จาก story `Playground` ใน `Drawer.stories.tsx`:
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
<Drawer swipeDirection="down" showSwipeHandle>
|
|
107
|
+
<DrawerTrigger render={<Button variant="outline" />}>
|
|
108
|
+
เพิ่มเงินสมทบ
|
|
109
|
+
</DrawerTrigger>
|
|
110
|
+
<DrawerContent>
|
|
111
|
+
<DrawerHeader>
|
|
112
|
+
<DrawerTitle>เพิ่มเงินสมทบ</DrawerTitle>
|
|
113
|
+
<DrawerDescription>เงินจะเข้าบัญชีภายใน 3 วันทำการ</DrawerDescription>
|
|
114
|
+
</DrawerHeader>
|
|
115
|
+
<div className="grid gap-2 p-4">
|
|
116
|
+
<Label htmlFor="drawer-amount">จำนวนเงิน (AUD)</Label>
|
|
117
|
+
<Input id="drawer-amount" type="number" placeholder="0.00" />
|
|
118
|
+
</div>
|
|
119
|
+
<DrawerFooter>
|
|
120
|
+
<Button>ยืนยัน</Button>
|
|
121
|
+
<DrawerClose render={<Button variant="outline" />}>ยกเลิก</DrawerClose>
|
|
122
|
+
</DrawerFooter>
|
|
123
|
+
</DrawerContent>
|
|
124
|
+
</Drawer>
|
|
125
|
+
```
|