เมนูคำสั่ง
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} />| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| items* จำเป็น | รายการ 4 รายการ[
{ label: "แก้ไข", icon: Pencil },
{ label: "ทำสำเนา", icon: Copy },
{ label: "พิมพ์", icon: Printer, href: "#print" },
{ label: "ลบ", icon: Trash, danger: true },
] | readonly MenuAction[] | The actions, in order, with any destructive one last. |
ปุ่มแบบเรียบ
label เปลี่ยนข้อความบนปุ่ม tone quiet ใช้ในพื้นที่ที่มีปุ่มหลายปุ่ม
<ActionMenu
items={[
{ label: "แก้ไข", icon: Pencil },
{ label: "ทำสำเนา", icon: Copy },
{ label: "พิมพ์", icon: Printer, href: "#print" },
]}
label="ส่งออก"
tone="quiet"
align="left"
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| items* จำเป็น | รายการ 3 รายการ[
{ label: "แก้ไข", icon: Pencil },
{ label: "ทำสำเนา", icon: Copy },
{ label: "พิมพ์", icon: Printer, href: "#print" },
] | readonly MenuAction[] | The actions, in order, with any destructive one last. |
| label | "ส่งออก" | string | The button's text, already in the screen language. Defaults to Actions. |
| tone | "quiet" | "secondary" | "quiet" ค่าที่ใช้ได้: "secondary""quiet" | The button's look. |
| align | "left" | "left" | "right" ค่าที่ใช้ได้: "left""right" | Which edge of the button the list lines up with. Use right near the right edge of the screen. |
props ทั้งหมด
ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| items* จำเป็น | readonly MenuAction[] | — | The actions, in order, with any destructive one last. |
| label | string | — | 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.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| label* จำเป็น | string | — | What it does, already in the screen language, such as Print. |
| icon | LucideIcon | — | Shown before the label. |
| danger | boolean | — | Red, for an action that deletes or can't be undone. Put it last. |
| disabled | boolean | — | Can't be used now, such as Edit on an approved record. |
| onSelect | () => void | — | Called after the menu closes. |
| href | string | — | Makes it a link instead, such as to a print page. |
ข้อควรปฏิบัติ
- มีคำสั่งหลักได้ไม่เกินหนึ่งปุ่ม ที่เหลืออยู่ในเมนู
- ใช้ align right เมื่อปุ่มอยู่ใกล้ขอบขวาของจอ
ซอร์สโค้ด: ui/src/menu.tsx