Library MCP Setup About Template Factory ↗
← Library / Overlays & Feedback UI SDK Agentic

Destructive Action Confirmation Dialog

Confirmation dialog for actions you can't take back: a clear warning, a plain-English list of what happens, an optional type-DELETE-to-confirm field, Cancel focused first, and a tactile crimson confirm button that only switches on once the word matches.

Install UI SDK & packages

npm install @ui-sdk/react @ui-sdk/core lucide-react

Give your agent the UI SDK skill

npx skills add vercel-labs/ui --skill ui-sdk

UI SDK entries: @ui-sdk/react/alert-dialog @ui-sdk/react/field @ui-sdk/react/input
"use client";

import * as React from "react";
import { CircleX, Trash2, TriangleAlert, type LucideIcon } from "lucide-react";
import {
  AlertDialog,
  AlertDialogBackdrop,
  AlertDialogClose,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@ui-sdk/react/alert-dialog";
import { Field, FieldLabel } from "@ui-sdk/react/field";
import { Input } from "@ui-sdk/react/input";

const card =
  "rounded-2xl border border-[#d8e0ea] bg-white shadow-[0_18px_44px_rgba(15,23,42,0.12)] dark:border-slate-400/20 dark:bg-[#111827] dark:shadow-[0_24px_60px_rgba(0,0,0,0.5)]";
const labelCls = "block text-[13px] font-semibold leading-snug text-slate-800 dark:text-slate-200";
const fieldBase =
  "w-full min-w-0 rounded-[10px] border-[1.5px] border-slate-300 bg-white text-sm font-medium text-slate-900 shadow-[0_1px_2px_rgba(15,23,42,0.06)] outline-none transition-[border-color,box-shadow] hover:border-slate-400 focus:border-sky-600 focus:ring-[3px] focus:ring-sky-600/25 dark:border-slate-400/35 dark:bg-[#182234] dark:text-slate-50 dark:shadow-[inset_0_1px_2px_rgba(0,0,0,0.35)] dark:hover:border-slate-400/55 dark:focus:border-sky-400 dark:focus:ring-sky-400/30";
const inputCls = `${fieldBase} h-11 px-3.5`;
const btnBase =
  "inline-flex cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-[10px] font-bold transition hover:-translate-y-px active:translate-y-px disabled:pointer-events-none disabled:opacity-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500";
const btnMd = "h-11 px-4 text-sm";
const btnGhost = `${btnBase} border border-slate-300 bg-linear-to-b from-white to-slate-100 text-slate-900 shadow-[inset_0_1px_0_rgba(255,255,255,0.95),inset_0_-1.5px_0_rgba(15,23,42,0.08),0_1px_2px_rgba(15,23,42,0.06)] hover:border-slate-400 dark:border-slate-400/35 dark:from-[#243047] dark:to-[#182234] dark:text-slate-50 dark:shadow-[inset_0_1px_0_rgba(255,255,255,0.09),inset_0_-1.5px_0_rgba(0,0,0,0.35)] dark:hover:border-slate-400/55`;
const btnDanger = `${btnBase} border border-red-200/45 bg-linear-to-b from-red-500 via-red-600 to-red-700 text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.3),inset_0_-2px_0_rgba(127,29,29,0.55),0_8px_20px_rgba(220,38,38,0.32)] hover:brightness-110 focus-visible:outline-red-400`;
const btnDangerSoft = `${btnBase} border-[1.5px] border-red-300 bg-red-50 text-red-800 hover:border-red-700 hover:bg-red-600 hover:text-white dark:border-red-400/65 dark:bg-linear-to-b dark:from-red-600/30 dark:to-red-800/40 dark:text-rose-50 dark:hover:border-red-400 dark:hover:from-red-600 dark:hover:to-red-600 dark:hover:text-white focus-visible:outline-red-400`;

const hairline = "border-[#d8e0ea] dark:border-slate-400/20";

export function ConfirmDangerDialog({
  icon: Icon = Trash2,
  triggerLabel = "Delete workspace",
  title = "Delete this workspace?",
  description = "This can't be undone. The moment you confirm:",
  consequences = [],
  confirmText = "DELETE",
  confirmLabel = "Delete permanently",
  cancelLabel = "Cancel",
  agentConfirm = "Permanently deletes this workspace and everything in it",
  onOpenChange,
  onConfirm,
}: {
  /** Shown on the trigger and the confirm button. */
  icon?: LucideIcon;
  triggerLabel?: string;
  title?: string;
  description?: string;
  /** Plain-English list of what happens once the person confirms. */
  consequences?: string[];
  /** The word the person must type before the confirm button switches on. Pass null to skip it. */
  confirmText?: string | null;
  confirmLabel?: string;
  cancelLabel?: string;
  /** The warning an agent must get approved before it can press the confirm button. */
  agentConfirm?: string;
  onOpenChange?: (open: boolean) => void;
  /** Return a promise to keep the dialog open, with the button busy, until the work is done. */
  onConfirm?: () => unknown;
}) {
  const [typed, setTyped] = React.useState("");
  const confirmId = React.useId();
  const canConfirm = !confirmText || typed.trim() === confirmText;

  return (
    <AlertDialog
      onOpenChange={(next) => {
        if (!next) setTyped("");
        onOpenChange?.(next);
      }}
    >
      <AlertDialogTrigger className={`${btnDangerSoft} ${btnMd}`}>
        <Icon className="size-4" aria-hidden="true" />
        <span>{triggerLabel}</span>
      </AlertDialogTrigger>
      <AlertDialogBackdrop className="fixed inset-0 z-50 bg-slate-900/45 backdrop-blur-[3px] dark:bg-[#04070d]/70" />
      <AlertDialogContent
        className={`${card} fixed inset-0 z-50 m-auto h-fit max-h-[calc(100dvh-1.75rem)] w-[min(28rem,calc(100vw-1.75rem))] overflow-y-auto p-0 text-slate-900 dark:text-slate-50`}
      >
        <div className="grid gap-3.5 p-5 sm:p-6">
          <div className="flex items-center gap-3">
            <span className="grid size-11 shrink-0 place-items-center rounded-xl bg-red-50 text-red-700 dark:bg-red-400/15 dark:text-red-300">
              <TriangleAlert className="size-[22px]" aria-hidden="true" />
            </span>
            <AlertDialogTitle className="text-lg font-bold tracking-tight text-balance">{title}</AlertDialogTitle>
          </div>
          <AlertDialogDescription className="text-sm leading-relaxed text-slate-600 dark:text-slate-400">{description}</AlertDialogDescription>

          {consequences.length > 0 && (
            <ul className="grid gap-2 rounded-xl bg-slate-50 px-3.5 py-3 dark:bg-[#162033]">
              {consequences.map((item) => (
                <li key={item} className="flex items-start gap-2.5 text-sm font-medium text-slate-800 dark:text-slate-200">
                  <CircleX className="mt-0.5 size-4 shrink-0 text-red-700 dark:text-red-300" aria-hidden="true" />
                  <span>{item}</span>
                </li>
              ))}
            </ul>
          )}

          {confirmText && (
            <Field name="confirm_text" className="flex min-w-0 flex-col gap-1.5">
              <FieldLabel className={labelCls}>
                Type <span className="font-mono font-bold">{confirmText}</span> to confirm
              </FieldLabel>
              <Input
                value={typed}
                onValueChange={setTyped}
                autoComplete="off"
                autoCapitalize="characters"
                spellCheck={false}
                onKeyDown={(event) => {
                  if (event.key === "Enter" && canConfirm) document.getElementById(confirmId)?.click();
                }}
                className={`${inputCls} font-mono tracking-wide`}
              />
            </Field>
          )}
        </div>

        <div className={`flex flex-col-reverse gap-2.5 border-t bg-slate-50 px-5 py-3.5 sm:flex-row sm:justify-end sm:px-6 dark:bg-[#162033] ${hairline}`}>
          <AlertDialogClose className={`${btnGhost} ${btnMd}`}>{cancelLabel}</AlertDialogClose>
          <AlertDialogClose
            id={confirmId}
            value="confirm"
            action={() => onConfirm?.()}
            disabled={!canConfirm}
            data-agent-confirm={agentConfirm}
            className={`${btnDanger} ${btnMd} data-pending:cursor-wait data-pending:opacity-70`}
          >
            <Icon className="size-4" aria-hidden="true" />
            <span>{confirmLabel}</span>
          </AlertDialogClose>
        </div>
      </AlertDialogContent>
    </AlertDialog>
  );
}

export default ConfirmDangerDialog;