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.

55 lines
1.4 KiB

import React from 'react';
const prefixCls = 'ant-tag';
9 years ago
import { transitionEndEvent, addEventListenerOnce } from '../util/index';
class AntTag extends React.Component {
constructor(props) {
super(props);
this.state = {
9 years ago
closing: false,
closed: false
};
}
9 years ago
close(e) {
let dom = React.findDOMNode(this);
dom.style.width = dom.offsetWidth + 'px';
// Magic code
// 重复是去除浏览器渲染bug;
dom.style.width = dom.offsetWidth + 'px';
this.setState({
9 years ago
closing: true
});
addEventListenerOnce(dom, transitionEndEvent, () => {
this.setState({
closed: true,
closing: false
});
});
this.props.onClose.call(this, e);
}
render() {
9 years ago
let close = this.props.closable ?
<i className="anticon anticon-cross" onClick={this.close.bind(this)}></i> : '';
9 years ago
let colorClass = this.props.color ? this.props.prefixCls + '-' + this.props.color : '';
9 years ago
let className = this.props.prefixCls + ' ' + colorClass;
9 years ago
className = this.state.closing ? className + ' ' + this.props.prefixCls + '-close' : className;
9 years ago
return (this.state.closed && !this.state.closing) ? null : <div className={className}>
9 years ago
<a className={this.props.prefixCls + '-text'} {...this.props} />
{close}
</div>;
}
}
AntTag.defaultProps = {
prefixCls: prefixCls,
closable: false,
onClose: function () {}
};
export default AntTag;