UNPKG

@trellixio/roaster-coffee

Version:
47 lines (43 loc) 1.45 kB
'use strict'; var React = require('react'); var Toast = require('../Toast.js'); function getAutoClose(autoClose, toastAutoClose) { if (typeof toastAutoClose === "number") { return toastAutoClose; } if (toastAutoClose === false || autoClose === false) { return false; } return autoClose; } function ToastsContainer({ toast, autoClose, onHide, innerRef, className }) { const { autoClose: toastAutoClose, message, ...toastProps } = toast; const autoCloseTimeout = getAutoClose(autoClose, toastAutoClose); const hideTimeout = React.useRef(); const handleHide = () => { onHide(toast.id); window.clearTimeout(hideTimeout.current); }; const cancelDelayedHide = () => { clearTimeout(hideTimeout.current); }; const handleDelayedHide = () => { if (typeof autoCloseTimeout === "number") { hideTimeout.current = window.setTimeout(handleHide, autoCloseTimeout); } }; React.useEffect(() => { if (typeof toast.onOpen === "function") { toast.onOpen(toast); } }, []); React.useEffect(() => { handleDelayedHide(); return cancelDelayedHide; }, [autoClose, toast.autoClose]); return /* @__PURE__ */ React.createElement(Toast.Toast, { ...toastProps, className, onClose: handleHide, ref: innerRef, message }); } ToastsContainer.displayName = "ToastContainer"; exports.ToastsContainer = ToastsContainer; exports.getAutoClose = getAutoClose; //# sourceMappingURL=index.js.map