Skip to main content

Card Popup

The cardPopup prop lets you replace the default editor click target with a custom popup component. When it's set, clicking a card opens your component in an anchored popup instead of the sidebar editor. Use it for quick previews or action panels that don't need a full form.

The popup takes over the card-click path. Without cardPopup, clicking a card dispatches select-card and opens the Editor. With cardPopup set, clicks open your popup component instead, and the editor doesn't open at all. Pressing Enter or Space opens the popup too, but only when the focused element is a card.

Your component receives two props:

  • card - the full KanbanCard object for the clicked card
  • close - a function that dismisses the popup

The popup anchors to the clicked card element and repositions on scroll. Pressing Escape or clicking outside the popup also closes it. Only one popup is visible at a time; clicking a second card swaps the content and anchor.

The popup keeps its state when <Kanban> reinitializes from new props. The card it holds is a snapshot taken when the popup opened, so it may be stale. If that matters, call close() when you replace the data.

Setup​

Pass a React component to the cardPopup prop.

import { Kanban } from "@svar-ui/react-kanban";
import QuickView from "./QuickView.jsx";

const columns = [
{ id: "todo", label: "To Do" },
{ id: "doing", label: "In Progress" },
{ id: "done", label: "Done" },
];
const cards = [
{ id: 1, label: "Draft spec", column: "todo" },
{ id: 2, label: "Build UI", column: "doing" },
];

<Kanban cards={cards} columns={columns} cardPopup={QuickView} />

The popup component itself is a regular React component:

// QuickView.jsx
import "./QuickView.css";

function QuickView({ card, close }) {
return (
<div className="quick-view">
<h4>{card.label}</h4>
{card.description && <p>{card.description}</p>}
<button onClick={close}>Close</button>
</div>
);
}

export default QuickView;
/* QuickView.css */
.quick-view {
background: white;
border-radius: 8px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
padding: 16px;
width: 280px;
}

Board with a card popup anchored to a clicked card showing a preview panel

The widget handles positioning and dismissal. You own the markup and styling inside the popup.

Component contract​

Your popup component must accept these props:

PropTypeDescription
cardKanbanCardThe clicked card's data
close() => voidCall this to dismiss the popup

Pointer events pass through to your content, so buttons, inputs, and links all work. The widget provides no default background, padding, or shadow; style everything in your component.

If your popup needs to dispatch actions (update a card, delete it, open the editor), get the API through the init callback and pass it to your component via context or props.

Coexistence with the editor​

When cardPopup is set, clicks always open the popup, never the editor. The two don't compete at runtime - the popup wins on every click path.

If you want both a preview popup and a full editor, wrap <Kanban> in a CardActionMenu or CardContextMenu. Their built-in edit-card item opens the editor, so clicks show the popup and the menu gives access to the editor:

import { useState } from "react";
import { Kanban, Editor, CardContextMenu } from "@svar-ui/react-kanban";
import CardPreview from "./CardPreview.jsx";

function App() {
const [api, setApi] = useState(null);

return (
<>
<CardContextMenu api={api}>
<Kanban
cards={cards}
columns={columns}
cardPopup={CardPreview}
init={a => setApi(a)}
/>
</CardContextMenu>
{api && <Editor api={api} />}
</>
);
}

Right-clicking a card opens the menu with the default items, and its edit-card item opens the sidebar editor. To open the same menu from a ⋯ button on the card, use CardActionMenu and set card={{ menu: true }} on <Kanban>.

You can also add an "Open editor" button inside your popup that dispatches select-card programmatically:

// CardPreview.jsx
import { useContext } from "react";
import { context } from "@svar-ui/react-core";

function CardPreview({ card, close }) {
const api = useContext(context.kanbanApi);

const openEditor = () => {
api.exec("select-card", { id: card.id });
close();
};

return (
<div className="preview">
<h4>{card.label}</h4>
<p>{card.description}</p>
<button onClick={openEditor}>Edit in sidebar</button>
<button onClick={close}>Close</button>
</div>
);
}

export default CardPreview;

Clicking a card shows the preview popup. The preview's "Edit in sidebar" button opens the full editor and closes the popup.

For the full prop reference, see cardPopup.