Getting Started
Prerequisites
- React 18+
- Next.js 13+ (app router) or any React project with Tailwind CSS v4
- shadcn/ui configured in your project
Installation
Install the USA map using the shadcn CLI. This pulls the component directly into your project — no npm package, no version lock.
bash
npx shadcn add https://shadcnmaps.com/r/usa-map.jsonThis installs the following files:
| File | Description |
|---|---|
components/shadcnmaps/map.tsx | Core SVG renderer |
components/shadcnmaps/map-context.tsx | Shared state context |
components/shadcnmaps/map-region.tsx | Individual region (path) |
components/shadcnmaps/map-tooltip.tsx | Hover/click tooltip |
components/shadcnmaps/map-marker.tsx | SVG marker overlay |
components/shadcnmaps/map-listbox.tsx | Accessible keyboard listbox |
components/shadcnmaps/types.ts | Shared TypeScript types |
components/shadcnmaps/maps/usa-map.tsx | USAMap component |
components/shadcnmaps/map-data/usa.ts | SVG path data for all 50 states + DC |
Basic usage
tsx
import { USAMap } from '@/components/shadcnmaps/maps/usa-map'
export default function Page() {
return <USAMap />
}That's it. The map is interactive out of the box — hover states, tooltips, and full keyboard navigation are included by default.
Build a state selector
This example builds a clickable state selector that highlights the selected state and shows a tooltip with the state name.
tsx
'use client'
import { useState } from 'react'
import { USAMap, type StateId } from '@/components/shadcnmaps/maps/usa-map'
export function StatePicker() {
const [selected, setSelected] = useState<StateId | null>(null)
return (
<div>
<p>{selected ? `Selected: ${selected}` : 'Click a state'}</p>
<USAMap
regions={
selected ? [{ id: selected, className: 'fill-map-region-selected' }] : []
}
onRegionClick={({ region }) =>
setSelected((prev) => (prev === region.id ? null : region.id as StateId))
}
renderTooltip={(region) => <span>{region.name}</span>}
/>
</div>
)
}How it works
regions— per-region overrides. PassclassNameto change fill color,tooltipContentfor custom tooltip content, or anyMapRegionDatafield.onRegionClick— fired on click and on keyboard Enter/Space. Receives{ region, nativeEvent }.renderTooltip— renders a tooltip that follows the cursor. Receives the fullMapRegionDatafor the hovered/clicked region.fill-map-region-selected— a Tailwind color class backed by the--map-region-selectedCSS variable. Swap it for any color class.
Keyboard navigation
The map is fully keyboard accessible — no extra setup needed. Tab to focus the map, then use arrow keys to navigate between states, Enter/Space to select, and Escape to clear.