2024-01-03 08:45:11 +08:00
|
|
|
import * as React from 'react';
|
2022-07-14 12:06:18 +08:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import { Popup } from 'rc-tooltip';
|
|
|
|
|
2024-01-03 08:45:11 +08:00
|
|
|
import type { PopoverProps } from '.';
|
2022-07-14 12:06:18 +08:00
|
|
|
import { getRenderPropValue } from '../_util/getRenderPropValue';
|
2024-01-03 08:45:11 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
2023-02-15 10:21:28 +08:00
|
|
|
import useStyle from './style';
|
2022-07-14 12:06:18 +08:00
|
|
|
|
2024-07-26 16:40:45 +08:00
|
|
|
interface OverlayProps {
|
|
|
|
prefixCls?: string;
|
|
|
|
title?: React.ReactNode;
|
|
|
|
content?: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Overlay: React.FC<OverlayProps> = ({ title, content, prefixCls }) => {
|
2024-01-03 08:45:11 +08:00
|
|
|
if (!title && !content) {
|
|
|
|
return null;
|
|
|
|
}
|
2022-07-14 12:06:18 +08:00
|
|
|
return (
|
|
|
|
<>
|
2024-07-26 16:40:45 +08:00
|
|
|
{title && <div className={`${prefixCls}-title`}>{title}</div>}
|
|
|
|
{content && <div className={`${prefixCls}-inner-content`}>{content}</div>}
|
2022-07-14 12:06:18 +08:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export interface PurePanelProps extends Omit<PopoverProps, 'children'> {
|
2022-07-15 15:28:09 +08:00
|
|
|
children?: React.ReactNode;
|
2022-07-14 12:06:18 +08:00
|
|
|
}
|
|
|
|
|
2023-07-08 21:48:52 +08:00
|
|
|
interface RawPurePanelProps extends PopoverProps {
|
|
|
|
hashId: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const RawPurePanel: React.FC<RawPurePanelProps> = (props) => {
|
2022-11-03 11:06:34 +08:00
|
|
|
const {
|
|
|
|
hashId,
|
|
|
|
prefixCls,
|
|
|
|
className,
|
|
|
|
style,
|
|
|
|
placement = 'top',
|
|
|
|
title,
|
|
|
|
content,
|
|
|
|
children,
|
|
|
|
} = props;
|
2022-07-14 12:06:18 +08:00
|
|
|
|
2024-07-26 16:40:45 +08:00
|
|
|
const titleNode = getRenderPropValue(title);
|
|
|
|
const contentNode = getRenderPropValue(content);
|
|
|
|
|
|
|
|
const cls = classNames(
|
|
|
|
hashId,
|
|
|
|
prefixCls,
|
|
|
|
`${prefixCls}-pure`,
|
|
|
|
`${prefixCls}-placement-${placement}`,
|
|
|
|
className,
|
|
|
|
);
|
|
|
|
|
2022-11-03 00:43:26 +08:00
|
|
|
return (
|
2024-07-26 16:40:45 +08:00
|
|
|
<div className={cls} style={style}>
|
2023-02-15 10:21:28 +08:00
|
|
|
<div className={`${prefixCls}-arrow`} />
|
2022-07-14 12:06:18 +08:00
|
|
|
<Popup {...props} className={hashId} prefixCls={prefixCls}>
|
2024-07-26 16:40:45 +08:00
|
|
|
{children || <Overlay prefixCls={prefixCls} title={titleNode} content={contentNode} />}
|
2022-07-14 12:06:18 +08:00
|
|
|
</Popup>
|
2022-11-03 00:43:26 +08:00
|
|
|
</div>
|
2022-07-14 12:06:18 +08:00
|
|
|
);
|
2023-07-08 21:48:52 +08:00
|
|
|
};
|
2022-11-03 00:43:26 +08:00
|
|
|
|
2023-07-08 21:48:52 +08:00
|
|
|
const PurePanel: React.FC<PurePanelProps> = (props) => {
|
2023-12-14 14:58:53 +08:00
|
|
|
const { prefixCls: customizePrefixCls, className, ...restProps } = props;
|
2022-11-03 00:43:26 +08:00
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
|
|
|
|
|
|
|
const prefixCls = getPrefixCls('popover', customizePrefixCls);
|
2023-12-14 14:58:53 +08:00
|
|
|
const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);
|
2022-11-03 00:43:26 +08:00
|
|
|
|
2023-12-14 14:58:53 +08:00
|
|
|
return wrapCSSVar(
|
|
|
|
<RawPurePanel
|
|
|
|
{...restProps}
|
|
|
|
prefixCls={prefixCls}
|
|
|
|
hashId={hashId}
|
|
|
|
className={classNames(className, cssVarCls)}
|
|
|
|
/>,
|
|
|
|
);
|
2023-07-08 21:48:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default PurePanel;
|