Canvas compatibility

.canvas.tsx is an experimental format. Uploads return experimental: true. The reading page transpiles it with Sucrase in the sandbox, then runs the default-exported function component. Imports are only allowed from cursor/canvas, and the names must be in the tables below. Other modules, unlisted export names and default imports all report UNSUPPORTED_IMPORT with the module and export name.

Transpiling runs in a Web Worker when possible and is stopped after 5 seconds. When the sandbox can't create a Worker, it transpiles synchronously in the sandbox page. The time of the page's first transpile is recorded in data-canvas-cold-ms on the preview root; later renders don't overwrite it.

useCanvasState only lasts for the page you have open and resets on reload. useCanvasAction doesn't call Cursor; clicking it explains that the action only works inside Cursor. Runtime namespace and decorators report UNSUPPORTED_SYNTAX before transpiling. declare namespace, import type and type modifiers in named imports are stripped without error.

Layout

Export Props
Stack children, gap (default 12), style
Row children, gap (default 8), align (start center end stretch), justify (start center end space-between), wrap, style
Grid children, columns (number or template string), gap, align, style
Divider style
Spacer None
Card children, variant (default borderless), size (base lg), collapsible, defaultOpen, open, onOpenChange, style
CardHeader children, trailing, style
CardBody children, style. Not rendered while a collapsible card is closed

Text

Export Props
H1 H2 H3 children, style
Text children, tone (primary secondary tertiary quaternary), size (body small), as (p span), weight, italic, truncate, style. Markdown links in strings become links
Code children, style
Link children, href, style. http(s) links open after the reading page asks for confirmation
Pill children, active, size (sm md), leadingContent, keyboardHint, disabled, title, onClick, style
Callout children, tone (success danger warning info neutral), title, icon, style
Stat value, label, tone, style

Tables, diffs and to-dos

Export Props
Table headers, rows, columnAlign, rowTone, framed, striped, stickyHeader, emptyMessage, style
DiffView lines (type is added removed unchanged, content, optional lineNumber), showLineNumbers, coloredLineNumbers, showAccentStrip, style. path and language exist only in the types and don't change the display
DiffStats additions, deletions, style. Not rendered when both are 0
TodoList todos (id, content, status: pending in_progress completed cancelled), dimmedTodoIds, onTodoClick, style
TodoListCard Same as above, plus defaultExpanded
CollapsibleSection title, leading, count, trailing, children, defaultOpen, style

Forms

Export Props
Button children, variant (primary secondary ghost), disabled, type, onClick, style
IconButton children, onClick, disabled, title, variant (default circle), size (sm md), style
TextInput value, onChange, placeholder, disabled, type, style
TextArea value, onChange, placeholder, disabled, rows, style
Checkbox checked, onChange, disabled, label, style
Toggle checked, onChange, disabled, size (sm md), style
Select value, onChange, options (value, label, disabled), placeholder, disabled, style

Charts and swatches

Export Props
BarChart categories, series (name, data, tone), height, stacked, horizontal, normalized, valuePrefix, valueSuffix, showValues, beginAtZero, yMin, yMax, referenceLines, style
LineChart categories, series, height, fill, valuePrefix, valueSuffix, showValues, beginAtZero, yMin, yMax, referenceLines, style
PieChart data (label, value, tone), size, donut, style
UsageBar segments (id, value, color), total, topLeftLabel, topRightLabel, style
Swatch color (gray purple green yellow cyan pink blue orange red), style

Charts are drawn as SVG in the sandbox, without a chart library or any external requests.

State and layout helpers

Export Description
useState useMemo useRef useEffect The React 19 hooks of the same name
useHostTheme Returns the current light or dark theme, following the system
useCanvasState (key, defaultValue) => [value, setValue]. Lives only as long as the page
useCanvasAction Accepts { type: "openAgent", agentId }, { type: "newComposerChat", userPrompt? } or { type: "openFile", path, selection? }. Doesn't call the IDE
computeDAGLayout { nodes, edges, direction?, nodeWidth?, nodeHeight?, rankGap?, nodeGap?, padding? }. Returns node positions, edges and isBackEdge

Theme constants

You can use these values directly in style. Samples don't have to import them.

canvasPaletteDark, canvasPaletteLight, canvasPaletteGrokDark, canvasPaletteGrokLight, canvasTokens, canvasTokensLight, categoryPaletteDark, categoryPaletteLight, colorPalette, usageColorSequence, mergeStyle.

mergeStyle(base, override) merges two style objects.

Not supported

  • Modules other than cursor/canvas, including react, relative paths and import().
  • Exports from cursor/canvas that aren't in the tables above, and default imports.
  • Runtime namespace and decorators. Sucrase would silently drop them, so they're rejected before transpiling.
  • Type checking. Transpiling only converts syntax; type errors show up at runtime.