1
+ import { useTheme } from '@mui/material/styles' ;
1
2
import _ from 'lodash' ;
2
3
import React from 'react' ;
3
4
import { Tooltip , TooltipProps } from '../../base' ;
@@ -12,6 +13,8 @@ type CustomTooltipProps = {
12
13
fontWeight ?: number ;
13
14
variant ?: 'standard' | 'small' ;
14
15
bgColor ?: string ;
16
+ textColor ?: string ;
17
+ useThemeColors ?: boolean ; // Add prop to enable theme-based colors
15
18
componentsProps ?: TooltipProps [ 'componentsProps' ] ;
16
19
} & Omit < TooltipProps , 'title' | 'onClick' > ;
17
20
@@ -24,9 +27,25 @@ function CustomTooltip({
24
27
fontWeight = 400 ,
25
28
variant = 'standard' ,
26
29
bgColor = '#141414' ,
30
+ textColor = WHITE ,
31
+ useThemeColors = false , // Default to false for backward compatibility
27
32
componentsProps = { } ,
28
33
...props
29
34
} : CustomTooltipProps ) : JSX . Element {
35
+ const theme = useTheme ( ) ;
36
+
37
+ // Determine colors based on theme when useThemeColors is true
38
+ const tooltipBgColor = useThemeColors
39
+ ? theme . palette . mode === 'dark'
40
+ ? '#141414'
41
+ : '#ffffff'
42
+ : bgColor ;
43
+
44
+ const tooltipTextColor = useThemeColors
45
+ ? theme . palette . mode === 'dark'
46
+ ? WHITE
47
+ : '#000000'
48
+ : textColor ;
30
49
return (
31
50
< Tooltip
32
51
enterTouchDelay = { 0 }
@@ -35,14 +54,17 @@ function CustomTooltip({
35
54
{
36
55
tooltip : {
37
56
sx : {
38
- background : bgColor ,
39
- color : WHITE ,
57
+ background : tooltipBgColor ,
58
+ color : tooltipTextColor ,
40
59
maxWidth : '600px' ,
41
60
fontSize : fontSize || ( variant === 'standard' ? '1rem' : '0.75rem' ) ,
42
61
fontWeight : { fontWeight } ,
43
62
borderRadius : '0.5rem' ,
44
63
padding : variant === 'standard' ? '0.9rem' : '0.5rem 0.75rem' ,
45
- boxShadow : 'rgba(0, 0, 0, 0.6) 0px 4px 10px, rgba(0, 0, 0, 0.5) 0px 2px 4px'
64
+ boxShadow :
65
+ useThemeColors && theme . palette . mode === 'light'
66
+ ? 'rgba(0, 0, 0, 0.1) 0px 4px 10px, rgba(0, 0, 0, 0.05) 0px 2px 4px'
67
+ : 'rgba(0, 0, 0, 0.6) 0px 4px 10px, rgba(0, 0, 0, 0.5) 0px 2px 4px'
46
68
}
47
69
} ,
48
70
popper : {
@@ -53,7 +75,7 @@ function CustomTooltip({
53
75
} ,
54
76
arrow : {
55
77
sx : {
56
- color : bgColor
78
+ color : tooltipBgColor
57
79
}
58
80
}
59
81
} ,
0 commit comments