Components
Map
NativeA pan and zoom map with markers, routes and street tiles from any XYZ source, such as OpenStreetMap. Works offline with the drawn MapSchematic.
Drag to pan. Focus the map and use arrow keys to pan, plus and minus to zoom. Use Tab to reach places and map controls.









- Station to Northline Studio · 4 minute walk. Route coordinates: 40.68606, -73.99089; 40.68698, -73.99030; 40.68746, -73.98997; 40.68820, -73.98950; 40.68830, -73.98945
- Your location
- Bergen Street station: 40.68606, -73.99089
- Fieldwork Coffee: 40.68653, -73.99062
- Brooklyn Library: 40.68677, -73.99293
- Saturday market: 40.68454, -73.98987
- Northline Studio: 40.68830, -73.98945
Streets and tiles from OpenStreetMap. Press a place for details; Escape closes them.
Installation
npx nook-ui@latest add mapPrompt
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 "Map" component to this project, exactly as Nook ships it.
A pan and zoom map with markers, routes and street tiles from any XYZ source, such as OpenStreetMap. Works offline with the drawn MapSchematic.
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 map`. It writes `components/ui/map.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/map.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
"use client";
import { Map, MapMarker, MapRoute, MapUserLocation } from "@/components/ui/map";
import { OSM_TILES, cityCenter, cityRoute, places, station, studio } from "./data";
export default function MapDefault() {
return (
<div className="grid w-full gap-3">
<Map
title="A walk through Boerum Hill"
className="h-[26rem]"
defaultValue={{ center: cityCenter, zoom: 16 }}
tileUrl={OSM_TILES}
attribution={
<>
©{" "}
<a href="https://www.openstreetmap.org/copyright" className="underline">
OpenStreetMap
</a>{" "}
contributors
</>
}
>
<MapRoute label="Station to Northline Studio · 4 minute walk" points={cityRoute} />
<MapUserLocation position={{ latitude: 40.68648, longitude: -73.99068 }} />
<MapMarker id="station" position={station} label="Bergen Street station">
Start here. The studio is a 4 minute walk up Smith Street.
</MapMarker>
{places.slice(0, 3).map((place) => (
<MapMarker key={place.id} id={place.id} compact position={place.position} label={place.name}>
{place.kind} · {place.note}
</MapMarker>
))}
<MapMarker id="studio" position={studio} label="Northline Studio">
18 Orchard Street
<br />
Open until 6 pm
</MapMarker>
</Map>
<p className="text-xs text-muted-foreground">Streets and tiles from OpenStreetMap. Press a place for details; Escape closes them.</p>
</div>
);
}
```
API
- `Map`: A Web Mercator viewport with square-dot background. No tile provider is chosen by the library.
- `title` (`string`): Accessible name for this map.
- `value / defaultValue / onValueChange` (`MapViewport / callback`): Controlled or local center { latitude, longitude } and zoom. Latitude is clamped to Mercator limits and longitude wraps.
- `minZoom / maxZoom` (`number`, default 0 / 20): Bounds shared by wheel, pinch, buttons and keyboard.
- `tileUrl / attribution` (`string / ReactNode`): Optional XYZ template containing {z}, {x}, {y}, such as https://tile.openstreetmap.org/{z}/{x}/{y}.png, and the attribution your provider requires (OpenStreetMap: © OpenStreetMap contributors with a link to openstreetmap.org/copyright). OpenStreetMap's public server is for light use; follow its tile usage policy or serve your own tiles for real traffic.
- `selectedMarker / defaultSelectedMarker / onMarkerSelect` (`string | null / callback`): Controlled or local selected place.
- `controls` (`boolean`, default true): Show default controls; custom MapControls may be placed as children.
- `MapMarker`: A square-mark place button with optional selected details.
- `id / position / label` (`string / MapCoordinate / string`): Unique marker id, geographic position and accessible place name.
- `children` (`ReactNode`): Details shown in a card under the marker while it is selected. Escape or the close button hides it.
- `compact` (`boolean`): Draw only a small square mark; the name shows when the marker is chosen. Use it on busy maps.
- `MapSchematic`: A drawn base map: named streets (major ones wider), water (hatched), parks (dotted) and blocks (solid). Areas differ by pattern, not color alone, and it follows the map while it pans and zooms.
- `roads` (`{ name?; points; major? }[]`): Streets as ordered coordinates.
- `areas` (`{ kind: "water" | "park" | "block"; name?; points }[]`): Filled shapes.
- `MapUserLocation`: The person's own position as a square mark with a pulse that stops when motion is reduced.
- `position` (`MapCoordinate`): Where they are.
- `MapRoute`: A projected polyline with a light casing, a filled start mark, an outlined end mark and a text coordinate alternative.
- `points / label / dashed` (`MapCoordinate[] / string / boolean`): Ordered route positions, description and optional dashed stroke.
- `MapControls / useMap`: Zoom, reset-view and pan buttons (the four-arrow button opens a pad), plus a scale bar. Or use the viewport, dimensions, project, panBy, zoomTo and centerOn API for custom overlays. projectMercator and unprojectMercator are exported too.
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 map for arrow-key panning and plus/minus zoom. Buttons offer the same operations as dragging, wheeling and pinching. Markers are native buttons and all markers and route coordinates are repeated in hidden lists. Wheel zoom requires map focus or Ctrl/Meta to preserve ordinary page scrolling.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
"use client";
import { Map, MapMarker, MapRoute, MapUserLocation } from "@/components/ui/map";
import { OSM_TILES, cityCenter, cityRoute, places, station, studio } from "./data";
export default function MapDefault() {
return (
<div className="grid w-full gap-3">
<Map
title="A walk through Boerum Hill"
className="h-[26rem]"
defaultValue={{ center: cityCenter, zoom: 16 }}
tileUrl={OSM_TILES}
attribution={
<>
©{" "}
<a href="https://www.openstreetmap.org/copyright" className="underline">
OpenStreetMap
</a>{" "}
contributors
</>
}
>
<MapRoute label="Station to Northline Studio · 4 minute walk" points={cityRoute} />
<MapUserLocation position={{ latitude: 40.68648, longitude: -73.99068 }} />
<MapMarker id="station" position={station} label="Bergen Street station">
Start here. The studio is a 4 minute walk up Smith Street.
</MapMarker>
{places.slice(0, 3).map((place) => (
<MapMarker key={place.id} id={place.id} compact position={place.position} label={place.name}>
{place.kind} · {place.note}
</MapMarker>
))}
<MapMarker id="studio" position={studio} label="Northline Studio">
18 Orchard Street
<br />
Open until 6 pm
</MapMarker>
</Map>
<p className="text-xs text-muted-foreground">Streets and tiles from OpenStreetMap. Press a place for details; Escape closes them.</p>
</div>
);
}Examples
Places nearby
The list and the map stay in step.
Drag to pan. Focus the map and use arrow keys to pan, plus and minus to zoom. Use Tab to reach places and map controls.









Fieldwork Coffee
- Fieldwork Coffee: 40.68653, -73.99062, selected
- Brooklyn Library: 40.68677, -73.99293
- Saturday market: 40.68454, -73.98987
- Court Street Gym: 40.68535, -73.99245
Without tiles
A drawn base map for offline use.
Drag to pan. Focus the map and use arrow keys to pan, plus and minus to zoom. Use Tab to reach places and map controls.
- Smith Street
- Hoyt Street
- Court Street
- Boerum Place
- Atlantic Avenue
- Dean Street
- Bergen Street
- Pierrepont Green
- Canal
- Station to studio. Route coordinates: 40.69050, -73.99150; 40.68800, -73.99150; 40.68800, -73.98750; 40.68440, -73.98750
- Your location
- Bergen station: 40.69050, -73.99150
- Northline Studio: 40.68440, -73.98750
A drawn base map for when you have no tiles: water is hatched, parks are dotted, blocks are solid.
Props
Map
A Web Mercator viewport with square-dot background. No tile provider is chosen by the library.
| Prop | Type | Default | Description |
|---|---|---|---|
| title | string | – | Accessible name for this map. |
| value / defaultValue / onValueChange | MapViewport / callback | – | Controlled or local center { latitude, longitude } and zoom. Latitude is clamped to Mercator limits and longitude wraps. |
| minZoom / maxZoom | number | 0 / 20 | Bounds shared by wheel, pinch, buttons and keyboard. |
| tileUrl / attribution | string / ReactNode | – | Optional XYZ template containing {z}, {x}, {y}, such as https://tile.openstreetmap.org/{z}/{x}/{y}.png, and the attribution your provider requires (OpenStreetMap: © OpenStreetMap contributors with a link to openstreetmap.org/copyright). OpenStreetMap's public server is for light use; follow its tile usage policy or serve your own tiles for real traffic. |
| selectedMarker / defaultSelectedMarker / onMarkerSelect | string | null / callback | – | Controlled or local selected place. |
| controls | boolean | true | Show default controls; custom MapControls may be placed as children. |
MapMarker
A square-mark place button with optional selected details.
| Prop | Type | Default | Description |
|---|---|---|---|
| id / position / label | string / MapCoordinate / string | – | Unique marker id, geographic position and accessible place name. |
| children | ReactNode | – | Details shown in a card under the marker while it is selected. Escape or the close button hides it. |
| compact | boolean | – | Draw only a small square mark; the name shows when the marker is chosen. Use it on busy maps. |
MapSchematic
A drawn base map: named streets (major ones wider), water (hatched), parks (dotted) and blocks (solid). Areas differ by pattern, not color alone, and it follows the map while it pans and zooms.
| Prop | Type | Default | Description |
|---|---|---|---|
| roads | { name?; points; major? }[] | – | Streets as ordered coordinates. |
| areas | { kind: "water" | "park" | "block"; name?; points }[] | – | Filled shapes. |
MapUserLocation
The person's own position as a square mark with a pulse that stops when motion is reduced.
| Prop | Type | Default | Description |
|---|---|---|---|
| position | MapCoordinate | – | Where they are. |
MapRoute
A projected polyline with a light casing, a filled start mark, an outlined end mark and a text coordinate alternative.
| Prop | Type | Default | Description |
|---|---|---|---|
| points / label / dashed | MapCoordinate[] / string / boolean | – | Ordered route positions, description and optional dashed stroke. |
MapControls / useMap
Zoom, reset-view and pan buttons (the four-arrow button opens a pad), plus a scale bar. Or use the viewport, dimensions, project, panBy, zoomTo and centerOn API for custom overlays. projectMercator and unprojectMercator are exported too.
Accessibility
Focus the map for arrow-key panning and plus/minus zoom. Buttons offer the same operations as dragging, wheeling and pinching. Markers are native buttons and all markers and route coordinates are repeated in hidden lists. Wheel zoom requires map focus or Ctrl/Meta to preserve ordinary page scrolling.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.