@@ -2,7 +2,7 @@ import type { ArrowType, TriggerProps, TriggerRef } from '@rc-component/trigger'
2
2
import Trigger from '@rc-component/trigger' ;
3
3
import type { ActionType , AlignType } from '@rc-component/trigger/lib/interface' ;
4
4
import useId from '@rc-component/util/lib/hooks/useId' ;
5
- import classNames from 'classnames' ;
5
+ import cls from 'classnames' ;
6
6
import * as React from 'react' ;
7
7
import { useImperativeHandle , useRef } from 'react' ;
8
8
import { placements } from './placements' ;
@@ -30,13 +30,6 @@ export interface TooltipProps
30
30
/** Config popup motion */
31
31
motion ?: TriggerProps [ 'popupMotion' ] ;
32
32
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
-
40
33
// Rest
41
34
trigger ?: ActionType | ActionType [ ] ;
42
35
defaultVisible ?: boolean ;
@@ -67,11 +60,9 @@ export interface TooltipRef extends TriggerRef {}
67
60
68
61
const Tooltip = React . forwardRef < TooltipRef , TooltipProps > ( ( props , ref ) => {
69
62
const {
70
- overlayClassName,
71
63
trigger = [ 'hover' ] ,
72
64
mouseEnterDelay = 0 ,
73
65
mouseLeaveDelay = 0.1 ,
74
- overlayStyle,
75
66
prefixCls = 'rc-tooltip' ,
76
67
children,
77
68
onVisibleChange,
@@ -82,13 +73,12 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
82
73
destroyOnHidden = false ,
83
74
defaultVisible,
84
75
getTooltipContainer,
85
- overlayInnerStyle,
86
76
arrowContent,
87
77
overlay,
88
78
id,
89
79
showArrow = true ,
90
- classNames : tooltipClassNames ,
91
- styles : tooltipStyles ,
80
+ classNames,
81
+ styles,
92
82
...restProps
93
83
} = props ;
94
84
@@ -103,31 +93,9 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
103
93
extraProps . popupVisible = props . visible ;
104
94
}
105
95
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 ==========================
129
97
// Process arrow configuration
130
- const getArrowConfig = ( ) => {
98
+ const mergedArrow = React . useMemo ( ( ) => {
131
99
if ( ! showArrow ) {
132
100
return false ;
133
101
}
@@ -138,16 +106,38 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
138
106
// Apply semantic styles with unified logic
139
107
return {
140
108
...arrowConfig ,
141
- className : classNames ( arrowConfig . className , tooltipClassNames ?. arrow ) ,
109
+ className : cls ( arrowConfig . className , classNames ?. arrow ) ,
142
110
content : arrowConfig . content || arrowContent ,
143
111
} ;
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 ;
144
123
} ;
145
124
125
+ // ========================= Render =========================
146
126
return (
147
127
< Trigger
148
- popupClassName = { classNames ( overlayClassName , tooltipClassNames ?. root ) }
128
+ popupClassName = { classNames ?. root }
149
129
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
+ }
151
141
action = { trigger }
152
142
builtinPlacements = { placements }
153
143
popupPlacement = { placement }
@@ -160,9 +150,9 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
160
150
defaultPopupVisible = { defaultVisible }
161
151
autoDestroy = { destroyOnHidden }
162
152
mouseLeaveDelay = { mouseLeaveDelay }
163
- popupStyle = { { ... overlayStyle , ... tooltipStyles ?. root } }
153
+ popupStyle = { styles ?. root }
164
154
mouseEnterDelay = { mouseEnterDelay }
165
- arrow = { getArrowConfig ( ) }
155
+ arrow = { mergedArrow }
166
156
{ ...extraProps }
167
157
>
168
158
{ getChildren ( ) }
0 commit comments