UNPKG

@difizen/mana-app

Version:

92 lines (91 loc) 5.17 kB
"use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.NotificationService = void 0; var _manaCommon = require("@difizen/mana-common"); var _manaReact = require("@difizen/mana-react"); var _manaSyringe = require("@difizen/mana-syringe"); var _uuid = require("uuid"); require("./index.less"); var _jsxRuntime = require("react/jsx-runtime"); var _dec, _class; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var NotificationContent = function NotificationContent(props) { var actions = props.actions || []; return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", { className: "mana-notification-content", children: [props.description || '', /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { className: "mana-notification-content-actions", children: actions.map(function (item) { return /*#__PURE__*/(0, _jsxRuntime.jsx)("button", { className: "mana-notification-content-actions-item", onClick: function onClick(e) { var _props$onAction; (_props$onAction = props.onAction) === null || _props$onAction === void 0 || _props$onAction.call(props, e, item); }, children: item.label || item.key }, item.key); }) })] }); }; var NotificationService = exports.NotificationService = (_dec = (0, _manaSyringe.singleton)(), _dec(_class = /*#__PURE__*/function () { function NotificationService() { _classCallCheck(this, NotificationService); } _createClass(NotificationService, [{ key: "open", value: function open(config) { var key = config.key; if (!key) { key = (0, _uuid.v1)(); } var description = /*#__PURE__*/(0, _jsxRuntime.jsx)(NotificationContent, _objectSpread({}, config)); _manaReact.notification.open(_objectSpread(_objectSpread({}, config), {}, { key: key, description: description })); return _manaCommon.Disposable.create(function () { _manaReact.notification.destroy(key); }); } }, { key: "warning", value: function warning(config) { return this.open(_objectSpread(_objectSpread({}, config), {}, { type: 'warning' })); } }, { key: "info", value: function info(config) { return this.open(_objectSpread(_objectSpread({}, config), {}, { type: 'info' })); } }, { key: "success", value: function success(config) { return this.open(_objectSpread(_objectSpread({}, config), {}, { type: 'success' })); } }, { key: "error", value: function error(config) { return this.open(_objectSpread(_objectSpread({}, config), {}, { type: 'error' })); } }]); return NotificationService; }()) || _class);