Map Card

Pro

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#

# One-time setup (tokens + lib helpers)npx koalaui-cli@latest init# Activate your Pro license (once per machine)npx koalaui-cli@latest login <key># Add this component (its dependencies come along)npx koalaui-cli@latest add map-card

Usage#

This example is part of Koala UI Pro

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.

PropTypeDefaultDescription
valuestring-Controlled: the picked place. An empty string picks none.
defaultValuestring""Uncontrolled: the place picked at first.
onValueChange(value: string) => void-Called when a pin or a row is picked, or the pick is cleared.
expandedboolean-Controlled: whether the card fills the screen.
defaultExpandedbooleanfalseUncontrolled: open full screen.
onExpandedChange(expanded: boolean) => void-Called when it opens or closes.
Data attributeDescription
data-slot"map-card"; the dialog is "map-card-dialog", the placeholder "map-card-slot".
data-expandedPresent while full screen.
data-phaseinline, 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.

PropTypeDefaultDescription
labelstring"Map"Names the map region for screen readers.
summaryReact.ReactNode-A short line in an outline badge on the map while full screen, such as a route's time and distance.
fitMaxZoomnumber15The closest the fit and Show all may zoom, so one place does not fill the frame.
buildingsbooleanfalseDraws building footprints. Off by default, so streets, parks and water carry the map.
...MapPropsMapProps-Any Map prop except frame, interactive, cooperativeGestures and onMapClick.
Data attributeDescription
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.

PropTypeDefaultDescription
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.
focusZoomnumber13Picking 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.
ratingstring | 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".
hoursReact.ReactNode-When it is open, beside the rating on its card.
addressReact.ReactNode-Where it is, the last line of its card.
labelMinZoomnumber16Without a rating, the zoom from which every inline pin shows its name.
imagestring-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.
childrenReact.ReactNode-Anything else for the card above the pin, after the rating, hours and address.
Data attributeDescription
data-map-card-placeThe 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.

PropTypeDefaultDescription
path*[number, number][]-The points in travel order.
idstring-The MapLibre source and layer id. Generated when left out.
animatebooleantrueDraw 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 attributeDescription
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 attributeDescription
data-slot"map-card-header".

MapCardHeading

Stacks the title over its description.

Data attributeDescription
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.

PropTypeDefaultDescription
as"h2" | "h3" | "h4""h3"The heading level.
Data attributeDescription
data-slot"map-card-title".

MapCardDescription

A small muted line in tabular-nums: the area, the distance, the arrival time.

Data attributeDescription
data-slot"map-card-description".

MapCardHeaderEnd

The header's end slot, for a travel mode switch or a badge.

Data attributeDescription
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.

PropTypeDefaultDescription
aria-labelstring-Names the list ("Cafés in Gràcia").
Data attributeDescription
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.

PropTypeDefaultDescription
value*string-The value of its MapCardPlace.
title*React.ReactNode-The place's name.
descriptionReact.ReactNode-A second line: rating, kind, hours.
metaReact.ReactNode-The end of the row, in ink: the walking time.
detailReact.ReactNode-A muted line under meta, such as the distance, so the end of the row holds two lines like its start.
ratingstring | number-The score, with a filled star, first on the second line.
hoursReact.ReactNode-When it is open ("Open until 20:00"), after the rating.
addressReact.ReactNode-Where it is, on its own line under the rating and hours.
imagestring-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.
logoReact.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.
logoColorAvatarProps["color"]-Tints the initials when the logo falls back to them.
Data attributeDescription
data-slot"map-card-item".
data-hoveredPresent 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 attributeDescription
data-slot"map-card-footer".

MapCardActions

The buttons, pushed to the end. App UI: size="sm", text only.

Data attributeDescription
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.

PropTypeDefaultDescription
rowsnumber3How many rows to hold.
Data attributeDescription
data-slot"map-card-skeleton".

FAQ#

Because it sits in a conversation that scrolls. Inline the map uses cooperative gestures: Ctrl or ⌘ and the wheel, or two fingers on a phone, move it, and plain scrolling keeps reading the thread. Full screen it takes every gesture.