# MapCanvas

> A drawn map: a stage holding one SVG coordinate space, where caller-drawn art, routes, moving markers and price pins all place by viewBox units.

```ts
import { MapCanvas } from "@sdxc/ui/map";
```

Renders the stage at the full width of its parent and at the viewBox's aspect ratio, the
art in an `aria-hidden` SVG and its parts over it. Anything drawn past the viewBox is
clipped, so the stage never widens the page.

## Examples

```tsx
<MapCanvas label="Stays in Lisbon" art={<rect width="400" height="300" fill="#e8efe3" />}>
	<MapCanvas.Pin x={120} y={80} label="$182" href="/stays/1" mapKey="1" />
</MapCanvas>
```

## Props

| Prop | Type | Description |
| --- | --- | --- |
| `viewBox?` | `string` | The SVG viewBox every part places by; a non-zero origin crops into one area of the art. The stage keeps its aspect ratio. |
| `art?` | `RemixNode` | SVG children drawn under everything else: land, water, parks, roads. |
| `label` | `string` | The map's accessible name, such as "Stays in Lisbon". |
| `children?` | `RemixNode` | MapCanvas.Route, MapCanvas.Marker and MapCanvas.Pin elements. |

Also accepts everything in `Omit<TagProps<"figure">, "children">`.


### MapCanvas.Route

Draws a route over the art: the travelled share as a solid line, the rest dashed, both over a light casing that keeps the line legible on any art.

| Prop | Type | Description |
| --- | --- | --- |
| `d` | `string` | Path data in viewBox units. |
| `done?` | `number` | Share of the route already travelled, from 0 to 1, drawn solid; the rest is dashed. |

Also accepts everything in `Omit<TagProps<"svg">, "children" | "viewBox">`.


### MapCanvas.Marker

Places a marker along a path with CSS motion paths, so a new `progress` glides it along the route instead of jumping; under reduced motion it moves straight to the new spot.

| Prop | Type | Description |
| --- | --- | --- |
| `route` | `string` | Path data in viewBox units the marker travels. |
| `progress` | `number` | Share of `route` travelled, from 0 to 1. |
| `children?` | `RemixNode` | SVG glyph centred on the origin; a dot with a halo when omitted. |

Also accepts everything in `Omit<TagProps<"svg">, "children" | "viewBox">`.


### MapCanvas.Pin

One pin: a pill whose tail tips onto its point, as a link with `href` or a button otherwise (pass `popovertarget` or `commandfor` to open a card).

| Prop | Type | Description |
| --- | --- | --- |
| `mix?` | `TagProps<"span">["mix"]` | Mixins for the pin, which renders as either a link or a button. |
| `x` | `number` | Horizontal position in viewBox units. |
| `y` | `number` | Vertical position in viewBox units. |
| `label` | `RemixNode` | The pill's content, such as a price or an icon; with text it names the pin. |
| `href?` | `string` | Renders the pin as a link to this address instead of a button. |
| `highlighted?` | `boolean` | Lights the pin as if pointed at, such as while its listing is hovered. |
| `current?` | `boolean` | Marks the selected pin: inverted colors, drawn above the rest, `aria-current`. |
| `tone?` | `"brand" \| "neutral"` | Colors of the pill at rest. |
| `mapKey?` | `string` | Record key shared with a listing row, linked through `mapLink`. |

Also accepts everything in `Omit<TagProps<"button">, "children" | "mix">`.

