1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
8 |
|
9 | var _react = require('react');
|
10 |
|
11 | var _react2 = _interopRequireDefault(_react);
|
12 |
|
13 | var _propTypes = require('prop-types');
|
14 |
|
15 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
16 |
|
17 | var _style = require('./style.scss');
|
18 |
|
19 | var _style2 = _interopRequireDefault(_style);
|
20 |
|
21 | var _bind = require('classnames/bind');
|
22 |
|
23 | var _bind2 = _interopRequireDefault(_bind);
|
24 |
|
25 | var _Icon = require('../Icon');
|
26 |
|
27 | var _Icon2 = _interopRequireDefault(_Icon);
|
28 |
|
29 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
30 |
|
31 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
32 |
|
33 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
34 |
|
35 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
36 |
|
37 | var Alert = function (_React$Component) {
|
38 | _inherits(Alert, _React$Component);
|
39 |
|
40 | function Alert(props) {
|
41 | _classCallCheck(this, Alert);
|
42 |
|
43 | var _this = _possibleConstructorReturn(this, (Alert.__proto__ || Object.getPrototypeOf(Alert)).call(this, props));
|
44 |
|
45 | _this.state = {
|
46 | timerStart: 0,
|
47 | timeout: _this.props.timeout,
|
48 | timer: false
|
49 | };
|
50 |
|
51 | _this.startTimer = function () {
|
52 | if (_this.props.timeout) {
|
53 | _this.setState({ timerStart: new Date(), timer: setTimeout(_this.closeAlert, _this.state.timeout) });
|
54 | }
|
55 | };
|
56 |
|
57 | _this.pauseTimer = function () {
|
58 | clearTimeout(_this.state.timer);
|
59 | var timeout = _this.state.timeout;
|
60 |
|
61 | timeout -= new Date() - _this.state.timerStart;
|
62 |
|
63 | _this.setState({ timeout: timeout });
|
64 | };
|
65 |
|
66 | _this.closeAlert = function () {
|
67 | if (_this.state.timer) {
|
68 | clearTimeout(_this.state.timer);
|
69 | }
|
70 | _this.props.onClose();
|
71 | };
|
72 |
|
73 | _this.componentDidMount = function () {
|
74 | _this.startTimer();
|
75 | };
|
76 |
|
77 | return _this;
|
78 | }
|
79 |
|
80 | _createClass(Alert, [{
|
81 | key: 'render',
|
82 | value: function render() {
|
83 | var cx = _bind2.default.bind(_style2.default);
|
84 | var alertClasses = cx(_style2.default.alert, this.props.optClass, this.props.type, this.props.closable ? 'closable' : '');
|
85 | var alertIcons = {
|
86 | success: 'md-success',
|
87 | warning: 'md-warning',
|
88 | info: 'md-info',
|
89 | danger: 'md-danger'
|
90 | };
|
91 |
|
92 | return _react2.default.createElement(
|
93 | 'div',
|
94 | { className: alertClasses, onMouseOver: this.pauseTimer, onMouseOut: this.startTimer },
|
95 | this.props.closable ? _react2.default.createElement(
|
96 | 'div',
|
97 | { className: _style2.default['close-icon'], onClick: this.closeAlert },
|
98 | _react2.default.createElement(_Icon2.default, { name: 'md-close', width: '12', height: '12' })
|
99 | ) : null,
|
100 | _react2.default.createElement(_Icon2.default, { name: alertIcons[this.props.type], width: '17', height: '17' }),
|
101 | _react2.default.createElement(
|
102 | 'div',
|
103 | null,
|
104 | this.props.children
|
105 | )
|
106 | );
|
107 | }
|
108 | }]);
|
109 |
|
110 | return Alert;
|
111 | }(_react2.default.Component);
|
112 |
|
113 | Alert.defaultProps = {
|
114 | type: 'success'
|
115 | };
|
116 | Alert.propTypes = {
|
117 | |
118 |
|
119 |
|
120 | type: _propTypes2.default.oneOf(['success', 'warning', 'info', 'danger']),
|
121 | |
122 |
|
123 |
|
124 | optClass: _propTypes2.default.string,
|
125 | |
126 |
|
127 |
|
128 | closable: _propTypes2.default.bool,
|
129 | |
130 |
|
131 |
|
132 | timeout: _propTypes2.default.number,
|
133 | |
134 |
|
135 |
|
136 | onClose: _propTypes2.default.func
|
137 |
|
138 | };
|
139 | exports.default = Alert; |
\ | No newline at end of file |