2015-07-28 17:08:06 +08:00
|
|
|
import React from 'react';
|
2015-10-21 17:59:57 +08:00
|
|
|
import ReactDOM from 'react-dom';
|
2015-08-21 17:12:42 +08:00
|
|
|
import Animate from 'rc-animate';
|
2015-10-02 16:39:15 +08:00
|
|
|
import Icon from '../iconfont';
|
2015-08-21 17:27:29 +08:00
|
|
|
const prefixCls = 'ant-tag';
|
2015-08-21 17:12:42 +08:00
|
|
|
|
2015-07-28 17:08:06 +08:00
|
|
|
class AntTag extends React.Component {
|
2015-07-30 23:52:44 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2015-08-21 17:27:29 +08:00
|
|
|
closing: false,
|
2015-07-30 23:52:44 +08:00
|
|
|
closed: false
|
|
|
|
};
|
|
|
|
}
|
2015-08-20 11:46:02 +08:00
|
|
|
|
2015-07-30 23:52:44 +08:00
|
|
|
close(e) {
|
2015-10-21 17:59:57 +08:00
|
|
|
let dom = ReactDOM.findDOMNode(this);
|
2015-08-20 13:56:08 +08:00
|
|
|
dom.style.width = dom.offsetWidth + 'px';
|
|
|
|
// It's Magic Code, don't know why
|
|
|
|
dom.style.width = dom.offsetWidth + 'px';
|
2015-07-30 23:52:44 +08:00
|
|
|
this.setState({
|
2015-08-21 17:27:29 +08:00
|
|
|
closing: true
|
2015-07-30 23:52:44 +08:00
|
|
|
});
|
2015-07-29 20:13:42 +08:00
|
|
|
this.props.onClose.call(this, e);
|
2015-07-28 17:08:06 +08:00
|
|
|
}
|
2015-08-21 17:27:29 +08:00
|
|
|
|
2015-08-21 17:12:42 +08:00
|
|
|
animationEnd() {
|
|
|
|
this.setState({
|
|
|
|
closed: true,
|
2015-08-21 17:27:29 +08:00
|
|
|
closing: false
|
2015-08-21 17:12:42 +08:00
|
|
|
});
|
|
|
|
}
|
2015-08-19 17:26:55 +08:00
|
|
|
|
2015-07-28 17:08:06 +08:00
|
|
|
render() {
|
2015-07-28 20:03:10 +08:00
|
|
|
let close = this.props.closable ?
|
2015-10-02 16:39:15 +08:00
|
|
|
<Icon type="cross" onClick={this.close.bind(this)} /> : '';
|
2015-08-20 11:46:02 +08:00
|
|
|
let colorClass = this.props.color ? this.props.prefixCls + '-' + this.props.color : '';
|
2015-08-19 17:26:55 +08:00
|
|
|
let className = this.props.prefixCls + ' ' + colorClass;
|
2015-08-21 17:27:29 +08:00
|
|
|
className = this.state.closing ? className + ' ' + this.props.prefixCls + '-close' : className;
|
2015-08-21 17:12:42 +08:00
|
|
|
|
|
|
|
return this.state.closed ? null
|
2015-08-21 17:27:29 +08:00
|
|
|
: <Animate component=""
|
2015-09-01 16:18:46 +08:00
|
|
|
showProp="data-show"
|
2015-08-21 17:27:29 +08:00
|
|
|
transitionName="zoom-tag"
|
|
|
|
onEnd={this.animationEnd.bind(this)}>
|
|
|
|
<div data-show={!this.state.closing} className={className}>
|
2015-08-20 13:43:57 +08:00
|
|
|
<a className={this.props.prefixCls + '-text'} {...this.props} />
|
|
|
|
{close}
|
2015-08-21 17:12:42 +08:00
|
|
|
</div>
|
|
|
|
</Animate>;
|
2015-07-28 17:08:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AntTag.defaultProps = {
|
|
|
|
prefixCls: prefixCls,
|
|
|
|
closable: false,
|
2015-08-20 13:43:57 +08:00
|
|
|
onClose: function() {}
|
2015-07-28 17:08:06 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default AntTag;
|