Components
Zoom pane
NativeExplore a map, plan or illustration with wheel, pinch, drag, buttons and keyboard controls.
Fieldwork campus
Visitor mapUse plus and minus to zoom, zero to reset, and arrow keys to pan. Drag to pan. Use Control and the wheel, or pinch, to zoom.
Drag to explore. Ctrl + scroll or pinch to zoom. Focus the map for + / −, 0 and arrow keys.
Installation
npx nook-ui@latest add zoom-panePrompt
Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.
Short. For assistants that can run commands in your project.
Add the Nook "Zoom pane" component to this project, exactly as Nook ships it.
Explore a map, plan or illustration with wheel, pinch, drag, buttons and keyboard controls.
Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add zoom-pane`. It writes `components/ui/zoom-pane.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/zoom-pane.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:
```tsx
import { ZoomPane } from "@/components/ui/zoom-pane";
export default function ZoomPaneDefault() {
const blocks = [
{ x: 50, y: 80, w: 160, h: 100, name: "North studio", color: "var(--chart-1)" },
{ x: 250, y: 80, w: 180, h: 100, name: "Print workshop", color: "var(--chart-2)" },
{ x: 470, y: 80, w: 180, h: 100, name: "The reading room", color: "var(--chart-3)" },
{ x: 50, y: 260, w: 160, h: 140, name: "Gallery", color: "var(--chart-4)" },
{ x: 250, y: 260, w: 180, h: 140, name: "Sculpture garden", color: "var(--chart-3)" },
{ x: 470, y: 260, w: 180, h: 140, name: "Coffee & conversation", color: "var(--chart-5)" },
];
return <div className="grid w-full gap-3"><div className="flex items-baseline justify-between gap-3"><h3 className="text-sm font-medium">Fieldwork campus</h3><span className="text-xs text-muted-foreground">Visitor map</span></div>
<ZoomPane label="Fieldwork campus map" defaultScale={0.7} className="h-96">
<svg role="img" aria-label="Six spaces around Foundry Lane: North studio, Print workshop, Reading room, Gallery, Sculpture garden, and Coffee and conversation." width="720" height="480" viewBox="0 0 720 480" className="bg-background text-foreground">
<path d="M0 220h720M230 0v480M450 0v480" stroke="var(--muted)" strokeWidth="28" />
<text x="52" y="38" fill="currentColor" fontSize="18" fontWeight="600">FIELDWORK / CAMPUS</text>
<text x="555" y="38" fill="currentColor" fontFamily="monospace" fontSize="11">N ↑</text>
{blocks.map((block) => <g key={block.name}><rect x={block.x} y={block.y} width={block.w} height={block.h} fill={block.color} opacity="0.12" stroke={block.color} /><text x={block.x + 12} y={block.y + 28} fill="currentColor" fontSize="12" fontWeight="500">{block.name}</text>{[0, 1, 2].map((row) => <path key={row} d={`M${block.x + 12} ${block.y + 48 + row * 15}h${block.w - 24}`} stroke={block.color} opacity="0.25" />)}</g>)}
<text x="72" y="224" fill="currentColor" fontSize="11" fontFamily="monospace">FOUNDRY LANE</text>
<text x="52" y="450" fill="currentColor" fontSize="11">Entrance →</text><path d="M530 450h120m-120-4v8m60-8v8m60-8v8" stroke="currentColor" /><text x="530" y="470" fill="currentColor" fontSize="10">0</text><text x="630" y="470" fill="currentColor" fontSize="10">100 m</text>
</svg>
</ZoomPane><p className="text-xs text-muted-foreground">Drag to explore. Ctrl + scroll or pinch to zoom. Focus the map for + / −, 0 and arrow keys.</p>
</div>;
}
```
API
- `ZoomPane`: A clipped viewport, transformed content, and a separate control layer.
- `label` (`string`, default Zoomable content): Names the keyboard-focusable viewport.
- `minZoom / maxZoom` (`number`, default 0.25 / 4): Scale limits.
- `scale / defaultScale` (`number`, default 1): Controlled or initial scale.
- `onScaleChange` (`(scale: number) => void`): Receives clamped scale changes.
- `controls` (`ReactNode`, default <ZoomControls />): Replace the controls, or pass null to hide them.
- `...props` (`React.HTMLAttributes<HTMLDivElement>`): Everything the native element accepts, such as `id`, `aria-*` and event handlers.
- `ZoomControls`: Zoom out, reset percentage, zoom in and fit. Reads its parent ZoomPane or an explicit controls object.
- `controls` (`ReturnType<typeof useZoomPan>`): State and actions for a custom viewport.
- `useZoomPan`: The same zoom state and gestures for custom surfaces. Returns viewportRef, contentRef, viewportProps, contentStyle, scale, position, zoomTo, zoomIn, zoomOut, panBy, reset and fit.
- `options` (`ZoomPanOptions`): The same scale limits, controlled state and callback as ZoomPane.
Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Focus the viewport and use plus/minus to zoom, zero to reset, and arrows to pan. Shift pans farther. Controls are named native buttons. Wheel pans, Ctrl+wheel or a two-pointer pinch zooms around the pointer. No motion is required to operate it.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
import { ZoomPane } from "@/components/ui/zoom-pane";
export default function ZoomPaneDefault() {
const blocks = [
{ x: 50, y: 80, w: 160, h: 100, name: "North studio", color: "var(--chart-1)" },
{ x: 250, y: 80, w: 180, h: 100, name: "Print workshop", color: "var(--chart-2)" },
{ x: 470, y: 80, w: 180, h: 100, name: "The reading room", color: "var(--chart-3)" },
{ x: 50, y: 260, w: 160, h: 140, name: "Gallery", color: "var(--chart-4)" },
{ x: 250, y: 260, w: 180, h: 140, name: "Sculpture garden", color: "var(--chart-3)" },
{ x: 470, y: 260, w: 180, h: 140, name: "Coffee & conversation", color: "var(--chart-5)" },
];
return <div className="grid w-full gap-3"><div className="flex items-baseline justify-between gap-3"><h3 className="text-sm font-medium">Fieldwork campus</h3><span className="text-xs text-muted-foreground">Visitor map</span></div>
<ZoomPane label="Fieldwork campus map" defaultScale={0.7} className="h-96">
<svg role="img" aria-label="Six spaces around Foundry Lane: North studio, Print workshop, Reading room, Gallery, Sculpture garden, and Coffee and conversation." width="720" height="480" viewBox="0 0 720 480" className="bg-background text-foreground">
<path d="M0 220h720M230 0v480M450 0v480" stroke="var(--muted)" strokeWidth="28" />
<text x="52" y="38" fill="currentColor" fontSize="18" fontWeight="600">FIELDWORK / CAMPUS</text>
<text x="555" y="38" fill="currentColor" fontFamily="monospace" fontSize="11">N ↑</text>
{blocks.map((block) => <g key={block.name}><rect x={block.x} y={block.y} width={block.w} height={block.h} fill={block.color} opacity="0.12" stroke={block.color} /><text x={block.x + 12} y={block.y + 28} fill="currentColor" fontSize="12" fontWeight="500">{block.name}</text>{[0, 1, 2].map((row) => <path key={row} d={`M${block.x + 12} ${block.y + 48 + row * 15}h${block.w - 24}`} stroke={block.color} opacity="0.25" />)}</g>)}
<text x="72" y="224" fill="currentColor" fontSize="11" fontFamily="monospace">FOUNDRY LANE</text>
<text x="52" y="450" fill="currentColor" fontSize="11">Entrance →</text><path d="M530 450h120m-120-4v8m60-8v8m60-8v8" stroke="currentColor" /><text x="530" y="470" fill="currentColor" fontSize="10">0</text><text x="630" y="470" fill="currentColor" fontSize="10">100 m</text>
</svg>
</ZoomPane><p className="text-xs text-muted-foreground">Drag to explore. Ctrl + scroll or pinch to zoom. Focus the map for + / −, 0 and arrow keys.</p>
</div>;
}Props
ZoomPane
A clipped viewport, transformed content, and a separate control layer.
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | Zoomable content | Names the keyboard-focusable viewport. |
| minZoom / maxZoom | number | 0.25 / 4 | Scale limits. |
| scale / defaultScale | number | 1 | Controlled or initial scale. |
| onScaleChange | (scale: number) => void | – | Receives clamped scale changes. |
| controls | ReactNode | <ZoomControls /> | Replace the controls, or pass null to hide them. |
| ...props | React.HTMLAttributes<HTMLDivElement> | – | Everything the native element accepts, such as `id`, `aria-*` and event handlers. |
ZoomControls
Zoom out, reset percentage, zoom in and fit. Reads its parent ZoomPane or an explicit controls object.
| Prop | Type | Default | Description |
|---|---|---|---|
| controls | ReturnType<typeof useZoomPan> | – | State and actions for a custom viewport. |
useZoomPan
The same zoom state and gestures for custom surfaces. Returns viewportRef, contentRef, viewportProps, contentStyle, scale, position, zoomTo, zoomIn, zoomOut, panBy, reset and fit.
| Prop | Type | Default | Description |
|---|---|---|---|
| options | ZoomPanOptions | – | The same scale limits, controlled state and callback as ZoomPane. |
Accessibility
Focus the viewport and use plus/minus to zoom, zero to reset, and arrows to pan. Shift pans farther. Controls are named native buttons. Wheel pans, Ctrl+wheel or a two-pointer pinch zooms around the pointer. No motion is required to operate it.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.