Canvas controls

Adjusts bounded zoom and exposes fit and reset actions for a canvas.

100%

The whole picture

Canvas scale · 100%

100%

Use it for

  • A canvas, diagram, map, or image with application-owned transforms.

Not for

  • Rendering or panning the canvas; these controls emit zoom and action callbacks.

Three ways in. They share one source, so the pixels match whichever you pick.

1. Import the package

npm install @noorddev/vlak-react

// once, next to your app's root
import "@noorddev/vlak-react/css";

import { CanvasControls } from "@noorddev/vlak-react";

Precompiled React and one stylesheet. No compiler to configure. Per-component imports work too: @noorddev/vlak-react/components/canvas-controls.

2. Vendor the source

npx @noorddev/vlak-cli add canvas-controls

The StyleX leaf lands in components/vlak/ with its dependencies, for your own compiler to own. See StyleX.

3. Through shadcn

npx shadcn add https://vlak.dev/r/canvas-controls.json

The same registry item, installed by shadcn's CLI.

CSS only

<link rel="stylesheet" href="node_modules/@noorddev/vlak/css/vlak.css" />

No React. Link vlak.css and use the markup and classes below.

import { CanvasControls } from "@noorddev/vlak-react";

<CanvasControls zoom={zoom} onZoomChange={setZoom} minZoom={0.25} maxZoom={4} onFit={fitCanvas} onReset={resetPan} />

CanvasControls

Zoom, fit, and reset actions for a canvas. The canvas owns pan and rendering.

PropTypeDefaultDescription
zoomnumber
defaultZoomnumber1
onZoomChange(zoom: number) => void
minZoomnumber0.25
maxZoomnumber4
stepnumber0.25
onFit() => void
onReset() => void
disabledbooleanfalse
labelstring"Canvas controls"

Also accepts HTMLAttributes<HTMLDivElement>.

KeysDoes
Tab, Enter, SpaceOperates zoom, optional fit, and reset buttons.
<div class="rs-canvas-controls" role="group" aria-label="Canvas controls"><button class="rs-btn-ghost rs-canvas-action" type="button" aria-label="Zoom out">−</button><output class="rs-canvas-zoom" aria-label="Zoom level">100%</output><button class="rs-btn-ghost rs-canvas-action" type="button" aria-label="Zoom in">+</button></div>
.rs-canvas-controls.rs-canvas-action.rs-canvas-zoom