UNPKG

4.16 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
3import _createClass from 'babel-runtime/helpers/createClass';
4import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
5import _inherits from 'babel-runtime/helpers/inherits';
6var __rest = this && this.__rest || function (s, e) {
7 var t = {};
8 for (var p in s) {
9 if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
10 }if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
11 if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]];
12 }return t;
13};
14import classnames from 'classnames';
15import React from 'react';
16import Icon from '../icon';
17import Marquee from './Marquee';
18
19var NoticeBar = function (_React$Component) {
20 _inherits(NoticeBar, _React$Component);
21
22 function NoticeBar(props) {
23 _classCallCheck(this, NoticeBar);
24
25 var _this = _possibleConstructorReturn(this, (NoticeBar.__proto__ || Object.getPrototypeOf(NoticeBar)).call(this, props));
26
27 _this.onClick = function () {
28 var _this$props = _this.props,
29 mode = _this$props.mode,
30 onClick = _this$props.onClick;
31
32 if (onClick) {
33 onClick();
34 }
35 if (mode === 'closable') {
36 _this.setState({
37 show: false
38 });
39 }
40 };
41 _this.state = {
42 show: true
43 };
44 return _this;
45 }
46
47 _createClass(NoticeBar, [{
48 key: 'render',
49 value: function render() {
50 var _a = this.props,
51 mode = _a.mode,
52 icon = _a.icon,
53 onClick = _a.onClick,
54 children = _a.children,
55 className = _a.className,
56 prefixCls = _a.prefixCls,
57 action = _a.action,
58 marqueeProps = _a.marqueeProps,
59 restProps = __rest(_a, ["mode", "icon", "onClick", "children", "className", "prefixCls", "action", "marqueeProps"]);
60 var extraProps = {};
61 var operationDom = null;
62 if (mode === 'closable') {
63 operationDom = React.createElement(
64 'div',
65 { className: prefixCls + '-operation', onClick: this.onClick, role: 'button', 'aria-label': 'close' },
66 action ? action : React.createElement(Icon, { type: 'cross', size: 'md' })
67 );
68 } else {
69 if (mode === 'link') {
70 operationDom = React.createElement(
71 'div',
72 { className: prefixCls + '-operation', role: 'button', 'aria-label': 'go to detail' },
73 action ? action : React.createElement(Icon, { type: 'right', size: 'md' })
74 );
75 }
76 extraProps.onClick = onClick;
77 }
78 var wrapCls = classnames(prefixCls, className);
79 return this.state.show ? React.createElement(
80 'div',
81 _extends({ className: wrapCls }, restProps, extraProps, { role: 'alert' }),
82 icon &&
83 // tslint:disable-next-line:jsx-no-multiline-js
84 React.createElement(
85 'div',
86 { className: prefixCls + '-icon', 'aria-hidden': 'true' },
87 icon
88 ),
89 React.createElement(
90 'div',
91 { className: prefixCls + '-content' },
92 React.createElement(Marquee, _extends({ prefixCls: prefixCls, text: children }, marqueeProps))
93 ),
94 operationDom
95 ) : null;
96 }
97 }]);
98
99 return NoticeBar;
100}(React.Component);
101
102export default NoticeBar;
103
104NoticeBar.defaultProps = {
105 prefixCls: 'am-notice-bar',
106 mode: '',
107 icon: React.createElement(Icon, { type: 'voice', size: 'xxs' }),
108 onClick: function onClick() {}
109};
\No newline at end of file