2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2019-12-05 16:15:10 +08:00
|
|
|
import Tooltip, { AbstractTooltipProps, TooltipPlacement } from '../tooltip';
|
2018-12-05 19:12:18 +08:00
|
|
|
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
2015-06-17 16:58:13 +08:00
|
|
|
|
2016-11-30 16:43:35 +08:00
|
|
|
export interface PopoverProps extends AbstractTooltipProps {
|
2018-12-07 20:02:01 +08:00
|
|
|
title?: React.ReactNode;
|
|
|
|
content?: React.ReactNode;
|
2016-07-29 14:45:06 +08:00
|
|
|
}
|
|
|
|
|
2017-11-21 15:37:39 +08:00
|
|
|
export default class Popover extends React.Component<PopoverProps, {}> {
|
2016-03-29 14:01:10 +08:00
|
|
|
static defaultProps = {
|
2018-04-10 10:50:59 +08:00
|
|
|
placement: 'top' as TooltipPlacement,
|
2016-04-07 15:02:22 +08:00
|
|
|
transitionName: 'zoom-big',
|
2019-12-05 16:15:10 +08:00
|
|
|
trigger: 'hover',
|
2016-03-29 14:01:10 +08:00
|
|
|
mouseEnterDelay: 0.1,
|
|
|
|
mouseLeaveDelay: 0.1,
|
2016-04-01 01:36:42 +08:00
|
|
|
overlayStyle: {},
|
2016-07-13 11:14:24 +08:00
|
|
|
};
|
2016-03-29 14:01:10 +08:00
|
|
|
|
2017-09-17 15:48:44 +08:00
|
|
|
private tooltip: Tooltip;
|
2016-11-30 16:43:35 +08:00
|
|
|
|
2015-11-04 17:15:33 +08:00
|
|
|
getPopupDomNode() {
|
2017-09-08 09:44:29 +08:00
|
|
|
return this.tooltip.getPopupDomNode();
|
2016-03-20 20:41:34 +08:00
|
|
|
}
|
2015-11-04 17:15:33 +08:00
|
|
|
|
2018-12-05 19:12:18 +08:00
|
|
|
getOverlay(prefixCls: string) {
|
|
|
|
const { title, content } = this.props;
|
2016-01-07 14:21:29 +08:00
|
|
|
return (
|
|
|
|
<div>
|
2016-04-01 01:36:42 +08:00
|
|
|
{title && <div className={`${prefixCls}-title`}>{title}</div>}
|
2018-12-07 20:02:01 +08:00
|
|
|
<div className={`${prefixCls}-inner-content`}>{content}</div>
|
2015-09-28 21:02:04 +08:00
|
|
|
</div>
|
2016-01-07 14:21:29 +08:00
|
|
|
);
|
2016-03-20 20:41:34 +08:00
|
|
|
}
|
2016-11-30 15:46:50 +08:00
|
|
|
|
2017-11-21 15:37:39 +08:00
|
|
|
saveTooltip = (node: any) => {
|
2017-09-08 09:44:29 +08:00
|
|
|
this.tooltip = node;
|
2018-12-07 20:02:01 +08:00
|
|
|
};
|
2017-09-08 09:44:29 +08:00
|
|
|
|
2018-12-05 19:12:18 +08:00
|
|
|
renderPopover = ({ getPrefixCls }: ConfigConsumerProps) => {
|
|
|
|
const { prefixCls: customizePrefixCls, ...props } = this.props;
|
2016-11-30 15:46:50 +08:00
|
|
|
delete props.title;
|
2018-12-05 19:12:18 +08:00
|
|
|
const prefixCls = getPrefixCls('popover', customizePrefixCls);
|
2016-11-30 15:46:50 +08:00
|
|
|
return (
|
|
|
|
<Tooltip
|
|
|
|
{...props}
|
2018-12-05 19:12:18 +08:00
|
|
|
prefixCls={prefixCls}
|
2017-09-08 09:44:29 +08:00
|
|
|
ref={this.saveTooltip}
|
2018-12-05 19:12:18 +08:00
|
|
|
overlay={this.getOverlay(prefixCls)}
|
2016-11-30 15:46:50 +08:00
|
|
|
/>
|
|
|
|
);
|
2018-12-07 20:02:01 +08:00
|
|
|
};
|
2018-12-05 19:12:18 +08:00
|
|
|
|
|
|
|
render() {
|
2018-12-07 20:02:01 +08:00
|
|
|
return <ConfigConsumer>{this.renderPopover}</ConfigConsumer>;
|
2018-12-05 19:12:18 +08:00
|
|
|
}
|
2016-03-20 20:41:34 +08:00
|
|
|
}
|