Components
Pin drop
A pin you drop on a surface. Click, tap or press Enter and the pin falls from above onto the spot, squashes on landing and sends out one ring. Arrow keys nudge a placed pin.
pnpm dlx shadcn@latest add @caliper/pin-dropWhen to use
Use it for
- Choosing a location on a map, photo or floor plan.
- Annotating an image with a single point.
Skip it when
- Many pins; use `CommentPins`.
- Pins that must snap to real places; pair it with a search.
Decisions
Why it is built this way, so you know what to keep when you change your copy.
Behaviour
- Position in percent
- The pin is stored as percentages of the surface, so it stays put when the surface resizes.
Usage
- One button, keys to nudge
- The surface is a single button; Enter drops a pin at the centre, and arrow keys move a placed pin. Each drop is announced.
- Still under reduced motion
- The pin appears in place with no fall and no ring.
Installation
pnpm dlx shadcn@latest add @caliper/pin-drop
Adds its 2 files to components/ui/, each with its own stylesheet, and installs their packages. No account needed. The first part also adds Caliper UI’s tokens; import them once as in Installation.
Usage
This is the code behind the preview above.
import { useState, type ReactNode } from "react" import { Button } from "@/components/ui/button" import { PinDrop, type PinPoint } from "@/components/ui/pin-drop" function Panel({ title, context, className = "max-w-md", children }: { title: string; context: string; className?: string; children: ReactNode }) { return ( <section className={`grid w-full gap-5 rounded-overlay border border-border bg-background p-6 shadow-resting max-sm:p-4 ${className}`}> <div className="grid gap-1"> <p className="font-medium">{title}</p> <p className="text-sm text-muted-foreground">{context}</p> </div> {children} </section> ); } export function PinDropDemo() { const [pin, setPin] = useState<PinPoint | null>(null); return ( <Panel title="Meeting point" context="Click the harbour to drop a pin." className="max-w-lg"> <PinDrop pin={pin} onPinChange={setPin} label="Harbour map" className="rounded-control"> <img src="/media/harbour.jpg" alt="" className="aspect-[16/10] w-full object-cover" /> </PinDrop> <div className="flex items-center justify-between gap-3 text-sm text-muted-foreground"> <span className="tabular-nums">{pin ? `${Math.round(pin.x)}% across, ${Math.round(pin.y)}% down` : "No pin yet"}</span> <Button variant="ghost" size="sm" disabled={!pin} onClick={() => setPin(null)}> Clear </Button> </div> </Panel> ); }
API reference
PinDrop
component
Also accepts the native props of its root element and a ref.
Accessibility
It exposes status semantics, with aria-label and aria-hidden kept in step with state. Changes that matter are announced through a live region.
No custom key handling; Tab and the native activation keys do the work.
Motion
It declares no animation in its component source. Any transition comes from its stylesheet, which uses the duration tokens that collapse to instant under prefers-reduced-motion.
Related
- Dotted mapA dotted world with places on it and routes between them. Routes draw in once, then a short light runs along each in its direction. Choosing a place keeps its routes lit and dims the rest.
- Image zoomAn image in a page that opens to fill the screen from where it sits: press it and it grows out of its own place with the page dimmed behind. Escape, a press anywhere, scrolling or resizing put it back and return focus to it.
- Comment pinsComments pinned to a point on the content: place a pin by clicking or with the keyboard, nudge it with the arrows, discuss in a thread beside it, resolve it, and find every pin in a numbered list.
