Skip to content

Commit 9491679

Browse files
Merge pull request #1181 from SplinterSword/boxShadowToolTip
Modified the Box Shadow of Tooltip Component for Darkmode
2 parents 249863a + 19fb093 commit 9491679

File tree

3 files changed

+61
-9
lines changed

3 files changed

+61
-9
lines changed

src/custom/CustomTooltip/customTooltip.tsx

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import _ from 'lodash';
22
import React from 'react';
3+
import type { Theme } from '@mui/material/styles';
4+
import { alpha, useTheme } from '@mui/material';
35
import { Tooltip, TooltipProps } from '../../base';
46
import { WHITE } from '../../theme';
57
import { RenderMarkdownTooltip } from '../Markdown';
@@ -27,10 +29,12 @@ function CustomTooltip({
2729
componentsProps = {},
2830
...props
2931
}: CustomTooltipProps): JSX.Element {
32+
const theme = useTheme();
33+
3034
return (
3135
<Tooltip
3236
enterDelay={150}
33-
enterNextDelay={400} //->delay when moving between siblings
37+
enterNextDelay={400}
3438
leaveDelay={700}
3539
componentsProps={_.merge(
3640
{
@@ -40,23 +44,36 @@ function CustomTooltip({
4044
color: WHITE,
4145
maxWidth: '600px',
4246
fontSize: fontSize || (variant === 'standard' ? '1rem' : '0.75rem'),
43-
fontWeight: { fontWeight },
47+
fontWeight,
4448
borderRadius: '0.5rem',
4549
padding: variant === 'standard' ? '0.9rem' : '0.5rem 0.75rem',
46-
boxShadow: 'rgba(0, 0, 0, 0.6) 0px 4px 10px, rgba(0, 0, 0, 0.5) 0px 2px 4px'
47-
}
50+
boxShadow: (themeArg?: Theme) => {
51+
const t = themeArg || theme;
52+
const isDefaultTheme = t.palette.primary.main === '#1976d2';
53+
console.log(isDefaultTheme)
54+
55+
if (t?.palette?.mode === 'light' && !isDefaultTheme) {
56+
return 'rgba(0, 0, 0, 0.6) 0px 4px 10px, rgba(0, 0, 0, 0.5) 0px 2px 4px';
57+
}
58+
59+
const green = '#00B39F';
60+
return `0 10px 30px ${alpha(green, 0.28)},
61+
0 2px 8px ${alpha(green, 0.2)},
62+
0 0 1px ${alpha(green, 0.32)}`;
63+
},
64+
},
4865
},
4966
popper: {
5067
sx: {
5168
zIndex: 9999999999,
52-
opacity: '1'
53-
}
69+
opacity: '1',
70+
},
5471
},
5572
arrow: {
5673
sx: {
57-
color: bgColor
58-
}
59-
}
74+
color: bgColor,
75+
},
76+
},
6077
},
6178
componentsProps
6279
)}

src/theme/components.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { MuiSwitch } from './components/switch.modifier';
2020
import { MuiTab } from './components/tab.modifier';
2121
import { MuiTableCombineTheme } from './components/table.modifier';
2222
import { MuiTabs } from './components/tabs.modifier';
23+
import { MuiTooltip } from './components/tooltip.modifier';
2324

2425
export const components: Components<Theme> = {
2526
MuiAppBar,
@@ -42,5 +43,6 @@ export const components: Components<Theme> = {
4243
MuiButtonGroup,
4344
MuiButton,
4445
MuiListItem,
46+
MuiTooltip,
4547
...MuiTableCombineTheme
4648
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { alpha } from '@mui/material';
2+
import type { Components, Theme } from '@mui/material/styles';
3+
4+
export const MuiTooltip: Components<Theme>['MuiTooltip'] = {
5+
styleOverrides: {
6+
tooltip: ({ theme }) => {
7+
// Detect whether this is the default MUI theme (no ThemeProvider)
8+
const isDefaultTheme = theme.palette.primary.main === '#1976d2'; // MUI default blue
9+
const isLight = theme.palette.mode === 'light';
10+
11+
// Conditional shadow logic
12+
const shadow =
13+
isLight && !isDefaultTheme
14+
? `0 10px 30px ${alpha('#000', 0.12)}, 0 2px 8px ${alpha('#000', 0.08)}`
15+
: (() => {
16+
const green = '#00B39F';
17+
return `0 10px 30px ${alpha(green, 0.28)},
18+
0 2px 8px ${alpha(green, 0.2)},
19+
0 0 1px ${alpha(green, 0.32)}`;
20+
})();
21+
22+
return {
23+
boxShadow: shadow,
24+
} as const;
25+
},
26+
27+
arrow: ({ theme }) => {
28+
return {
29+
color: theme.palette.divider,
30+
} as const;
31+
},
32+
},
33+
};

0 commit comments

Comments
 (0)