@hacline/ui/confirm-buttonConfirmButton
In-place morphing confirmation button for destructive actions. Smoothly expands into Confirm/Cancel or charges a 1.5s hold progress bar with full keyboard and focus management.
Import
import { ConfirmButton } from "@/components/ui/hacline/components/confirm-button";Expand Mode (Default)
Clicking the trigger smoothly morphs the button in-place into [ Confirm | Cancel ] with zero gaze jump. Focus automatically moves to the Cancel button by default (initialFocus="cancel"), supports ArrowLeft / ArrowRight roving navigation, and disarms on Escape or outside press.
import { ConfirmButton } from "@/components/ui/hacline/components/confirm-button";
import { Trash2Icon } from "lucide-react";
export function ConfirmButtonExpand() {
return (
<ConfirmButton
cancelLabel="Cancel"
confirmLabel="Confirm delete"
onConfirm={() => deleteProject()}
variant="outline"
>
<Trash2Icon aria-hidden="true" />
Delete project
</ConfirmButton>
);
}Hold-to-Confirm Mode
Set mode="hold" to charge an in-button progress bar over holdDuration (defaults to 1500ms). Works with mouse, touch, pen, and keyboard (Space or Enter), and cancels smoothly on early release, pointer drift, Escape, or blur.
import { ConfirmButton } from "@/components/ui/hacline/components/confirm-button";
import { RotateCcwIcon } from "lucide-react";
export function ConfirmButtonHold() {
return (
<ConfirmButton
holdDuration={1500}
holdingLabel="Keep holding…"
mode="hold"
onConfirm={() => resetWorkspace()}
variant="danger"
>
<RotateCcwIcon aria-hidden="true" />
Hold to reset
</ConfirmButton>
);
}Async Loading State
When onConfirm returns a Promise, the button automatically enters data-pending, sets aria-busy="true", blocks duplicate submissions and Escape dismissal until settled, and collapses back to idle on resolution. If the Promise rejects, it clears data-pending while staying armed so the user can retry or cancel.
import { ConfirmButton } from "@/components/ui/hacline/components/confirm-button";
import { LoaderCircleIcon, Trash2Icon } from "lucide-react";
export function ConfirmButtonAsync() {
return (
<ConfirmButton
cancelLabel="Cancel"
confirmLabel="Confirm delete"
onConfirm={async () => {
await deleteRecord();
}}
pendingAnnouncement="Deleting record"
pendingLabel={
<>
<LoaderCircleIcon aria-hidden="true" className="animate-spin" />
Deleting…
</>
}
variant="outline"
>
<Trash2Icon aria-hidden="true" />
Delete record
</ConfirmButton>
);
}Sizes
Adjust the button and expanded capsule height with size (sm, md, lg).
import { ConfirmButton } from "@/components/ui/hacline/components/confirm-button";
export function ConfirmButtonSizes() {
return (
<div className="flex flex-wrap items-center gap-3">
<ConfirmButton confirmLabel="Delete" size="sm" variant="outline">
Small
</ConfirmButton>
<ConfirmButton confirmLabel="Delete" size="md" variant="outline">
Default
</ConfirmButton>
<ConfirmButton confirmLabel="Delete" size="lg" variant="outline">
Large
</ConfirmButton>
</div>
);
}Props
Keyboard Interactions
| Key | Behavior |
|---|---|
Enter / Space | In expand mode, arms the button and focuses initialFocus. In hold mode, hold to charge confirmation. |
ArrowLeft / ArrowRight | Moves focus between the Confirm and Cancel actions while armed. |
Escape | Disarms expand mode and restores focus to the trigger, or cancels an active hold gesture. |
Data Attributes
| Attribute | Description |
|---|---|
data-slot="confirm-button" | Root container element |
data-mode="expand" | "hold" | Current confirmation mode |
data-armed | Present while expanded in expand mode |
data-holding | Present while pressing in hold mode |
data-held | Present once holdDuration has elapsed |
data-pending | Present while an async onConfirm Promise is pending |
data-disabled | Present when disabled |