Confirmation Dialog
A standardized way to ask for user confirmation before executing critical actions like deleting data, logging out, or making irreversible changes.
Installation
npx shadcn@latest add https://shuip.xyz/r/confirmation-dialog.json
Preview
Simple integration
<Dialog><DialogTrigger asChild><Button variant="destructive">Delete</Button></DialogTrigger><DialogContent><DialogHeader><DialogTitle>Are you sure?</DialogTitle><DialogDescription>This action cannot be undone. This will permanently delete the item.</DialogDescription></DialogHeader><DialogFooter><Button variant="outline" onClick={() => setOpen(false)}>Cancel</Button><Button variant="destructive" onClick={handleDelete}>Delete</Button></DialogFooter></DialogContent></Dialog>
With ConfirmationDialog
, the same result in a clean, reusable component:
<ConfirmationDialogtrigger={<Button variant="destructive">Delete</Button>}title="Are you sure?"description="This action cannot be undone. This will permanently delete the item."labelConfirmButton="Delete"onConfirm={handleDelete}/>
Common use cases
// Delete confirmation<ConfirmationDialogtrigger={<Button variant="destructive">Delete Account</Button>}title="Delete Account"description="This will permanently delete your account and all associated data. This action cannot be undone."labelConfirmButton="Delete Account"onConfirm={() => deleteAccount()}/>// Save confirmation<ConfirmationDialogtrigger={<Button>Save Changes</Button>}title="Save Changes"description="Are you sure you want to save these changes?"labelConfirmButton="Save"onConfirm={() => saveChanges()}/>// Custom trigger with icon<ConfirmationDialogtrigger={<Button variant="ghost" size="icon"><Trash2 className="size-4" /></Button>}title="Delete Item"description="This item will be permanently removed."labelConfirmButton="Delete"onConfirm={() => deleteItem(id)}/>
Examples
Default
Props
Name | Type | Description |
---|---|---|
trigger | React.ReactNode | The trigger to open the dialog |
title | string | The title of the dialog |
description | string | The description of the dialog |
labelConfirmButton | string | The label of the confirmation button |
onConfirm | () => void | The function to call when the confirmation button is clicked |
...props | React.RefAttributes<HTMLDialogElement> | All props to apply to the dialog |