2022-03-25 13:20:42 +08:00
|
|
|
import classNames from 'classnames';
|
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';
|
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
|
|
|
}
|
|
|
|
|
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>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2016-03-29 14:01:10 +08:00
|
|
|
|
2022-09-30 10:17:49 +08:00
|
|
|
const Popover = React.forwardRef<unknown, PopoverProps>((props, ref) => {
|
|
|
|
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 = {},
|
2023-01-19 11:21:05 +08:00
|
|
|
arrowPointAtCenter,
|
|
|
|
arrow,
|
2022-09-30 10:17:49 +08:00
|
|
|
...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);
|
|
|
|
|
2023-01-19 11:21:05 +08:00
|
|
|
const mergedArrowPointAtCenter =
|
|
|
|
(typeof arrow !== 'boolean' && arrow?.arrowPointAtCenter) ?? arrowPointAtCenter ?? false;
|
|
|
|
const mergedArrow = arrow ?? { arrowPointAtCenter: mergedArrowPointAtCenter };
|
|
|
|
|
2022-10-11 20:29:55 +08:00
|
|
|
return wrapSSR(
|
2022-09-30 10:17:49 +08:00
|
|
|
<Tooltip
|
|
|
|
placement={placement}
|
2023-01-19 11:21:05 +08:00
|
|
|
arrow={mergedArrow}
|
2022-09-30 10:17:49 +08:00
|
|
|
trigger={trigger}
|
|
|
|
mouseEnterDelay={mouseEnterDelay}
|
|
|
|
mouseLeaveDelay={mouseLeaveDelay}
|
|
|
|
overlayStyle={overlayStyle}
|
|
|
|
{...otherProps}
|
|
|
|
prefixCls={prefixCls}
|
2022-10-11 20:29:55 +08:00
|
|
|
overlayClassName={overlayCls}
|
2022-09-30 10:17:49 +08:00
|
|
|
ref={ref}
|
2022-12-06 23:14:30 +08:00
|
|
|
overlay={<Overlay prefixCls={prefixCls} title={title} content={content} />}
|
2022-09-30 10:17:49 +08:00
|
|
|
transitionName={getTransitionName(rootPrefixCls, 'zoom-big', otherProps.transitionName)}
|
2022-10-11 20:29:55 +08:00
|
|
|
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;
|