ant-design/components/tooltip/PurePanel.tsx
二货爱吃白萝卜 86b5c50cb4
refactor: Tooltip support auto arrow & auto shift (#40632)
* chore: adjust doc

* chore: simplify arrow offset

* chore: auto adjust shift

* docs: adjust demo

* chore: update snapshot

* chore: provide ref

* test: prepare

* chore: update deps

* test: fix part test

* test: fix part test

* test: fix part test

* test: fix part test

* test: fix part test

* test: update snapshot

* fix: missing pure render

* fix: Popover pure panel

* test: update snapshot

* test: update tour snapshot

* chore: bump trigger ver

* test: fix render ssr logic

* test: skip unnecessary case

* test: fix test case

* test: update snapshot

* test: update snapshot

* test: update snapshot

* test: update snapshot

* test: update snapshot

* test: fix test case

* test: fix test case

* chore: clean up useless warning

* test: add check for placement

* chore: ignore default
2023-02-15 10:21:28 +08:00

57 lines
1.5 KiB
TypeScript

import classNames from 'classnames';
import { Popup } from 'rc-tooltip';
import * as React from 'react';
import type { TooltipProps } from '.';
import { ConfigContext } from '../config-provider';
import useStyle from './style';
import { parseColor } from './util';
export interface PurePanelProps extends Omit<TooltipProps, 'children'> {}
// ant-tooltip css-dev-only-do-not-override-w2s56n ant-tooltip-placement-top ant-tooltip-hidden
export default function PurePanel(props: PurePanelProps) {
const {
prefixCls: customizePrefixCls,
className,
placement = 'top',
title,
color,
overlayInnerStyle,
} = props;
const { getPrefixCls } = React.useContext(ConfigContext);
const prefixCls = getPrefixCls('tooltip', customizePrefixCls);
const [wrapSSR, hashId] = useStyle(prefixCls, true);
// Color
const colorInfo = parseColor(prefixCls, color);
const formattedOverlayInnerStyle = { ...overlayInnerStyle, ...colorInfo.overlayStyle };
const arrowContentStyle = colorInfo.arrowStyle;
return wrapSSR(
<div
className={classNames(
hashId,
prefixCls,
`${prefixCls}-pure`,
`${prefixCls}-placement-${placement}`,
className,
colorInfo.className,
)}
style={arrowContentStyle}
>
<div className={`${prefixCls}-arrow`} />
<Popup
{...props}
className={hashId}
prefixCls={prefixCls}
overlayInnerStyle={formattedOverlayInnerStyle}
>
{title}
</Popup>
</div>,
);
}