2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2022-03-25 13:20:42 +08:00
|
|
|
import classNames from 'classnames';
|
2019-12-05 16:15:10 +08:00
|
|
|
import Tooltip, { AbstractTooltipProps, TooltipPlacement } from '../tooltip';
|
2020-04-27 11:59:05 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
2020-03-10 13:57:02 +08:00
|
|
|
import { getRenderPropValue, RenderFunction } from '../_util/getRenderPropValue';
|
2021-02-08 17:09:13 +08:00
|
|
|
import { getTransitionName } from '../_util/motion';
|
2015-06-17 16:58:13 +08:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-04-27 11:59:05 +08:00
|
|
|
const Popover = React.forwardRef<unknown, PopoverProps>(
|
2022-03-25 13:20:42 +08:00
|
|
|
({ prefixCls: customizePrefixCls, title, content, overlayClassName, ...otherProps }, ref) => {
|
2022-04-07 21:50:35 +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);
|
2022-04-07 21:50:35 +08:00
|
|
|
const [wrapSSR, hashId] = useStyle(prefixCls);
|
2021-02-08 17:09:13 +08:00
|
|
|
const rootPrefixCls = getPrefixCls();
|
|
|
|
|
2022-03-25 17:54:57 +08:00
|
|
|
const overlayCls = classNames(overlayClassName, hashId);
|
2022-03-25 13:20:42 +08:00
|
|
|
|
|
|
|
return wrapSSR(
|
2016-11-30 15:46:50 +08:00
|
|
|
<Tooltip
|
2020-04-27 11:59:05 +08:00
|
|
|
{...otherProps}
|
2018-12-05 19:12:18 +08:00
|
|
|
prefixCls={prefixCls}
|
2022-03-25 13:20:42 +08:00
|
|
|
overlayClassName={overlayCls}
|
2020-04-27 11:59:05 +08:00
|
|
|
ref={ref as any}
|
|
|
|
overlay={getOverlay(prefixCls)}
|
2021-02-08 17:09:13 +08:00
|
|
|
transitionName={getTransitionName(rootPrefixCls, 'zoom-big', otherProps.transitionName)}
|
2022-03-25 13:20:42 +08:00
|
|
|
/>,
|
2016-11-30 15:46:50 +08:00
|
|
|
);
|
2020-04-27 11:59:05 +08:00
|
|
|
},
|
|
|
|
);
|
2018-12-05 19:12:18 +08:00
|
|
|
|
2020-04-27 11:59:05 +08:00
|
|
|
Popover.displayName = 'Popover';
|
|
|
|
|
|
|
|
Popover.defaultProps = {
|
|
|
|
placement: 'top' as TooltipPlacement,
|
|
|
|
trigger: 'hover',
|
|
|
|
mouseEnterDelay: 0.1,
|
|
|
|
mouseLeaveDelay: 0.1,
|
|
|
|
overlayStyle: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Popover;
|