Files
nahodka-front/src/components/Toast.jsx
SlimusMinus 7f59ee1f38 fixed code
2026-08-11 00:24:07 +03:00

28 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// src/components/Toast.jsx
import { useEffect } from "react";
/**
* Toast — всплывающее сообщение об ошибке/успехе, автоматически скрывается.
*
* @param {string} message — текст сообщения
* @param {"error"|"success"} [type="error"]
* @param {function} onDismiss — вызывается по истечении таймера или по клику на крестик
* @param {number} [duration=4000] — время жизни в мс
*/
export default function Toast({ message, type = "error", onDismiss, duration = 4000 }) {
useEffect(() => {
const timer = setTimeout(onDismiss, duration);
return () => clearTimeout(timer);
}, [onDismiss, duration]);
if (!message) return null;
return (
<div className={`f-toast f-toast-${type}`} role="alert">
<span>{message}</span>
<button type="button" className="f-toast-close" onClick={onDismiss} aria-label="Close">
×
</button>
</div>
);
}