ant-design/components/popover/index.jsx

70 lines
1.6 KiB
React
Raw Normal View History

2015-06-19 12:29:22 +08:00
import React from 'react';
import Tooltip from 'rc-tooltip';
import getPlacements from './placements';
import warning from 'warning';
const placements = getPlacements();
2015-06-17 16:58:13 +08:00
export default class Popover extends React.Component {
static defaultProps = {
2016-04-01 01:36:42 +08:00
prefixCls: 'ant-popover',
placement: 'top',
trigger: 'hover',
mouseEnterDelay: 0.1,
mouseLeaveDelay: 0.1,
2016-04-01 01:36:42 +08:00
overlayStyle: {},
}
render() {
2015-06-19 12:29:22 +08:00
const transitionName = ({
2015-06-17 17:10:10 +08:00
top: 'zoom-down',
bottom: 'zoom-up',
left: 'zoom-right',
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:10:10 +08:00
})[this.props.placement];
2015-06-17 16:58:13 +08:00
return (
<Tooltip transitionName={transitionName}
builtinPlacements={placements}
ref="tooltip"
{...this.props}
overlay={this.getOverlay()}>
2015-06-17 16:58:13 +08:00
{this.props.children}
</Tooltip>
);
}
2015-11-04 17:15:33 +08:00
getPopupDomNode() {
2015-11-04 21:07:00 +08:00
return this.refs.tooltip.getPopupDomNode();
}
2015-11-04 17:15:33 +08:00
componentDidMount() {
if ('overlay' in this.props) {
2016-04-01 23:06:38 +08:00
warning(false, '`overlay` prop of Popover is deprecated, use `content` instead.');
}
}
getOverlay() {
// use content replace overlay
// keep overlay for compatibility
const { title, prefixCls, overlay, content } = this.props;
return (
<div>
2016-04-01 01:36:42 +08:00
{title && <div className={`${prefixCls}-title`}>{title}</div>}
2016-03-17 15:10:49 +08:00
<div className={`${prefixCls}-inner-content`}>
{content || overlay}
</div>
</div>
);
}
}