ant-design/components/popover/index.tsx
Gibson C 428f743b50
feat: Support render props for <Popover/> and <Popconfirm/> (#22034)
* feat: Support render props for <Popover/>

* feat: Support render props for <Popconfirm/>

* docs: Update Popconfirm docs
2020-03-10 13:57:02 +08:00

59 lines
1.6 KiB
TypeScript

import * as React from 'react';
import Tooltip, { AbstractTooltipProps, TooltipPlacement } from '../tooltip';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import { getRenderPropValue, RenderFunction } from '../_util/getRenderPropValue';
export interface PopoverProps extends AbstractTooltipProps {
title?: React.ReactNode | RenderFunction;
content?: React.ReactNode | RenderFunction;
}
export default class Popover extends React.Component<PopoverProps, {}> {
static defaultProps = {
placement: 'top' as TooltipPlacement,
transitionName: 'zoom-big',
trigger: 'hover',
mouseEnterDelay: 0.1,
mouseLeaveDelay: 0.1,
overlayStyle: {},
};
private tooltip: Tooltip;
getPopupDomNode() {
return this.tooltip.getPopupDomNode();
}
getOverlay(prefixCls: string) {
const { title, content } = this.props;
return (
<div>
{title && <div className={`${prefixCls}-title`}>{getRenderPropValue(title)}</div>}
<div className={`${prefixCls}-inner-content`}>{getRenderPropValue(content)}</div>
</div>
);
}
saveTooltip = (node: any) => {
this.tooltip = node;
};
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)}
/>
);
};
render() {
return <ConfigConsumer>{this.renderPopover}</ConfigConsumer>;
}
}