Dialog
FreeA modal that scales in on desktop and becomes a bottom sheet on phones.
Installation
pnpm dlx shadcn@latest add @viewport/dialog
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above.
import { Dialog, DialogClose, DialogContent, DialogTrigger } from "@/components/viewport/dialog";
const button = "inline-flex h-10 items-center justify-center rounded-xl px-4 text-sm font-medium outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring";
export default function DialogDemo() {
return (
<Dialog>
<DialogTrigger className={`${button} bg-foreground text-background hover:bg-foreground/90`}>Delete project</DialogTrigger>
<DialogContent title="Delete this project?" description="This removes the project, its deployments and its analytics. You can't undo this.">
<div className="flex flex-col-reverse gap-2 sm:flex-row sm:justify-end">
<DialogClose className={`${button} border border-border hover:bg-accent`}>Cancel</DialogClose>
<DialogClose className={`${button} bg-destructive text-white hover:bg-destructive/90`}>Delete project</DialogClose>
</div>
</DialogContent>
</Dialog>
);
}Props
| Prop | Type | Default |
|---|---|---|
| title* | string | — |
| description | string | — |
Accessibility
- Built on Radix Dialog: focus trap, focus restore, Escape to close.
- Title and description are wired to the dialog.
- Respects the safe-area inset on phones.