2015-07-23 22:23:11 +08:00
|
|
|
import React from 'react';
|
|
|
|
import Tooltip from 'rc-tooltip';
|
2015-06-03 17:08:43 +08:00
|
|
|
|
2015-07-23 22:23:11 +08:00
|
|
|
export default React.createClass({
|
2015-06-17 17:15:34 +08:00
|
|
|
getDefaultProps() {
|
2015-06-03 17:08:43 +08:00
|
|
|
return {
|
2015-09-24 18:38:31 +08:00
|
|
|
prefixCls: 'ant-tooltip',
|
|
|
|
placement: 'top',
|
|
|
|
mouseEnterDelay: 0.1,
|
|
|
|
mouseLeaveDelay: 0.1
|
2015-06-03 17:08:43 +08:00
|
|
|
};
|
|
|
|
},
|
2015-10-26 16:30:27 +08:00
|
|
|
getInitialState() {
|
|
|
|
return {
|
|
|
|
visible: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
onVisibleChange(visible) {
|
|
|
|
this.setState({ visible });
|
|
|
|
},
|
2015-06-17 17:15:34 +08:00
|
|
|
render() {
|
2015-09-01 16:18:46 +08:00
|
|
|
let transitionName = ({
|
2015-06-17 17:15:34 +08:00
|
|
|
top: 'zoom-down',
|
|
|
|
bottom: 'zoom-up',
|
|
|
|
left: 'zoom-right',
|
2015-11-03 13:50:36 +08:00
|
|
|
right: 'zoom-left',
|
|
|
|
topLeft: 'zoom-down',
|
|
|
|
bottomLeft: 'zoom-up',
|
|
|
|
leftTop: 'zoom-right',
|
|
|
|
rightTop: 'zoom-left',
|
|
|
|
topRight: 'zoom-down',
|
|
|
|
bottomRight: 'zoom-up',
|
|
|
|
leftBottom: 'zoom-right',
|
|
|
|
rightBottom: 'zoom-left',
|
2015-06-17 17:15:34 +08:00
|
|
|
})[this.props.placement];
|
2015-10-26 16:30:27 +08:00
|
|
|
|
|
|
|
// Hide tooltip when there is no title
|
|
|
|
let visible = this.state.visible;
|
|
|
|
if (!this.props.title) {
|
|
|
|
visible = false;
|
|
|
|
}
|
|
|
|
|
2015-06-10 17:59:32 +08:00
|
|
|
return (
|
2016-01-07 17:46:46 +08:00
|
|
|
<Tooltip transitionName={transitionName}
|
2015-09-24 18:38:31 +08:00
|
|
|
overlay={this.props.title}
|
2015-10-26 16:30:27 +08:00
|
|
|
visible={visible}
|
|
|
|
onVisibleChange={this.onVisibleChange}
|
2015-09-24 18:38:31 +08:00
|
|
|
{...this.props}>
|
2015-06-03 17:08:43 +08:00
|
|
|
{this.props.children}
|
2015-10-26 16:30:27 +08:00
|
|
|
</Tooltip>
|
2015-06-03 17:08:43 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|