ant-design/components/spin/index.jsx

71 lines
1.8 KiB
React
Raw Normal View History

2015-10-27 10:10:27 +08:00
import React from 'react';
import { classSet } from 'rc-util';
import { isCssAnimationSupported } from 'css-animation';
const AntSpin = React.createClass({
2015-10-27 10:10:27 +08:00
getDefaultProps() {
return {
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
},
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';
const nestedStatus = this.isNestedPattern();
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
let loadingClassName = classSet({
'ant-spin-nested-loading': nestedStatus
});
let spinClassName = classSet({
2015-10-27 14:01:55 +08:00
'ant-spin': true,
[className]: !!className
2015-10-27 10:10:27 +08:00
});
let spinEl;
if (!isCssAnimationSupported) {
// not support for animation, just use text instead
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 (
<div {...this.props} className={ loadingClassName }>
{ spinEl }
{ spinContainerEl }
2015-10-27 10:10:27 +08:00
</div>
);
}
});
export default AntSpin;