You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.5 KiB

import React from 'react';
import ReactDOM from 'react-dom';
import Animate from 'rc-animate';
import Icon from '../iconfont';
const prefixCls = 'ant-tag';
class AntTag extends React.Component {
constructor(props) {
super(props);
this.state = {
closing: false,
closed: false
};
}
9 years ago
close(e) {
let dom = ReactDOM.findDOMNode(this);
dom.style.width = dom.offsetWidth + 'px';
// It's Magic Code, don't know why
dom.style.width = dom.offsetWidth + 'px';
this.setState({
closing: true
});
this.props.onClose.call(this, e);
}
animationEnd() {
this.setState({
closed: true,
closing: false
});
}
render() {
9 years ago
let close = this.props.closable ?
<Icon type="cross" onClick={this.close.bind(this)} /> : '';
9 years ago
let colorClass = this.props.color ? this.props.prefixCls + '-' + this.props.color : '';
let className = this.props.prefixCls + ' ' + colorClass;
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}>
<a className={this.props.prefixCls + '-text'} {...this.props} />
{close}
</div>
</Animate>;
}
}
AntTag.defaultProps = {
prefixCls: prefixCls,
closable: false,
onClose: function() {}
};
export default AntTag;