modo-mobile
Version:
A mobile UI toolkit, based on React
105 lines (94 loc) • 3.46 kB
JavaScript
import _extends from 'babel-runtime/helpers/extends';
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 * as React from 'react';
import Marquee from './Marquee';
import Icon from '../icon';
var NoticeBar = function (_React$PureComponent) {
_inherits(NoticeBar, _React$PureComponent);
function NoticeBar(props) {
_classCallCheck(this, NoticeBar);
var _this = _possibleConstructorReturn(this, (NoticeBar.__proto__ || Object.getPrototypeOf(NoticeBar)).call(this, props));
_this.handleHide = function (time) {
var timer = setTimeout(function () {
_this.handleClose();
clearTimeout(timer);
}, time);
};
_this.handleClose = function () {
_this.setState({
closed: true
});
var onClick = _this.props.onClick;
if (onClick) onClick();
};
_this.state = {
closed: false
};
return _this;
}
_createClass(NoticeBar, [{
key: 'componentDidMount',
value: function componentDidMount() {
var duration = this.props.duration;
if (duration) {
this.handleHide(duration);
}
}
}, {
key: 'render',
value: function render() {
var _props = this.props,
icon = _props.icon,
prefixCls = _props.prefixCls,
action = _props.action,
children = _props.children,
mode = _props.mode,
onClick = _props.onClick;
var extraProps = {};
var closeIcon = null;
if (mode === 'closable') {
closeIcon = React.createElement(
'div',
{ onClick: this.handleClose, className: prefixCls + '-close-icon' },
action || React.createElement(Icon, { type: 'close' })
);
} else {
if (mode === 'link') {
closeIcon = React.createElement(
'div',
{ className: prefixCls + '-close-icon' },
action || React.createElement(Icon, { type: 'right' })
);
}
extraProps.onClick = onClick;
}
return this.state.closed ? null : React.createElement(
'div',
_extends({ className: prefixCls }, extraProps),
React.createElement(
'div',
{ className: prefixCls + '-icon' },
icon
),
React.createElement(
'div',
{ className: prefixCls + '-content' },
React.createElement(Marquee, { prefixCls: prefixCls, text: children })
),
closeIcon
);
}
}]);
return NoticeBar;
}(React.PureComponent);
export default NoticeBar;
NoticeBar.defaultProps = {
prefixCls: 'm-notice-bar',
mode: '',
duration: 0,
icon: React.createElement(Icon, { type: 'info-circle' }),
onClick: function onClick() {}
};