UNPKG

@bubbles-ui/notifications

Version:

The Bubbles Design System is Leemonade's open-source design system for products and experiences.

61 lines (60 loc) 2.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NotificationContainer = void 0; var _react = _interopRequireWildcard(require("react")); var _Notification = require("../Notification"); var _helpers = require("./helpers"); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } const NotificationContainer = _ref => { let { className, sx, notification, autoClose, onHide, type } = _ref; const autoCloseTimeout = (0, _helpers.getAutoClose)(autoClose, notification); const hideTimeout = (0, _react.useRef)(); const handleHide = () => { onHide(notification.id); window.clearTimeout(hideTimeout.current); }; const cancelDelayedHide = () => { clearTimeout(hideTimeout.current); }; const handleDelayedHide = () => { if (typeof autoCloseTimeout === 'number') { hideTimeout.current = window.setTimeout(handleHide, autoCloseTimeout); } }; (0, _react.useEffect)(() => { if (typeof notification.onOpen === 'function') { notification.onOpen(notification); } }, []); (0, _react.useEffect)(() => { handleDelayedHide(); return cancelDelayedHide; }, [autoClose, notification.autoClose]); function empty() {} return /*#__PURE__*/_react.default.createElement(_Notification.Notification, { sx: sx, type: type, className: className, title: notification.title, onClose: handleHide, severity: notification.severity, avatar: notification.avatar, leftSide: notification.leftSide, loading: notification.loading, disallowClose: notification.disallowClose, onMouseEnter: cancelDelayedHide, onMouseLeave: handleDelayedHide, onClick: e => notification.onClick ? notification.onClick(e, notification) : empty }, notification.message); }; exports.NotificationContainer = NotificationContainer;