chore(tag): some code style

pull/940/head
afc163 9 years ago
parent 65b338de2b
commit 5719a83f36

@ -9,55 +9,53 @@ class AntTag extends React.Component {
this.state = { this.state = {
closing: false, closing: false,
closed: false closed: false,
}; };
} }
close(e) { close(e) {
let dom = ReactDOM.findDOMNode(this); const dom = ReactDOM.findDOMNode(this);
dom.style.width = dom.offsetWidth + 'px'; dom.style.width = dom.offsetWidth + 'px';
// It's Magic Code, don't know why // It's Magic Code, don't know why
dom.style.width = dom.offsetWidth + 'px'; dom.style.width = dom.offsetWidth + 'px';
this.setState({ this.setState({
closing: true closing: true,
}); });
this.props.onClose.call(this, e); this.props.onClose(e);
} }
animationEnd() { animationEnd() {
this.setState({ this.setState({
closed: true, closed: true,
closing: false closing: false,
}); });
} }
render() { render() {
let close = this.props.closable ? const close = this.props.closable ?
<Icon type="cross" onClick={this.close.bind(this)} /> : ''; <Icon type="cross" onClick={this.close.bind(this)} /> : '';
let colorClass = this.props.color ? this.props.prefixCls + '-' + this.props.color : ''; const colorClass = this.props.color ? this.props.prefixCls + '-' + this.props.color : '';
let className = this.props.prefixCls + ' ' + colorClass; let className = this.props.prefixCls + ' ' + colorClass;
className = this.state.closing ? className + ' ' + this.props.prefixCls + '-close' : className; className = this.state.closing ? className + ' ' + this.props.prefixCls + '-close' : className;
return this.state.closed ? null return this.state.closed ? null : (
: ( <Animate component=""
<Animate component="" showProp="data-show"
showProp="data-show" transitionName={this.props.prefixCls + '-zoom'}
transitionName={this.props.prefixCls + '-zoom'} onEnd={this.animationEnd.bind(this)}>
onEnd={this.animationEnd.bind(this)}> <div data-show={!this.state.closing} className={className}>
<div data-show={!this.state.closing} className={className}> <span className={this.props.prefixCls + '-text'} {...this.props} />
<span className={this.props.prefixCls + '-text'} {...this.props} /> {close}
{close} </div>
</div> </Animate>
</Animate> );
);
} }
} }
function NOOP() {}
AntTag.defaultProps = { AntTag.defaultProps = {
prefixCls: 'ant-tag', prefixCls: 'ant-tag',
closable: false, closable: false,
onClose: NOOP, onClose() {},
}; };
export default AntTag; export default AntTag;

Loading…
Cancel
Save