SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

MapCanvas

A drawn map.

View code
tsx
<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.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Usage

typescript
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.

  • MapCanvas
  • MapCanvas.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 new progress glides 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 with href or a button otherwise (pass popovertarget or commandfor to open a card).

Props

Read from the component's own types, so every prop, every default and every allowed value is listed.

PropTypeRequiredDescription
viewBoxstringNoThe SVG viewBox every part places by; a non-zero origin crops into one area of the art. The stage keeps its aspect ratio.
artRemixNodeNoSVG children drawn under everything else: land, water, parks, roads.
labelstringYesThe map's accessible name, such as "Stays in Lisbon".
childrenRemixNodeNoMapCanvas.Route, MapCanvas.Marker and MapCanvas.Pin elements.

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

MapCanvas.Route

PropTypeRequiredDescription
dstringYesPath data in viewBox units.
donenumberNoShare 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

PropTypeRequiredDescription
routestringYesPath data in viewBox units the marker travels.
progressnumberYesShare of route travelled, from 0 to 1.
childrenRemixNodeNoSVG glyph centred on the origin; a dot with a halo when omitted.

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

MapCanvas.Pin

PropTypeRequiredDescription
mixTagProps<"span">["mix"]NoMixins for the pin, which renders as either a link or a button.
xnumberYesHorizontal position in viewBox units.
ynumberYesVertical position in viewBox units.
labelRemixNodeYesThe pill's content, such as a price or an icon; with text it names the pin.
hrefstringNoRenders the pin as a link to this address instead of a button.
highlightedbooleanNoLights the pin as if pointed at, such as while its listing is hovered.
currentbooleanNoMarks the selected pin: inverted colors, drawn above the rest, aria-current.
tone"brand" | "neutral"NoColors of the pill at rest.
mapKeystringNoRecord key shared with a listing row, linked through mapLink.

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

@sdxc/ui

Can’t find it? Contact us