Globe
A 3D globe of real country shapes that wears your theme. Hairline borders, markers from the Map, routes that draw themselves in, countries to pick and a real day and night, with drag and inertia, on a plain canvas with no dependencies.
Installation#
Usage#
The preview is yours to explore. Its code comes with a Pro license, paid once and used in every project.
Have a license? Unlock it here
The Globe is square and fills its width, so cap it with a max-w-*. It shares the Map's coordinates, [longitude, latitude], and its markers: anything that works inside MapMarker, MapPin in every shape included, works inside GlobeMarker. Use the Map to find a street; use the Globe to show where in the world things are.
Anatomy#
import { Globe, GlobeMarker, GlobeArc } from "@/components/ui/globe"
<Globe>
<GlobeArc from={…} to={…} />
<GlobeMarker lngLat={…}>…</GlobeMarker>
</Globe>Markers#
Markers stay in your tree, so Context, state and events work as usual. They fade out at the edge of the sphere rather than popping, and a marker behind the globe stops taking the pointer. Every marker stays in the accessibility tree as an item of the marker list, and tabbing to an interactive one turns the globe to face it. A dot with a captionkeeps the map readable; a labelled chip suits one or two places.
Routes#
GlobeArc draws the shortest path between two points, lifted more the further it travels. Routes draw in one after another by order, land with a ring, then send a short pulse along themselves now and then. Many to many reads as a network; keep the markers small, such as MapPin shape="dot" with a caption, so the routes lead.
Day and night#
daylight veils the half of the world in darkness, from the sun's real position, and follows the clock as it turns. Pass a Date to show another moment. Pair it with local times in the markers for a distributed team or the status of regions.
Select countries#
selectionMode turns the globe into a picker. Hovering a country tints it, traces its outline and names it with its flag beside the pointer, with a check once it is picked. The label holds for a beat across a border or a strait, so it glides from one country to the next instead of blinking, and turns below the pointer near the top edge. A click fills the country in ink, and the hairline borders keep neighbours apart. countries limits the choice, here to Europe, and rests everything else lighter; zoom frames the region. Selection is ISO codes, the same as Flag, so the list beside the globe is yours to compose. Behind the canvas sits a real checkbox per country (radios in "single" mode): tabbing through them turns the globe to each one, and Space picks it.
Markets 3
- Spain
- France
- Germany
"single" keeps one country, for a shipping or billing country picked on the map. A second click on it clears the choice.
Surface#
Every colour is a mix of the theme's ink and background, with no accent, read from the --globe-* variables, so the globe re-paints in place when the theme changes and any one of them can be re-tinted with a utility. graticule adds hairline meridians and parallels; sphere={false} leaves the land on the page inside a hairline outline.
Still#
autoRotate={false} and draggable={false} make a still globe framed on center, for a contact page or a card. It draws once and then only when the theme or its size changes.
API reference#
Globe
A labelled, focusable group that draws every country as a real shape, with hairline borders, on a canvas. It is square and fills its width. Forwards native <div> props. Every part accepts className, merged last.
| Prop | Type | Default | Description |
|---|---|---|---|
| center | [number, number] | - | The point that faces you first, [longitude, latitude]. Seeds the camera once. Without it the globe turns to the visitor's time zone. |
| autoRotate | boolean | number | true | Turns the globe slowly when nobody is dragging it. A number sets the speed in degrees per second (true is 4). Off under reduced motion. |
| draggable | boolean | true | Drag with inertia and turn with the arrow keys. false also takes it out of the tab order. |
| daylight | boolean | Date | false | Dims the night side from the sun's real position, now or at the Date you pass. |
| zoom | number | 1 | Brings the sphere closer for a region such as Europe. Above 1 the globe becomes a framed, rounded view that crops the sphere. |
| sphere | boolean | true | Paints the sea with --globe-ocean. false leaves the land on the page inside the outline of the sphere. |
| graticule | boolean | false | Draws hairline meridians and parallels every 30 degrees. |
| label | string | "Globe" | The group's accessible name. |
| selectionMode | "none" | "single" | "multiple" | "none" | Lets the reader pick countries: hover tints one and names it, a click fills it in ink, a second click lets it go. |
| countries | string[] | - | The ISO codes that can be picked, such as Europe only. The rest of the world rests dimmer. Every country when unset. |
| selected | string[] | - | The picked ISO codes, controlled. |
| defaultSelected | string[] | [] | The picked ISO codes to start with, uncontrolled. |
| onSelectedChange | (selected: string[]) => void | - | Called with every new selection. |
| Data attribute | Description |
|---|---|
| data-slot | globe, globe-canvas, globe-markers, globe-tooltip, globe-choices. |
| CSS variable | Description |
|---|---|
| --globe-land | Country fill. Defaults to 17% ink over --background, 30% in dark themes so the land stays readable beside a selection. |
| --globe-ocean | The sea. Defaults to 4% ink over --background. |
| --globe-border | Country borders and coastlines, hairline. Defaults to --background, so borders read as cuts. |
| --globe-limb | The outline of the sphere. Defaults to --border. |
| --globe-selected | Selected and hovered countries. Defaults to --foreground, softened to 88% in dark themes. |
| --globe-arc | Routes and their end points. Defaults to --foreground. |
GlobeMarker
Pins any React content to a coordinate, centred on it. It fades out as it turns past the edge and stops taking the pointer behind the globe. Focusing anything inside turns the globe to face it. Forwards native <div> props.
| Prop | Type | Default | Description |
|---|---|---|---|
| lngLat | [number, number] | - | Where it sits, [longitude, latitude]. |
| label | string | - | The list item's accessible name, read in the marker list. |
| Data attribute | Description |
|---|---|
| data-slot | globe-marker. |
| data-hidden | Present while the marker is behind the globe. |
GlobeArc
A great-circle route that lifts with its length, draws itself in and sends a pulse along now and then. Renders nothing in the DOM.
| Prop | Type | Default | Description |
|---|---|---|---|
| from | [number, number] | - | Where it leaves, [longitude, latitude]. |
| to | [number, number] | - | Where it lands. |
| order | number | 0 | Its place in the stagger, so routes draw in one after another. |