import React, { useEffect, useState } from 'react' import { createPortal } from 'react-dom' /** * ShareToast — a minimal, auto-dismissing toast notification. * * Props: * message – text to display * visible – whether the toast is currently shown * onHide – callback when the toast finishes (auto-hidden after ~2 s) * duration – ms before auto-dismiss (default 2000) */ export default function ShareToast({ message = 'Link copied!', visible = false, onHide, duration = 2000 }) { const [show, setShow] = useState(false) useEffect(() => { if (visible) { // Small delay so the enter transition plays const enterTimer = requestAnimationFrame(() => setShow(true)) const hideTimer = setTimeout(() => { setShow(false) setTimeout(() => onHide?.(), 200) // let exit transition finish }, duration) return () => { cancelAnimationFrame(enterTimer) clearTimeout(hideTimer) } } else { setShow(false) } }, [visible, duration, onHide]) if (!visible) return null return createPortal(