ant-design/components/tag/index.jsx
2015-08-19 19:21:40 +08:00

46 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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