Browse Source

Add `debounce` props to `Spin`

close #1273
pull/1606/head
RaoHai 9 years ago
parent
commit
6467bc7a73
  1. 24
      components/spin/index.jsx
  2. 1
      components/spin/index.md

24
components/spin/index.jsx

@ -8,8 +8,15 @@ export default class Spin extends React.Component {
static defaultProps = { static defaultProps = {
prefixCls: 'ant-spin', prefixCls: 'ant-spin',
spinning: true, spinning: true,
debounce: 0,
} }
constructor(props) {
super(props);
this.state = {
spinning: props.spinning || props.spining,
};
}
static propTypes = { static propTypes = {
className: React.PropTypes.string, className: React.PropTypes.string,
size: React.PropTypes.oneOf(['small', 'default', 'large']), size: React.PropTypes.oneOf(['small', 'default', 'large']),
@ -26,10 +33,21 @@ export default class Spin extends React.Component {
findDOMNode(this).className += ` ${this.props.prefixCls}-show-text`; findDOMNode(this).className += ` ${this.props.prefixCls}-show-text`;
} }
} }
componentWillReceiveProps(nextProps) {
render() { const { spining = true, debounce } = nextProps;
const { className, size, prefixCls, tip, spining = true } = this.props;
const spinning = this.props.spinning && spining; // Backwards support const spinning = this.props.spinning && spining; // Backwards support
if (this.debounceTimeout) {
clearTimeout(this.debounceTimeout);
}
if (debounce && spinning) {
this.debounceTimeout = setTimeout(() => this.setState({ spinning }), debounce);
} else {
this.setState({ spinning });
}
}
render() {
const { className, size, prefixCls, tip } = this.props;
const { spinning } = this.state;
const spinClassName = classNames({ const spinClassName = classNames({
[prefixCls]: true, [prefixCls]: true,

1
components/spin/index.md

@ -20,3 +20,4 @@ english: Spin
| size | enum | default | spin组件中点的大小,可选值为 small default large | | size | enum | default | spin组件中点的大小,可选值为 small default large |
| spinning | boolean | true | 用于内嵌其他组件的模式,可以关闭 loading 效果 | | spinning | boolean | true | 用于内嵌其他组件的模式,可以关闭 loading 效果 |
| tip | string | 无 | 自定义描述文案 | | tip | string | 无 | 自定义描述文案 |
| debounce | number | 0 | 毫秒,用于设定去抖动的 debounce 值。|

Loading…
Cancel
Save