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

เมนูคำสั่ง

ActionMenu

A button that opens a short list of actions, such as Edit, Copy, Print and Delete beside a record's main action. Keep the step's main action as its own Button, and put the rest here. The arrow keys move through the list, Enter runs an action, and Esc closes it.

ใช้รวมคำสั่งรองของรายการไว้ในปุ่มเดียว เช่น แก้ไข ทำสำเนา พิมพ์ และลบ ข้างคำสั่งหลัก คำสั่งหลักของขั้นตอนเป็น Button แยกเสมอ คำสั่งที่ลบหรือย้อนกลับไม่ได้อยู่ท้ายสุดและเป็นสีแดง

import { ActionMenu } from "@bsru/ui";

ตัวอย่าง

คำสั่งหลักและเมนูคำสั่ง

แต่ละรายการมี label icon และ onSelect หรือ href danger ทำให้เป็นสีแดง ลูกศรขึ้นลงเลื่อน Enter เลือก และ Esc ปิด

const items: MenuAction[] = [
  { label: "แก้ไข", icon: Pencil, onSelect: () => {} },
  { label: "ทำสำเนา", icon: Copy, onSelect: () => {} },
  { label: "พิมพ์", icon: Printer, href: "#print" },
  { label: "ลบ", icon: Trash, danger: true, onSelect: () => {} },
];

<Button label="อนุมัติ" tone="primary" onClick={approve} />
<ActionMenu items={items} />

ปุ่มแบบเรียบ

label เปลี่ยนข้อความบนปุ่ม tone quiet ใช้ในพื้นที่ที่มีปุ่มหลายปุ่ม

<ActionMenu
  items={[
    { label: "แก้ไข", icon: Pencil },
    { label: "ทำสำเนา", icon: Copy },
    { label: "พิมพ์", icon: Printer, href: "#print" },
  ]}
  label="ส่งออก"
  tone="quiet"
  align="left"
/>

props ทั้งหมด

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

ActionMenu props
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
items* จำเป็นreadonly MenuAction[]—The actions, in order, with any destructive one last.
labelstring—The button's text, already in the screen language. Defaults to Actions.
align"left" | "right""left"Which edge of the button the list lines up with. Use right near the right edge of the screen.
tone"secondary" | "quiet""secondary"The button's look.

ชนิดข้อมูล

MenuAction

One action in an ActionMenu.

MenuAction fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
label* จำเป็นstring—What it does, already in the screen language, such as Print.
iconLucideIcon—Shown before the label.
dangerboolean—Red, for an action that deletes or can't be undone. Put it last.
disabledboolean—Can't be used now, such as Edit on an approved record.
onSelect() => void—Called after the menu closes.
hrefstring—Makes it a link instead, such as to a print page.

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

  • มีคำสั่งหลักได้ไม่เกินหนึ่งปุ่ม ที่เหลืออยู่ในเมนู
  • ใช้ align right เมื่อปุ่มอยู่ใกล้ขอบขวาของจอ

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