Skip to content
caliper ui docs

Components

Dialog

A modal window that asks for a decision or a short form, with focus kept inside.

Free
pnpm dlx shadcn@latest add @caliper/dialog

Members

Halden Analytics · 14 seats on Team at $6 each

  • Tomás FerreiraEditor
  • Ines CarvalhoViewer
  • Kofi MensahViewer

3 selected · 11 remain

Installs components/ui/dialog.tsxDepends on @radix-ui/react-dialog, @radix-ui/react-slot, lucide-reactMotion none in component source

When to use

Use it for

  • Confirming something consequential or collecting a few fields.
  • The task must be finished or cancelled before continuing.

Skip it when

  • The content is a quick, optional detail; use a popover.
  • Phones and long flows; use a bottom sheet or drawer.

Decisions

Why it is built this way, so you know what to keep when you change your copy.

Behaviour

A busy confirm keeps the dialog open
While the action runs the dialog stays, so a failure can be shown where the decision was made. Focus returns to whatever opened it when it closes.
The footer is pinned
With a long body the actions stay in view behind a divider, so the decision is always one press away.

Styling

A sheet on phones
Under 640px the dialog rises from the bottom edge with stacked 44px actions, where thumbs reach.

Usage

The title states the decision with real numbers
“Remove 3 seats? You will be credited €72” beats “Are you sure?”. The confirming button repeats the action, never just OK.

Installation

terminal
pnpm dlx shadcn@latest add @caliper/dialog

Adds its 3 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 Dialog, DialogTrigger, DialogClose, DialogContent, DialogHeader, DialogFooter, DialogTitle and DialogDescription.

example.tsx
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 { Checkbox } from "@/components/ui/checkbox"
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"
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>
  );
}

const removed = ["Tomás Ferreira", "Ines Carvalho", "Kofi Mensah"];

export function InviteDialog() {
  const [keys, setKeys] = useState(true);
  const [busy, setBusy] = useState(false);
  const [open, setOpen] = useState(false);
  const [result, setResult] = useState("3 selected · 11 remain");
  return (
    <Panel title="Members" context="Halden Analytics · 14 seats on Team at $6 each" media={<Avatar name="Halden Analytics" shape="square" />}>
      <ul className="grid gap-3">
        {removed.map((name, index) => (
          <li key={name} className="flex items-center gap-3 text-sm">
            <Avatar name={name} alt="" />
            <span className="flex-1 font-medium">{name}</span>
            <Badge tone={index === 0 ? "violet" : "slate"}>{index === 0 ? "Editor" : "Viewer"}</Badge>
          </li>
        ))}
      </ul>
      <div className="flex flex-wrap items-center justify-between gap-3 border-t border-border pt-5">
        <p role="status" className="max-w-xs text-sm text-muted-foreground">{result}</p>
        <Dialog open={open} onOpenChange={(next) => !busy && setOpen(next)}>
          <DialogTrigger asChild>
            <Button variant="secondary" className="text-danger">Remove 3 members</Button>
          </DialogTrigger>
          <DialogContent role="alertdialog">
            <DialogHeader>
              <DialogTitle>Remove 3 members from Halden Analytics?</DialogTitle>
              <DialogDescription>
                They lose access right away. Their dashboards and comments stay. Your bill drops by <span className="font-medium text-foreground tabular-nums">$18 per month</span> from 1 November.
              </DialogDescription>
            </DialogHeader>
            <ul className="grid gap-2 text-sm">
              {removed.map((name) => (
                <li key={name} className="flex items-center gap-2.5"><Avatar name={name} alt="" className="size-6" />{name}</li>
              ))}
            </ul>
            <label className="flex items-center gap-3 text-sm">
              <Checkbox checked={keys} onChange={(event) => setKeys(event.currentTarget.checked)} />
              Also revoke their 4 API keys
            </label>
            <DialogFooter>
              <DialogClose asChild><Button variant="secondary" disabled={busy}>Cancel</Button></DialogClose>
              <Button
                variant="destructive"
                loading={busy}
                onClick={() => {
                  setBusy(true);
                  window.setTimeout(() => {
                    setBusy(false);
                    setOpen(false);
                    setResult(`Removed Tomás Ferreira, Ines Carvalho and Kofi Mensah${keys ? " and revoked 4 API keys" : ""}.`);
                  }, 900);
                }}
              >
                Remove 3 members
              </Button>
            </DialogFooter>
          </DialogContent>
        </Dialog>
      </div>
    </Panel>
  );
}

API reference

Dialog

component

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

DialogTrigger

component

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

DialogClose

component

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

DialogContent

component

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

PropTypeDefault
showCloseButtonbooleantrue

DialogHeader

component

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

DialogFooter

component

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

DialogTitle

component

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

DialogDescription

component

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

Accessibility

It is built on native elements and keeps aria-label and aria-hidden in step with state.

Keyboard and focus handling comes from Radix dialog: 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