Dialog
Dialog example: a centered modal with blurred overlay, header, title, description and footer. A ghost close button sits in the top corner by default.
pnpm dlx shadcn add @01orbital/dialog"use client"
import * as React from "react"
import { Dialog as DialogPrimitive } from "@base-ui/react/dialog"
import { XIcon } from "@phosphor-icons/react"
import { cn } from "cn"
import { Button } from "@/components/ui/button"
function Dialog({ ...props }: DialogPrimitive.Root.Props) {
return <DialogPrimitive.Root data-slot="dialog" {...props} />
}
function DialogTrigger({ ...props }: DialogPrimitive.Trigger.Props) {
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
}
function DialogPortal({ ...props }: DialogPrimitive.Portal.Props) {
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
}
function DialogClose({ ...props }: DialogPrimitive.Close.Props) {
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
}
function DialogOverlay({
className,
...props
}: DialogPrimitive.Backdrop.Props) {
return (
<DialogPrimitive.Backdrop
data-slot="dialog-overlay"
className={cn(
"fixed inset-0 isolate z-50 bg-black/30 duration-100 supports-backdrop-filter:backdrop-blur-sm data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
className
)}
{...props}
/>
)
}
function DialogContent({
className,
children,
showCloseButton = true,
...props
}: DialogPrimitive.Popup.Props & {
showCloseButton?: boolean
}) {
return (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Popup
data-slot="dialog-content"
className={cn(
"fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-6 rounded-4xl bg-popover p-6 text-sm text-popover-foreground shadow-xl ring-1 ring-foreground/5 duration-100 outline-none sm:max-w-md dark:ring-foreground/10 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
className
)}
{...props}
>
{children}
{showCloseButton && (
<DialogPrimitive.Close
data-slot="dialog-close"
render={
<Button
variant="ghost"
className="absolute top-4 right-4 bg-secondary"
size="icon-sm"
/>
}
>
<XIcon />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
)}
</DialogPrimitive.Popup>
</DialogPortal>
)
}
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="dialog-header"
className={cn("flex flex-col gap-1.5", className)}
{...props}
/>
)
}
function DialogFooter({
className,
showCloseButton = false,
children,
...props
}: React.ComponentProps<"div"> & {
showCloseButton?: boolean
}) {
return (
<div
data-slot="dialog-footer"
className={cn(
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
className
)}
{...props}
>
{children}
{showCloseButton && (
<DialogPrimitive.Close render={<Button variant="outline" />}>
Close
</DialogPrimitive.Close>
)}
</div>
)
}
function DialogTitle({ className, ...props }: DialogPrimitive.Title.Props) {
return (
<DialogPrimitive.Title
data-slot="dialog-title"
className={cn("text-base leading-none font-medium", className)}
{...props}
/>
)
}
function DialogDescription({
className,
...props
}: DialogPrimitive.Description.Props) {
return (
<DialogPrimitive.Description
data-slot="dialog-description"
className={cn(
"text-sm text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",
className
)}
{...props}
/>
)
}
export {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogOverlay,
DialogPortal,
DialogTitle,
DialogTrigger,
}
"use client"
import { Button } from "@/components/ui/button"
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
// The copy: change text here, not in the markup.
const COPY = {
trigger: "Open",
title: "Install Eclipse Noir",
description: "Its Button and Film Grain dependencies install with it.",
cancel: "Cancel",
copy: "Copy command",
} as const
/** Dialog, open, with a title, a description and two footer buttons. */
export default function DialogDemo() {
return (
<Dialog defaultOpen>
<DialogTrigger
render={<Button variant="secondary">{COPY.trigger}</Button>}
/>
<DialogContent className="max-w-sm">
<DialogHeader>
<DialogTitle>{COPY.title}</DialogTitle>
<DialogDescription>{COPY.description}</DialogDescription>
</DialogHeader>
<DialogFooter>
<DialogClose
render={<Button variant="ghost">{COPY.cancel}</Button>}
/>
<Button>{COPY.copy}</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
Examples
Upcoming Chargedialog-billing-upcoming-charge-01
Next billing date and amount with a short breakdown and payment method.
pnpm dlx shadcn add @01orbital/dialog-billing-upcoming-charge-01"use client"
import { useState } from "react"
import { CalendarIcon } from "@phosphor-icons/react"
import { Button } from "@/components/ui/button"
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
const COPY = {
title: "Upcoming charge",
description: "Here is what we will bill you next.",
amount: "$92.00",
date: "December 3, 2026",
viewInvoice: "Preview invoice",
hideInvoice: "Hide invoice",
invoiceTotal: "Total due",
changeMethod: "Change method",
dialogTitle: "Change payment method",
dialogDescription: "Choose the card we charge on the date above.",
save: "Use this card",
cancel: "Cancel",
}
const BREAKDOWN = [
{ id: "b1", label: "Studio plan", amount: "$48.00" },
{ id: "b2", label: "5 seats", amount: "$36.00" },
{ id: "b3", label: "Storage add-on", amount: "$8.00" },
]
const METHODS = [
{ id: "visa", label: "Visa ending 4242" },
{ id: "mastercard", label: "Mastercard ending 8210" },
{ id: "amex", label: "Amex ending 3005" },
]
export default function BillingUpcomingCharge() {
const [showInvoice, setShowInvoice] = useState(false)
const [open, setOpen] = useState(false)
const [methodId, setMethodId] = useState(METHODS[0].id)
const [draftId, setDraftId] = useState(METHODS[0].id)
const method = METHODS.find((m) => m.id === methodId) ?? METHODS[0]
return (
<Card className="mx-auto w-full max-w-md">
<CardHeader>
<CardTitle>{COPY.title}</CardTitle>
<CardDescription>{COPY.description}</CardDescription>
</CardHeader>
<CardContent className="flex flex-col gap-5">
<div className="flex items-center gap-4 rounded-2xl bg-muted p-4">
<span className="flex size-11 items-center justify-center rounded-xl bg-background">
<CalendarIcon className="size-5" />
</span>
<div className="flex flex-col">
<span className="text-2xl font-semibold tabular-nums">
{COPY.amount}
</span>
<span className="text-xs text-muted-foreground">
{COPY.date} · {method.label}
</span>
</div>
</div>
{showInvoice && (
<ul className="flex flex-col gap-2 text-sm">
{BREAKDOWN.map((row) => (
<li key={row.id} className="flex justify-between">
<span className="text-muted-foreground">{row.label}</span>
<span className="tabular-nums">{row.amount}</span>
</li>
))}
<li className="flex justify-between border-t pt-2 font-medium">
<span>{COPY.invoiceTotal}</span>
<span className="tabular-nums">{COPY.amount}</span>
</li>
</ul>
)}
</CardContent>
<CardFooter className="gap-2">
<Button
variant="outline"
className="flex-1"
aria-expanded={showInvoice}
onClick={() => setShowInvoice((v) => !v)}
>
{showInvoice ? COPY.hideInvoice : COPY.viewInvoice}
</Button>
<Dialog
open={open}
onOpenChange={(next) => {
setOpen(next)
if (next) setDraftId(methodId)
}}
>
<DialogTrigger render={<Button variant="ghost" />}>
{COPY.changeMethod}
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>{COPY.dialogTitle}</DialogTitle>
<DialogDescription>{COPY.dialogDescription}</DialogDescription>
</DialogHeader>
<RadioGroup value={draftId} onValueChange={setDraftId}>
{METHODS.map((m) => (
<div key={m.id} className="flex items-center gap-3">
<RadioGroupItem id={`method-${m.id}`} value={m.id} />
<Label htmlFor={`method-${m.id}`}>{m.label}</Label>
</div>
))}
</RadioGroup>
<DialogFooter>
<DialogClose render={<Button variant="outline" />}>
{COPY.cancel}
</DialogClose>
<Button
onClick={() => {
setMethodId(draftId)
setOpen(false)
}}
>
{COPY.save}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</CardFooter>
</Card>
)
}
Dependencies
npm: @base-ui/react, @phosphor-icons/react, cn. The CLI installs them for you. cn merges Tailwind class names, in place of clsx and tailwind-merge.
Registry pieces it installs with it:
Used in blocks
4 blocks are built with Dialog: