1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00
unleash.unleash/frontend/src/component/common/HtmlTooltip/HtmlTooltip.tsx
Tymoteusz Czech e916deda74
fix: prevent project cell overflow on api keys table (#7472)
Preparations for virtualizing API tokens table - projects column for tokens with a list of projects assigned will not overflow the cell.
2024-07-02 12:10:02 +02:00

78 lines
2.1 KiB
TypeScript

import {
styled,
Tooltip,
tooltipClasses,
type TooltipProps,
} from '@mui/material';
import type { SpacingArgument } from '@mui/system/createTheme/createSpacing';
const StyledHtmlTooltipBody = styled('div')(({ theme }) => ({
overflow: 'auto',
padding: theme.spacing(1, 1.5),
}));
const StyledHtmlTooltip = styled(
({
className,
maxWidth,
maxHeight,
fontSize,
...props
}: IHtmlTooltipProps) => (
<Tooltip
{...props}
title={<StyledHtmlTooltipBody>{props.title}</StyledHtmlTooltipBody>}
classes={{ popper: className }}
/>
),
{
shouldForwardProp: (prop) =>
prop !== 'maxWidth' && prop !== 'maxHeight' && prop !== 'fontSize',
},
)<{
maxWidth?: SpacingArgument;
maxHeight?: SpacingArgument;
fontSize?: string;
}>(
({
theme,
maxWidth = theme.spacing(37.5),
maxHeight = theme.spacing(37.5),
fontSize = theme.fontSizes.smallerBody,
}) => ({
maxWidth,
[`& .${tooltipClasses.tooltip}`]: {
display: 'flex',
flexDirection: 'column',
backgroundColor: theme.palette.background.paper,
padding: 0,
borderRadius: theme.shape.borderRadiusMedium,
boxShadow: theme.shadows[2],
color: theme.palette.text.primary,
fontWeight: theme.fontWeight.medium,
maxWidth: 'inherit',
border: `1px solid ${theme.palette.divider}`,
maxHeight,
fontSize,
},
[`& .${tooltipClasses.arrow}`]: {
'&:before': {
border: `1px solid ${theme.palette.divider}`,
},
color: theme.palette.background.paper,
},
}),
);
export interface IHtmlTooltipProps extends TooltipProps {
maxWidth?: SpacingArgument;
maxHeight?: SpacingArgument;
fontSize?: string;
tabIndex?: number;
}
export const HtmlTooltip = (props: IHtmlTooltipProps) => {
if (!props.title) return props.children;
return <StyledHtmlTooltip {...props}>{props.children}</StyledHtmlTooltip>;
};