Get started
Show a map

Customize labels and icons

Customize labels and icons

Change three things: the colours and sizes the elements paint with, the words they say, and the icons they draw. Set each once on the provider, or per element.

Theme with tokens

Every element reads --mtya-* CSS custom properties. Set the ones you care about once, through tokens on the provider:

<MountayaElementsProvider map={map} tokens={{ "--mtya-accent": "#e9501e" }}>
  <MapControls compass zoom />
</MountayaElementsProvider>
TokenDefaultPaints
--mtya-accent#1c7ed6Selections, focus, highlights
--mtya-fontsystem-ui, …Every label
--mtya-control-size36pxEach control button
--mtya-control-radius8pxControl corners
--mtya-control-bg#ffffffControl background
--mtya-control-fg#212529Control icons and text
--mtya-panel-bg#ffffffPanel background
--mtya-panel-radius12pxPanel corners
--mtya-panel-width280pxPanel width
--mtya-edge-inset16pxGap between the stack and the map's edge

The dark column is the value under data-mtya-color-scheme="dark", where it differs.

For the dark scheme, set data-mtya-color-scheme="dark" on an ancestor.

Override the words

Pass a partial override to the provider's strings prop. The rest stay as they are:

<MountayaElementsProvider strings={{ profile: { ascent: "Dénivelé positif" } }}>
  <ItineraryProfile itineraryId={itineraryId} />
</MountayaElementsProvider>

English is built in. For French, import frElementsStrings from @mountaya/elements/i18n/fr and pass translations={{ fr: frElementsStrings }} with language="fr".

Swap the icon set

Every icon is a role, such as action-copy, and the provider draws it. Build a provider from your own artwork:

import { createIconProvider } from "@mountaya/elements/icons";

const ourGlyphs = createIconProvider({
  markup: ourGlyphMarkup,
  name: "acme-ui",
  paint: "stroke",
});

Pass it to the provider's controlIcons, uiIcons or markerIcons prop. Lucide is the default.

Catch the elements' errors

Everything the elements throw descends from MountayaElementsError, from @mountaya/elements/errors:

import { MountayaElementsError } from "@mountaya/elements/errors";
import { createIconProvider, fallbackProvider, lucideIconProvider } from "@mountaya/elements/icons";

try {
  fallbackProvider(
    createIconProvider({ markup: ourGlyphMarkup, name: "acme-ui", paint: "fill" }),
    lucideIconProvider,
  );
} catch (error) {
  if (error instanceof MountayaElementsError) {
    reportMisuse(error);
  }
}

Next steps

Last updated