UNPKG

ukelli-ui

Version:

Base on React's UI lib. Make frontend's dev simpler and faster.

62 lines (61 loc) 2.19 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React from 'react'; import ReactDOM from 'react-dom'; import { HasValue, UUID } from 'basic-helper'; import Notification from './notification'; import setDOMById from '../set-dom'; var notifyDOMId = 'NOTIFICATION_CONTAINER'; var notificationEntity; var setNotification = function () { return new Promise(function (resolve) { if (notificationEntity) { resolve(notificationEntity); } else { var notifyDOM = setDOMById(notifyDOMId); ReactDOM.render(React.createElement(Notification, { ref: function (e) { notificationEntity = e; resolve(notificationEntity); } }), notifyDOM); } }); }; /** * 将返回 config 的 id,用于消除该通知 * @param {object} options */ export default function Notify(options) { var position = options.position, config = options.config, _a = options.id, id = _a === void 0 ? UUID() : _a, handleClick = options.handleClick, otherConfig = __rest(options, ["position", "config", "id", "handleClick"]); setNotification().then(function (notify) { notify.receiveNotify(Object.assign({ id: id }, config, otherConfig), position); }); // const { // position, config, id = UUID(), handleClick, ...otherConfig // } = options; // notificationEntity.receiveNotify( // Object.assign({ // id // }, config, otherConfig), position // ); return id; } /** * 用于消除 Notify ,传入 notifyID */ export function CancelNotify(id) { if (!HasValue(id)) return console.warn('must to pass {id}!'); return notificationEntity.closeTip(id); }