@@ -2,12 +2,14 @@ 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' ;
9
9
import Popup from './Popup' ;
10
10
11
+ export type SemanticName = 'root' | 'arrow' | 'body' ;
12
+
11
13
export interface TooltipProps
12
14
extends Pick <
13
15
TriggerProps ,
@@ -21,56 +23,46 @@ export interface TooltipProps
21
23
| 'forceRender'
22
24
| 'popupVisible'
23
25
> {
26
+ // Style
27
+ classNames ?: Partial < Record < SemanticName , string > > ;
28
+ styles ?: Partial < Record < SemanticName , React . CSSProperties > > ;
29
+
30
+ /** Config popup motion */
31
+ motion ?: TriggerProps [ 'popupMotion' ] ;
32
+
33
+ // Rest
24
34
trigger ?: ActionType | ActionType [ ] ;
25
35
defaultVisible ?: boolean ;
26
36
visible ?: boolean ;
27
37
placement ?: string ;
28
- /** Config popup motion */
29
- motion ?: TriggerProps [ 'popupMotion' ] ;
38
+
30
39
onVisibleChange ?: ( visible : boolean ) => void ;
31
40
afterVisibleChange ?: ( visible : boolean ) => void ;
32
41
overlay : ( ( ) => React . ReactNode ) | React . ReactNode ;
33
- /** @deprecated Please use `styles={{ root: {} }}` */
34
- overlayStyle ?: React . CSSProperties ;
35
- /** @deprecated Please use `classNames={{ root: '' }}` */
36
- overlayClassName ?: string ;
42
+
37
43
getTooltipContainer ?: ( node : HTMLElement ) => HTMLElement ;
38
44
destroyOnHidden ?: boolean ;
39
45
align ?: AlignType ;
40
46
showArrow ?: boolean | ArrowType ;
41
47
arrowContent ?: React . ReactNode ;
42
48
id ?: string ;
43
- /** @deprecated Please use `styles={{ body: {} }}` */
44
- overlayInnerStyle ?: React . CSSProperties ;
49
+
45
50
zIndex ?: number ;
46
- styles ?: TooltipStyles ;
47
- classNames ?: TooltipClassNames ;
51
+
48
52
/**
49
53
* Configures Tooltip to reuse the background for transition usage.
50
54
* This is an experimental API and may not be stable.
51
55
*/
52
56
unique ?: TriggerProps [ 'unique' ] ;
53
57
}
54
58
55
- export interface TooltipStyles {
56
- root ?: React . CSSProperties ;
57
- body ?: React . CSSProperties ;
58
- }
59
-
60
- export interface TooltipClassNames {
61
- root ?: string ;
62
- body ?: string ;
63
- }
64
-
65
59
export interface TooltipRef extends TriggerRef { }
66
60
67
61
const Tooltip = React . forwardRef < TooltipRef , TooltipProps > ( ( props , ref ) => {
68
62
const {
69
- overlayClassName,
70
63
trigger = [ 'hover' ] ,
71
64
mouseEnterDelay = 0 ,
72
65
mouseLeaveDelay = 0.1 ,
73
- overlayStyle,
74
66
prefixCls = 'rc-tooltip' ,
75
67
children,
76
68
onVisibleChange,
@@ -81,13 +73,12 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
81
73
destroyOnHidden = false ,
82
74
defaultVisible,
83
75
getTooltipContainer,
84
- overlayInnerStyle,
85
76
arrowContent,
86
77
overlay,
87
78
id,
88
79
showArrow = true ,
89
- classNames : tooltipClassNames ,
90
- styles : tooltipStyles ,
80
+ classNames,
81
+ styles,
91
82
...restProps
92
83
} = props ;
93
84
@@ -102,18 +93,26 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
102
93
extraProps . popupVisible = props . visible ;
103
94
}
104
95
105
- const getPopupElement = ( ) => (
106
- < Popup
107
- key = "content"
108
- prefixCls = { prefixCls }
109
- id = { mergedId }
110
- bodyClassName = { tooltipClassNames ?. body }
111
- overlayInnerStyle = { { ...overlayInnerStyle , ...tooltipStyles ?. body } }
112
- >
113
- { overlay }
114
- </ Popup >
115
- ) ;
96
+ // ========================= Arrow ==========================
97
+ // Process arrow configuration
98
+ const mergedArrow = React . useMemo ( ( ) => {
99
+ if ( ! showArrow ) {
100
+ return false ;
101
+ }
102
+
103
+ // Convert true to object for unified processing
104
+ const arrowConfig = showArrow === true ? { } : showArrow ;
105
+
106
+ // Apply semantic styles with unified logic
107
+ return {
108
+ ...arrowConfig ,
109
+ className : cls ( arrowConfig . className , classNames ?. arrow ) ,
110
+ style : { ...arrowConfig . style , ...styles ?. arrow } ,
111
+ content : arrowConfig . content ?? arrowContent ,
112
+ } ;
113
+ } , [ showArrow , classNames ?. arrow , styles ?. arrow , arrowContent ] ) ;
116
114
115
+ // ======================== Children ========================
117
116
const getChildren = ( ) => {
118
117
const child = React . Children . only ( children ) ;
119
118
const originalProps = child ?. props || { } ;
@@ -124,11 +123,22 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
124
123
return React . cloneElement < any > ( children , childProps ) as any ;
125
124
} ;
126
125
126
+ // ========================= Render =========================
127
127
return (
128
128
< Trigger
129
- popupClassName = { classNames ( overlayClassName , tooltipClassNames ?. root ) }
129
+ popupClassName = { classNames ?. root }
130
130
prefixCls = { prefixCls }
131
- popup = { getPopupElement }
131
+ popup = {
132
+ < Popup
133
+ key = "content"
134
+ prefixCls = { prefixCls }
135
+ id = { mergedId }
136
+ classNames = { classNames }
137
+ styles = { styles }
138
+ >
139
+ { overlay }
140
+ </ Popup >
141
+ }
132
142
action = { trigger }
133
143
builtinPlacements = { placements }
134
144
popupPlacement = { placement }
@@ -141,9 +151,9 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
141
151
defaultPopupVisible = { defaultVisible }
142
152
autoDestroy = { destroyOnHidden }
143
153
mouseLeaveDelay = { mouseLeaveDelay }
144
- popupStyle = { { ... overlayStyle , ... tooltipStyles ?. root } }
154
+ popupStyle = { styles ?. root }
145
155
mouseEnterDelay = { mouseEnterDelay }
146
- arrow = { showArrow }
156
+ arrow = { mergedArrow }
147
157
{ ...extraProps }
148
158
>
149
159
{ getChildren ( ) }
0 commit comments