import React from "react";
/**
* Toast — transient feedback. role="status" (error uses role="alert"),
* aria-live announced, auto-dismiss with a pause on hover/focus.
*/
export function Toast({ tone = "info", title, children, action, onClose, duration = 5000, style }) {
const [hover, setHover] = React.useState(false);
const [focusWithin, setFocusWithin] = React.useState(false);
const paused = hover || focusWithin; // R07: 둘 중 하나라도 참이면 타이머 정지
React.useEffect(() => {
if (!duration || paused || !onClose) return;
const t = setTimeout(onClose, duration);
return () => clearTimeout(t);
}, [duration, paused, onClose]);
const icons = {
success: "M20 6 9 17l-5-5",
warning: "M12 9v4m0 4h.01M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z",
info: "M12 16v-4m0-4h.01",
error: "M15 9l-6 6m0-6 6 6",
};
return (
setHover(true)} onMouseLeave={() => setHover(false)}
onFocusCapture={() => setFocusWithin(true)} onBlurCapture={(e) => { if (!e.currentTarget.contains(e.relatedTarget)) setFocusWithin(false); }}
style={{
display: "flex", gap: 10, alignItems: "flex-start",
width: 360, maxWidth: "calc(100vw - 32px)", padding: "12px 14px",
background: "hsl(var(--popover))", color: "hsl(var(--foreground))",
border: "1px solid hsl(var(--popover-border))",
borderRadius: 8, boxShadow: "var(--shadow-lg)",
fontFamily: "var(--font-sans)", fontSize: 14, lineHeight: 1.45,
animation: "var(--motion-toast-in)", ...style,
}}
>
{title &&
{title}
}
{children &&
{children}
}
{action &&
{action}
}
{onClose && (
)}
);
}
/** Fixed stack for toasts. Renders bottom-right by default. */
export function ToastStack({ position = "bottom-right", children, style }) {
const [v, h] = position.split("-");
return (
);
}