แผงด้านข้าง
Drawer
A panel from the right edge, for a record's details beside the list it came from: a quick look and a decision without losing your place. The number goes in the header, summary shows what it is, its status and its key figure, and children are its sections, such as RecordSection with a FieldList, spaced evenly. Actions sit in the footer, sharing its width. While the record loads, pass loading for placeholder lines.
ใช้ดูรายละเอียดของรายการจากตารางหรือรายการ โดยไม่ออกจากหน้าและไม่เสียตำแหน่งที่เลื่อนไว้ เพื่อดูเร็วและตัดสินใจ เลขที่อยู่ที่ส่วนหัว summary แสดงชื่อรายการ สถานะ และตัวเลขสำคัญ แล้วตามด้วยส่วนต่าง ๆ ปุ่มอยู่ด้านล่าง ถ้าต้องได้คำตอบก่อนทำต่อ ใช้ Dialog ถ้าเป็นงานยาว ให้เปิดหน้าเต็ม
import { Drawer } from "@bsru/ui";ตัวอย่าง
ดูเร็วพร้อมปุ่มดำเนินการ
summary คือชื่อรายการ ป้ายสถานะ และตัวเลขสำคัญตัวเดียว children คือ RecordSection แต่ละส่วนซึ่งเว้นระยะเท่ากันเอง loading แสดงเส้นรอโหลดขณะดึงข้อมูล ปุ่มใน footer แบ่งความกว้างเท่ากัน ลองเปิดดู
const summary: DrawerSummary = {
title: "ครุภัณฑ์คอมพิวเตอร์โน้ตบุ๊ก 5 เครื่อง",
status: { tone: "pending", label: "รออนุมัติ", icon: Clock },
figure: { label: "วงเงิน", value: "150,000.00", unit: "บาท" },
};
<Drawer
open={open}
onClose={() => setOpen(false)}
title="PR-2570-0001"
summary={summary}
loading={isLoading}
headerAction={<IconButton icon={ExternalLink} label="เปิดหน้าเต็ม" href={fullPage} />}
footer={
<>
<Button label="อนุมัติ" tone="primary" onClick={approve} />
<Button label="ไม่อนุมัติ" onClick={reject} />
</>
}
>
<RecordSection title="รายละเอียด">
<FieldList fields={fields} />
</RecordSection>
<RecordSection title="รายการ">
<LineItems caption="รายการในคำขอ PR-2570-0001" columns={columns} items={items} totalLabel="รวมทั้งสิ้น" total={record.total} />
</RecordSection>
<RecordSection title="ไฟล์แนบ">
<AttachmentList files={files} downloadLabel="ดาวน์โหลด" />
</RecordSection>
<RecordSection title="การอนุมัติ">
<ApprovalChain levels={levels} />
</RecordSection>
</Drawer>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| open* จำเป็น | false | boolean | Shows the drawer. The screen keeps this in its state. |
| title* จำเป็น | "PR-2570-0001" | ReactNode | The record's name or number. |
| summary | ออบเจกต์ 3 ฟิลด์{
title: "ครุภัณฑ์คอมพิวเตอร์โน้ตบุ๊ก 5 เครื่อง",
status: { tone: "pending", label: "รออนุมัติ", icon: Clock },
figure: { label: "วงเงิน", value: "150,000.00", unit: "บาท" },
} | DrawerSummary | What the record is, its status and its key figure, at the top of the body. |
| loading | false | boolean | Shows placeholder lines in place of the summary and sections while the record loads. |
| footer | "<Button />" | ReactNode | Actions on the record, fixed at the bottom. One primary at most. They share the width. |
| headerAction | "<IconButton />" | ReactNode | An icon button or link before Close, such as Open full page. Give it an aria-label. |
| onClose* จำเป็น | () => setOpen(false) | () => void | Called on Esc, a click outside, or the close button. Set open to false here. |
อ่านอย่างเดียว พร้อมลิงก์หน้าเต็ม
headerAction วาง IconButton ไว้ก่อนปุ่มปิด เมื่อไม่มีปุ่มดำเนินการตามสถานะ เช่น อนุมัติแล้ว ไม่ต้องส่ง footer
<Drawer
open={open}
onClose={() => setOpen(false)}
title="PR-2570-0001"
summary={{
title: "ครุภัณฑ์คอมพิวเตอร์โน้ตบุ๊ก 5 เครื่อง",
status: { tone: "approved", label: "อนุมัติแล้ว", icon: Check },
figure: { label: "วงเงิน", value: "150,000.00", unit: "บาท" },
}}
headerAction={<IconButton icon={ExternalLink} label="เปิดหน้าเต็ม" href={fullPage} />}
>
<RecordSection title="รายละเอียด">
<FieldList fields={fields} />
</RecordSection>
</Drawer>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| open* จำเป็น | false | boolean | Shows the drawer. The screen keeps this in its state. |
| title* จำเป็น | "PR-2570-0001" | ReactNode | The record's name or number. |
| summary | ออบเจกต์ 3 ฟิลด์{
title: "ครุภัณฑ์คอมพิวเตอร์โน้ตบุ๊ก 5 เครื่อง",
status: { tone: "approved", label: "อนุมัติแล้ว", icon: Check },
figure: { label: "วงเงิน", value: "150,000.00", unit: "บาท" },
} | DrawerSummary | What the record is, its status and its key figure, at the top of the body. |
| headerAction | "<IconButton />" | ReactNode | An icon button or link before Close, such as Open full page. Give it an aria-label. |
| onClose* จำเป็น | () => setOpen(false) | () => void | Called on Esc, a click outside, or the close button. Set open to false here. |
props ทั้งหมด
ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| open* จำเป็น | boolean | — | Shows the drawer. The screen keeps this in its state. |
| onClose* จำเป็น | () => void | — | Called on Esc, a click outside, or the close button. Set open to false here. |
| title* จำเป็น | ReactNode | — | The record's name or number. |
| summary | DrawerSummary | — | What the record is, its status and its key figure, at the top of the body. |
| loading | boolean | false | Shows placeholder lines in place of the summary and sections while the record loads. |
| children | ReactNode | — | The record's sections, such as RecordSection with a FieldList. This part scrolls. |
| footer | ReactNode | — | Actions on the record, fixed at the bottom. One primary at most. They share the width. |
| headerAction | ReactNode | — | An icon button or link before Close, such as Open full page. Give it an aria-label. |
ชนิดข้อมูล
DrawerSummary
The top of a drawer's body: what the record is, its status and its key figure, as the guide's quick view shows.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| title | string | — | What the record is, such as its item, under the number in the header. |
| status | BadgeStyle | — | The status badge, the same as the list's status column. |
| figure | KeyFigure | — | The one figure that matters most, such as the amount, in large type. |
BadgeStyle
How a badge column shows one value, such as pending.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| tone* จำเป็น | BadgeTone ค่าที่ใช้ได้: "draft""pending""approved""paid""request""rejected""line" | — | — |
| label* จำเป็น | string | — | The badge text, already in the screen language. |
| icon | LucideIcon | — | — |
BadgeTone
The state a badge reports. Each one has its own colour. line is for facts that aren't a state.
type BadgeTone = "draft" | "pending" | "approved" | "paid" | "request" | "rejected" | "line";KeyFigure
One key figure of a record.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| label* จำเป็น | string | — | What the figure is, such as วงเงิน. Unique within the strip. |
| value* จำเป็น | ReactNode | — | The figure, already formatted, such as with money() or fmtDate(). |
| unit | string | — | The unit after the value, such as บาท. |
ข้อควรปฏิบัติ
- ใช้ dialog ของเบราว์เซอร์ โฟกัสจึงอยู่ในแผง Esc ปุ่มปิด หรือคลิกนอกแผงเรียก onClose
- ปุ่มตามสถานะ มีปุ่มหลักได้ไม่เกินหนึ่งปุ่ม: รออนุมัติมีอนุมัติและไม่อนุมัติ ร่างมีแก้ไข อนุมัติแล้วมีพิมพ์
- ถ้าปุ่มในแผงเปิด Dialog ให้ปิดแผงก่อน เพราะเปิดหน้าต่างซ้อนกันไม่ได้
- ส่วนหัวและ footer อยู่กับที่ เนื้อหาเลื่อนได้ บนมือถือแผงเต็มความกว้างจอ
ซอร์สโค้ด: ui/src/dialog.tsx