HapplyUI

Components

Region Map

Every landmass as a dot pattern, with a marker wherever you pass a point. Hover a marker for its label and count; the buttons zoom, dragging pans. No tile provider or API key: the land outline ships with the component.


Installation

bunx @happlyui/cli@latest add region-map

Dependencies

npm packages

  • maplibre-gl@^5.9.0
  • @remixicon/react@^4.6.0

Registry dependencies

These are automatically installed when you add this component.

  • happly-ui-utils
  • chart-tooltip
  • compact-button

Usage

import * as RegionMap from "@/components/ui/region-map"

<RegionMap.Root
  points={[{ label: "Location A", value: 120, lat: 43.65, lng: -79.38 }]}
  unit="Items"
/>

Examples

Default

Points carry their own coordinates; turn a country or city into lat/lng before passing it. The map fills its container, so give the card a height.

Card title

  • Location A: 120 Items
  • Location B: 84 Items
  • Location C: 46 Items
  • Location D: 38 Items
  • Location E: 27 Items
  • Location F: 12 Items
<RegionMap.Root points={points} unit="Items" />

With top region

Pass top to head the map with the leading place: its figure, a tag with its name and an optional image such as a flag, and a strip of its three biggest parts with their shares. Work out the shares before passing them; the map shows them as given.

Card title

Top region

120Region A
  • Location A 50%
  • Location B 30%
  • Location C 20%
  • Location A: 120 Items
  • Location B: 84 Items
  • Location C: 46 Items
  • Location D: 38 Items
  • Location E: 27 Items
  • Location F: 12 Items
<RegionMap.Root
  points={points}
  unit="Items"
  top={{
    label: "Top region",
    value: 120,
    name: "Region A",
    image: flagUrl,
    shares: [
      { label: "Location A", percent: 50 },
      { label: "Location B", percent: 30 },
      { label: "Location C", percent: 20 },
    ],
  }}
/>

Updates

Changing points clears the current hover without resetting the view. Theme changes recolour the map while it remains mounted.

Changing map

  • Location A: 120 Items
  • Location B: 84 Items
  • Location C: 46 Items
  • Location D: 38 Items
  • Location E: 27 Items
  • Location F: 12 Items
<RegionMap.Root points={updated ? updatedPoints : points} unit="Items" />

API Reference

RegionMap.Root

The map, its tooltip and its zoom buttons. Fills its container. Loads maplibre-gl in the browser, so it is safe to render on the server.

PropTypeDefaultDescription
points{ label: string; value: number; lat: number; lng: number }[]-One marker per point. They can change after mount without resetting the view
unitstring-What the values count, beside the value in the tooltip
zoomInLabelstring'Zoom in'Accessible name of the zoom-in button
zoomOutLabelstring'Zoom out'Accessible name of the zoom-out button
top{ label: string; value: number; name: string; image?: string; shares: { label: string; percent: number }[] }-The leading place above the map: label is the caption over value, name and image make the tag, shares are its three biggest parts. Omit it for the bare map

Previous
Ranked List