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.
75 lines
1.9 KiB
75 lines
1.9 KiB
9 years ago
|
import React from 'react';
|
||
9 years ago
|
import ReactDOM from 'react-dom';
|
||
9 years ago
|
import Animate from 'rc-animate';
|
||
9 years ago
|
import Icon from '../icon';
|
||
9 years ago
|
import classNames from 'classnames';
|
||
9 years ago
|
import splitObject from '../_util/splitObject';
|
||
9 years ago
|
export default class Tag extends React.Component {
|
||
9 years ago
|
static defaultProps = {
|
||
|
prefixCls: 'ant-tag',
|
||
|
closable: false,
|
||
|
onClose() {},
|
||
|
afterClose() {},
|
||
|
}
|
||
|
|
||
9 years ago
|
constructor(props) {
|
||
|
super(props);
|
||
|
|
||
|
this.state = {
|
||
9 years ago
|
closing: false,
|
||
9 years ago
|
closed: false,
|
||
9 years ago
|
};
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
close = (e) => {
|
||
9 years ago
|
this.props.onClose(e);
|
||
9 years ago
|
if (e.defaultPrevented) return;
|
||
9 years ago
|
const dom = ReactDOM.findDOMNode(this);
|
||
9 years ago
|
dom.style.width = `${dom.getBoundingClientRect().width}px`;
|
||
9 years ago
|
// It's Magic Code, don't know why
|
||
9 years ago
|
dom.style.width = `${dom.getBoundingClientRect().width}px`;
|
||
9 years ago
|
this.setState({
|
||
9 years ago
|
closing: true,
|
||
9 years ago
|
});
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
9 years ago
|
animationEnd = (key, existed) => {
|
||
9 years ago
|
if (!existed && !this.state.closed) {
|
||
9 years ago
|
this.setState({
|
||
|
closed: true,
|
||
|
closing: false,
|
||
|
});
|
||
|
this.props.afterClose();
|
||
|
}
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
9 years ago
|
render() {
|
||
9 years ago
|
const [{
|
||
|
prefixCls, closable, color, className, children
|
||
|
},restProps] = splitObject(this.props,
|
||
|
['prefixCls', 'closable', 'color','className','children']);
|
||
9 years ago
|
const close = closable ? <Icon type="cross" onClick={this.close} /> : '';
|
||
9 years ago
|
const classString = classNames({
|
||
9 years ago
|
[prefixCls]: true,
|
||
9 years ago
|
[`${prefixCls}-${color}`]: !!color,
|
||
|
[`${prefixCls}-close`]: this.state.closing,
|
||
9 years ago
|
[className]: !!className,
|
||
9 years ago
|
});
|
||
9 years ago
|
return (
|
||
9 years ago
|
<Animate component=""
|
||
|
showProp="data-show"
|
||
9 years ago
|
transitionName={`${prefixCls}-zoom`}
|
||
9 years ago
|
transitionAppear
|
||
9 years ago
|
onEnd={this.animationEnd}
|
||
|
>
|
||
9 years ago
|
{this.state.closed ? null : (
|
||
9 years ago
|
<div data-show={!this.state.closing} {...restProps} className={classString}>
|
||
|
<span className={`${prefixCls}-text`}>{children}</span>
|
||
9 years ago
|
{close}
|
||
|
</div>
|
||
|
)}
|
||
9 years ago
|
</Animate>
|
||
|
);
|
||
9 years ago
|
}
|
||
|
}
|