2024-03-18 13:58:05 +01:00
|
|
|
import {
|
|
|
|
styled,
|
|
|
|
Tooltip,
|
|
|
|
tooltipClasses,
|
|
|
|
type TooltipProps,
|
|
|
|
} from '@mui/material';
|
|
|
|
import type { SpacingArgument } from '@mui/system/createTheme/createSpacing';
|
2022-11-11 11:24:56 +01:00
|
|
|
|
2023-01-19 14:46:26 +01:00
|
|
|
const StyledHtmlTooltipBody = styled('div')(({ theme }) => ({
|
|
|
|
overflow: 'auto',
|
|
|
|
padding: theme.spacing(1, 1.5),
|
|
|
|
}));
|
|
|
|
|
2023-01-16 13:04:52 +01:00
|
|
|
const StyledHtmlTooltip = styled(
|
2023-01-20 18:09:01 +01:00
|
|
|
({
|
|
|
|
className,
|
|
|
|
maxWidth,
|
|
|
|
maxHeight,
|
|
|
|
fontSize,
|
|
|
|
...props
|
|
|
|
}: IHtmlTooltipProps) => (
|
2023-01-19 14:46:26 +01:00
|
|
|
<Tooltip
|
|
|
|
{...props}
|
|
|
|
title={<StyledHtmlTooltipBody>{props.title}</StyledHtmlTooltipBody>}
|
|
|
|
classes={{ popper: className }}
|
|
|
|
/>
|
2023-01-16 13:04:52 +01:00
|
|
|
),
|
|
|
|
{
|
2023-10-02 14:25:46 +02:00
|
|
|
shouldForwardProp: (prop) =>
|
2023-01-20 18:09:01 +01:00
|
|
|
prop !== 'maxWidth' && prop !== 'maxHeight' && prop !== 'fontSize',
|
2023-10-02 14:25:46 +02:00
|
|
|
},
|
2023-01-20 18:09:01 +01:00
|
|
|
)<{
|
|
|
|
maxWidth?: SpacingArgument;
|
|
|
|
maxHeight?: SpacingArgument;
|
|
|
|
fontSize?: string;
|
|
|
|
}>(
|
|
|
|
({
|
|
|
|
theme,
|
|
|
|
maxWidth = theme.spacing(37.5),
|
|
|
|
maxHeight = theme.spacing(37.5),
|
|
|
|
fontSize = theme.fontSizes.smallerBody,
|
|
|
|
}) => ({
|
|
|
|
maxWidth,
|
2023-01-16 13:04:52 +01:00
|
|
|
[`& .${tooltipClasses.tooltip}`]: {
|
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'column',
|
|
|
|
backgroundColor: theme.palette.background.paper,
|
2023-01-19 14:46:26 +01:00
|
|
|
padding: 0,
|
2023-01-16 13:04:52 +01:00
|
|
|
borderRadius: theme.shape.borderRadiusMedium,
|
|
|
|
boxShadow: theme.shadows[2],
|
|
|
|
color: theme.palette.text.primary,
|
|
|
|
fontWeight: theme.fontWeight.medium,
|
|
|
|
maxWidth: 'inherit',
|
2023-03-06 11:58:36 +01:00
|
|
|
border: `1px solid ${theme.palette.divider}`,
|
2023-01-20 18:09:01 +01:00
|
|
|
maxHeight,
|
|
|
|
fontSize,
|
2022-11-29 09:06:29 +01:00
|
|
|
},
|
2023-01-16 13:04:52 +01:00
|
|
|
[`& .${tooltipClasses.arrow}`]: {
|
|
|
|
'&:before': {
|
2023-03-06 11:58:36 +01:00
|
|
|
border: `1px solid ${theme.palette.divider}`,
|
2023-01-16 13:04:52 +01:00
|
|
|
},
|
|
|
|
color: theme.palette.background.paper,
|
|
|
|
},
|
2023-10-02 14:25:46 +02:00
|
|
|
}),
|
2023-01-16 13:04:52 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
export interface IHtmlTooltipProps extends TooltipProps {
|
|
|
|
maxWidth?: SpacingArgument;
|
|
|
|
maxHeight?: SpacingArgument;
|
2023-01-20 18:09:01 +01:00
|
|
|
fontSize?: string;
|
2024-07-02 12:10:02 +02:00
|
|
|
tabIndex?: number;
|
2023-01-16 13:04:52 +01:00
|
|
|
}
|
2022-11-11 11:24:56 +01:00
|
|
|
|
2023-06-14 15:40:40 +02:00
|
|
|
export const HtmlTooltip = (props: IHtmlTooltipProps) => {
|
2023-10-02 14:25:46 +02:00
|
|
|
if (!props.title) return props.children;
|
2023-06-14 15:40:40 +02:00
|
|
|
return <StyledHtmlTooltip {...props}>{props.children}</StyledHtmlTooltip>;
|
|
|
|
};
|