2015-10-27 10:10:27 +08:00
|
|
|
import React from 'react';
|
2016-03-30 23:02:11 +08:00
|
|
|
import { findDOMNode } from 'react-dom';
|
2015-11-24 20:03:57 +08:00
|
|
|
import classNames from 'classnames';
|
2015-10-30 11:56:23 +08:00
|
|
|
import { isCssAnimationSupported } from 'css-animation';
|
2015-10-31 02:00:03 +08:00
|
|
|
|
2016-03-20 20:41:34 +08:00
|
|
|
export default class Spin extends React.Component {
|
2016-03-29 14:01:10 +08:00
|
|
|
static defaultProps = {
|
|
|
|
prefixCls: 'ant-spin',
|
2016-04-14 15:26:55 +08:00
|
|
|
spinning: true,
|
|
|
|
// Backwards support
|
2016-03-29 14:01:10 +08:00
|
|
|
spining: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
className: React.PropTypes.string,
|
|
|
|
size: React.PropTypes.oneOf(['small', 'default', 'large']),
|
|
|
|
}
|
|
|
|
|
2015-10-28 19:33:25 +08:00
|
|
|
isNestedPattern() {
|
2015-10-31 02:00:03 +08:00
|
|
|
return !!(this.props && this.props.children);
|
2016-03-20 20:41:34 +08:00
|
|
|
}
|
2015-10-28 19:33:25 +08:00
|
|
|
|
2016-03-30 23:02:11 +08:00
|
|
|
componentDidMount() {
|
|
|
|
if (!isCssAnimationSupported) {
|
|
|
|
// Show text in IE8/9
|
|
|
|
findDOMNode(this).className += ` ${this.props.prefixCls}-show-text`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-27 10:10:27 +08:00
|
|
|
render() {
|
2016-02-19 20:20:45 +08:00
|
|
|
const { className, size, prefixCls, tip } = this.props;
|
2016-04-14 15:26:55 +08:00
|
|
|
const spinning = this.props.spinning && this.props.spining;
|
2015-10-27 10:34:05 +08:00
|
|
|
|
2015-11-24 20:03:57 +08:00
|
|
|
let spinClassName = classNames({
|
2015-11-06 23:49:37 +08:00
|
|
|
[prefixCls]: true,
|
2016-01-27 12:00:27 +08:00
|
|
|
[`${prefixCls}-sm`]: size === 'small',
|
|
|
|
[`${prefixCls}-lg`]: size === 'large',
|
2015-11-06 23:43:23 +08:00
|
|
|
[className]: !!className,
|
2016-04-14 15:26:55 +08:00
|
|
|
[`${prefixCls}-spinning`]: spinning,
|
2016-03-30 23:02:11 +08:00
|
|
|
[`${prefixCls}-show-text`]: !!this.props.tip,
|
2015-10-27 10:10:27 +08:00
|
|
|
});
|
|
|
|
|
2016-03-30 23:02:11 +08:00
|
|
|
const spinElement = (
|
|
|
|
<div className={spinClassName}>
|
|
|
|
<span className={`${prefixCls}-dot ${prefixCls}-dot-first`} />
|
|
|
|
<span className={`${prefixCls}-dot ${prefixCls}-dot-second`} />
|
|
|
|
<span className={`${prefixCls}-dot ${prefixCls}-dot-third`} />
|
|
|
|
<div className={`${prefixCls}-text`}>{tip || '加载中...'}</div>
|
|
|
|
</div>
|
|
|
|
);
|
2015-10-28 19:33:25 +08:00
|
|
|
|
2015-10-31 02:00:03 +08:00
|
|
|
if (this.isNestedPattern()) {
|
|
|
|
return (
|
2016-04-14 15:26:55 +08:00
|
|
|
<div className={spinning ? (`${prefixCls}-nested-loading`) : ''}>
|
2015-10-31 02:00:03 +08:00
|
|
|
{spinElement}
|
2016-02-17 18:04:42 +08:00
|
|
|
<div className={`${prefixCls}-container`}>
|
2015-10-31 02:00:03 +08:00
|
|
|
{this.props.children}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-01-07 14:21:29 +08:00
|
|
|
return spinElement;
|
2015-10-27 10:10:27 +08:00
|
|
|
}
|
2016-03-20 20:41:34 +08:00
|
|
|
}
|