ant-design/components/spin/index.jsx

65 lines
1.8 KiB
React
Raw Normal View History

2015-10-27 10:10:27 +08:00
import React from 'react';
import { findDOMNode } from 'react-dom';
import classNames from 'classnames';
import { isCssAnimationSupported } from 'css-animation';
2015-10-31 02:00:03 +08:00
export default class Spin extends React.Component {
static defaultProps = {
prefixCls: 'ant-spin',
spinning: true,
// Backwards support
spining: true,
}
static propTypes = {
className: React.PropTypes.string,
size: React.PropTypes.oneOf(['small', 'default', 'large']),
}
isNestedPattern() {
2015-10-31 02:00:03 +08:00
return !!(this.props && this.props.children);
}
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;
const spinning = this.props.spinning && this.props.spining;
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,
[`${prefixCls}-spinning`]: spinning,
[`${prefixCls}-show-text`]: !!this.props.tip,
2015-10-27 10:10:27 +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-31 02:00:03 +08:00
if (this.isNestedPattern()) {
return (
<div className={spinning ? (`${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
}
}