Skip to content

Commit ecfb752

Browse files
authored
add sx prop to tooltip component (#692)
add sx prop to tooltip component (#692)
1 parent dfb75bf commit ecfb752

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/components/Tooltip/Tooltip.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import React from 'react';
22

3-
import { Tooltip as MUITooltip, TooltipProps, useTheme } from '@mui/material';
3+
import { Tooltip as MUITooltip, SxProps, TooltipProps, useTheme } from '@mui/material';
44

55
import { useDeviceInfo } from '../../utils';
66

7-
export default function Tooltip({ placement = 'top-start', title, children }: TooltipProps): JSX.Element {
7+
type CustomTooltipProps = TooltipProps & {
8+
sx?: SxProps;
9+
};
10+
11+
export default function Tooltip({ placement = 'top-start', sx, title, children }: CustomTooltipProps): JSX.Element {
812
const [open, setOpen] = React.useState(false);
913
const { isMobile } = useDeviceInfo();
1014
const theme = useTheme();
@@ -26,20 +30,23 @@ export default function Tooltip({ placement = 'top-start', title, children }: To
2630
onClose={handleTooltipClose}
2731
open={open}
2832
placement={placement}
29-
sx={{
30-
maxWidth: isMobile ? '342px' : '464px',
31-
'& .MuiTooltip-arrow': {
32-
color: theme.palette.TwClrBaseGray800,
33-
},
34-
'& .MuiTooltip-tooltip': {
35-
backgroundColor: theme.palette.TwClrBaseGray800,
36-
color: theme.palette.TwClrBaseWhite,
37-
padding: '8px',
38-
'& a': {
33+
sx={[
34+
{
35+
maxWidth: isMobile ? '342px' : '464px',
36+
'& .MuiTooltip-arrow': {
37+
color: theme.palette.TwClrBaseGray800,
38+
},
39+
'& .MuiTooltip-tooltip': {
40+
backgroundColor: theme.palette.TwClrBaseGray800,
3941
color: theme.palette.TwClrBaseWhite,
42+
padding: '8px',
43+
'& a': {
44+
color: theme.palette.TwClrBaseWhite,
45+
},
4046
},
4147
},
42-
}}
48+
...(Array.isArray(sx) ? sx : [sx]),
49+
]}
4350
title={title}
4451
>
4552
<span onClick={handleTooltipOpen}>{children}</span>

0 commit comments

Comments
 (0)