Skip to content

Commit 19fb093

Browse files
committed
Made green box shadow the default even if no theme is provided
Signed-off-by: SplinterSword <[email protected]>
1 parent 4343d0a commit 19fb093

File tree

2 files changed

+40
-23
lines changed

2 files changed

+40
-23
lines changed

src/custom/CustomTooltip/customTooltip.tsx

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import _ from 'lodash';
22
import React from 'react';
33
import type { Theme } from '@mui/material/styles';
4-
import { alpha } from '@mui/material';
4+
import { alpha, useTheme } from '@mui/material';
55
import { Tooltip, TooltipProps } from '../../base';
66
import { WHITE } from '../../theme';
77
import { RenderMarkdownTooltip } from '../Markdown';
@@ -29,10 +29,12 @@ function CustomTooltip({
2929
componentsProps = {},
3030
...props
3131
}: CustomTooltipProps): JSX.Element {
32+
const theme = useTheme();
33+
3234
return (
3335
<Tooltip
3436
enterDelay={150}
35-
enterNextDelay={400} //->delay when moving between siblings
37+
enterNextDelay={400}
3638
leaveDelay={700}
3739
componentsProps={_.merge(
3840
{
@@ -42,29 +44,36 @@ function CustomTooltip({
4244
color: WHITE,
4345
maxWidth: '600px',
4446
fontSize: fontSize || (variant === 'standard' ? '1rem' : '0.75rem'),
45-
fontWeight: fontWeight,
47+
fontWeight,
4648
borderRadius: '0.5rem',
4749
padding: variant === 'standard' ? '0.9rem' : '0.5rem 0.75rem',
48-
boxShadow: (theme: Theme) => {
49-
if (theme.palette.mode === 'light') {
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) {
5056
return 'rgba(0, 0, 0, 0.6) 0px 4px 10px, rgba(0, 0, 0, 0.5) 0px 2px 4px';
5157
}
52-
const green = theme.palette.primary.main;
53-
return `0 10px 30px ${alpha(green, 0.28)}, 0 2px 8px ${alpha(green, 0.2)}, 0 0 1px ${alpha(green, 0.32)}`;
54-
}
55-
}
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+
},
5665
},
5766
popper: {
5867
sx: {
5968
zIndex: 9999999999,
60-
opacity: '1'
61-
}
69+
opacity: '1',
70+
},
6271
},
6372
arrow: {
6473
sx: {
65-
color: bgColor
66-
}
67-
}
74+
color: bgColor,
75+
},
76+
},
6877
},
6978
componentsProps
7079
)}

src/theme/components/tooltip.modifier.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,30 @@ import type { Components, Theme } from '@mui/material/styles';
44
export const MuiTooltip: Components<Theme>['MuiTooltip'] = {
55
styleOverrides: {
66
tooltip: ({ theme }) => {
7+
// Detect whether this is the default MUI theme (no ThemeProvider)
8+
const isDefaultTheme = theme.palette.primary.main === '#1976d2'; // MUI default blue
79
const isLight = theme.palette.mode === 'light';
8-
const shadow = isLight
9-
? `0 10px 30px ${alpha('#000', 0.12)}, 0 2px 8px ${alpha('#000', 0.08)}`
10-
: (() => {
11-
const green = theme.palette.primary.main;
12-
return `0 10px 30px ${alpha(green, 0.28)}, 0 2px 8px ${alpha(green, 0.2)}, 0 0 1px ${alpha(green, 0.32)}`;
13-
})();
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+
})();
1421

1522
return {
1623
boxShadow: shadow,
1724
} as const;
1825
},
26+
1927
arrow: ({ theme }) => {
2028
return {
21-
color: theme.palette.divider
29+
color: theme.palette.divider,
2230
} as const;
23-
}
24-
}
31+
},
32+
},
2533
};

0 commit comments

Comments
 (0)