2015-07-28 17:08:06 +08:00
|
|
|
import React from 'react';
|
|
|
|
const prefixCls = 'ant-tag';
|
2015-08-20 11:46:02 +08:00
|
|
|
import { transitionEndEvent, addEventListenerOnce } from '../util/index';
|
2015-07-28 17:08:06 +08:00
|
|
|
|
2015-08-21 17:12:42 +08:00
|
|
|
import Animate from 'rc-animate';
|
|
|
|
|
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:12:42 +08:00
|
|
|
closing: true,
|
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-08-19 19:21:40 +08:00
|
|
|
let dom = React.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:12:42 +08:00
|
|
|
closing: false
|
2015-07-30 23:52:44 +08:00
|
|
|
});
|
2015-08-21 17:12:42 +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:12:42 +08:00
|
|
|
animationEnd() {
|
|
|
|
this.setState({
|
|
|
|
closed: true,
|
|
|
|
closing: true
|
|
|
|
});
|
|
|
|
}
|
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-07-30 23:52:44 +08:00
|
|
|
<i className="anticon anticon-cross" onClick={this.close.bind(this)}></i> : '';
|
2015-08-20 11:46:02 +08:00
|
|
|
let colorClass = this.props.color ? this.props.prefixCls + '-' + this.props.color : '';
|
2015-07-28 20:03:10 +08:00
|
|
|
|
2015-08-19 17:26:55 +08:00
|
|
|
let className = this.props.prefixCls + ' ' + colorClass;
|
2015-08-21 17:12:42 +08:00
|
|
|
className = !this.state.closing ? className + ' ' + this.props.prefixCls + '-close' : className;
|
|
|
|
|
|
|
|
return this.state.closed ? null
|
|
|
|
: <Animate
|
|
|
|
component=""
|
|
|
|
showProp='data-show'
|
|
|
|
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;
|