Skip to content

Commit 5cc8708

Browse files
committed
chore: align the case
1 parent b6343cb commit 5cc8708

File tree

2 files changed

+39
-50
lines changed

2 files changed

+39
-50
lines changed

src/Popup.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
import classNames from 'classnames';
1+
import cls from 'classnames';
22
import * as React from 'react';
3+
import type { TooltipProps } from './Tooltip';
34

45
export interface ContentProps {
56
prefixCls?: string;
67
children: (() => React.ReactNode) | React.ReactNode;
78
id?: string;
8-
overlayInnerStyle?: React.CSSProperties;
9-
className?: string;
10-
style?: React.CSSProperties;
11-
bodyClassName?: string;
9+
classNames?: TooltipProps['classNames'];
10+
styles?: TooltipProps['styles'];
1211
}
1312

1413
const Popup: React.FC<ContentProps> = (props) => {
15-
const { children, prefixCls, id, className, style, bodyClassName, overlayInnerStyle } = props;
14+
const { children, prefixCls, id, classNames, styles } = props;
1615

1716
return (
1817
<div
1918
id={id}
20-
className={classNames(`${prefixCls}-body`, className, bodyClassName)}
21-
style={{ ...overlayInnerStyle, ...style }}
19+
className={cls(`${prefixCls}-body`, classNames?.body)}
20+
style={styles.body}
2221
role="tooltip"
2322
>
2423
{typeof children === 'function' ? children() : children}

src/Tooltip.tsx

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ArrowType, TriggerProps, TriggerRef } from '@rc-component/trigger'
22
import Trigger from '@rc-component/trigger';
33
import type { ActionType, AlignType } from '@rc-component/trigger/lib/interface';
44
import useId from '@rc-component/util/lib/hooks/useId';
5-
import classNames from 'classnames';
5+
import cls from 'classnames';
66
import * as React from 'react';
77
import { useImperativeHandle, useRef } from 'react';
88
import { placements } from './placements';
@@ -30,13 +30,6 @@ export interface TooltipProps
3030
/** Config popup motion */
3131
motion?: TriggerProps['popupMotion'];
3232

33-
/** @deprecated Please use `styles={{ root: {} }}` */
34-
overlayStyle?: React.CSSProperties;
35-
/** @deprecated Please use `classNames={{ root: '' }}` */
36-
overlayClassName?: string;
37-
/** @deprecated Please use `styles={{ body: {} }}` */
38-
overlayInnerStyle?: React.CSSProperties;
39-
4033
// Rest
4134
trigger?: ActionType | ActionType[];
4235
defaultVisible?: boolean;
@@ -67,11 +60,9 @@ export interface TooltipRef extends TriggerRef {}
6760

6861
const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
6962
const {
70-
overlayClassName,
7163
trigger = ['hover'],
7264
mouseEnterDelay = 0,
7365
mouseLeaveDelay = 0.1,
74-
overlayStyle,
7566
prefixCls = 'rc-tooltip',
7667
children,
7768
onVisibleChange,
@@ -82,13 +73,12 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
8273
destroyOnHidden = false,
8374
defaultVisible,
8475
getTooltipContainer,
85-
overlayInnerStyle,
8676
arrowContent,
8777
overlay,
8878
id,
8979
showArrow = true,
90-
classNames: tooltipClassNames,
91-
styles: tooltipStyles,
80+
classNames,
81+
styles,
9282
...restProps
9383
} = props;
9484

@@ -103,31 +93,9 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
10393
extraProps.popupVisible = props.visible;
10494
}
10595

106-
const getPopupElement = () => (
107-
<Popup
108-
key="content"
109-
prefixCls={prefixCls}
110-
id={mergedId}
111-
bodyClassName={tooltipClassNames?.body}
112-
overlayInnerStyle={overlayInnerStyle}
113-
style={tooltipStyles?.body}
114-
>
115-
{overlay}
116-
</Popup>
117-
);
118-
119-
const getChildren = () => {
120-
const child = React.Children.only(children);
121-
const originalProps = child?.props || {};
122-
const childProps = {
123-
...originalProps,
124-
'aria-describedby': overlay ? mergedId : null,
125-
};
126-
return React.cloneElement<any>(children, childProps) as any;
127-
};
128-
96+
// ========================= Arrow ==========================
12997
// Process arrow configuration
130-
const getArrowConfig = () => {
98+
const mergedArrow = React.useMemo(() => {
13199
if (!showArrow) {
132100
return false;
133101
}
@@ -138,16 +106,38 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
138106
// Apply semantic styles with unified logic
139107
return {
140108
...arrowConfig,
141-
className: classNames(arrowConfig.className, tooltipClassNames?.arrow),
109+
className: cls(arrowConfig.className, classNames?.arrow),
142110
content: arrowConfig.content || arrowContent,
143111
};
112+
}, [showArrow, classNames?.arrow, arrowContent]);
113+
114+
// ======================== Children ========================
115+
const getChildren = () => {
116+
const child = React.Children.only(children);
117+
const originalProps = child?.props || {};
118+
const childProps = {
119+
...originalProps,
120+
'aria-describedby': overlay ? mergedId : null,
121+
};
122+
return React.cloneElement<any>(children, childProps) as any;
144123
};
145124

125+
// ========================= Render =========================
146126
return (
147127
<Trigger
148-
popupClassName={classNames(overlayClassName, tooltipClassNames?.root)}
128+
popupClassName={classNames?.root}
149129
prefixCls={prefixCls}
150-
popup={getPopupElement}
130+
popup={
131+
<Popup
132+
key="content"
133+
prefixCls={prefixCls}
134+
id={mergedId}
135+
classNames={classNames}
136+
styles={styles}
137+
>
138+
{overlay}
139+
</Popup>
140+
}
151141
action={trigger}
152142
builtinPlacements={placements}
153143
popupPlacement={placement}
@@ -160,9 +150,9 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
160150
defaultPopupVisible={defaultVisible}
161151
autoDestroy={destroyOnHidden}
162152
mouseLeaveDelay={mouseLeaveDelay}
163-
popupStyle={{ ...overlayStyle, ...tooltipStyles?.root }}
153+
popupStyle={styles?.root}
164154
mouseEnterDelay={mouseEnterDelay}
165-
arrow={getArrowConfig()}
155+
arrow={mergedArrow}
166156
{...extraProps}
167157
>
168158
{getChildren()}

0 commit comments

Comments
 (0)