Browse docs
Browse docs
Imperative dialog that resolves a promise when the user confirms or cancels. Add ConfirmDialogProvider once at your app root, then call useConfirm() anywhere to trigger a modal.
function MyComponent() {
const confirm = useConfirm();
const handleDelete = async () => {
const res = await confirm({
title: 'Delete item?',
description: 'This action cannot be undone.',
confirmText: 'Delete',
cancelText: 'Cancel',
});
if (res.status === 'confirmed') {
// proceed with delete
}
};
return <Button onClick={handleDelete}>Delete</Button>;
}// 1. Add the provider at app root (once)
import { ConfirmDialogProvider } from '@dashforge/ui';
function App() {
return (
<ConfirmDialogProvider>
<Router />
</ConfirmDialogProvider>
);
}
// 2. Call useConfirm() in any component
import { useConfirm } from '@dashforge/ui';
function DeleteButton({ id }: { id: string }) {
const confirm = useConfirm();
const handleDelete = async () => {
const result = await confirm({
title: 'Delete item?',
description: 'This action cannot be undone.',
confirmText: 'Delete',
cancelText: 'Cancel',
});
if (result.status === 'confirmed') {
await deleteItem(id);
}
};
return (
<Button color="error" onClick={handleDelete}>Delete</Button>
);
}useConfirm() options| Option | Type | Default | Description |
|---|---|---|---|
title | string | — | Dialog title text. Required. |
description | string | — | Body text explaining the action. |
confirmText | string | 'Confirm' | Label for the confirm button. |
cancelText | string | 'Cancel' | Label for the cancel button. |
confirmColor | 'primary' | 'error' | 'warning' | 'primary' | Color of the confirm button. |
useConfirm() returns a function. Calling that function returns a Promise<{ status: 'confirmed' | 'cancelled' }>.
ConfirmDialogProvider renders a single dialog instance shared across the app — multiple useConfirm() calls queue if triggered simultaneously.