2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
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';
|
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;
|
2016-07-29 14:45:06 +08:00
|
|
|
}
|
|
|
|
|
2020-04-27 11:59:05 +08:00
|
|
|
const Popover = React.forwardRef<unknown, PopoverProps>(
|
|
|
|
({ prefixCls: customizePrefixCls, title, content, ...otherProps }, ref) => {
|
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
2016-03-29 14:01:10 +08:00
|
|
|
|
2020-04-27 11:59:05 +08:00
|
|
|
const getOverlay = (prefixCls: string) => {
|
|
|
|
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);
|
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}
|
|
|
|
overlay={getOverlay(prefixCls)}
|
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,
|
|
|
|
transitionName: 'zoom-big',
|
|
|
|
trigger: 'hover',
|
|
|
|
mouseEnterDelay: 0.1,
|
|
|
|
mouseLeaveDelay: 0.1,
|
|
|
|
overlayStyle: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Popover;
|