modo-mobile
Version:
A mobile UI toolkit, based on React
112 lines (101 loc) • 3.94 kB
JavaScript
import _defineProperty from 'babel-runtime/helpers/defineProperty';
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _createClass from 'babel-runtime/helpers/createClass';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
import classNames from 'classnames';
import * as React from 'react';
import Popup from '../popup';
// import Roller from "components/ActivityIndicator/roller";
// import Icon from "components/Icon";
import { defaultProps } from './PropsType';
import './style/index.less';
var Toast = function (_React$PureComponent) {
_inherits(Toast, _React$PureComponent);
function Toast() {
_classCallCheck(this, Toast);
var _this = _possibleConstructorReturn(this, (Toast.__proto__ || Object.getPrototypeOf(Toast)).apply(this, arguments));
_this.state = {
visible: true
};
_this.clearCloseTimer = function () {
var duration = _this.props.duration;
if (duration) {
clearTimeout(_this.closeTimer);
_this.closeTimer = null;
}
};
_this.startCloseTimer = function (duration) {
clearTimeout(_this.closeTimer);
_this.setState({ visible: true });
if (duration) {
_this.closeTimer = setTimeout(function () {
_this.onClose();
}, duration);
}
};
_this.onClose = function () {
_this.setState({ visible: false });
};
_this.handleAnimateEnd = function (exists) {
var willUnmount = _this.props.willUnmount;
if (!exists && willUnmount) {
willUnmount();
}
};
return _this;
}
_createClass(Toast, [{
key: 'componentDidMount',
value: function componentDidMount() {
this.startCloseTimer(this.props.duration);
}
}, {
key: 'UNSAFE_componentWillReceiveProps',
value: function UNSAFE_componentWillReceiveProps(nextProps) {
this.clearCloseTimer();
this.startCloseTimer(nextProps.duration);
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.clearCloseTimer();
}
}, {
key: 'render',
value: function render() {
var _classNames;
var _props = this.props,
prefixCls = _props.prefixCls,
icon = _props.icon,
content = _props.content,
hasMask = _props.hasMask,
position = _props.position;
var wrapCls = classNames((_classNames = {}, _defineProperty(_classNames, '' + prefixCls, true), _defineProperty(_classNames, prefixCls + '-icon', icon), _defineProperty(_classNames, position, true), _classNames));
return React.createElement(
'div',
{ className: wrapCls },
React.createElement(
Popup,
{ visible: this.state.visible, hasMask: hasMask, onAnimateEnd: this.handleAnimateEnd },
React.createElement(
'div',
{ className: prefixCls + '-wrapper' },
React.createElement(
'div',
{ className: prefixCls + '-content' },
content ? React.createElement(
'span',
null,
content
) : ''
)
)
)
);
}
}]);
return Toast;
}(React.PureComponent);
Toast.defaultProps = defaultProps;
export default Toast;