UNPKG

antd

Version:

An enterprise-class UI design language and React-based implementation

109 lines (98 loc) 3.26 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _rcNotification = require('rc-notification'); var _rcNotification2 = _interopRequireDefault(_rcNotification); var _icon = require('../icon'); var _icon2 = _interopRequireDefault(_icon); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } var defaultDuration = 1.5; var defaultTop = void 0; var messageInstance = void 0; var key = 1; var prefixCls = 'ant-message'; function getMessageInstance() { messageInstance = messageInstance || _rcNotification2["default"].newInstance({ prefixCls: prefixCls, transitionName: 'move-up', style: { top: defaultTop } }); return messageInstance; } function notice(content) { var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultDuration; var type = arguments[2]; var onClose = arguments[3]; var iconType = { info: 'info-circle', success: 'check-circle', error: 'cross-circle', warning: 'exclamation-circle', loading: 'loading' }[type]; var instance = getMessageInstance(); instance.notice({ key: key, duration: duration, style: {}, content: _react2["default"].createElement( 'div', { className: prefixCls + '-custom-content ' + prefixCls + '-' + type }, _react2["default"].createElement(_icon2["default"], { type: iconType }), _react2["default"].createElement( 'span', null, content ) ), onClose: onClose }); return function () { var target = key++; return function () { instance.removeNotice(target); }; }(); } exports["default"] = { info: function info(content, duration, onClose) { return notice(content, duration, 'info', onClose); }, success: function success(content, duration, onClose) { return notice(content, duration, 'success', onClose); }, error: function error(content, duration, onClose) { return notice(content, duration, 'error', onClose); }, // Departed usage, please use warning() warn: function warn(content, duration, onClose) { return notice(content, duration, 'warning', onClose); }, warning: function warning(content, duration, onClose) { return notice(content, duration, 'warning', onClose); }, loading: function loading(content, duration, onClose) { return notice(content, duration, 'loading', onClose); }, config: function config(options) { if (options.top !== undefined) { defaultTop = options.top; } if (options.duration !== undefined) { defaultDuration = options.duration; } if (options.prefixCls !== undefined) { prefixCls = options.prefixCls; } }, destroy: function destroy() { if (messageInstance) { messageInstance.destroy(); messageInstance = null; } } }; module.exports = exports['default'];