@trellixio/roaster-coffee
Version:
Beans' product component library
44 lines (41 loc) • 1.41 kB
JavaScript
import React__default, { useRef, useEffect } from 'react';
import { Toast } from '../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 = 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);
}
};
useEffect(() => {
if (typeof toast.onOpen === "function") {
toast.onOpen(toast);
}
}, []);
useEffect(() => {
handleDelayedHide();
return cancelDelayedHide;
}, [autoClose, toast.autoClose]);
return /* @__PURE__ */ React__default.createElement(Toast, { ...toastProps, className, onClose: handleHide, ref: innerRef, message });
}
ToastsContainer.displayName = "ToastContainer";
export { ToastsContainer, getAutoClose };
//# sourceMappingURL=index.js.map