Dialog confirm
Asks for confirmation before a destructive or irreversible action, optionally by typing a word.
import { Button, Dialog, DialogConfirm, type DialogConfirmPayload } from "@openperf/deft";
import { Preview } from "../../src/Preview";
const HANDLE = Dialog.createHandle<DialogConfirmPayload>();
export default function DialogConfirmBasic() {
return (
<Preview overlay={true}>
<Dialog.Trigger
handle={HANDLE}
payload={{ title: "Title", description: "Description", onConfirm: () => HANDLE.close() }}
render={<Button.Root />}
>
Open dialog
</Dialog.Trigger>
<DialogConfirm handle={HANDLE} />
</Preview>
);
}
- Use it before an action that deletes data or can’t be undone. Use a Dialog for anything that needs a form.
- Create a handle with
Dialog.createHandleand pass it to everyDialog.Triggerand to oneDialogConfirm. - The dialog’s content comes from the
payloadof the trigger that opened it, so oneDialogConfirmserves every trigger on the page. - A destructive confirm button is
dangerwith a verb label, such as “Delete”. The button that opens the dialog staysdefaultorghost. - Close the dialog from
onConfirmwithhandle.close()once the action is done. - While
pendingis true, the confirm button shows a spinner, Cancel is disabled, and Escape and outside clicks don’t close the dialog.
Typed confirmation
import { Button, Dialog, DialogConfirm, type DialogConfirmPayload } from "@openperf/deft";
import { Preview } from "../../src/Preview";
const HANDLE = Dialog.createHandle<DialogConfirmPayload>();
export default function DialogConfirmExpected() {
return (
<Preview overlay={true}>
<Dialog.Trigger
handle={HANDLE}
payload={{
title: "Title",
description: "Description",
expected: "Value",
onConfirm: () => HANDLE.close(),
}}
render={<Button.Root />}
>
Open dialog
</Dialog.Trigger>
<DialogConfirm handle={HANDLE} />
</Preview>
);
}
Set expected in the payload to add a field labelled “Type … to confirm”. The confirm button stays disabled until the typed text matches; spaces around it are ignored.
API
PropType
handleDialogHandle<DialogConfirmPayload>
From Dialog.createHandle, shared with the triggers.
Type
DialogHandle<DialogConfirmPayload>pending?boolean
Shows a spinner and blocks Cancel and dismissal.
Type
booleanDefault
falsechildren?(payload) => ReactNode
Extra detail rendered under the description.
Type
(payload) => ReactNodePayload
PropType
titleReactNode
Type
ReactNodeonConfirm() => void
Type
() => voiddescription?ReactNode
Type
ReactNodeexpected?string
Text the user must type to enable confirmation.
Type
stringconfirmLabel?ReactNode
Type
ReactNodeDefault
"Confirm"cancelLabel?ReactNode
Type
ReactNodeDefault
"Cancel"confirmVariant?"default" | "field" | "primary" | "ghost" | "danger"
Variant of the confirm button.
Type
"default" | "field" | "primary" | "ghost" | "danger"Default
"primary"