2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2022-05-23 15:41:59 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
2022-09-30 10:17:49 +08:00
|
|
|
import type { AbstractTooltipProps } from '../tooltip';
|
2022-05-07 14:31:54 +08:00
|
|
|
import Tooltip from '../tooltip';
|
|
|
|
import type { RenderFunction } from '../_util/getRenderPropValue';
|
|
|
|
import { getRenderPropValue } from '../_util/getRenderPropValue';
|
2021-02-08 17:09:13 +08:00
|
|
|
import { getTransitionName } from '../_util/motion';
|
2015-06-17 16:58:13 +08:00
|
|
|
|
2016-11-30 16:43:35 +08:00
|
|
|
export interface PopoverProps extends AbstractTooltipProps {
|
2020-03-10 13:57:02 +08:00
|
|
|
title?: React.ReactNode | RenderFunction;
|
|
|
|
content?: React.ReactNode | RenderFunction;
|
2022-06-01 18:28:31 +08:00
|
|
|
/** @private Used For Popconfirm. Safe to remove. */
|
2022-05-23 15:41:59 +08:00
|
|
|
_overlay?: React.ReactNode;
|
2016-07-29 14:45:06 +08:00
|
|
|
}
|
|
|
|
|
2022-09-30 10:17:49 +08:00
|
|
|
interface OverlayPorps {
|
|
|
|
prefixCls?: string;
|
|
|
|
title?: PopoverProps['title'];
|
|
|
|
content?: PopoverProps['content'];
|
|
|
|
}
|
|
|
|
|
|
|
|
const Overlay: React.FC<OverlayPorps> = ({ title, content, prefixCls }) => {
|
|
|
|
if (!title && !content) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{title && <div className={`${prefixCls}-title`}>{getRenderPropValue(title)}</div>}
|
|
|
|
<div className={`${prefixCls}-inner-content`}>{getRenderPropValue(content)}</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const Popover = React.forwardRef<unknown, PopoverProps>((props, ref) => {
|
|
|
|
const {
|
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
title,
|
|
|
|
content,
|
|
|
|
_overlay,
|
|
|
|
placement = 'top',
|
|
|
|
trigger = 'hover',
|
|
|
|
mouseEnterDelay = 0.1,
|
|
|
|
mouseLeaveDelay = 0.1,
|
|
|
|
overlayStyle = {},
|
|
|
|
...otherProps
|
|
|
|
} = props;
|
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
|
|
|
|
|
|
|
const prefixCls = getPrefixCls('popover', customizePrefixCls);
|
|
|
|
const rootPrefixCls = getPrefixCls();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Tooltip
|
|
|
|
placement={placement}
|
|
|
|
trigger={trigger}
|
|
|
|
mouseEnterDelay={mouseEnterDelay}
|
|
|
|
mouseLeaveDelay={mouseLeaveDelay}
|
|
|
|
overlayStyle={overlayStyle}
|
|
|
|
{...otherProps}
|
|
|
|
prefixCls={prefixCls}
|
|
|
|
ref={ref}
|
|
|
|
overlay={_overlay || <Overlay prefixCls={prefixCls} title={title} content={content} />}
|
|
|
|
transitionName={getTransitionName(rootPrefixCls, 'zoom-big', otherProps.transitionName)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
2018-12-05 19:12:18 +08:00
|
|
|
|
2022-06-21 10:24:52 +08:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
Popover.displayName = 'Popover';
|
|
|
|
}
|
2020-04-27 11:59:05 +08:00
|
|
|
|
|
|
|
export default Popover;
|