"use client"; import { useEffect, useRef, useState, type ReactNode } from "react"; import { Button } from "@kandev/ui/button"; export type InlineConfirmActionsProps = { density?: "compact" | "touch"; disabled?: boolean; testId?: string; ariaLabel?: string; description?: ReactNode; cancelLabel: ReactNode; confirmLabel: ReactNode; confirmAriaLabel?: string; confirmTestId?: string; onCancel: () => void; onClose?: () => void; onConfirm: () => void | Promise; }; /** * Inline confirmation actions for rows and menus, without owning mutation state. */ export function InlineConfirmActions({ density = "compact", disabled = false, testId = "inline-confirm-actions", ariaLabel, description, cancelLabel, confirmLabel, confirmAriaLabel, confirmTestId, onCancel, onClose, onConfirm, }: InlineConfirmActionsProps) { const cancelRef = useRef(null); const [confirmed, setConfirmed] = useState(false); const touch = density === "touch"; const actionClass = touch ? "h-11 min-w-11 px-2" : "h-10 min-w-10 px-2 text-xs"; useEffect(() => { cancelRef.current?.focus(); }, []); const handleConfirm = () => { if (disabled) return; onClose?.(); setConfirmed(true); queueMicrotask(() => { void Promise.resolve() .then(onConfirm) .catch(() => { setConfirmed(false); }); }); }; if (confirmed) return null; return (
event.stopPropagation()} onClick={(event) => event.stopPropagation()} onKeyDown={(event) => { if (event.key !== "Escape") return; event.preventDefault(); event.stopPropagation(); onCancel(); }} > {description ?

{description}

: null}
); }