Skip to content

refactor(site): make HelpTooltip easier to reuse and compose #11242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Dec 19, 2023
32 changes: 13 additions & 19 deletions site/src/components/HelpTooltip/HelpTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const HelpTooltipContent = (

type HelpTooltipTriggerProps = HTMLAttributes<HTMLButtonElement> & {
size?: Size;
hoverEffect?: boolean;
};

export const HelpTooltipTrigger = forwardRef<
Expand All @@ -61,9 +62,17 @@ export const HelpTooltipTrigger = forwardRef<
const {
size = "medium",
children = <HelpTooltipIcon />,
hoverEffect = true,
...buttonProps
} = props;

const hoverEffectStyles = css({
opacity: 0.5,
"&:hover": {
opacity: 0.75,
},
});

return (
<PopoverTrigger>
<button
Expand All @@ -75,24 +84,19 @@ export const HelpTooltipTrigger = forwardRef<
display: flex;
align-items: center;
justify-content: center;
width: ${theme.spacing(getButtonSpacingFromSize(size))};
height: ${theme.spacing(getButtonSpacingFromSize(size))};
padding: 0;
padding: 4px 0;
border: 0;
background: transparent;
color: ${theme.palette.text.primary};
opacity: 0.5;
cursor: pointer;

&:hover {
opacity: 0.75;
}
color: inherit;

& svg {
color: ${theme.palette.text.primary};
width: ${getIconSpacingFromSize(size)}px;
height: ${getIconSpacingFromSize(size)}px;
}
`,
hoverEffect ? hoverEffectStyles : null,
]}
>
{children}
Expand Down Expand Up @@ -174,16 +178,6 @@ export const HelpTooltipLinksGroup: FC<PropsWithChildren> = ({ children }) => {
);
};

const getButtonSpacingFromSize = (size?: Size): number => {
switch (size) {
case "small":
return 2.5;
case "medium":
default:
return 3;
}
};

const getIconSpacingFromSize = (size?: Size): number => {
switch (size) {
case "small":
Expand Down