@@ -2,12 +2,14 @@ import type { ArrowType, TriggerProps, TriggerRef } from '@rc-component/trigger'
22import Trigger from '@rc-component/trigger' ;
33import type { ActionType , AlignType } from '@rc-component/trigger/lib/interface' ;
44import useId from '@rc-component/util/lib/hooks/useId' ;
5- import classNames from 'classnames' ;
5+ import cls from 'classnames' ;
66import * as React from 'react' ;
77import { useImperativeHandle , useRef } from 'react' ;
88import { placements } from './placements' ;
99import Popup from './Popup' ;
1010
11+ export type SemanticName = 'root' | 'arrow' | 'body' ;
12+
1113export interface TooltipProps
1214 extends Pick <
1315 TriggerProps ,
@@ -21,56 +23,46 @@ export interface TooltipProps
2123 | 'forceRender'
2224 | 'popupVisible'
2325 > {
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
2434 trigger ?: ActionType | ActionType [ ] ;
2535 defaultVisible ?: boolean ;
2636 visible ?: boolean ;
2737 placement ?: string ;
28- /** Config popup motion */
29- motion ?: TriggerProps [ 'popupMotion' ] ;
38+
3039 onVisibleChange ?: ( visible : boolean ) => void ;
3140 afterVisibleChange ?: ( visible : boolean ) => void ;
3241 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+
3743 getTooltipContainer ?: ( node : HTMLElement ) => HTMLElement ;
3844 destroyOnHidden ?: boolean ;
3945 align ?: AlignType ;
4046 showArrow ?: boolean | ArrowType ;
4147 arrowContent ?: React . ReactNode ;
4248 id ?: string ;
43- /** @deprecated Please use `styles={{ body: {} }}` */
44- overlayInnerStyle ?: React . CSSProperties ;
49+
4550 zIndex ?: number ;
46- styles ?: TooltipStyles ;
47- classNames ?: TooltipClassNames ;
51+
4852 /**
4953 * Configures Tooltip to reuse the background for transition usage.
5054 * This is an experimental API and may not be stable.
5155 */
5256 unique ?: TriggerProps [ 'unique' ] ;
5357}
5458
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-
6559export interface TooltipRef extends TriggerRef { }
6660
6761const Tooltip = React . forwardRef < TooltipRef , TooltipProps > ( ( props , ref ) => {
6862 const {
69- overlayClassName,
7063 trigger = [ 'hover' ] ,
7164 mouseEnterDelay = 0 ,
7265 mouseLeaveDelay = 0.1 ,
73- overlayStyle,
7466 prefixCls = 'rc-tooltip' ,
7567 children,
7668 onVisibleChange,
@@ -81,13 +73,12 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
8173 destroyOnHidden = false ,
8274 defaultVisible,
8375 getTooltipContainer,
84- overlayInnerStyle,
8576 arrowContent,
8677 overlay,
8778 id,
8879 showArrow = true ,
89- classNames : tooltipClassNames ,
90- styles : tooltipStyles ,
80+ classNames,
81+ styles,
9182 ...restProps
9283 } = props ;
9384
@@ -102,18 +93,26 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
10293 extraProps . popupVisible = props . visible ;
10394 }
10495
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 ] ) ;
116114
115+ // ======================== Children ========================
117116 const getChildren = ( ) => {
118117 const child = React . Children . only ( children ) ;
119118 const originalProps = child ?. props || { } ;
@@ -124,11 +123,22 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
124123 return React . cloneElement < any > ( children , childProps ) as any ;
125124 } ;
126125
126+ // ========================= Render =========================
127127 return (
128128 < Trigger
129- popupClassName = { classNames ( overlayClassName , tooltipClassNames ?. root ) }
129+ popupClassName = { classNames ?. root }
130130 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+ }
132142 action = { trigger }
133143 builtinPlacements = { placements }
134144 popupPlacement = { placement }
@@ -141,9 +151,9 @@ const Tooltip = React.forwardRef<TooltipRef, TooltipProps>((props, ref) => {
141151 defaultPopupVisible = { defaultVisible }
142152 autoDestroy = { destroyOnHidden }
143153 mouseLeaveDelay = { mouseLeaveDelay }
144- popupStyle = { { ... overlayStyle , ... tooltipStyles ?. root } }
154+ popupStyle = { styles ?. root }
145155 mouseEnterDelay = { mouseEnterDelay }
146- arrow = { showArrow }
156+ arrow = { mergedArrow }
147157 { ...extraProps }
148158 >
149159 { getChildren ( ) }
0 commit comments