Action menu
The actions on a record behind “…” or a right click, with submenus.
import { ActionMenu, ContextMenu } from "@forgeron/ui";import {
ArrowUpRight01Icon,
Copy01Icon,
Delete02Icon,
MoreHorizontalIcon,
Notification01Icon,
} from "@forgeron/icons";
import { ActionMenu, IconButton } from "@forgeron/ui";
export default function Default() {
return (
<ActionMenu
label="Actions on OPS-40"
trigger={<IconButton icon={MoreHorizontalIcon} label="Issue actions" variant="boxed" />}
onSelect={() => {}}
items={[
{ id: "open", label: "Open issue", icon: ArrowUpRight01Icon, kbd: "↵" },
{ id: "copy", label: "Copy ID", icon: Copy01Icon },
{ id: "subscribe", label: "Subscribe", icon: Notification01Icon },
{ separator: true },
{ id: "delete", label: "Delete issue", icon: Delete02Icon, danger: true },
]}
/>
);
}OPS-40Supplier invoices arrive twice from OdooHB
import {
ArrowUpRight01Icon,
Copy01Icon,
Delete02Icon,
MoreHorizontalIcon,
Notification01Icon,
NotificationOff01Icon,
} from "@forgeron/icons";
import {
ActionMenu,
Avatar,
IconButton,
PRIORITY_NAMES,
PriorityGlyph,
STATUS_NAMES,
StatusGlyph,
type ActionMenuEntry,
type PriorityLevel,
type StatusKind,
} from "@forgeron/ui";
import { useState } from "react";
const statuses: StatusKind[] = ["backlog", "todo", "progress", "review", "done", "canceled"];
const priorities: PriorityLevel[] = [0, 1, 2, 3, 4];
const people = ["Camille Roy", "Hugo Bernard", "Léa Martin", "Nadia Petit", "Tom Garnier"];
export default function Issue() {
const [status, setStatus] = useState<StatusKind>("progress");
const [priority, setPriority] = useState<PriorityLevel>(2);
const [assignee, setAssignee] = useState("Hugo Bernard");
const [subscribed, setSubscribed] = useState(true);
const [said, setSaid] = useState("");
const items: ActionMenuEntry[] = [
{
id: "status",
label: "Status",
glyph: <StatusGlyph status={status} />,
kbd: "S",
items: statuses.map((s, i) => ({
id: `status:${s}`,
label: STATUS_NAMES[s],
glyph: <StatusGlyph status={s} />,
kbd: String(i + 1),
checked: s === status,
})),
},
{
id: "priority",
label: "Priority",
glyph: <PriorityGlyph level={priority} />,
kbd: "P",
items: priorities.map((p) => ({
id: `priority:${p}`,
label: PRIORITY_NAMES[p],
glyph: <PriorityGlyph level={p} />,
kbd: String(p),
checked: p === priority,
})),
},
{
id: "assignee",
label: "Assignee",
glyph: <Avatar name={assignee} size={14} />,
kbd: "A",
items: people.map((name) => ({
id: `assignee:${name}`,
label: name === "Camille Roy" ? `${name} (you)` : name,
glyph: <Avatar name={name} size={14} />,
checked: name === assignee,
})),
},
{ separator: true },
{ id: "open", label: "Open issue", icon: ArrowUpRight01Icon, kbd: "↵" },
{ id: "copy", label: "Copy ID", icon: Copy01Icon },
{
id: "subscribe",
label: subscribed ? "Unsubscribe" : "Subscribe",
icon: subscribed ? NotificationOff01Icon : Notification01Icon,
},
{ separator: true },
{ id: "delete", label: "Delete issue", icon: Delete02Icon, danger: true },
];
const onSelect = (id: string) => {
const [field, value = ""] = id.split(":");
if (field === "status") setStatus(value as StatusKind);
else if (field === "priority") setPriority(Number(value) as PriorityLevel);
else if (field === "assignee") setAssignee(value);
else if (field === "subscribe") setSubscribed(!subscribed);
setSaid(`Chose ${id}`);
};
return (
<div style={{ width: "100%", display: "grid", gap: 10 }}>
<div
style={{
display: "flex",
alignItems: "center",
gap: 10,
height: 44,
padding: "0 8px 0 12px",
border: "1px solid var(--line)",
background: "var(--bg)",
}}
>
<PriorityGlyph level={priority} />
<span style={{ color: "var(--ink-dim)", font: "400 11.5px/1 var(--font-mono)" }}>
OPS-40
</span>
<StatusGlyph status={status} />
<span style={{ flex: 1 }}>Supplier invoices arrive twice from Odoo</span>
<Avatar name={assignee} size={20} />
<ActionMenu
label="Actions on OPS-40"
trigger={<IconButton icon={MoreHorizontalIcon} label="Issue actions" size="sm" />}
align="end"
items={items}
onSelect={onSelect}
/>
</div>
{said ? (
<span style={{ color: "var(--ink-dim)", font: "400 12px/1 var(--font-mono)" }}>{said}</span>
) : null}
</div>
);
}OPS-22Fire exit signage auditRight click
import { ArrowUpRight01Icon, Copy01Icon, Delete02Icon } from "@forgeron/icons";
import { ContextMenu, STATUS_NAMES, StatusGlyph, type StatusKind } from "@forgeron/ui";
import { useState } from "react";
const statuses: StatusKind[] = ["todo", "progress", "review", "done"];
export default function RightClick() {
const [status, setStatus] = useState<StatusKind>("todo");
return (
<div style={{ width: "100%" }}>
<ContextMenu
label="Actions on OPS-22"
onSelect={(id) => {
if (id.startsWith("status:")) setStatus(id.slice(7) as StatusKind);
}}
items={[
{
id: "status",
label: "Status",
glyph: <StatusGlyph status={status} />,
kbd: "S",
items: statuses.map((s) => ({
id: `status:${s}`,
label: STATUS_NAMES[s],
glyph: <StatusGlyph status={s} />,
checked: s === status,
})),
},
{ separator: true },
{ id: "open", label: "Open issue", icon: ArrowUpRight01Icon, kbd: "↵" },
{ id: "copy", label: "Copy ID", icon: Copy01Icon },
{ separator: true },
{ id: "delete", label: "Delete issue", icon: Delete02Icon, danger: true },
]}
>
<div
style={{
display: "flex",
alignItems: "center",
gap: 10,
height: 44,
padding: "0 12px",
border: "1px dashed var(--line-strong)",
background: "var(--bg)",
}}
>
<span style={{ color: "var(--ink-dim)", font: "400 11.5px/1 var(--font-mono)" }}>
OPS-22
</span>
<StatusGlyph status={status} />
<span style={{ flex: 1 }}>Fire exit signage audit</span>
<span style={{ color: "var(--ink-dim)", font: "400 11.5px/1 var(--font-mono)" }}>
Right click
</span>
</div>
</ContextMenu>
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
items | ActionMenuEntry[] | — | { id, label, icon?, glyph?, kbd?, danger?, checked?, items? }, { separator: true }, { heading }. |
onSelect | (id: string) => void | — | The row chosen, in the menu or a submenu. |
trigger | ReactElement | — | ActionMenu: the control that opens it, e.g. an IconButton. |
children | ReactNode | — | ContextMenu: the area that opens it on right click. |
open / onOpenChange | boolean / (open) => void | — | Optional. |
label | string | — | Names the menu, e.g. Actions on OPS-40. |