index.jsx 1.2 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}
36 37
               {...this.props}
               overlay={this.getOverlay()}>
A
afc163 已提交
38 39 40
        {this.props.children}
      </Tooltip>
    );
41 42 43 44 45 46 47 48 49 50 51 52
  },

  getOverlay() {
    return <div>
      <div className={prefixCls + '-title'}>
        {this.props.title}
      </div>
      <div className={prefixCls + '-content'}>
        {this.props.overlay}
      </div>
    </div>;
  },
A
afc163 已提交
53
});
54 55

export default Popover;