getColumnMenuOptions
Returns the default column menu items. The list holds a single item, Add card. These are the default items of the ColumnActionMenu and ColumnContextMenu wrappers.
Use the result as a base for custom column actions that keep the default item.
Usage
import { getColumnMenuOptions } from "@svar-ui/react-kanban";
getColumnMenuOptions(): { id: string; text: string; icon: string }[];
Returns:
[{ id: "add-card", text: "Add card", icon: "wxi-plus" }];
The column menu wrappers run built-in ids before onClick:
add-cardadds a card to the column (and to the lane in stack layout) and opens the editor on it.collapse-columntoggles the column'scollapsedstate throughupdate-column. It isn't part of the defaults and must be added tooptionsexplicitly.
Custom ids reach only the onClick callback.
When you omit options, the wrappers hide add-card on columns with addCard: false. A custom options array is used exactly as given. To get the same behavior, filter the array manually.
Example
Extend the defaults with a collapse item and a custom action:
import { useState } from "react";
import {
Kanban,
ColumnActionMenu,
ColumnContextMenu,
getColumnMenuOptions,
} from "@svar-ui/react-kanban";
// the ⋯ button is opt-in per column
const columns = [
{ id: "todo", label: "To Do", menu: true },
{ id: "done", label: "Done", menu: true, addCard: false },
];
function MyComponent({ cards }) {
const [api, setApi] = useState();
function options(ctx) {
const items = getColumnMenuOptions().filter(
(o) => o.id !== "add-card" || ctx.column.addCard !== false
);
items.push({ id: "collapse-column", text: "Collapse" });
if (ctx.cards.length)
items.push({ id: "clear-column", text: `Delete ${ctx.cards.length} card(s)` });
return items;
}
function onClick({ action, context }) {
if (action.id === "clear-column")
context.cards.forEach((card) => api.exec("delete-card", { id: card.id }));
}
return (
<ColumnContextMenu api={api} options={options} onClick={onClick}>
<ColumnActionMenu api={api} options={options} onClick={onClick}>
<Kanban init={setApi} cards={cards} columns={columns} />
</ColumnActionMenu>
</ColumnContextMenu>
);
}
export default MyComponent;
Related
- Menus guide - card and column menus
- ColumnActionMenu - column
⋯button menu that uses these options by default - ColumnContextMenu - right-click column header menu that uses these options by default
- getMenuOptions - default card menu options