Loading...
Loading...
An alert component with integrated action buttons for confirm, cancel, or custom call-to-action workflows.
import { useState } from "react";
interface AlertActionProps {
type?: "confirm" | "undo" | "custom";
message: string;
onConfirm?: () => void;
onUndo?: () => void;
onCustom?: () => void;
customLabel?: string;
}
export function AlertAction({ type = "confirm", message, onConfirm, onUndo, onCustom, customLabel }: AlertActionProps) {
const [dismissed, setDismissed] = useState(false);
if (dismissed) return null;
return (
<div className="flex items-center justify-between gap-4 px-5 py-3 bg-white border border-gray-200 rounded-xl shadow-sm" role="alert">
<div className="flex items-center gap-3">
<svg className="w-5 h-5 text-gray-400 shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
<path strokeLinecap="round" strokeLinejoin="round" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<p className="text-sm text-gray-700">{message}</p>
</div>
<div className="flex items-center gap-2 shrink-0">
{type === "confirm" && (
<>
<button onClick={onConfirm} className="px-4 py-1.5 bg-blue-600 text-white text-xs font-semibold rounded-lg hover:bg-blue-700 transition-colors">Confirm</button>
<button onClick={() => setDismissed(true)} className="px-4 py-1.5 text-gray-500 text-xs font-semibold rounded-lg hover:bg-gray-100 transition-colors">Cancel</button>
</>
)}
{type === "undo" && (
<>
<button onClick={onUndo} className="px-4 py-1.5 bg-orange-500 text-white text-xs font-semibold rounded-lg hover:bg-orange-600 transition-colors">Undo</button>
<button onClick={() => setDismissed(true)} className="px-4 py-1.5 text-gray-500 text-xs font-semibold rounded-lg hover:bg-gray-100 transition-colors">Dismiss</button>
</>
)}
{type === "custom" && (
<>
<button onClick={onCustom} className="px-4 py-1.5 bg-gray-900 text-white text-xs font-semibold rounded-lg hover:bg-gray-800 transition-colors">{customLabel || "Action"}</button>
<button onClick={() => setDismissed(true)} className="px-4 py-1.5 text-gray-500 text-xs font-semibold rounded-lg hover:bg-gray-100 transition-colors">Later</button>
</>
)}
</div>
</div>
);
}