Map Card
The map an assistant puts in its reply: places that answer to a list under them, or a route drawn in ink. Open it and the card itself grows to fill the screen, then settles back into the chat.
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
Coordinates go in as [longitude, latitude], the order MapLibre and GeoJSON use. Distances, times and ratings go in already formatted. The basemap is the themed Map, so it follows light, dark and moonlight with no extra work.
Anatomy#
The map first, then a body with the header, the list and the footer. Keep everything that is not the map inside MapCardBody: it is what becomes the column beside the map when the card fills the screen. Every part inside it is droppable: a single place needs no list, a route needs no rows.
import {
MapCard,
MapCardMap,
MapCardPlace,
MapCardRoute,
MapCardBody,
MapCardHeader,
MapCardHeading,
MapCardTitle,
MapCardDescription,
MapCardHeaderEnd,
MapCardList,
MapCardItem,
MapCardFooter,
MapCardActions,
MapCardSkeleton,
} from "@/components/ui/map-card"
<MapCard>
<MapCardMap>
<MapCardRoute />
<MapCardPlace />
</MapCardMap>
<MapCardBody>
<MapCardHeader>
<MapCardHeading>
<MapCardTitle />
<MapCardDescription />
</MapCardHeading>
<MapCardHeaderEnd />
</MapCardHeader>
<MapCardList>
<MapCardItem />
</MapCardList>
<MapCardFooter>
<MapCardActions />
</MapCardFooter>
</MapCardBody>
</MapCard>
<MapCardSkeleton />Places and list#
Give a MapCardPlace and a MapCardItem the same value and they move together. Give each place a rating and its pin shows the score with a star, so the best places stand out on the map; full screen the name joins it. Pick a row or a pin and the pin inverts to ink, the row takes a faint chip, and the map eases over to it with its card open above. Hover a card and its pin lifts its shadow; hover a pin and its card lights. Escape clears the pick. In the chat the places sit as minimal cards in a row, photo first; full screen they open into full rows with the hours, the address and the distance. The pins are the Map's own labelled pins, so a Map Card and a Map read as one family.
Full screen#
The corner button opens it. The card itself lifts out of the reply and grows to fill the screen, 8px in from the edges, with the map taking the height and the body moving into a column beside it, or under it on a phone. It is the same map, so the view, the drawn route and the pick stay as they were. Back to chat sits alone in the map's corner, above zoom and Show all; Escape clears a pick first and closes on the next press. Closing settles the card back into its place in the thread and returns focus to the button that opened it.
Route#
MapCardRoute draws the path in ink over a casing in the page colour, from the start to the end. Change the path and it draws again, so switching from walking to cycling reads as a new answer rather than a swap. Put the time in the title, larger, and pass summary for the badge it shows on the full screen map.
One place#
A single place needs no list. Cap the zoom with fitMaxZoom so the street around it stays readable.
Loading#
While the answer streams in, MapCardSkeleton holds the map, the title and the rows, so the reply does not jump when the places arrive.
API reference#
MapCard
One answer on a map, and the state every part shares: the picked place, the one under the pointer, and whether it is full screen. Inline it is an <article> in the reply. Full screen it lifts into a modal <dialog> in the browser's top layer, so no scrolling or masked chat around it can clip it, and the rest of the page goes inert. A placeholder of its height holds its place in the thread. Every part accepts className, merged last. mapCardVariants is the recipe.
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | - | Controlled: the picked place. An empty string picks none. |
| defaultValue | string | "" | Uncontrolled: the place picked at first. |
| onValueChange | (value: string) => void | - | Called when a pin or a row is picked, or the pick is cleared. |
| expanded | boolean | - | Controlled: whether the card fills the screen. |
| defaultExpanded | boolean | false | Uncontrolled: open full screen. |
| onExpandedChange | (expanded: boolean) => void | - | Called when it opens or closes. |
| Data attribute | Description |
|---|---|
| data-slot | "map-card"; the dialog is "map-card-dialog", the placeholder "map-card-slot". |
| data-expanded | Present while full screen. |
| data-phase | inline, lifting, opening, full, releasing, closing or landing, for styling the flight. |
MapCardMap
The map, inset 8px in the card and 224px tall. It wraps Map, so it wears the theme and takes the same basemap props. On load it fits every place and route. Inline it uses cooperative gestures, so the chat keeps its scroll: Ctrl or ⌘ and the wheel, or two fingers, move it. Its corner has one control, Open full screen. Full screen the map fills the card's height beside the body, takes every gesture, and its corner holds Back to chat on its own, then zoom and Show all.
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | "Map" | Names the map region for screen readers. |
| summary | React.ReactNode | - | A short line in an outline badge on the map while full screen, such as a route's time and distance. |
| fitMaxZoom | number | 15 | The closest the fit and Show all may zoom, so one place does not fill the frame. |
| buildings | boolean | false | Draws building footprints. Off by default, so streets, parks and water carry the map. |
| ...MapProps | MapProps | - | Any Map prop except frame, interactive, cooperativeGestures and onMapClick. |
| Data attribute | Description |
|---|---|
| data-slot | "map-card-map". |
MapCardPlace
A place on the map, as the Map's labelled pin. Inline, where five names would collide, pins rest as dots and name themselves on hover, while picked or when you zoom in; full screen every pin shows its name. Picked, the pin inverts to ink and the map eases to it. Its children open in a card above the pin.
| Prop | Type | Default | Description |
|---|---|---|---|
| value* | string | - | Ties the pin to its MapCardItem. |
| lngLat* | [number, number] | - | Longitude, then latitude. |
| label* | string | - | The place's name, on the pin and as the card's title. |
| focusZoom | number | 13 | Picking a place pans to it and keeps the zoom, so its neighbours stay in view; it only zooms in up to this level when the map is further out. |
| rating | string | number | - | Turns the pin into a rating chip, a star and the score, so the best places stand out at a glance. Full screen the name joins it. Read as "Bar Lluna, rated 4.5". |
| hours | React.ReactNode | - | When it is open, beside the rating on its card. |
| address | React.ReactNode | - | Where it is, the last line of its card. |
| labelMinZoom | number | 16 | Without a rating, the zoom from which every inline pin shows its name. |
| image | string | - | A photo of the place, at the top of its card while full screen. Inline the card stays text only so it fits the 224px map. |
| children | React.ReactNode | - | Anything else for the card above the pin, after the rating, hours and address. |
| Data attribute | Description |
|---|---|
| data-map-card-place | The place's value, on its marker. Its card is data-slot="map-card-callout". |
MapCardRoute
A line through the path, in ink on a background casing, drawn from start to end when it arrives and again when the path changes. With reduced motion it appears whole.
| Prop | Type | Default | Description |
|---|---|---|---|
| path* | [number, number][] | - | The points in travel order. |
| id | string | - | The MapLibre source and layer id. Generated when left out. |
| animate | boolean | true | Draw the line in. Off, it appears whole. |
MapCardBody
Everything under the map, a <div>. Inline it stacks under the map. Full screen it becomes the column beside it (under it on a phone) and scrolls on its own; it fades out while the card flies and back in once it lands.
| Data attribute | Description |
|---|---|
| data-slot | "map-card-body". |
MapCardHeader
The line under the map, a <div>: a heading on the start edge and whatever sits at the end.
| Data attribute | Description |
|---|---|
| data-slot | "map-card-header". |
MapCardHeading
Stacks the title over its description.
| Data attribute | Description |
|---|---|
| data-slot | "map-card-heading". |
MapCardTitle
What the map answers, 14px medium. It also names the full screen dialog. For a route, pass the time and make it larger.
| Prop | Type | Default | Description |
|---|---|---|---|
| as | "h2" | "h3" | "h4" | "h3" | The heading level. |
| Data attribute | Description |
|---|---|
| data-slot | "map-card-title". |
MapCardDescription
A small muted line in tabular-nums: the area, the distance, the arrival time.
| Data attribute | Description |
|---|---|
| data-slot | "map-card-description". |
MapCardHeaderEnd
The header's end slot, for a travel mode switch or a badge.
| Data attribute | Description |
|---|---|
| data-slot | "map-card-header-end". |
MapCardList
The places, in two shapes. In the chat they are minimal cards in a row that scrolls sideways: the photo with its logo badge, the name, and the rating with the walking time; the left and right arrows move between them. Full screen they become a single select List of full rows in the column beside the map, with the hours, the address and the distance; the up and down arrows move between them.
| Prop | Type | Default | Description |
|---|---|---|---|
| aria-label | string | - | Names the list ("Cafés in Gràcia"). |
| Data attribute | Description |
|---|---|
| data-slot | "map-card-list". |
MapCardItem
One place, a <button>: a minimal card in the chat, a full row full screen. Picking it picks its pin and the map eases there; picking it again clears it, and a card picked from the map scrolls into view. Over it, its pin casts a deeper shadow; over a pin, it lights.
| Prop | Type | Default | Description |
|---|---|---|---|
| value* | string | - | The value of its MapCardPlace. |
| title* | React.ReactNode | - | The place's name. |
| description | React.ReactNode | - | A second line: rating, kind, hours. |
| meta | React.ReactNode | - | The end of the row, in ink: the walking time. |
| detail | React.ReactNode | - | A muted line under meta, such as the distance, so the end of the row holds two lines like its start. |
| rating | string | number | - | The score, with a filled star, first on the second line. |
| hours | React.ReactNode | - | When it is open ("Open until 20:00"), after the rating. |
| address | React.ReactNode | - | Where it is, on its own line under the rating and hours. |
| image | string | - | A photo of the place, with the house image edge: the top of the card in the chat, a 48px square at the start of the row full screen. Pass one about 320px wide. |
| logo | React.ReactNode | - | The business logo. With an image it sits as a small round badge on the photo's corner; without one it takes the photo's place as a 48px square. A string is an image URL, falling back to the place's initials; a node, such as a PlaceholderLogo mark, is drawn as is. |
| logoColor | AvatarProps["color"] | - | Tints the initials when the logo falls back to them. |
| Data attribute | Description |
|---|---|
| data-slot | "map-card-item". |
| data-hovered | Present while the pointer is over its pin. |
MapCardFooter
The last line under a hairline: a note on the start edge, the actions on the end. Full screen it sits at the bottom of the column.
| Data attribute | Description |
|---|---|
| data-slot | "map-card-footer". |
MapCardActions
The buttons, pushed to the end. App UI: size="sm", text only.
| Data attribute | Description |
|---|---|
| data-slot | "map-card-actions". |
MapCardSkeleton
The card's shape while the answer streams in: the map, the title and the rows. Hidden from screen readers.
| Prop | Type | Default | Description |
|---|---|---|---|
| rows | number | 3 | How many rows to hold. |
| Data attribute | Description |
|---|---|
| data-slot | "map-card-skeleton". |