index.jsx 1.3 KB
Newer Older
A
afc163 已提交
1 2
import React from 'react';
import Tooltip from 'rc-tooltip';
3

A
afc163 已提交
4
const prefixCls = 'ant-popover';
A
afc163 已提交
5

6
const Popover = React.createClass({
A
afc163 已提交
7
  getDefaultProps() {
A
afc163 已提交
8
    return {
9
      prefixCls: prefixCls,
A
afc163 已提交
10
      placement: 'top',
Y
yiminghe 已提交
11
      trigger: 'hover',
12 13
      mouseEnterDelay: 0.1,
      mouseLeaveDelay: 0.1,
Y
yiminghe 已提交
14
      overlayStyle: {}
A
afc163 已提交
15 16
    };
  },
A
afc163 已提交
17

18
  render() {
A
afc163 已提交
19
    const transitionName = ({
A
afc163 已提交
20 21 22
      top: 'zoom-down',
      bottom: 'zoom-up',
      left: 'zoom-right',
23 24 25 26 27 28 29 30 31
      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',
A
afc163 已提交
32 33
    })[this.props.placement];

A
afc163 已提交
34
    return (
35
      <Tooltip transitionName={transitionName}
P
popomore 已提交
36
               ref="tooltip"
37 38
               {...this.props}
               overlay={this.getOverlay()}>
A
afc163 已提交
39 40 41
        {this.props.children}
      </Tooltip>
    );
42 43
  },

P
popomore 已提交
44
  getPopupDomNode() {
P
popomore 已提交
45
    return this.refs.tooltip.getPopupDomNode();
P
popomore 已提交
46 47
  },

48 49
  getOverlay() {
    return <div>
50
      {this.props.title && <div className={prefixCls + '-title'}>{this.props.title}</div>}
51 52 53 54 55
      <div className={prefixCls + '-content'}>
        {this.props.overlay}
      </div>
    </div>;
  },
A
afc163 已提交
56
});
57 58

export default Popover;