Merge branch 'spinDebounce' of https://github.com/RaoHai/ant-design into RaoHai-spinDebounce

This commit is contained in:
afc163 2016-05-09 16:00:25 +08:00
commit abdb38e11f
2 changed files with 30 additions and 4 deletions

View File

@ -27,7 +27,7 @@ const Card = React.createClass({
);
return (
<div>
<Spin spinning={this.state.loading}>{container}</Spin>
<Spin spining={this.state.loading}>{container}</Spin>
切换加载状态:<Switch checked={this.state.loading} onChange={this.toggle} />
</div>
);

View File

@ -10,6 +10,13 @@ export default class Spin extends React.Component {
spinning: true,
}
constructor(props) {
super(props);
const spinning = this.getSpinning(props);
this.state = {
spinning,
};
}
static propTypes = {
className: React.PropTypes.string,
size: React.PropTypes.oneOf(['small', 'default', 'large']),
@ -26,10 +33,29 @@ export default class Spin extends React.Component {
findDOMNode(this).className += ` ${this.props.prefixCls}-show-text`;
}
}
getSpinning(props) {
warning(!('spining' in this.props), '`spining` property of Popover is a spell mistake, use `spinning` instead.');
const { spinning, spining } = props;
// Backwards support
if (spining !== undefined) {
return spining;
}
return spinning;
}
componentWillReceiveProps(nextProps) {
const spinning = this.getSpinning(nextProps);
if (this.debounceTimeout) {
clearTimeout(this.debounceTimeout);
}
if (spinning) {
this.debounceTimeout = setTimeout(() => this.setState({ spinning }), 500);
} else {
this.setState({ spinning });
}
}
render() {
const { className, size, prefixCls, tip, spining = true } = this.props;
const spinning = this.props.spinning && spining; // Backwards support
const { className, size, prefixCls, tip } = this.props;
const { spinning } = this.state;
const spinClassName = classNames({
[prefixCls]: true,