Skip to content
h v3.13.3
Search the docs
Find a component, section or page.

Canvas

A board for cards, arrows, shapes and freehand pen strokes.

Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.

Installation

pnpm add @heyramzi/ui

Usage

import { createCanvasDispatcher, createRegistry } from "@heyramzi/ui/canvas";

Keyboard and accessibility

Key Does
Tab Moves between the tool rail, the style bar and the nodes. Each bar is one stop.
Arrow Up Arrow Down Home End On the tool rail, moves between the tools. ArrowLeft and ArrowRight do it on the style bar.
Space Enter On a bar, picks the focused tool, colour or size. On a node, selects it.
Esc Deselects the focused node, or cancels a stroke being drawn.
Arrow Up Arrow Down Arrow Left Arrow Right Moves the selected nodes 5px. Hold Shift for 20px.
Backspace Delete Deletes the selected nodes.
V H L P M E T R O D F Picks the tool its tooltip names, while focus is on the canvas and not in a text field.
  • A live region announces every arrow move.
  • Tools, colours and sizes are named radios that report checked, and each tool's tooltip and aria-keyshortcuts give its letter. resolveToolKey turns a key press into the tool, so a host binds the letters in one line.
  • A node is named by its words: "Draw on me", "Rectangle: Idea", or "Pen stroke" for a drawing. The name follows edits.
  • Drawing, placing a shape or text, connecting nodes and resizing a shape are still pointer only.
  • Enter doesn't open a node's text yet. The host owns that key and calls requestStartEdit.
  • A node's text field keeps the keys you type in it, and Esc leaves it.
  • With reduced motion on, the toolbar doesn't animate.

API reference

CanvasToolbar

tool required bindable "select" | "hand" | "connect" | "frame" | "pen" | "highlighter" | "eraser" | "text" | "rectangle" | "ellipse" | "diamond"
color required bindable PenColor
level required bindable 0 | 1 | 2
labels required ToolbarLabels
onNote () => void
The note button drops a note card, so the host owns what it does. Omit it to hide the button.
extra Snippet
Sits last on the rail, for what only the host knows, like the card palette.
Prop Type Default
tool required bindable "select" | "hand" | "connect" | "frame" | "pen" | "highlighter" | "eraser" | "text" | "rectangle" | "ellipse" | "diamond"
color required bindable PenColor
level required bindable 0 | 1 | 2
labels required ToolbarLabels
onNote

The note button drops a note card, so the host owns what it does. Omit it to hide the button.

() => void
extra

Sits last on the rail, for what only the host knows, like the card palette.

Snippet

PenLayer

tool required "pen" | "highlighter" | "eraser" | "text" | "rectangle" | "ellipse" | "diamond"
color required PenColor
size number
nodes required readonly ErasableNode[]
commit required (ops: PenOp[]) => void
startGesture required () => () => void
onTextPlaced (nodeId: string) => void
Prop Type Default
tool required "pen" | "highlighter" | "eraser" | "text" | "rectangle" | "ellipse" | "diamond"
color required PenColor
size number
nodes required readonly ErasableNode[]
commit required (ops: PenOp[]) => void
startGesture required () => () => void
onTextPlaced (nodeId: string) => void