Skip to main content

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/svelte-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-card adds a card to the column (and to the lane in stack layout) and opens the editor on it.
  • collapse-column toggles the column's collapsed state through update-column. It isn't part of the defaults and must be added to options explicitly.

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:

<script lang="ts">
import {
Kanban,
ColumnActionMenu,
ColumnContextMenu,
getColumnMenuOptions,
type ColumnMenuContext,
} from "@svar-ui/svelte-kanban";

let api = $state();

// 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 options(ctx: ColumnMenuContext) {
const items: any[] = 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 }));
}
</script>

<ColumnContextMenu {api} {options} {onclick}>
<ColumnActionMenu {api} {options} {onclick}>
<Kanban bind:this={api} {cards} {columns} />
</ColumnActionMenu>
</ColumnContextMenu>