1 | import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
2 | import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
3 | import _createClass from "@babel/runtime/helpers/createClass";
|
4 | import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
5 | import _inherits from "@babel/runtime/helpers/inherits";
|
6 | import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
7 | import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
8 |
|
9 | function _createSuper(Derived) {
|
10 | function isNativeReflectConstruct() {
|
11 | if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
12 | if (Reflect.construct.sham) return false;
|
13 | if (typeof Proxy === "function") return true;
|
14 |
|
15 | try {
|
16 | Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
|
17 | return true;
|
18 | } catch (e) {
|
19 | return false;
|
20 | }
|
21 | }
|
22 |
|
23 | return function () {
|
24 | var Super = _getPrototypeOf(Derived),
|
25 | result;
|
26 |
|
27 | if (isNativeReflectConstruct()) {
|
28 | var NewTarget = _getPrototypeOf(this).constructor;
|
29 |
|
30 | result = Reflect.construct(Super, arguments, NewTarget);
|
31 | } else {
|
32 | result = Super.apply(this, arguments);
|
33 | }
|
34 |
|
35 | return _possibleConstructorReturn(this, result);
|
36 | };
|
37 | }
|
38 |
|
39 | import React, { Component } from 'react';
|
40 | import { findDOMNode } from 'react-dom';
|
41 | import classNames from 'classnames';
|
42 | import Icon from '../icon';
|
43 | import Animate from '../animate';
|
44 | import { getPrefixCls } from '../configure';
|
45 |
|
46 | var Alert =
|
47 |
|
48 | function (_Component) {
|
49 | _inherits(Alert, _Component);
|
50 |
|
51 | var _super = _createSuper(Alert);
|
52 |
|
53 | function Alert() {
|
54 | var _this;
|
55 |
|
56 | _classCallCheck(this, Alert);
|
57 |
|
58 | _this = _super.apply(this, arguments);
|
59 | _this.state = {
|
60 | closing: true,
|
61 | closed: false
|
62 | };
|
63 |
|
64 | _this.handleClose = function (e) {
|
65 | e.preventDefault();
|
66 | var dom = findDOMNode(_assertThisInitialized(_this));
|
67 | dom.style.height = "".concat(dom.offsetHeight, "px");
|
68 |
|
69 |
|
70 | dom.style.height = "".concat(dom.offsetHeight, "px");
|
71 |
|
72 | _this.setState({
|
73 | closing: false
|
74 | });
|
75 |
|
76 | var onClose = _this.props.onClose;
|
77 |
|
78 | if (onClose) {
|
79 | onClose(e);
|
80 | }
|
81 | };
|
82 |
|
83 | _this.animationEnd = function () {
|
84 | _this.setState({
|
85 | closed: true,
|
86 | closing: true
|
87 | });
|
88 |
|
89 | var afterClose = _this.props.afterClose;
|
90 |
|
91 | if (afterClose) {
|
92 | afterClose();
|
93 | }
|
94 | };
|
95 |
|
96 | return _this;
|
97 | }
|
98 |
|
99 | _createClass(Alert, [{
|
100 | key: "render",
|
101 | value: function render() {
|
102 | var _classNames;
|
103 |
|
104 | var props = this.props;
|
105 | var description = props.description,
|
106 | customizePrefixCls = props.prefixCls,
|
107 | message = props.message,
|
108 | closeText = props.closeText,
|
109 | banner = props.banner,
|
110 | _props$className = props.className,
|
111 | className = _props$className === void 0 ? '' : _props$className,
|
112 | style = props.style;
|
113 | var closable = props.closable,
|
114 | showIcon = props.showIcon,
|
115 | type = props.type,
|
116 | iconType = props.iconType;
|
117 | var _this$state = this.state,
|
118 | closing = _this$state.closing,
|
119 | closed = _this$state.closed;
|
120 | var prefixCls = getPrefixCls('alert', customizePrefixCls);
|
121 |
|
122 | showIcon = banner && showIcon === undefined ? true : showIcon;
|
123 |
|
124 | type = banner && type === undefined ? 'warning' : type || 'info';
|
125 |
|
126 | if (!iconType) {
|
127 | switch (type) {
|
128 | case 'success':
|
129 | iconType = 'check_circle';
|
130 | break;
|
131 |
|
132 | case 'info':
|
133 | iconType = 'info';
|
134 | break;
|
135 |
|
136 | case 'error':
|
137 | iconType = 'error';
|
138 | break;
|
139 |
|
140 | case 'warning':
|
141 | iconType = 'warning';
|
142 | break;
|
143 |
|
144 | default:
|
145 | iconType = 'default';
|
146 | }
|
147 | }
|
148 |
|
149 | var alertCls = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-").concat(type), true), _defineProperty(_classNames, "".concat(prefixCls, "-close"), !closing), _defineProperty(_classNames, "".concat(prefixCls, "-with-description"), !!description), _defineProperty(_classNames, "".concat(prefixCls, "-no-icon"), !showIcon), _defineProperty(_classNames, "".concat(prefixCls, "-banner"), !!banner), _classNames), className);
|
150 |
|
151 | if (closeText) {
|
152 | closable = true;
|
153 | }
|
154 |
|
155 | var closeIcon = closable ? React.createElement("a", {
|
156 | onClick: this.handleClose,
|
157 | className: "".concat(prefixCls, "-close-icon")
|
158 | }, closeText || React.createElement(Icon, {
|
159 | type: "close"
|
160 | })) : null;
|
161 | return closed ? null : React.createElement(Animate, {
|
162 | component: "",
|
163 | hiddenProp: "hidden",
|
164 | transitionName: "".concat(prefixCls, "-slide-up"),
|
165 | onEnd: this.animationEnd
|
166 | }, React.createElement("div", {
|
167 | hidden: !closing,
|
168 | className: alertCls,
|
169 | style: style
|
170 | }, showIcon ? React.createElement(Icon, {
|
171 | className: "".concat(prefixCls, "-icon"),
|
172 | type: iconType
|
173 | }) : null, React.createElement("span", {
|
174 | className: "".concat(prefixCls, "-message")
|
175 | }, message), React.createElement("span", {
|
176 | className: "".concat(prefixCls, "-description")
|
177 | }, description), closeIcon));
|
178 | }
|
179 | }]);
|
180 |
|
181 | return Alert;
|
182 | }(Component);
|
183 |
|
184 | export { Alert as default };
|
185 | Alert.displayName = 'Alert';
|
186 |
|