index.jsx 957 字节
Newer Older
U
ustccjw 已提交
1 2
import React from 'react';
import Tooltip from 'rc-tooltip';
A
afc163 已提交
3

U
ustccjw 已提交
4
export default React.createClass({
A
afc163 已提交
5
  getDefaultProps() {
A
afc163 已提交
6
    return {
7 8 9 10
      prefixCls: 'ant-tooltip',
      placement: 'top',
      mouseEnterDelay: 0.1,
      mouseLeaveDelay: 0.1
A
afc163 已提交
11 12
    };
  },
13 14 15 16 17 18 19 20
  getInitialState() {
    return {
      visible: false
    };
  },
  onVisibleChange(visible) {
    this.setState({ visible });
  },
A
afc163 已提交
21
  render() {
A
afc163 已提交
22
    let transitionName = ({
A
afc163 已提交
23 24 25 26 27
      top: 'zoom-down',
      bottom: 'zoom-up',
      left: 'zoom-right',
      right: 'zoom-left'
    })[this.props.placement];
28 29 30 31 32 33 34

    // Hide tooltip when there is no title
    let visible = this.state.visible;
    if (!this.props.title) {
      visible = false;
    }

A
afc163 已提交
35
    return (
36
       <Tooltip transitionName={transitionName}
37
        overlay={this.props.title}
38 39
        visible={visible}
        onVisibleChange={this.onVisibleChange}
40
        {...this.props}>
A
afc163 已提交
41
        {this.props.children}
42
      </Tooltip>
A
afc163 已提交
43 44 45
    );
  }
});