Created
December 1, 2023 17:13
-
-
Save crazy4groovy/06f04fcb517c2850dbb2fda2de47a2f5 to your computer and use it in GitHub Desktop.
A custom styled MUI tooltip component with body (JavaScript)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import ReactDOM from "react-dom"; | |
import { Tooltip, Popper, TooltipProps } from "@mui/material"; | |
import { styled } from "@mui/material/styles"; | |
const StyledPopper = styled(Popper)({ | |
padding: "1rem", // offset for larger arrow size | |
"& .MuiTooltip-tooltip": { | |
backgroundColor: "white", | |
// border: "1px solid lightgrey", // can't style arrow border :( | |
}, | |
"& .MuiTooltip-tooltipArrow, & .MuiTooltip-popperArrow, & .MuiTooltip-arrow": | |
{ | |
color: "white", | |
fontSize: "3rem", // larger arrow size | |
}, | |
"& .MuiTooltip-tooltipArrow > * > *": { | |
fontSize: "1rem", // normal inner contents size | |
}, | |
}); | |
interface Body { | |
body: JSX.Element; | |
children: JSX.Element | JSX.Element[]; | |
} | |
export default function CustomTooltip({ | |
body, | |
children, | |
...props | |
}: Partial<TooltipProps> & Body) { | |
return ( | |
<Tooltip PopperComponent={StyledPopper} {...props} title={body}> | |
{children} | |
</Tooltip> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment