ant-design/components/popover/index.tsx

59 lines
1.6 KiB
TypeScript
Raw Normal View History

import * as React from 'react';
import Tooltip, { AbstractTooltipProps, TooltipPlacement } from '../tooltip';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import { getRenderPropValue, RenderFunction } from '../_util/getRenderPropValue';
2015-06-17 16:58:13 +08:00
2016-11-30 16:43:35 +08:00
export interface PopoverProps extends AbstractTooltipProps {
title?: React.ReactNode | RenderFunction;
content?: React.ReactNode | RenderFunction;
2016-07-29 14:45:06 +08:00
}
export default class Popover extends React.Component<PopoverProps, {}> {
static defaultProps = {
placement: 'top' as TooltipPlacement,
2016-04-07 15:02:22 +08:00
transitionName: 'zoom-big',
trigger: 'hover',
mouseEnterDelay: 0.1,
mouseLeaveDelay: 0.1,
2016-04-01 01:36:42 +08:00
overlayStyle: {},
2016-07-13 11:14:24 +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() {
return this.tooltip.getPopupDomNode();
}
2015-11-04 17:15:33 +08:00
getOverlay(prefixCls: string) {
const { title, content } = this.props;
return (
<>
{title && <div className={`${prefixCls}-title`}>{getRenderPropValue(title)}</div>}
<div className={`${prefixCls}-inner-content`}>{getRenderPropValue(content)}</div>
</>
);
}
saveTooltip = (node: any) => {
this.tooltip = node;
2018-12-07 20:02:01 +08:00
};
renderPopover = ({ getPrefixCls }: ConfigConsumerProps) => {
const { prefixCls: customizePrefixCls, ...props } = this.props;
delete props.title;
const prefixCls = getPrefixCls('popover', customizePrefixCls);
return (
<Tooltip
{...props}
prefixCls={prefixCls}
ref={this.saveTooltip}
overlay={this.getOverlay(prefixCls)}
/>
);
2018-12-07 20:02:01 +08:00
};
render() {
2018-12-07 20:02:01 +08:00
return <ConfigConsumer>{this.renderPopover}</ConfigConsumer>;
}
}