Whiteboard
A board you can pan and zoom, with sticky notes, text and Momo cards you move around freely. It is the look and the feel of a whiteboard: everything stays in the page, and it tells you what changed so you can save it your way.
Try it
Drag anything to move it. Drag the empty board to pan. Double-click the board for a new note, a note to type in it, or a card to open its form. "Add card" has six kinds: a picture, a task, a checklist, a quote, a color palette and a link, each with its own form.
Open it full screen The example remembers your changes on this device; "Reset" starts over.
What you can do on it
| To | Mouse or finger | Keys |
|---|---|---|
| Move something | Drag it (with several selected, they all move) | Arrow keys, Shift for 1 pixel |
| Resize | Drag the round mark on the bottom corner of the selected item | |
| Pan | Drag the empty board, or use the Hand tool; the wheel pans too | Arrow keys with nothing selected, or hold Space and drag |
| Zoom | Ctrl + wheel, or pinch with two fingers | + -, 0 for 100%, 1 to fit everything |
| Add a note | Double-click the empty board, or pick the Note tool and click | N, then click |
| Write | Double-click a note, a shape or a text | Enter, then Esc when done |
| Open a card | Double-click it (your edit form shows) | Enter |
| Select several | Shift + click, or Shift + drag a box | Ctrl + A |
| Color | Click a swatch (it paints what is selected) | |
| Remove, copy, undo | The buttons in the bar | Del, Ctrl + D, Ctrl + Z / Y |
A selected item gets a thicker border. Nothing tilts when you pick it up: a dragged item only gets a shadow.
The markup
A .board holds a toolbar and a .board-canvas with a .board-world inside. Each thing on the board is a .board-item with its place and size in data-x, data-y, data-w, data-h.
<div class="board" data-momo-board style="--board-height: 36rem">
<div class="board-toolbar" role="toolbar" aria-label="Tools">
<button class="btn btn-icon btn-sm btn-ghost" data-board-tool="select" aria-label="Select"><i class="mi mi-mouse-pointer-2"></i></button>
<button class="btn btn-icon btn-sm btn-ghost" data-board-tool="note" aria-label="Sticky note"><i class="mi mi-sticky-note"></i></button>
<button class="board-swatch bg-yellow" data-board-color="yellow" aria-label="Yellow"></button>
<button class="btn btn-icon btn-sm btn-ghost" data-board-action="undo" aria-label="Undo"><i class="mi mi-undo-2"></i></button>
</div>
<div class="board-canvas">
<div class="board-world">
<div class="board-item board-note bg-yellow" data-id="n1" data-x="80" data-y="80" data-w="180" data-h="160">
<div class="board-text">Free shipping for the first 100 orders</div>
</div>
<div class="board-item board-label" data-id="h1" data-x="80" data-y="20">
<div class="board-text">Launch week</div>
</div>
<div class="board-item board-card" data-id="c1" data-x="320" data-y="80" data-w="260">
<article class="card">…any Momo card…</article>
</div>
</div>
</div>
<div class="board-zoom">
<button class="btn btn-icon btn-sm btn-ghost" data-board-action="zoom-out" aria-label="Zoom out"><i class="mi mi-minus"></i></button>
<button class="btn btn-sm btn-ghost" data-board-action="zoom-reset"><span data-board-zoom-label>100%</span></button>
<button class="btn btn-icon btn-sm btn-ghost" data-board-action="zoom-in" aria-label="Zoom in"><i class="mi mi-plus"></i></button>
</div>
</div>The kinds of things
| Class | What it is |
|---|---|
.board-note + .bg-<color> | A sticky note |
.board-shape.board-shape-rect, .board-shape-ellipse | A box, a circle, with words in the middle (paint it with .bg-<color>). Not in the example's toolbar; add the Box and Circle tools if you want them |
.board-label (data-size="sm", "lg") | Plain text: a heading or a label |
.board-card | Anything else, usually a Momo card. It fires momo:board-open when opened |
.board-cursor | Someone else's pointer with a name flag (decoration; place it with left and top) |
Cards with an edit form
A .board-card can hold anything: the example has six kinds, all ordinary Momo cards built from a little data. A card is one thing to grab, so the links and buttons inside it do nothing on the board. Opening it (a double-click, or Enter) fires momo:board-open: show your own dialog, then hand the result back with update(). Keep the card's fields in data-board-data (JSON) and they come along when you save.
const board = Momo.board('#board');
boardEl.addEventListener('momo:board-open', (e) => {
const task = e.detail.item.data; // { title, team, who, due }
fillTheForm(task);
Momo.dialog.open('#task-dialog');
currentId = e.detail.id;
});
form.addEventListener('submit', () => {
const task = readTheForm();
board.update(currentId, { data: task, html: cardHTML(task) });
});Saving
The board fires momo:board-change after every change, with everything on it. Send that to your server, or keep it in the browser as the example does. load() puts it back.
boardEl.addEventListener('momo:board-change', (e) => {
save(e.detail); // { items: [{ id, type, x, y, w, h, color, text | html, data }] }
});
board.load(await fetchBoard());
board.fit();Good to know
- This is the interface only. Several people on one board at the same time needs a server that passes changes along; the two pointers in the example are for show.
- The wheel only pans once the board is in use (clicked or focused), so a board in the middle of a page does not trap scrolling.
- Every item can be reached with Tab, moved with the arrow keys and opened with Enter.
.board-shadowson the board gives notes, shapes and cards the hard shadow;.board-flushremoves the outline for a full-screen board;.board-toolbar-sidestands the toolbar down the side.- There are no connecting lines: it is a free board of things you place where you like. For columns of cards that snap into lists, use Kanban.
Reference
| Attribute / API | What it does |
|---|---|
data-momo-board, --board-height, data-board-fit | Turns it on, its height (100%), fit everything in view at the start |
data-board-tool="…" | A tool button: select, hand, note, text, rect, ellipse |
data-board-action="…" | undo, redo, delete, duplicate, zoom-in, zoom-out, zoom-reset, fit |
data-board-color="yellow", data-board-zoom-label | A color swatch, where the zoom percent is written |
Momo.board(el) | toJSON(), load(data), add(type, opts), update(id, patch), remove(ids), select(ids), tool(name), fit(), zoom(k), view(), undo(), redo() |
Event momo:board-change | After every change; detail: { items } |
Event momo:board-select, momo:board-open | detail: { ids }; detail: { el, id, item } |