@@ -8,6 +8,8 @@ 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,47 +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
+ /** @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
+ // Rest
24
41
trigger ?: ActionType | ActionType [ ] ;
25
42
defaultVisible ?: boolean ;
26
43
visible ?: boolean ;
27
44
placement ?: string ;
28
- /** Config popup motion */
29
- motion ?: TriggerProps [ 'popupMotion' ] ;
45
+
30
46
onVisibleChange ?: ( visible : boolean ) => void ;
31
47
afterVisibleChange ?: ( visible : boolean ) => void ;
32
48
overlay : ( ( ) => React . ReactNode ) | React . ReactNode ;
33
- /** @deprecated Please use `styles={{ root: {} }}` */
34
- overlayStyle ?: React . CSSProperties ;
35
- /** @deprecated Please use `classNames={{ root: '' }}` */
36
- overlayClassName ?: string ;
49
+
37
50
getTooltipContainer ?: ( node : HTMLElement ) => HTMLElement ;
38
51
destroyOnHidden ?: boolean ;
39
52
align ?: AlignType ;
40
53
showArrow ?: boolean | ArrowType ;
41
54
arrowContent ?: React . ReactNode ;
42
55
id ?: string ;
43
- /** @deprecated Please use `styles={{ body: {} }}` */
44
- overlayInnerStyle ?: React . CSSProperties ;
56
+
45
57
zIndex ?: number ;
46
- styles ?: TooltipStyles ;
47
- classNames ?: TooltipClassNames ;
58
+
48
59
/**
49
60
* Configures Tooltip to reuse the background for transition usage.
50
61
* This is an experimental API and may not be stable.
51
62
*/
52
63
unique ?: TriggerProps [ 'unique' ] ;
53
64
}
54
65
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
66
export interface TooltipRef extends TriggerRef { }
66
67
67
68
const Tooltip = React . forwardRef < TooltipRef , TooltipProps > ( ( props , ref ) => {
@@ -108,7 +109,8 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
108
109
prefixCls = { prefixCls }
109
110
id = { mergedId }
110
111
bodyClassName = { tooltipClassNames ?. body }
111
- overlayInnerStyle = { { ...overlayInnerStyle , ...tooltipStyles ?. body } }
112
+ overlayInnerStyle = { overlayInnerStyle }
113
+ style = { tooltipStyles ?. body }
112
114
>
113
115
{ overlay }
114
116
</ Popup >
@@ -124,6 +126,23 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
124
126
return React . cloneElement < any > ( children , childProps ) as any ;
125
127
} ;
126
128
129
+ // Process arrow configuration
130
+ const getArrowConfig = ( ) => {
131
+ if ( ! showArrow ) {
132
+ return false ;
133
+ }
134
+
135
+ // Convert true to object for unified processing
136
+ const arrowConfig = showArrow === true ? { } : showArrow ;
137
+
138
+ // Apply semantic styles with unified logic
139
+ return {
140
+ ...arrowConfig ,
141
+ className : classNames ( arrowConfig . className , tooltipClassNames ?. arrow ) ,
142
+ content : arrowConfig . content || arrowContent ,
143
+ } ;
144
+ } ;
145
+
127
146
return (
128
147
< Trigger
129
148
popupClassName = { classNames ( overlayClassName , tooltipClassNames ?. root ) }
@@ -143,7 +162,7 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
143
162
mouseLeaveDelay = { mouseLeaveDelay }
144
163
popupStyle = { { ...overlayStyle , ...tooltipStyles ?. root } }
145
164
mouseEnterDelay = { mouseEnterDelay }
146
- arrow = { showArrow }
165
+ arrow = { getArrowConfig ( ) }
147
166
{ ...extraProps }
148
167
>
149
168
{ getChildren ( ) }
0 commit comments