Skip to content
caliper ui docs

Components

Popover

A small panel anchored to a trigger for quick settings or details.

Free
pnpm dlx shadcn@latest add @caliper/popover

INV-0416

Ostra Freight · sent 30 Sep to Rafael Abreu

Amount due
$12,960.50
Status
Opened twice

Rafael opened it on 2 Oct; no payment yet.

Installs components/ui/popover.tsxDepends on @radix-ui/react-popoverMotion none in component source

When to use

Use it for

  • Quick settings that should not leave the page.
  • Content that needs controls inside it.

Skip it when

  • The content is only a label; use a tooltip.
  • The decision blocks everything else; use a dialog.

Installation

terminal
pnpm dlx shadcn@latest add @caliper/popover

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. It is built from Popover, PopoverTrigger, PopoverClose, PopoverAnchor and PopoverContent.

example.tsx
import { Calendar } from "lucide-react"
import { useState, type ReactNode } from "react"
import { Avatar } from "@/components/ui/avatar"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { SegmentedControl } from "@/components/ui/segmented-control"
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"
import { cn } from "@/components/ui/lib/cn"

function Panel({ title, context, media, action, className, children }: { title: string; context: string; media?: ReactNode; action?: ReactNode; className?: string; children?: ReactNode }) {
  return (
    <section className={cn("grid w-full max-w-md gap-5 rounded-overlay border border-border bg-background p-6 shadow-resting", className)}>
      <div className="flex items-center gap-3">
        {media}
        <div className="grid min-w-0 flex-1 gap-1">
          <p className="font-medium">{title}</p>
          <p className="text-sm text-muted-foreground">{context}</p>
        </div>
        {action}
      </div>
      {children}
    </section>
  );
}

export function QuickSettings() {
  const [open, setOpen] = useState(false);
  const [remind, setRemind] = useState("3");
  const [saved, setSaved] = useState<string | null>(null);
  const dates: Record<string, string> = { "1": "13 Oct", "3": "11 Oct", "7": "7 Oct" };
  return (
    <Panel title="INV-0416" context="Ostra Freight · sent 30 Sep to Rafael Abreu" media={<Avatar name="Ostra Freight" shape="square" />}>
      <dl className="grid grid-cols-2 gap-4 text-sm">
        <div className="grid gap-0.5"><dt className="text-muted-foreground">Amount due</dt><dd className="m-0 text-2xl font-medium tracking-tight tabular-nums">$12,960.50</dd></div>
        <div className="grid content-start justify-items-start gap-1.5"><dt className="text-muted-foreground">Status</dt><dd className="m-0"><Badge variant="warning">Opened twice</Badge></dd></div>
      </dl>
      <div className="grid justify-items-start gap-3 border-t border-border pt-5">
        <Popover open={open} onOpenChange={setOpen}>
          <PopoverTrigger asChild>
            <Button variant="secondary" size="sm"><Calendar aria-hidden="true" />Due 14 Oct · remind {remind === "7" ? "1 week" : `${remind} day${remind === "1" ? "" : "s"}`} before</Button>
          </PopoverTrigger>
          <PopoverContent arrow aria-label="Reminder" className="grid gap-3">
            <p className="text-sm font-medium">Remind Ostra Freight</p>
            <SegmentedControl
              label="Remind before"
              value={remind}
              onValueChange={setRemind}
              options={[{ value: "1", label: "1 day" }, { value: "3", label: "3 days" }, { value: "7", label: "1 week" }]}
            />
            <p className="text-xs text-muted-foreground">Sends the invoice again with a pay link on {dates[remind]}.</p>
            <div className="flex justify-end gap-2">
              <Button variant="ghost" size="sm" onClick={() => setOpen(false)}>Cancel</Button>
              <Button size="sm" onClick={() => { setSaved(dates[remind]); setOpen(false); }}>Save reminder</Button>
            </div>
          </PopoverContent>
        </Popover>
        <p role="status" className="text-sm text-muted-foreground">{saved ? `Reminder set for ${saved}, 09:00 in Ostra Freight’s time zone.` : "Rafael opened it on 2 Oct; no payment yet."}</p>
      </div>
    </Panel>
  );
}

API reference

Popover

component

No props of its own; it accepts the native props of its root element.

PopoverTrigger

component

No props of its own; it accepts the native props of its root element.

PopoverClose

component

No props of its own; it accepts the native props of its root element.

PopoverAnchor

component

No props of its own; it accepts the native props of its root element.

PopoverContent

component

Also accepts the native props of its root element and a ref.

PropTypeDefaultDescription
arrowbooleanfalsePoints at the trigger and follows collision shifts.

Accessibility

It is built on native elements, so roles and focus come from the browser.

Keyboard and focus handling comes from Radix popover: arrow keys move through items, Enter and Space select, and Escape closes and returns focus.

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.

All Overlays & tabs examples