UNPKG

@jdcfe/yep-react

Version:

一套移动端的React组件库

121 lines (105 loc) 4.16 kB
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"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } import * as React from 'react'; import classNames from 'classnames'; import RemindOutlined from '@jdcfe/icons-react/RemindOutlined'; import CloseOutlined from '@jdcfe/icons-react/CloseOutlined'; var Message = /*#__PURE__*/function (_React$PureComponent) { _inherits(Message, _React$PureComponent); var _super = _createSuper(Message); function Message(props) { var _this; _classCallCheck(this, Message); _this = _super.call(this, props); _this.state = { isShow: true }; _this.closeMessage = _this.closeMessage.bind(_assertThisInitialized(_this)); _this.showMessage = _this.showMessage.bind(_assertThisInitialized(_this)); return _this; } _createClass(Message, [{ key: "componentDidMount", value: function componentDidMount() { var _this2 = this; var duration = this.props.duration; if (duration > 0) { this.timer = setTimeout(function () { _this2.closeMessage(); }, duration); } } }, { key: "closeMessage", value: function closeMessage() { // 清空定时器 if (this.timer) { clearTimeout(this.timer); this.timer = null; } this.setState({ isShow: false }); } }, { key: "showMessage", value: function showMessage() { // 清空定时器 if (this.timer) { clearTimeout(this.timer); this.timer = null; } this.setState({ isShow: true }); } }, { key: "render", value: function render() { if (!this.state.isShow) return null; var _this$props = this.props, prefixCls = _this$props.prefixCls, className = _this$props.className, style = _this$props.style, type = _this$props.type, position = _this$props.position, icon = _this$props.icon, closeable = _this$props.closeable, children = _this$props.children; var wrapperCls = classNames(prefixCls, position, className); var box = classNames('box', "box-".concat(type)); // icon分为info,warn,error三级 return /*#__PURE__*/React.createElement("div", { className: wrapperCls, style: style }, /*#__PURE__*/React.createElement("div", { className: box }, icon && /*#__PURE__*/React.createElement(RemindOutlined, { className: "".concat(prefixCls, "-icon-remind") }), /*#__PURE__*/React.createElement("div", { className: "message-text" }, children), closeable && /*#__PURE__*/React.createElement(CloseOutlined, { onClick: this.closeMessage, className: "".concat(prefixCls, "-icon-close") }))); } }]); return Message; }(React.PureComponent); export { Message as default }; Message.defaultProps = { children: null, prefixCls: 'Yep-message', className: '', style: {}, duration: -1, type: 'info', position: 'in-place', icon: true, closeable: false };