Confirm
Promise-based confirm dialog called like toast: await confirm({ title, description, destructive }) resolves true or false. Built on Dialog's alert mode, Cancel takes the first focus, Esc cancels, one host mounted in the layout.
"use client";import { Button } from "@/components/ui/button";import { confirm } from "@/components/ui/confirm";import { toast } from "@/components/ui/toast";export function DeleteProject({ onDelete }: { onDelete: () => Promise<void> }) { return ( <Button variant="destructive" onClick={async () => { const ok = await confirm({ title: "Delete project?", description: "All clips are removed. This cannot be undone.", destructive: true, }); if (ok) toast.promise(onDelete(), { loading: "Deleting…", success: "Deleted", error: "Failed", }); }} > Delete project </Button> );}"use client";import { Drawer, DrawerContent, DrawerTitle } from "@/components/ui/drawer";import { Button } from "@/components/ui/button";import { useDisclosure } from "@/lib/use-disclosure";// Open state for any overlay, opened from anywhere.export function Cart() { const cart = useDisclosure(); return ( <> <Button onClick={cart.show}>Cart</Button> <Drawer {...cart.props}> <DrawerContent side="right"> <DrawerTitle>Your cart</DrawerTitle> </DrawerContent> </Drawer> </> );}<Confirmer>
Host for confirm(). Mount once, next to <Toaster />.
confirm()
Asks before acting; resolves true on confirm, false on cancel, Esc or a newer confirm(). if (await confirm({ title: "Delete project?", destructive: true })) remove(). Needs <Confirmer /> mounted once (root layout).
confirm(options: ConfirmOptions) => Promise<boolean>
- type ConfirmOptions
- { title: ReactNode; description?: ReactNode; confirmLabel?: ReactNode; cancelLabel?: ReactNode; destructive?: boolean; }
* required. Every component also takes className.