2015-10-27 10:10:27 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { classSet } from 'rc-util';
|
2015-10-30 11:56:23 +08:00
|
|
|
import { isCssAnimationSupported } from 'css-animation';
|
2015-10-28 19:33:25 +08:00
|
|
|
const AntSpin = React.createClass({
|
2015-10-27 10:10:27 +08:00
|
|
|
getDefaultProps() {
|
|
|
|
return {
|
2015-10-30 11:56:23 +08:00
|
|
|
size: 'default'
|
2015-10-27 10:10:27 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
className: React.PropTypes.string,
|
2015-10-27 14:58:04 +08:00
|
|
|
size: React.PropTypes.oneOf(['small', 'default', 'large'])
|
2015-10-27 10:10:27 +08:00
|
|
|
},
|
|
|
|
|
2015-10-28 19:33:25 +08:00
|
|
|
isNestedPattern() {
|
|
|
|
return this.props.children ? true : false;
|
|
|
|
},
|
|
|
|
|
2015-10-27 10:10:27 +08:00
|
|
|
render() {
|
2015-10-27 14:01:55 +08:00
|
|
|
const prefix = 'ant-spin';
|
2015-10-28 19:33:25 +08:00
|
|
|
const nestedStatus = this.isNestedPattern();
|
2015-10-30 11:56:23 +08:00
|
|
|
const { className, size, ...others } = this.props;
|
2015-10-27 14:01:55 +08:00
|
|
|
const sizeCls = ({
|
|
|
|
'large': 'lg',
|
|
|
|
'small': 'sm'
|
|
|
|
})[size] || '';
|
2015-10-27 10:34:05 +08:00
|
|
|
|
2015-10-28 19:33:25 +08:00
|
|
|
let loadingClassName = classSet({
|
2015-10-30 11:56:23 +08:00
|
|
|
'ant-spin-nested-loading': nestedStatus
|
2015-10-28 19:33:25 +08:00
|
|
|
});
|
|
|
|
let spinClassName = classSet({
|
2015-10-27 14:01:55 +08:00
|
|
|
'ant-spin': true,
|
|
|
|
[className]: !!className
|
2015-10-27 10:10:27 +08:00
|
|
|
});
|
|
|
|
|
2015-10-28 19:33:25 +08:00
|
|
|
let spinEl;
|
2015-10-30 11:56:23 +08:00
|
|
|
if (!isCssAnimationSupported) {
|
|
|
|
// not support for animation, just use text instead
|
2015-10-28 19:33:25 +08:00
|
|
|
spinEl = <div className={ spinClassName }>加载中...</div>;
|
|
|
|
}else {
|
|
|
|
let spinWrapperClassName = classSet({
|
|
|
|
'ant-spin-wrapper': true,
|
|
|
|
[`${prefix}-${sizeCls}`]: sizeCls
|
|
|
|
});
|
|
|
|
spinEl = (<div className={ spinWrapperClassName }>
|
|
|
|
<div className={ spinClassName }>
|
|
|
|
<span className="ant-spin-dot ant-spin-dot-first" />
|
|
|
|
<span className="ant-spin-dot ant-spin-dot-second" />
|
|
|
|
<span className="ant-spin-dot ant-spin-dot-third" />
|
|
|
|
</div>
|
|
|
|
</div>);
|
|
|
|
}
|
|
|
|
|
|
|
|
let spinContainerEl = nestedStatus ?
|
|
|
|
<div className="ant-spin-container">
|
|
|
|
{ this.props.children }
|
|
|
|
</div> : null;
|
|
|
|
|
2015-10-27 10:10:27 +08:00
|
|
|
return (
|
2015-10-28 19:33:25 +08:00
|
|
|
<div {...this.props} className={ loadingClassName }>
|
|
|
|
{ spinEl }
|
|
|
|
{ spinContainerEl }
|
2015-10-27 10:10:27 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default AntSpin;
|
2015-10-28 19:33:25 +08:00
|
|
|
|