Cookie Consent Banner
Per-category consent where refusing is exactly as easy as accepting, nothing non-essential is pre-ticked, and the page behind it stays readable — the shape the law expects, wired to your own script gating.
A type-to-confirm dialog built on native <dialog>, so the focus trap, top layer and escape handling come from the browser. Focus lands on Cancel, and the button says the verb.
components/confirm-dialog.tsxnpx hoverlab add confirm-dialog
Or over MCP, from your editor's agent — no account needed.
Free to read, copy and install, for personal and non-commercial projects. Shipping it in client work or a paid product needs Pro ($79 once). The source lands in your repo and stops being ours — no attribution, nothing to upgrade.
Start a page with this section — add more, order them, and leave with the page source.
Rendered live in your current theme — this is the same component whose source is below, not a screenshot of it.
'use client'
/**
* <ConfirmDialog> — the "are you sure" for something you cannot undo.
*
* Built on the native `<dialog>` element and `showModal()`, which is the
* reason this is short. The browser gives you, for free, the four things a
* hand-rolled modal spends a hundred lines getting wrong: a focus trap, the
* top layer (so no `z-index` can cover it), inertness of the page behind,
* and Escape-to-close.
*
* What is left to do by hand, and is done here:
*
* - `aria-labelledby` / `aria-describedby` on the dialog, so it announces
* as its title and body rather than as an unlabelled group.
* - Escape is intercepted while a destructive action is in flight. The
* browser's default cancel would close the dialog mid-request and leave
* the user unsure whether the delete happened.
* - A backdrop click closes it — native `<dialog>` does not do this. The
* check is on the event target being the dialog itself, which works
* because the backdrop's clicks are reported against the dialog element
* while the content sits in a child.
* - Focus is placed on Cancel, not Delete. The safe option is the default
* for the same reason a "Save changes?" prompt does not focus Discard.
*
* Destructive styling is `bg-destructive`, and the word is the verb —
* "Delete project", not "OK". A confirm dialog whose buttons say OK and
* Cancel makes the reader re-read the sentence to work out which is which.
*/
import * as React from 'react'
import { AlertTriangle, Loader2 } from 'lucide-react'
export interface ConfirmDialogProps {
triggerLabel?: string
title?: string
description?: string
/** The verb, repeated on the button. Never "OK". */
confirmLabel?: string
cancelLabel?: string
/** Type-to-confirm guard. When set, the button unlocks only on an exact match. */
confirmPhrase?: string
onConfirm?: () => void | Promise<void>
className?: string
}
export function ConfirmDialog({
triggerLabel = 'Delete project',
title = 'Delete this project?',
description =
'This removes the project, its deployments and its logs. Team members lose access immediately. This cannot be undone.',
confirmLabel = 'Delete project',
cancelLabel = 'Cancel',
confirmPhrase = 'acme-web',
onConfirm,
className = '',
}: ConfirmDialogProps) {
// Per-instance ids. A literal id in a reusable component is a
// collision waiting for the second copy on the page — and a <label>
// then resolves to whichever input rendered first.
const uid = React.useId()
const dialogRef = React.useRef<HTMLDialogElement>(null)
const cancelRef = React.useRef<HTMLButtonElement>(null)
const [typed, setTyped] = React.useState('')
const [busy, setBusy] = React.useState(false)
const unlocked = !confirmPhrase || typed === confirmPhrase
function open() {
setTyped('')
dialogRef.current?.showModal()
// Focus the safe action, not the destructive one.
requestAnimationFrame(() => cancelRef.current?.focus())
}
function close() {
if (busy) return
dialogRef.current?.close()
}
async function confirm() {
if (!unlocked || busy) return
setBusy(true)
try {
await (onConfirm?.() ?? new Promise((r) => setTimeout(r, 900)))
dialogRef.current?.close()
} finally {
setBusy(false)
}
}
return (
<div className={`flex justify-center p-10 ${className}`}>
<button
type="button"
onClick={open}
className="inline-flex h-11 items-center rounded-xl bg-destructive px-5 text-sm font-semibold text-destructive-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
>
{triggerLabel}
</button>
<dialog
ref={dialogRef}
aria-labelledby={`${uid}-confirm-title`}
aria-describedby={`${uid}-confirm-description`}
// The browser fires `cancel` for Escape. Blocking it while a
// request is in flight keeps the dialog up until the outcome is
// known, rather than leaving the user guessing.
onCancel={(e) => {
if (busy) e.preventDefault()
}}
// Native <dialog> reports backdrop clicks against the dialog itself;
// clicks on the content hit a child, so this only fires outside.
onClick={(e) => {
if (e.target === dialogRef.current) close()
}}
className="max-w-md rounded-2xl border border-border/60 bg-background p-0 text-foreground shadow-2xl backdrop:bg-black/50 backdrop:backdrop-blur-sm"
>
<div className="p-6">
<div className="flex gap-4">
<span className="flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-destructive/10 text-destructive">
<AlertTriangle aria-hidden className="h-5 w-5" />
</span>
<div className="min-w-0">
<h2 id={`${uid}-confirm-title`} className="text-base font-semibold">
{title}
</h2>
<p id={`${uid}-confirm-description`} className="mt-2 text-sm leading-relaxed text-muted-foreground">
{description}
</p>
</div>
</div>
{confirmPhrase ? (
<div className="mt-5">
<label htmlFor={`${uid}-confirm-phrase`} className="block text-sm text-muted-foreground">
Type <span className="font-mono font-semibold text-foreground">{confirmPhrase}</span>{' '}
to confirm
</label>
<input
id={`${uid}-confirm-phrase`}
value={typed}
onChange={(e) => setTyped(e.target.value)}
autoComplete="off"
className="mt-1.5 h-10 w-full rounded-lg border border-border/60 bg-card/60 px-3 font-mono text-sm focus:border-destructive/50 focus:outline-none focus:ring-2 focus:ring-destructive/20"
/>
</div>
) : null}
<div className="mt-6 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end">
<button
ref={cancelRef}
type="button"
onClick={close}
disabled={busy}
className="inline-flex h-10 items-center justify-center rounded-lg border border-border/60 px-4 text-sm font-semibold transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50"
>
{cancelLabel}
</button>
<button
type="button"
onClick={confirm}
disabled={!unlocked || busy}
className="inline-flex h-10 items-center justify-center gap-2 rounded-lg bg-destructive px-4 text-sm font-semibold text-destructive-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50"
>
{busy ? (
<>
<Loader2
aria-hidden
className="h-4 w-4 animate-spin motion-reduce:[animation-duration:1.6s]"
/>
Deleting
</>
) : (
confirmLabel
)}
</button>
</div>
</div>
</dialog>
</div>
)
}
bg-card, text-muted-foreground) — it inherits your theme instead of overriding it.Drop it at components/confirm-dialog.tsx and import it where you need the section:
import { ConfirmDialog } from '@/components/confirm-dialog'5 of this block’s props are simple enough to drive from here. Change them and the block below re-renders — it is the same component whose source is above, not a mock of it. Everything else it accepts is in the table underneath.
Read out of the component’s own type and signature, so this cannot drift from the source below. Every prop has a default — the component renders standalone before you pass it anything.
| Prop | Type | Default |
|---|---|---|
triggerLabel | string | 'Delete project' |
title | string | 'Delete this project?' |
description | string | — |
confirmLabelThe verb, repeated on the button. Never "OK". | string | 'Delete project' |
cancelLabel | string | 'Cancel' |
confirmPhraseType-to-confirm guard. When set, the button unlocks only on an exact match. | string | 'acme-web' |
onConfirm | () => void | Promise<void> | — |
className | string | '' |
The same block rendered once to markup, wrapped as a file your framework compiles. Tailwind classes are framework-agnostic, so the design transfers intact — the behaviour does not.
This block is interactive. The markup below is its initial state with the event handlers stripped — you will need to re-wire the behaviour in your framework.
<!--
Destructive Confirm Dialog — markup from the Hoverlab catalog.
This is the block rendered once to HTML and wrapped as a component
file. It is not a port of the React source: the Tailwind classes carry
the design, which is the part that took the work, and they are the same
in every framework.
This block is interactive in React and the handlers are NOT here.
Buttons, toggles and menus render in their initial state and do
nothing until you wire them up.
-->
<div class="flex justify-center p-10 ">
<button type="button" class="inline-flex h-11 items-center rounded-xl bg-destructive px-5 text-sm font-semibold text-destructive-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background">Delete project</button>
<dialog aria-labelledby="_R_0_-confirm-title" aria-describedby="_R_0_-confirm-description" class="max-w-md rounded-2xl border border-border/60 bg-background p-0 text-foreground shadow-2xl backdrop:bg-black/50 backdrop:backdrop-blur-sm">
<div class="p-6">
<div class="flex gap-4">
<span class="flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-destructive/10 text-destructive">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-triangle-alert h-5 w-5" aria-hidden="true">
<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"></path>
<path d="M12 9v4"></path>
<path d="M12 17h.01"></path>
</svg>
</span>
<div class="min-w-0">
<h2 id="_R_0_-confirm-title" class="text-base font-semibold">Delete this project?</h2>
<p id="_R_0_-confirm-description" class="mt-2 text-sm leading-relaxed text-muted-foreground">This removes the project, its deployments and its logs. Team members lose access immediately. This cannot be undone.</p>
</div>
</div>
<div class="mt-5">
<label for="_R_0_-confirm-phrase" class="block text-sm text-muted-foreground">Type <span class="font-mono font-semibold text-foreground">acme-web</span> to confirm</label>
<input id="_R_0_-confirm-phrase" autoComplete="off" class="mt-1.5 h-10 w-full rounded-lg border border-border/60 bg-card/60 px-3 font-mono text-sm focus:border-destructive/50 focus:outline-none focus:ring-2 focus:ring-destructive/20" value="" />
</div>
<div class="mt-6 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end">
<button type="button" class="inline-flex h-10 items-center justify-center rounded-lg border border-border/60 px-4 text-sm font-semibold transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50">Cancel</button>
<button type="button" disabled="" class="inline-flex h-10 items-center justify-center gap-2 rounded-lg bg-destructive px-4 text-sm font-semibold text-destructive-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50">Delete project</button>
</div>
</div>
</dialog>
</div>
What each framework gets across the whole catalog — effects convert properly; this rung is markup.
The component, its props, the design tokens it expects and the command that installs it — as one prompt. Paste it into Claude, Cursor, v0 or ChatGPT and what they build around it will match the rest of the catalog instead of inventing its own system.
Want the whole screen instead of this one section? Open a page and copy it entire.
All of them free to read, copy and install — no account, no locked tiles, no watermarked preview. The whole catalog is open, and so are the API and the CLI.
Browse Modals & DrawersCopying the code is free. Putting it in client work or a paid product is what Pro is for — the licence, not the access.
Per-category consent where refusing is exactly as easy as accepting, nothing non-essential is pre-ticked, and the page behind it stays readable — the shape the law expects, wired to your own script gating.
A side sheet for editing a record without losing the list behind it — native <dialog> for the trapping, a data attribute for the slide, and a sticky footer so Save never scrolls away.
Facets with per-option counts, zero-result options disabled rather than hidden so the list never jumps, and a pending selection applied on a button that says how many choices changed.
The share modal where a design mistake is a data leak: general access stated as its consequence rather than its setting, and a copy button that never silently widens access.
Half and full snap points where the content owns the scroll and overscroll-contain keeps the page behind still. The drag handle is a real button, Escape and the backdrop close it, and safe-area padding keeps the last row pressable.
The interception that keeps work: three answers rather than two, the changed fields listed by name, a destructive-styled discard, and Escape resolving to cancel.
A non-modal drawer that keeps the list on screen, with previous and next controls for moving between records and an activity tab beside the fields.