MapCanvas
A drawn map.
View code
<MapCanvas label="Stays in Porto Novo" art={<Town />}>
<MapCanvas.Route d={route} done={0.6} />
<MapCanvas.Marker route={route} progress={0.6} />
{stays.map((stay) => (
<MapCanvas.Pin
x={stay.x}
y={stay.y}
label={stay.price}
href={`/stays/${stay.id}`}
mapKey={stay.id}
current={stay.id === selected}
/>
))}
</MapCanvas>Installation
An ordinary dependency: install it, import the theme once, and import the component where it is used.
npm add @sdxc/ui remiximport "@sdxc/ui/theme.css";Usage
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.
Composition
The parts the component publishes, each a static property of the host.
MapCanvasMapCanvas.RouteDraws 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.MapCanvas.MarkerPlaces a marker along a path with CSS motion paths, so a newprogressglides it along the route instead of jumping; under reduced motion it moves straight to the new spot.MapCanvas.PinOne pin: a pill whose tail tips onto its point, as a link withhrefor a button otherwise (passpopovertargetorcommandforto open a card).
Props
Read from the component's own types, so every prop, every default and every allowed value is listed.
| Prop | Type | Required | Description |
|---|---|---|---|
viewBox | string | No | 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 | No | SVG children drawn under everything else: land, water, parks, roads. |
label | string | Yes | The map's accessible name, such as "Stays in Lisbon". |
children | RemixNode | No | MapCanvas.Route, MapCanvas.Marker and MapCanvas.Pin elements. |
Also accepts everything in Omit<TagProps<"figure">, "children">.
MapCanvas.Route
| Prop | Type | Required | Description |
|---|---|---|---|
d | string | Yes | Path data in viewBox units. |
done | number | No | 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
| Prop | Type | Required | Description |
|---|---|---|---|
route | string | Yes | Path data in viewBox units the marker travels. |
progress | number | Yes | Share of route travelled, from 0 to 1. |
children | RemixNode | No | SVG glyph centred on the origin; a dot with a halo when omitted. |
Also accepts everything in Omit<TagProps<"svg">, "children" | "viewBox">.
MapCanvas.Pin
| Prop | Type | Required | Description |
|---|---|---|---|
mix | TagProps<"span">["mix"] | No | Mixins for the pin, which renders as either a link or a button. |
x | number | Yes | Horizontal position in viewBox units. |
y | number | Yes | Vertical position in viewBox units. |
label | RemixNode | Yes | The pill's content, such as a price or an icon; with text it names the pin. |
href | string | No | Renders the pin as a link to this address instead of a button. |
highlighted | boolean | No | Lights the pin as if pointed at, such as while its listing is hovered. |
current | boolean | No | Marks the selected pin: inverted colors, drawn above the rest, aria-current. |
tone | "brand" | "neutral" | No | Colors of the pill at rest. |
mapKey | string | No | Record key shared with a listing row, linked through mapLink. |
Also accepts everything in Omit<TagProps<"button">, "children" | "mix">.