choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
143 lines (118 loc) • 4.25 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function _createSuper(Derived) {
function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
return function () {
var Super = _getPrototypeOf(Derived),
result;
if (isNativeReflectConstruct()) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
import React, { Component } from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
var Notice =
/*#__PURE__*/
function (_Component) {
_inherits(Notice, _Component);
var _super = _createSuper(Notice);
function Notice() {
var _this;
_classCallCheck(this, Notice);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_defineProperty(_assertThisInitialized(_this), "close", function () {
_this.clearCloseTimer();
_this.props.onClose();
});
_defineProperty(_assertThisInitialized(_this), "startCloseTimer", function () {
if (_this.props.duration) {
_this.closeTimer = setTimeout(function () {
_this.close();
}, _this.props.duration * 1000);
}
});
_defineProperty(_assertThisInitialized(_this), "clearCloseTimer", function () {
if (_this.closeTimer) {
clearTimeout(_this.closeTimer);
_this.closeTimer = null;
}
});
return _this;
}
_createClass(Notice, [{
key: "componentDidMount",
value: function componentDidMount() {
this.startCloseTimer();
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this.clearCloseTimer();
}
}, {
key: "render",
value: function render() {
var _className;
var props = this.props;
var contentClassName = props.contentClassName;
var componentClass = "".concat(props.prefixCls, "-notice");
var className = (_className = {}, _defineProperty(_className, "".concat(componentClass), 1), _defineProperty(_className, "".concat(componentClass, "-closable"), props.closable), _defineProperty(_className, props.className, !!props.className), _className);
return React.createElement("div", {
className: classNames(className),
style: props.style,
onMouseEnter: this.clearCloseTimer,
onMouseLeave: this.startCloseTimer
}, React.createElement("div", {
className: "".concat(componentClass, "-content ").concat(contentClassName)
}, props.children), props.closable ? React.createElement("a", {
tabIndex: "0",
onClick: this.close,
className: "".concat(componentClass, "-close")
}, props.closeIcon || React.createElement("span", {
className: "".concat(componentClass, "-close-x")
})) : null);
}
}]);
return Notice;
}(Component);
_defineProperty(Notice, "propTypes", {
duration: PropTypes.number,
onClose: PropTypes.func,
children: PropTypes.any,
closeIcon: PropTypes.node,
contentClassName: PropTypes.string
});
_defineProperty(Notice, "defaultProps", {
onEnd: function onEnd() {},
onClose: function onClose() {},
duration: 1.5,
style: {
right: '50%'
}
});
export { Notice as default };
//# sourceMappingURL=Notice.js.map