UNPKG

@bubbles-ui/notifications

Version:

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

117 lines (116 loc) 5.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Notification = exports.NOTIFICATION_PROP_TYPES = exports.NOTIFICATION_DEFAULT_PROPS = void 0; var _react = _interopRequireWildcard(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _lodash = require("lodash"); var _core = require("@mantine/core"); var _components = require("@bubbles-ui/components"); var _solid = require("@bubbles-ui/icons/solid"); var _Notification = require("./Notification.styles"); var _context = require("../NotificationProvider/context"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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; } function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } const NOTIFICATION_DEFAULT_PROPS = { severity: 'none', loading: false, disallowClose: false, icon: null, type: _context.CONTEXT_TYPES.DEFAULT, avatar: '' }; exports.NOTIFICATION_DEFAULT_PROPS = NOTIFICATION_DEFAULT_PROPS; const NOTIFICATION_PROP_TYPES = { /** Called when close button is clicked */ onClose: _propTypes.default.func, /** Notification line or icon color */ severity: _propTypes.default.oneOf(['none', ..._components.ALERT_SEVERITIES]), /** Notification icon, displayed at left of body */ icon: _propTypes.default.node, /** Notification title, displayed before body */ title: _propTypes.default.string, /** Notification message, place main text here */ message: _propTypes.default.string, /** Notification body, place main text here */ children: _propTypes.default.node, /** Replaces colored line or icon with Loader component */ loading: _propTypes.default.bool, /** Removes close button */ disallowClose: _propTypes.default.bool, /** Notification type */ type: _propTypes.default.string, /** Notification avatar */ avatar: _propTypes.default.string }; exports.NOTIFICATION_PROP_TYPES = NOTIFICATION_PROP_TYPES; const SEVERITY_ICONS = { info: _solid.AlertInformationCircleIcon, success: _solid.CheckIcon, error: _solid.BlockIcon, warning: _solid.AlertWarningTriangleIcon }; const Notification = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => { let { children, message, leftSide, severity, icon: iconProp, type, avatar, ...props } = _ref; const icon = (0, _react.useMemo)(() => { if (leftSide) { return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null); } if (!(0, _lodash.isEmpty)(avatar)) { return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null); } if (!(0, _lodash.isEmpty)(severity) && severity !== 'none') { const IconComp = SEVERITY_ICONS[severity]; return /*#__PURE__*/_react.default.createElement(IconComp, null); } return iconProp; }, [severity, iconProp, avatar]); const { classes, cx } = (0, _Notification.NotificationStyles)({ hasIcon: !(0, _lodash.isEmpty)(icon), severity, type }, { name: `Notification_${type}` }); return /*#__PURE__*/_react.default.createElement(_core.Notification, _extends({}, props, { ref: ref, classNames: classes, icon: icon }), leftSide ? /*#__PURE__*/_react.default.createElement(_components.Box, { style: { position: 'absolute', left: 15, top: 15 } }, leftSide) : null, !(0, _lodash.isEmpty)(avatar) && /*#__PURE__*/_react.default.createElement(_components.Box, { style: { position: 'absolute', left: 15, top: 15 } }, /*#__PURE__*/_react.default.createElement(_components.Avatar, { image: avatar })), !(0, _lodash.isEmpty)(message) && /*#__PURE__*/_react.default.createElement(_components.Box, null, /*#__PURE__*/_react.default.createElement(_components.Text, { role: "productive", size: "xs", className: classes.message }, message)), children); }); exports.Notification = Notification; Notification.defaultProps = NOTIFICATION_DEFAULT_PROPS; Notification.propTypes = NOTIFICATION_PROP_TYPES;