ant-design/components/spin/index.jsx

64 lines
1.7 KiB
React
Raw Normal View History

2015-10-27 10:10:27 +08:00
import React from 'react';
import classNames from 'classnames';
import { isCssAnimationSupported } from 'css-animation';
2015-10-31 02:00:03 +08:00
const AntSpin = React.createClass({
2015-10-27 10:10:27 +08:00
getDefaultProps() {
return {
2015-11-06 23:49:37 +08:00
prefixCls: 'ant-spin',
2016-02-21 14:48:14 +08:00
spining: true,
2015-10-27 10:10:27 +08:00
};
},
propTypes: {
className: React.PropTypes.string,
2016-02-21 14:48:14 +08:00
size: React.PropTypes.oneOf(['small', 'default', 'large']),
2015-10-27 10:10:27 +08:00
},
isNestedPattern() {
2015-10-31 02:00:03 +08:00
return !!(this.props && this.props.children);
},
2015-10-27 10:10:27 +08:00
render() {
2016-02-19 20:20:45 +08:00
const { className, size, prefixCls, tip } = this.props;
2015-10-27 10:34:05 +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',
[className]: !!className,
2015-11-06 23:49:37 +08:00
[`${prefixCls}-spining`]: this.props.spining,
2015-10-27 10:10:27 +08:00
});
2015-10-31 02:00:03 +08:00
let spinElement;
2016-02-21 14:48:14 +08:00
if (!isCssAnimationSupported || 'tip' in this.props) {
// not support for animation, just use text instead
2016-02-19 20:20:45 +08:00
spinElement = <div className={spinClassName}>{tip || '加载中...'}</div>;
2015-10-31 02:00:03 +08:00
} else {
spinElement = (
<div className={spinClassName}>
2016-02-19 20:20:45 +08:00
<div className={`${prefixCls}-dots`}>
<span className={`${prefixCls}-dot ${prefixCls}-dot-first`} />
<span className={`${prefixCls}-dot ${prefixCls}-dot-second`} />
<span className={`${prefixCls}-dot ${prefixCls}-dot-third`} />
</div>
2015-10-31 02:00:03 +08:00
</div>
);
}
2015-10-31 02:00:03 +08:00
if (this.isNestedPattern()) {
return (
<div className={this.props.spining ? (`${prefixCls}-nested-loading`) : ''}>
2015-10-31 02:00:03 +08:00
{spinElement}
<div className={`${prefixCls}-container`}>
2015-10-31 02:00:03 +08:00
{this.props.children}
</div>
</div>
);
}
return spinElement;
2015-10-27 10:10:27 +08:00
}
});
export default AntSpin;