index.jsx 1.6 KB
Newer Older
K
KgTong 已提交
1
import React from 'react';
2
import classNames from 'classnames';
3
import { isCssAnimationSupported } from 'css-animation';
A
afc163 已提交
4

5
const AntSpin = React.createClass({
K
KgTong 已提交
6 7
  getDefaultProps() {
    return {
A
afc163 已提交
8
      prefixCls: 'ant-spin',
9
      spining: true
K
KgTong 已提交
10 11 12 13 14
    };
  },

  propTypes: {
    className: React.PropTypes.string,
K
KgTong 已提交
15
    size: React.PropTypes.oneOf(['small', 'default', 'large'])
K
KgTong 已提交
16 17
  },

18
  isNestedPattern() {
A
afc163 已提交
19
    return !!(this.props && this.props.children);
20 21
  },

K
KgTong 已提交
22
  render() {
A
afc163 已提交
23
    const { className, size, prefixCls } = this.props;
K
KgTong 已提交
24

25
    let spinClassName = classNames({
A
afc163 已提交
26
      [prefixCls]: true,
B
Benjy Cui 已提交
27 28
      [`${prefixCls}-sm`]: size === 'small',
      [`${prefixCls}-lg`]: size === 'large',
29
      [className]: !!className,
A
afc163 已提交
30
      [`${prefixCls}-spining`]: this.props.spining,
K
KgTong 已提交
31 32
    });

A
afc163 已提交
33
    let spinElement;
34 35
    if (!isCssAnimationSupported) {
      // not support for animation, just use text instead
A
afc163 已提交
36 37 38 39
      spinElement = <div className={spinClassName}>加载中...</div>;
    } else {
      spinElement = (
        <div className={spinClassName}>
A
afc163 已提交
40 41 42
          <span className={`${prefixCls}-dot ${prefixCls}-dot-first`} />
          <span className={`${prefixCls}-dot ${prefixCls}-dot-second`} />
          <span className={`${prefixCls}-dot ${prefixCls}-dot-third`} />
A
afc163 已提交
43 44
        </div>
      );
45 46
    }

A
afc163 已提交
47 48
    if (this.isNestedPattern()) {
      return (
49
        <div className={this.props.spining ? (`${prefixCls}-nested-loading`) : ''}>
A
afc163 已提交
50
          {spinElement}
51
          <div className={`${prefixCls}-container`}>
A
afc163 已提交
52 53 54 55 56
            {this.props.children}
          </div>
        </div>
      );
    }
57
    return spinElement;
K
KgTong 已提交
58 59 60 61
  }
});

export default AntSpin;