ConfirmDialog
Shared ComponentsPre-configured confirmation dialog for destructive actions with customizable title, message, and button labels.
Responsive viewport — resize the window to explore. Direction and density apply only to this preview. Theme applies to the docs too.
"use client";
import { ConfirmDialog } from "@dashboardpack/core/components/shared/confirm-dialog";
import { Button } from "@dashboardpack/core/components/ui/button";
import { useState } from "react";
export default function ConfirmDialogExample() {
const [open, setOpen] = useState(false);
const [destructive, setDestructive] = useState(false);
const [result, setResult] = useState(
"Choose an action to open a confirmation.",
);
return (
<div className="space-y-4">
<div className="flex flex-wrap gap-3">
<Button
variant="outline"
onClick={() => {
setDestructive(false);
setOpen(true);
}}
>
Publish report
</Button>
<Button
variant="destructive"
onClick={() => {
setDestructive(true);
setOpen(true);
}}
>
Delete project
</Button>
</div>
<ConfirmDialog
open={open}
onOpenChange={setOpen}
title={destructive ? "Delete this project?" : "Publish this report?"}
description={
destructive
? "This is a local preview. No real project will be deleted."
: "This is a local preview. No report will be published."
}
confirmLabel={destructive ? "Delete project" : "Publish report"}
variant={destructive ? "destructive" : "default"}
onConfirm={() =>
setResult(
destructive
? "Project deleted in preview."
: "Report published in preview.",
)
}
/>
<p role="status" className="text-sm text-muted-foreground">
{result}
</p>
</div>
);
}Usage
Use for a short confirmation with a default or destructive action. onConfirm is synchronous and the dialog closes immediately. Use a controlled Dialog for asynchronous operations that must remain open on failure.
import { ConfirmDialog } from "@dashboardpack/core/components/shared/confirm-dialog";Available in the included @dashboardpack/core package. Copy the complete example from Source code for all imports and state. Add "use client" when using hooks or event handlers. See installation and theming for project setup.
API reference
Common props and defaults. Slot-specific props are named below; native elements also accept their standard HTML attributes. The component TypeScript definitions are the complete type reference.
| Prop | Type / Default | Description |
|---|---|---|
| open | booleanDefault: required | Controlled visibility. |
| onOpenChange | (open: boolean) => voidDefault: required | Handle dismissal. |
| title / description | stringDefault: required | Action and its consequences. |
| confirmLabel | stringDefault: Confirm | Confirmation button text. |
| variant | default | destructiveDefault: default | Confirmation action appearance. |
| onConfirm | () => voidDefault: required | Synchronous callback; closes immediately afterward. |