UNPKG

zarm-web

Version:
244 lines (199 loc) 9.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _classnames = _interopRequireDefault(require("classnames")); var _transition = _interopRequireDefault(require("../transition")); var _icon = _interopRequireDefault(require("../icon")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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 _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { 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, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } var Notification = /*#__PURE__*/ function (_Component) { _inherits(Notification, _Component); function Notification() { var _getPrototypeOf2; var _this; _classCallCheck(this, Notification); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Notification)).call.apply(_getPrototypeOf2, [this].concat(args))); _this.state = { visible: false }; _this.timeout = void 0; _this.offsetHeight = void 0; _this.notification = void 0; _this.onClick = function (event) { if (_this.props.onClick) { _this.props.onClick(event); } }; _this.onClose = function (event) { var onClose = _this.props.onClose; _this.stopTimer(); _this.leave(); if (typeof onClose === 'function') { onClose(event); } }; _this.onMouseEnter = function () { _this.stopTimer(); }; _this.onMouseLeave = function () { _this.startTimer(); }; return _this; } _createClass(Notification, [{ key: "componentDidMount", value: function componentDidMount() { this.enter(); this.startTimer(); } }, { key: "componentWillUnmount", value: function componentWillUnmount() { clearInterval(this.timeout); } }, { key: "startTimer", value: function startTimer() { var _this2 = this; var stayTime = this.props.stayTime; if (stayTime) { this.timeout = setTimeout(function () { _this2.onClose(); }, stayTime); } } }, { key: "stopTimer", value: function stopTimer() { clearInterval(this.timeout); } }, { key: "enter", value: function enter() { this.setState({ visible: true }); } }, { key: "leave", value: function leave() { this.setState({ visible: false }); } }, { key: "render", value: function render() { var _this3 = this; var _this$props = this.props, prefixCls = _this$props.prefixCls, className = _this$props.className, top = _this$props.top, style = _this$props.style, title = _this$props.title, message = _this$props.message, theme = _this$props.theme, isMessage = _this$props.isMessage, willUnMount = _this$props.willUnMount, btn = _this$props.btn; var visible = this.state.visible; var componentName = isMessage ? 'message' : 'notification'; return _react.default.createElement(_transition.default, { visible: visible, name: componentName, duration: 200, unmountOnHide: true, onStart: function onStart() { _this3.offsetHeight = _this3.notification.offsetHeight; }, onBeforeHide: function onBeforeHide() { return willUnMount(_this3.offsetHeight, parseInt(_this3.notification.style.top, 10)); } }, _react.default.createElement("div", { ref: function ref(el) { _this3.notification = el; }, className: (0, _classnames.default)(prefixCls, className), onClick: this.onClick, style: _objectSpread({}, style, { top: top }) }, _react.default.createElement("div", { className: (0, _classnames.default)("za-".concat(componentName, "__content"), { 'has-icon': theme }) }, !isMessage && _react.default.createElement("div", { className: "za-".concat(componentName, "__close"), onClick: this.onClose }, _react.default.createElement(_icon.default, { type: "wrong" })), !isMessage && theme && _react.default.createElement(_icon.default, { type: this.type, className: "za-".concat(componentName, "__icon"), theme: theme }), title && _react.default.createElement("div", { className: "za-".concat(componentName, "__title") }, title), _react.default.createElement("div", { className: "za-".concat(componentName, "__custom-content"), onMouseEnter: this.onMouseEnter, onMouseLeave: this.onMouseLeave }, isMessage && _react.default.createElement(_icon.default, { type: this.type, className: "za-".concat(componentName, "__icon"), theme: theme }), message, !isMessage && _react.default.createElement("span", { className: "za-".concat(componentName, "__action-area") }, btn))))); } }, { key: "type", get: function get() { var theme = this.props.theme; switch (theme) { case 'success': return 'right-round-fill'; case 'danger': return 'wrong-round-fill'; case 'primary': return 'info-round-fill'; case 'warning': return 'warning-round-fill'; // case 'loading': // return 'loading'; default: return ''; } } }]); return Notification; }(_react.Component); exports.default = Notification; Notification.defaultProps = { prefixCls: 'za-notification', message: '', top: 20, stayTime: 4500, onClick: function onClick() {}, onClose: function onClose() {} };