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-05-07 14:31:54 +08:00
|
|
|
import type { AbstractTooltipProps, TooltipPlacement } from '../tooltip';
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-04-27 11:59:05 +08:00
|
|
|
const Popover = React.forwardRef<unknown, PopoverProps>(
|
2022-05-23 15:41:59 +08:00
|
|
|
({ prefixCls: customizePrefixCls, title, content, _overlay, ...otherProps }, ref) => {
|
2020-04-27 11:59:05 +08:00
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
2016-03-29 14:01:10 +08:00
|
|
|
|
2022-02-07 15:28:46 +08:00
|
|
|
const getOverlay = (prefixCls: string) => {
|
|
|
|
if (!title && !content) return undefined;
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{title && <div className={`${prefixCls}-title`}>{getRenderPropValue(title)}</div>}
|
|
|
|
<div className={`${prefixCls}-inner-content`}>{getRenderPropValue(content)}</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2016-11-30 16:43:35 +08:00
|
|
|
|
2018-12-05 19:12:18 +08:00
|
|
|
const prefixCls = getPrefixCls('popover', customizePrefixCls);
|
2021-02-08 17:09:13 +08:00
|
|
|
const rootPrefixCls = getPrefixCls();
|
|
|
|
|
2016-11-30 15:46:50 +08:00
|
|
|
return (
|
|
|
|
<Tooltip
|
2020-04-27 11:59:05 +08:00
|
|
|
{...otherProps}
|
2018-12-05 19:12:18 +08:00
|
|
|
prefixCls={prefixCls}
|
2020-04-27 11:59:05 +08:00
|
|
|
ref={ref as any}
|
2022-05-23 15:41:59 +08:00
|
|
|
overlay={_overlay || getOverlay(prefixCls)}
|
2021-02-08 17:09:13 +08:00
|
|
|
transitionName={getTransitionName(rootPrefixCls, 'zoom-big', otherProps.transitionName)}
|
2016-11-30 15:46:50 +08:00
|
|
|
/>
|
|
|
|
);
|
2020-04-27 11:59:05 +08:00
|
|
|
},
|
|
|
|
);
|
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
|
|
|
|
|
|
|
Popover.defaultProps = {
|
|
|
|
placement: 'top' as TooltipPlacement,
|
|
|
|
trigger: 'hover',
|
|
|
|
mouseEnterDelay: 0.1,
|
|
|
|
mouseLeaveDelay: 0.1,
|
|
|
|
overlayStyle: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Popover;
|