ColumnActionMenu
Menu wrapper that opens when the user clicks the ⋯ button in a column header. Wrapping <Kanban> in <ColumnActionMenu> gives each column its own actions, such as adding a card or collapsing the column.
The button is opt-in per column: set menu: true on a ColumnConfig. Columns without it have no button, and a click elsewhere on the header never opens this menu.
Usage
import { ColumnActionMenu } from "@svar-ui/react-kanban";
Props
The props are the same as on the other menu wrappers (KanbanMenuProps<ColumnMenuContext>).
| Prop | Type | Default | Description |
|---|---|---|---|
api | KanbanInstanceApi | null | null | Kanban instance used to resolve the column and run built-in items. The menu never opens until it's set. |
options | any[] | ((ctx: ColumnMenuContext) => any[] | null | undefined | false) | defaults | Menu items, or a function called on every open. An empty result keeps the menu closed. |
resolver | ((ctx: ColumnMenuContext, ev: MouseEvent) => any) | null | null | Gate called after the column resolves. Return a falsy value to keep the menu closed. |
filter | ((item: any, ctx: ColumnMenuContext) => boolean) | null | null | Per-item filter. Return false to hide an item for the current column. |
onClick | (ev: any) => void | undefined | Fires after built-in handling for a chosen item. Receives { action, context }. |
at | string | "point" | Menu placement mode. |
css | string | undefined | Extra CSS class forwarded to the inner menu. |
children | ReactNode | - | Wrapped content, typically <Kanban> or another menu wrapper. |
onClick doesn't fire when the user closes the menu without choosing an item.
Context
options, resolver, filter, and onClick (as ev.context) receive a ColumnMenuContext:
type ColumnMenuContext = {
column: ColumnView;
cards: KanbanCard[];
swimlane?: SwimlaneView;
};
| Field | Type | Description |
|---|---|---|
column | ColumnView | The projected column: its cards, summaries, collapsed flag, and config fields |
cards | KanbanCard[] | Cards under the header. In the stack layout, only the cards of that lane |
swimlane | SwimlaneView | The lane of the group header. Set only in the stack layout |
Methods
| Method | Signature | Description |
|---|---|---|
show | show(ev: Event, obj?: any) | Opens the menu programmatically; obj is the target column ID. |
Default items
Without options, the menu shows getColumnMenuOptions(), which returns a single add-card item. The menu hides it on columns with addCard: false.
Custom options are used exactly as passed. Code that builds on getColumnMenuOptions() has to filter out add-card for addCard: false columns.
Built-in item IDs
| ID | Text | Dispatches |
|---|---|---|
add-card | Add card | add-card into the column (and the lane, in the stack layout) with edit: true, so the editor opens on the new card |
collapse-column | Collapse column | update-column that toggles the column's collapsed flag |
collapse-column isn't in the defaults. Add { id: "collapse-column", text: "Collapse column" } to options to show it. Item texts are localized through the kanban locale group. Custom item IDs don't auto-dispatch. Handle them in onClick.
Example
Default menu on every column's ⋯ button:
import { useState } from "react";
import { Kanban, ColumnActionMenu } from "@svar-ui/react-kanban";
const columns = [
{ id: "todo", label: "To Do", menu: true },
{ id: "doing", label: "In Progress", menu: true },
{ id: "done", label: "Done", menu: true },
];
const cards = [];
function App() {
const [api, setApi] = useState();
return (
<ColumnActionMenu api={api}>
<Kanban init={setApi} cards={cards} columns={columns} />
</ColumnActionMenu>
);
}
export default App;
Items that follow the column's content. The options function runs on every open, so the "Delete" item shows the current card count:
import { useState } from "react";
import {
Kanban,
ColumnActionMenu,
getColumnMenuOptions,
type ColumnMenuContext,
} from "@svar-ui/react-kanban";
const columns = [
{ id: "todo", label: "To Do", menu: true },
{ id: "done", label: "Done", menu: true },
];
const cards = [];
function App() {
const [api, setApi] = useState<any>();
function options(ctx: ColumnMenuContext) {
const items: any[] = getColumnMenuOptions().filter(
o => o.id !== "add-card" || ctx.column.addCard
);
items.push({ id: "collapse-column", text: "Collapse column" });
if (ctx.cards.length)
items.push({ id: "clear-column", text: `Delete ${ctx.cards.length} card(s)` });
return items;
}
function onClick({ action, context }: any) {
if (action.id === "clear-column")
context.cards.forEach(c => api.exec("delete-card", { id: c.id }));
}
return (
<ColumnActionMenu api={api} options={options} onClick={onClick}>
<Kanban init={setApi} cards={cards} columns={columns} />
</ColumnActionMenu>
);
}
export default App;
Related
- Card menu guide - card and column menus, custom items
- columns - enable the header button with
menu: true - ColumnContextMenu - the same column menu on header right click
- getColumnMenuOptions - default column menu items