ข้ามไปยังเนื้อหา

แผงด้านข้าง

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>

อ่านอย่างเดียว พร้อมลิงก์หน้าเต็ม

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>

props ทั้งหมด

ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้

Drawer 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.
summaryDrawerSummary—What the record is, its status and its key figure, at the top of the body.
loadingbooleanfalseShows placeholder lines in place of the summary and sections while the record loads.
childrenReactNode—The record's sections, such as RecordSection with a FieldList. This part scrolls.
headerActionReactNode—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.

DrawerSummary fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
titlestring—What the record is, such as its item, under the number in the header.
statusBadgeStyle—The status badge, the same as the list's status column.
figureKeyFigure—The one figure that matters most, such as the amount, in large type.

BadgeStyle

How a badge column shows one value, such as pending.

BadgeStyle fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
tone* จำเป็นBadgeTone
ค่าที่ใช้ได้:"draft""pending""approved""paid""request""rejected""line"
——
label* จำเป็นstring—The badge text, already in the screen language.
iconLucideIcon——

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.

KeyFigure fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
label* จำเป็นstring—What the figure is, such as วงเงิน. Unique within the strip.
value* จำเป็นReactNode—The figure, already formatted, such as with money() or fmtDate().
unitstring—The unit after the value, such as บาท.

ข้อควรปฏิบัติ

  • ใช้ dialog ของเบราว์เซอร์ โฟกัสจึงอยู่ในแผง Esc ปุ่มปิด หรือคลิกนอกแผงเรียก onClose
  • ปุ่มตามสถานะ มีปุ่มหลักได้ไม่เกินหนึ่งปุ่ม: รออนุมัติมีอนุมัติและไม่อนุมัติ ร่างมีแก้ไข อนุมัติแล้วมีพิมพ์
  • ถ้าปุ่มในแผงเปิด Dialog ให้ปิดแผงก่อน เพราะเปิดหน้าต่างซ้อนกันไม่ได้
  • ส่วนหัวและ footer อยู่กับที่ เนื้อหาเลื่อนได้ บนมือถือแผงเต็มความกว้างจอ

ซอร์สโค้ด: ui/src/dialog.tsx