mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-03 00:09:39 +08:00
c4b8c9df93
* refactor: genStyleHooks * chore: update sciprt * refactor: affix * refactor: select * chore: update * refactor: update * refactor: update * refactor: done * chore: code clean * chore: code clean * chore: fix lint * chore: decrease size limit * chore: code clean * chore: code clean * chore: remove export
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
import classNames from 'classnames';
|
|
import { Popup } from 'rc-tooltip';
|
|
import * as React from 'react';
|
|
import type { PopoverProps } from '.';
|
|
import { ConfigContext } from '../config-provider';
|
|
|
|
import { getRenderPropValue } from '../_util/getRenderPropValue';
|
|
import useStyle from './style';
|
|
|
|
export const getOverlay = (
|
|
prefixCls: string,
|
|
title?: PopoverProps['title'],
|
|
content?: PopoverProps['content'],
|
|
) => {
|
|
if (!title && !content) return undefined;
|
|
return (
|
|
<>
|
|
{title && <div className={`${prefixCls}-title`}>{getRenderPropValue(title)}</div>}
|
|
<div className={`${prefixCls}-inner-content`}>{getRenderPropValue(content)}</div>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export interface PurePanelProps extends Omit<PopoverProps, 'children'> {
|
|
children?: React.ReactNode;
|
|
}
|
|
|
|
interface RawPurePanelProps extends PopoverProps {
|
|
hashId: string;
|
|
}
|
|
|
|
export const RawPurePanel: React.FC<RawPurePanelProps> = (props) => {
|
|
const {
|
|
hashId,
|
|
prefixCls,
|
|
className,
|
|
style,
|
|
placement = 'top',
|
|
title,
|
|
content,
|
|
children,
|
|
} = props;
|
|
|
|
return (
|
|
<div
|
|
className={classNames(
|
|
hashId,
|
|
prefixCls,
|
|
`${prefixCls}-pure`,
|
|
`${prefixCls}-placement-${placement}`,
|
|
className,
|
|
)}
|
|
style={style}
|
|
>
|
|
<div className={`${prefixCls}-arrow`} />
|
|
<Popup {...props} className={hashId} prefixCls={prefixCls}>
|
|
{children || getOverlay(prefixCls!, title, content)}
|
|
</Popup>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const PurePanel: React.FC<PurePanelProps> = (props) => {
|
|
const { prefixCls: customizePrefixCls, ...restProps } = props;
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
|
|
|
const prefixCls = getPrefixCls('popover', customizePrefixCls);
|
|
const [wrapCSSVar, hashId] = useStyle(prefixCls);
|
|
|
|
return wrapCSSVar(<RawPurePanel {...restProps} prefixCls={prefixCls} hashId={hashId} />);
|
|
};
|
|
|
|
export default PurePanel;
|