Skip to content

ConfirmDialog

Convenience wrapper around AlertDialog for confirmation flows

Default

Usage

tsx
import { ConfirmDialog } from '@tryvienna/ui'

<ConfirmDialog
  trigger={<Button variant="destructive">Delete Item</Button>}
  title="Delete this item?"
  description="This action cannot be undone. The item and all associated data will be permanently removed."
  confirmLabel="Delete"
  variant="destructive"
  onConfirm={() => alert('Item deleted!')}
/>

Examples

Default

Default
tsx
<ConfirmDialog
  trigger={<Button variant="destructive">Delete Item</Button>}
  title="Delete this item?"
  description="This action cannot be undone. The item and all associated data will be permanently removed."
  confirmLabel="Delete"
  variant="destructive"
  onConfirm={() => alert('Item deleted!')}
/>

Non Destructive

Non Destructive
tsx
<ConfirmDialog
  trigger={<Button variant="outline">Save Changes</Button>}
  title="Save changes?"
  description="Your changes will be saved and applied immediately."
  confirmLabel="Save"
  variant="default"
  onConfirm={() => alert('Changes saved!')}
/>

Controlled

Controlled
tsx
<div className="flex flex-col items-center gap-4">
  <Button onClick={() => setOpen(true)}>Open Confirm Dialog</Button>
  <ConfirmDialog
    open={open}
    onOpenChange={setOpen}
    title="Discard draft?"
    description="You have unsaved changes. Are you sure you want to discard them?"
    confirmLabel="Discard"
    cancelLabel="Keep Editing"
    variant="destructive"
    onConfirm={() => {
      alert('Draft discarded!');
      setOpen(false);
    }}
    onCancel={() => setOpen(false)}
  />
  <p className="text-xs text-muted-foreground">
    Dialog is controlled via state: {open ? 'open' : 'closed'}
  </p>
</div>

Custom Labels

Custom Labels
tsx
<ConfirmDialog
  trigger={<Button variant="outline">Archive Project</Button>}
  title="Archive this project?"
  description="The project will be moved to the archive. You can restore it later from the archive page."
  confirmLabel="Yes, Archive"
  cancelLabel="No, Keep Active"
  variant="default"
  onConfirm={() => alert('Project archived!')}
/>

API Reference

ConfirmDialog

PropTypeDefaultDescription
openboolean-
onOpenChange(open: boolean) =&gt; void-
triggerReact.ReactNode-
titlestring-
descriptionstring-
confirmLabelstring-
cancelLabelstring-
variant'default' | 'destructive'-
onConfirm() =&gt; void | Promise&lt;void&gt;-
onCancel() =&gt; void-
size'default' | 'sm'-

Data Attributes

Componentdata-slot
ConfirmDialog"confirm-dialog"