UNPKG

7.65 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
3import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
4import _inherits from 'babel-runtime/helpers/inherits';
5
6var _class, _temp;
7
8import React from 'react';
9import PropTypes from 'prop-types';
10import classNames from 'classnames';
11import Overlay from '../overlay';
12import ConfigProvider from '../config-provider';
13import { obj, func } from '../util';
14
15/* eslint-disable react/prefer-stateless-function */
16
17/** Loading */
18var Loading = (_temp = _class = function (_React$Component) {
19 _inherits(Loading, _React$Component);
20
21 function Loading() {
22 _classCallCheck(this, Loading);
23
24 return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
25 }
26
27 Loading.prototype.render = function render() {
28 var _classNames2, _classNames3, _classNames4;
29
30 var _props = this.props,
31 tip = _props.tip,
32 visible = _props.visible,
33 children = _props.children,
34 className = _props.className,
35 style = _props.style,
36 indicator = _props.indicator,
37 color = _props.color,
38 prefix = _props.prefix,
39 fullScreen = _props.fullScreen,
40 disableScroll = _props.disableScroll,
41 onVisibleChange = _props.onVisibleChange,
42 tipAlign = _props.tipAlign,
43 size = _props.size,
44 inline = _props.inline,
45 rtl = _props.rtl,
46 safeNode = _props.safeNode;
47
48
49 var indicatorDom = null;
50 var dotCls = prefix + 'loading-dot';
51
52 if (indicator) {
53 indicatorDom = indicator;
54 } else {
55 var _classNames;
56
57 var backgroundColor = color;
58 var fusionReactorCls = classNames((_classNames = {}, _classNames[prefix + 'loading-fusion-reactor'] = true, _classNames[prefix + 'loading-medium-fusion-reactor'] = size === 'medium', _classNames));
59 indicatorDom = React.createElement(
60 'div',
61 { className: fusionReactorCls, dir: rtl ? 'rtl' : undefined },
62 React.createElement('span', { className: dotCls, style: { backgroundColor: backgroundColor } }),
63 React.createElement('span', { className: dotCls, style: { backgroundColor: backgroundColor } }),
64 React.createElement('span', { className: dotCls, style: { backgroundColor: backgroundColor } }),
65 React.createElement('span', { className: dotCls, style: { backgroundColor: backgroundColor } })
66 );
67 }
68
69 var loadingCls = classNames((_classNames2 = {}, _classNames2[prefix + 'loading'] = true, _classNames2[prefix + 'open'] = visible, _classNames2[prefix + 'loading-inline'] = inline, _classNames2[className] = className, _classNames2));
70
71 var tipCls = classNames((_classNames3 = {}, _classNames3[prefix + 'loading-tip'] = true, _classNames3[prefix + 'loading-tip-fullscreen'] = fullScreen, _classNames3[prefix + 'loading-right-tip'] = tipAlign === 'right', _classNames3));
72
73 var others = obj.pickOthers(Loading.propTypes, this.props);
74
75 var contentCls = classNames((_classNames4 = {}, _classNames4[prefix + 'loading-component'] = visible, _classNames4[prefix + 'loading-wrap'] = true, _classNames4));
76
77 return fullScreen ? [children, React.createElement(
78 Overlay,
79 _extends({
80 key: 'overlay',
81 hasMask: true,
82 align: 'cc cc',
83 safeNode: safeNode,
84 disableScroll: disableScroll
85 }, others, {
86 className: className,
87 style: style,
88 visible: visible,
89 onRequestClose: onVisibleChange
90 }),
91 React.createElement(
92 'div',
93 { className: tipCls },
94 React.createElement(
95 'div',
96 { className: prefix + 'loading-indicator' },
97 indicatorDom
98 ),
99 React.createElement(
100 'div',
101 { className: prefix + 'loading-tip-content' },
102 tip
103 ),
104 React.createElement(
105 'div',
106 { className: prefix + 'loading-tip-placeholder' },
107 tip
108 )
109 )
110 )] : React.createElement(
111 'div',
112 _extends({ className: loadingCls, style: style }, others),
113 visible ? React.createElement(
114 'div',
115 { className: tipCls },
116 React.createElement(
117 'div',
118 { className: prefix + 'loading-indicator' },
119 indicatorDom
120 ),
121 React.createElement(
122 'div',
123 { className: prefix + 'loading-tip-content' },
124 tip
125 ),
126 React.createElement(
127 'div',
128 { className: prefix + 'loading-tip-placeholder' },
129 tip
130 )
131 ) : null,
132 React.createElement(
133 'div',
134 { className: contentCls },
135 visible ? React.createElement('div', { className: prefix + 'loading-masker' }) : null,
136 children
137 )
138 );
139 };
140
141 return Loading;
142}(React.Component), _class.propTypes = _extends({}, ConfigProvider.propTypes, {
143 /**
144 * 样式前缀
145 */
146 prefix: PropTypes.string,
147 /**
148 * 自定义内容,可以传入string或reactElement
149 */
150 tip: PropTypes.any,
151 /**
152 * 自定义内容位置
153 * @enumdesc 出现在动画右边, 出现在动画下面
154 */
155 tipAlign: PropTypes.oneOf(['right', 'bottom']),
156 /**
157 * loading 状态, 默认 true
158 */
159 visible: PropTypes.bool,
160 /**
161 * 全屏模式下,loading弹层请求关闭时触发的回调函数
162 * @param {String} type 弹层关闭的来源
163 * @param {Object} e DOM 事件
164 */
165 onVisibleChange: PropTypes.func,
166 /**
167 * 自定义class
168 */
169 className: PropTypes.string,
170 /**
171 * 自定义内联样式
172 */
173 style: PropTypes.object,
174 /**
175 * 设置动画尺寸
176 * @description 仅仅对默认动画效果起作用
177 * @enumdesc 大号, 中号
178 */
179 size: PropTypes.oneOf(['large', 'medium']),
180 /**
181 * 自定义动画
182 */
183 indicator: PropTypes.any,
184 /**
185 * 动画颜色
186 */
187 color: PropTypes.string,
188 /**
189 * 全屏展示
190 */
191 fullScreen: PropTypes.bool,
192 /**
193 * 当点击 document 的时候,如果包含该节点则不会关闭弹层,
194 * 如果是函数需要返回 ref,如果是字符串则是该 DOM 的 id,也可以直接传入 DOM 节点,或者以上值组成的数组
195 * 是否禁用滚动,仅在 fullScreen 模式下生效
196 */
197 disableScroll: PropTypes.bool,
198 /**
199 * 安全节点,fullScreen时有效,
200 */
201 safeNode: PropTypes.any,
202 /**
203 * 子元素
204 */
205 children: PropTypes.any,
206 inline: PropTypes.bool,
207 rtl: PropTypes.bool
208}), _class.defaultProps = {
209 prefix: 'next-',
210 visible: true,
211 onVisibleChange: func.noop,
212 animate: null,
213 tipAlign: 'bottom',
214 size: 'large',
215 inline: true,
216 disableScroll: false
217}, _temp);
218Loading.displayName = 'Loading';
219
220
221export default ConfigProvider.config(Loading);
\No newline at end of file