Confirmation
Overlay & FeedbackAction confirmation dialog with customizable buttons.
Preview
Usage
example.jsx
import { Confirmation } from "@/components/ui/confirmation";
export default function Example() {
return <Confirmation />;
}Source Code
Copy this file into components/ui/confirmation.jsx in your project.
confirmation.jsx
"use client";
import { forwardRef } from "react";
import { cn } from "@/lib/utils";
const Confirmation = forwardRef(({ className, open, onConfirm, onCancel, title, description, confirmLabel = "Confirm", cancelLabel = "Cancel", variant = "default", ...props }, ref) => {
if (!open) return null;
return (
<div className="fixed inset-0 z-50 flex items-center justify-center">
<div className="fixed inset-0 bg-black/50 backdrop-blur-sm" onClick={onCancel} />
<div ref={ref} className={cn("relative z-50 w-full max-w-md rounded-lg border bg-background p-6 shadow-lg", className)} {...props}>
{title && <h3 className="text-lg font-semibold">{title}</h3>}
{description && <p className="mt-2 text-sm text-muted-foreground">{description}</p>}
<div className="mt-6 flex justify-end gap-2">
<button onClick={onCancel} className="inline-flex h-9 items-center rounded-md border px-4 text-sm font-medium hover:bg-accent">{cancelLabel}</button>
<button onClick={onConfirm}
className={cn("inline-flex h-9 items-center rounded-md px-4 text-sm font-medium text-white",
variant === "destructive" ? "bg-destructive hover:bg-destructive/90" : "bg-primary hover:bg-primary/90"
)}
>{confirmLabel}</button>
</div>
</div>
</div>
);
});
Confirmation.displayName = "Confirmation";
export { Confirmation };
Quick Install
Make sure you have the cn() utility set up. It requires clsx and tailwind-merge.
npm install clsx tailwind-merge