2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
2023-10-20 14:53:36 +08:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { RenderFunction } from '../_util/getRenderPropValue';
|
|
|
|
import { getRenderPropValue } from '../_util/getRenderPropValue';
|
2021-02-08 17:09:13 +08:00
|
|
|
import { getTransitionName } from '../_util/motion';
|
2023-05-08 19:33:34 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
2023-07-08 17:39:59 +08:00
|
|
|
import type { AbstractTooltipProps, TooltipRef } from '../tooltip';
|
2023-05-08 19:33:34 +08:00
|
|
|
import Tooltip from '../tooltip';
|
2022-10-11 20:29:55 +08:00
|
|
|
import PurePanel from './PurePanel';
|
2022-03-25 13:20:42 +08:00
|
|
|
// CSSINJS
|
|
|
|
import useStyle from './style';
|
|
|
|
|
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;
|
2016-07-29 14:45:06 +08:00
|
|
|
}
|
|
|
|
|
2023-02-23 21:56:43 +08:00
|
|
|
interface OverlayProps {
|
2022-09-30 10:17:49 +08:00
|
|
|
prefixCls?: string;
|
|
|
|
title?: PopoverProps['title'];
|
|
|
|
content?: PopoverProps['content'];
|
|
|
|
}
|
|
|
|
|
2023-05-08 19:33:34 +08:00
|
|
|
const Overlay: React.FC<OverlayProps> = ({ title, content, prefixCls }) => (
|
|
|
|
<>
|
|
|
|
{title && <div className={`${prefixCls}-title`}>{getRenderPropValue(title)}</div>}
|
|
|
|
<div className={`${prefixCls}-inner-content`}>{getRenderPropValue(content)}</div>
|
|
|
|
</>
|
|
|
|
);
|
2016-03-29 14:01:10 +08:00
|
|
|
|
2023-07-08 17:39:59 +08:00
|
|
|
const Popover = React.forwardRef<TooltipRef, PopoverProps>((props, ref) => {
|
2022-09-30 10:17:49 +08:00
|
|
|
const {
|
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
title,
|
|
|
|
content,
|
2022-10-11 20:29:55 +08:00
|
|
|
overlayClassName,
|
2022-09-30 10:17:49 +08:00
|
|
|
placement = 'top',
|
|
|
|
trigger = 'hover',
|
|
|
|
mouseEnterDelay = 0.1,
|
|
|
|
mouseLeaveDelay = 0.1,
|
|
|
|
overlayStyle = {},
|
|
|
|
...otherProps
|
|
|
|
} = props;
|
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
2021-02-08 17:09:13 +08:00
|
|
|
|
2022-09-30 10:17:49 +08:00
|
|
|
const prefixCls = getPrefixCls('popover', customizePrefixCls);
|
2022-10-11 20:29:55 +08:00
|
|
|
const [wrapSSR, hashId] = useStyle(prefixCls);
|
2022-09-30 10:17:49 +08:00
|
|
|
const rootPrefixCls = getPrefixCls();
|
2022-03-25 13:20:42 +08:00
|
|
|
|
2022-10-11 20:29:55 +08:00
|
|
|
const overlayCls = classNames(overlayClassName, hashId);
|
|
|
|
|
|
|
|
return wrapSSR(
|
2023-10-23 17:16:41 +08:00
|
|
|
<Tooltip
|
|
|
|
placement={placement}
|
|
|
|
trigger={trigger}
|
|
|
|
mouseEnterDelay={mouseEnterDelay}
|
|
|
|
mouseLeaveDelay={mouseLeaveDelay}
|
|
|
|
overlayStyle={overlayStyle}
|
|
|
|
{...otherProps}
|
|
|
|
prefixCls={prefixCls}
|
|
|
|
overlayClassName={overlayCls}
|
|
|
|
ref={ref}
|
|
|
|
overlay={
|
|
|
|
title || content ? <Overlay prefixCls={prefixCls} title={title} content={content} /> : null
|
|
|
|
}
|
|
|
|
transitionName={getTransitionName(rootPrefixCls, 'zoom-big', otherProps.transitionName)}
|
|
|
|
data-popover-inject
|
|
|
|
/>,
|
2022-09-30 10:17:49 +08:00
|
|
|
);
|
2022-10-11 20:29:55 +08:00
|
|
|
}) as React.ForwardRefExoticComponent<
|
2022-07-14 12:06:18 +08:00
|
|
|
React.PropsWithoutRef<PopoverProps> & React.RefAttributes<unknown>
|
|
|
|
> & {
|
|
|
|
_InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel;
|
|
|
|
};
|
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
|
|
|
|
2022-07-14 12:06:18 +08:00
|
|
|
Popover._InternalPanelDoNotUseOrYouWillBeFired = PurePanel;
|
|
|
|
|
2020-04-27 11:59:05 +08:00
|
|
|
export default Popover;
|