2015-07-28 17:08:06 +08:00
|
|
|
import React from 'react';
|
2015-10-21 17:59:57 +08:00
|
|
|
import ReactDOM from 'react-dom';
|
2015-08-21 17:12:42 +08:00
|
|
|
import Animate from 'rc-animate';
|
2015-11-20 11:05:34 +08:00
|
|
|
import Icon from '../icon';
|
2016-01-27 01:47:12 +08:00
|
|
|
import classNames from 'classnames';
|
2015-08-21 17:12:42 +08:00
|
|
|
|
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:27:29 +08:00
|
|
|
closing: false,
|
2016-01-26 23:40:20 +08:00
|
|
|
closed: false,
|
2015-07-30 23:52:44 +08:00
|
|
|
};
|
|
|
|
}
|
2015-08-20 11:46:02 +08:00
|
|
|
|
2015-07-30 23:52:44 +08:00
|
|
|
close(e) {
|
2016-01-26 23:40:20 +08:00
|
|
|
const dom = ReactDOM.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({
|
2016-01-26 23:40:20 +08:00
|
|
|
closing: true,
|
2015-07-30 23:52:44 +08:00
|
|
|
});
|
2016-01-26 23:40:20 +08:00
|
|
|
this.props.onClose(e);
|
2015-07-28 17:08:06 +08:00
|
|
|
}
|
2015-08-21 17:27:29 +08:00
|
|
|
|
2016-01-27 01:20:05 +08:00
|
|
|
animationEnd(key, existed) {
|
|
|
|
if (!existed) {
|
|
|
|
this.setState({
|
|
|
|
closed: true,
|
|
|
|
closing: false,
|
|
|
|
});
|
|
|
|
this.props.afterClose();
|
|
|
|
}
|
2015-08-21 17:12:42 +08:00
|
|
|
}
|
2015-08-19 17:26:55 +08:00
|
|
|
|
2015-07-28 17:08:06 +08:00
|
|
|
render() {
|
2016-01-27 01:47:12 +08:00
|
|
|
const { prefixCls, closable, color, ...restProps } = this.props;
|
|
|
|
const close = closable ? <Icon type="cross" onClick={this.close.bind(this)} /> : '';
|
|
|
|
const className = classNames({
|
|
|
|
[prefixCls]: true,
|
|
|
|
[prefixCls + '-' + color]: !!color,
|
|
|
|
[prefixCls + '-close']: this.state.closing,
|
|
|
|
});
|
2016-01-27 01:51:54 +08:00
|
|
|
return (
|
2016-01-27 14:48:25 +08:00
|
|
|
<Animate component=""
|
|
|
|
showProp="data-show"
|
|
|
|
transitionName={prefixCls + '-zoom'}
|
|
|
|
transitionAppear
|
|
|
|
onEnd={this.animationEnd.bind(this)}>
|
2016-01-27 01:51:54 +08:00
|
|
|
{this.state.closed ? null : (
|
|
|
|
<div data-show={!this.state.closing} className={className}>
|
|
|
|
<span className={prefixCls + '-text'} {...restProps} />
|
|
|
|
{close}
|
|
|
|
</div>
|
|
|
|
)}
|
2016-01-26 23:40:20 +08:00
|
|
|
</Animate>
|
|
|
|
);
|
2015-07-28 17:08:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AntTag.defaultProps = {
|
2015-11-19 00:13:16 +08:00
|
|
|
prefixCls: 'ant-tag',
|
2015-07-28 17:08:06 +08:00
|
|
|
closable: false,
|
2016-01-26 23:40:20 +08:00
|
|
|
onClose() {},
|
2016-01-27 01:20:05 +08:00
|
|
|
afterClose() {},
|
2015-07-28 17:08:06 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default AntTag;
|