UNPKG

design-react-kit

Version:

Componenti React per Bootstrap 5

30 lines 1.1 kB
import React, { useEffect } from 'react'; import { cssTransition, useToast } from 'react-toastify'; const dummyTransition = /* @__PURE__ */ cssTransition({ enter: '', exit: '' }); export const Notification = (props) => { const { toastRef, eventHandlers } = useToast({ ...props, transition: dummyTransition }); const { children, autoClose, onClick, role, toastId, deleteToast, closeToast, isIn } = props; const customStyle = { display: isIn ? 'block' : 'none' }; useEffect(() => { if (!isIn) deleteToast(); }, [isIn]); useEffect(() => { let timer; if (autoClose) { timer = setTimeout(() => closeToast(), autoClose); } return () => { if (timer != null) { clearTimeout(Number(timer)); } }; }, [autoClose, closeToast]); return (React.createElement("div", { id: toastId, onClick: onClick, ...eventHandlers, style: customStyle, ref: toastRef, ...(isIn && { role: role }) }, children)); }; //# sourceMappingURL=Notification.js.map