Zoom controls
Zoom out, the percent with a menu (presets, fit, fill, 100%), zoom in, with shortcut hints.
import { ZoomControls, editorStepZoom, editorFitZoom, editorFillZoom, editorZoomText, editorParseZoom, editorZoomAround, EDITOR_ZOOM_STEPS } from "@forgeron/ui";ZOOM 1.000 · TRY ⌘+ ⌘− ⌘0 ⇧1 ⇧2
import { editorFillZoom, editorFitZoom, ZoomControls } from "@forgeron/ui";
import { useState } from "react";
const content = { w: 1600, h: 900 };
const screen = { w: 640, h: 400 };
export default function Default() {
const [zoom, setZoom] = useState(1);
return (
<div style={{ display: "flex", flexDirection: "column", gap: 12, alignItems: "flex-start" }}>
<ZoomControls
zoom={zoom}
onZoomChange={setZoom}
onFit={() => setZoom(editorFitZoom(content, screen, 32))}
onFill={() => setZoom(editorFillZoom(content, screen))}
bindShortcuts
/>
<span style={{ font: "400 12px var(--font-mono)", color: "var(--ink-muted)" }}>
ZOOM {zoom.toFixed(3)} · TRY ⌘+ ⌘− ⌘0 ⇧1 ⇧2
</span>
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
zoom | number | — | 1 = 100%. |
onZoomChange | (zoom: number) => void | — | Every change, kept inside min and max. |
onFit / onFill | () => void | — | Add “Zoom to fit” and “Zoom to fill” to the menu: the canvas works the zoom out (editorFitZoom, editorFillZoom). |
presets | number[] | [0.25, 0.5, 1, 2] | The zooms listed in the menu; the current one is ticked. |
min / max / steps | number; number[] | — | The limits and the steps of + and −. |
shortcuts | { zoomIn, zoomOut, reset, fit, fill } | — | The keys shown (⌘+, ⌘−, ⌘0, ⇧1, ⇧2 by default). |
bindShortcuts | boolean | false | Binds those keys on the page; a canvas often handles its own. |
mac | boolean | — | Reads ⌘ (true) or Ctrl (false) in the hints. Default: from the platform. |
className | string | — | Extra classes. |