Skip to content
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

fix(Tip): Fixes hover gap and click issues with ToolTips and PreviewTips #3018

Merged
merged 15 commits into from
Jan 31, 2025
17 changes: 11 additions & 6 deletions packages/gamut/src/Popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useWindowScroll, useWindowSize } from 'react-use';
import { FocusTrap } from '../FocusTrap';
import {
Beak,
BeakBox,
PatternContainer,
PopoverContainer,
PopoverPortal,
Expand Down Expand Up @@ -172,12 +173,16 @@ export const Popover: React.FC<PopoverProps> = ({
widthRestricted={widthRestricted}
>
{beak && (
<Beak
outline={outline ? 'outline' : 'boxShadow'}
beak={`${position}-${beak}${variant === 'secondary' ? '-sml' : ''}`}
data-testid="popover-beak"
size={variant === 'secondary' ? 'sml' : 'lrg'}
/>
<BeakBox variant={position}>
<Beak
beak={`${position}-${beak}${
variant === 'secondary' ? '-sml' : ''
}`}
data-testid="popover-beak"
size={variant === 'secondary' ? 'sml' : 'lrg'}
hasBorder={outline || variant === 'secondary'}
/>
</BeakBox>
)}
{children}
</RaisedDiv>
Expand Down
13 changes: 9 additions & 4 deletions packages/gamut/src/Popover/elements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { AnimatePresence, motion } from 'framer-motion';
import * as React from 'react';

import { BodyPortal } from '../BodyPortal';
import { Box } from '../Box';
import { Box, FlexBox } from '../Box';
import { popoverToolTipBodyAlignments } from '../Tip/shared/styles';
import { WithChildrenProp } from '../utils';
import {
beakBorderStates,
beakBoxVariants,
beakSize,
beakVariants,
outlineVariants,
Expand Down Expand Up @@ -39,10 +41,13 @@ export const RaisedDiv = styled.div<

export const Beak = styled(Box)<
StyleProps<typeof popoverStates> &
StyleProps<typeof outlineVariants> &
StyleProps<typeof beakVariants> &
StyleProps<typeof beakSize>
>(beakVariants, beakSize);
StyleProps<typeof beakSize> &
StyleProps<typeof beakBorderStates>
>(beakBorderStates, beakVariants, beakSize);

export const BeakBox =
styled(FlexBox)<StyleProps<typeof beakBoxVariants>>(beakBoxVariants);

export const PatternContainer = styled.div(
variant({
Expand Down
30 changes: 27 additions & 3 deletions packages/gamut/src/Popover/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const raisedDivVariants = variant({
},
});

const borderStyles = { borderColor: 'secondary', border: 1 } as const;
Copy link
Contributor

@LinKCoding LinKCoding Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need borderColor: 'secondary'
border: 1 should already be: 1px solid ${colors['border-primary']}
see: https://github.com/Codecademy/gamut/blob/main/packages/gamut-styles/src/themes/core.ts
and border-primary and secondary both use navy-800

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good eye! will fix

export const outlineVariants = variant({
defaultVariant: 'boxShadow',
prop: 'outline',
Expand All @@ -36,8 +37,7 @@ export const outlineVariants = variant({
boxShadow: '0 0 16px rgba(0, 0, 0, 0.1), 0 0 24px rgba(0, 0, 0, 0.15)',
},
outline: {
borderColor: 'secondary',
border: 1,
...borderStyles,
boxShadow: 'none',
},
},
Expand All @@ -50,6 +50,28 @@ export const widthStates = states({
},
});

export const beakBorderStates = states({
hasBorder: borderStyles,
});

export const beakBoxVariants = variant({
base: {
alignItems: 'flex-end',
height: '15px',
justifyContent: 'center',
left: 0,
position: 'absolute',
width: '100%',
},
variants: {
above: {
bottom: -15,
},
below: {
top: -15,
},
},
});
const beakVariantsArray = [
'below-left',
'below-right',
Expand All @@ -72,8 +94,10 @@ const beakVariantStyles = createVariantsFromAlignments(

export const beakVariants = variant({
base: {
position: 'absolute',
transform: 'rotate(45deg)',
background: 'transparent',
zIndex: 1,
position: 'fixed',
},
prop: 'beak',
variants: beakVariantStyles,
Expand Down
16 changes: 8 additions & 8 deletions packages/gamut/src/Popover/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { theme } from '@codecademy/gamut-styles';
import { tooltipBackgroundColor } from '../Tip/shared/styles';

const popoverAbove = {
borderRight: 'inherit',
borderBottom: 'inherit',
borderLeft: 'none',
borderTop: 'none',
top: 'calc(100% - 10px)',
} as const;

const popoverBelow = {
borderLeft: 'inherit',
borderTop: 'inherit',
borderRight: 'none',
borderBottom: 'none',
top: '-10px',
} as const;

Expand All @@ -27,14 +27,14 @@ const beakCenter = {
};

const popoverAboveSml = {
borderRight: 'inherit',
borderBottom: 'inherit',
borderLeft: 'none',
borderTop: 'none',
top: 'calc(100% - 8px)',
} as const;

const popoverBelowSml = {
borderLeft: 'inherit',
borderTop: 'inherit',
borderRight: 'none',
borderBottom: 'none',
top: '-8px',
} as const;

Expand Down
1 change: 1 addition & 0 deletions packages/gamut/src/Tip/shared/FloatingTip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const FloatingTip: React.FC<TipWrapperProps> = ({
onFocus={toolOnlyEventFunc}
onBlur={toolOnlyEventFunc}
onMouseEnter={toolOnlyEventFunc}
onMouseDown={(e) => e.preventDefault()}
onKeyDown={
escapeKeyPressHandler ? (e) => escapeKeyPressHandler(e) : undefined
}
Expand Down
15 changes: 15 additions & 0 deletions packages/gamut/src/Tip/shared/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ export const topStyles = {
pb: containerOffsetVertical,
} as const;

const beforeStyles = {
content: '""',
position: 'absolute',
width: '100%',
};

export const topStylesBefore = { ...beforeStyles, height: 16, bottom: '-4px' };

export const topStylesAfter = {
borderColor: 'currentColor',
borderWidth: '0 1px 1px 0',
Expand All @@ -42,6 +50,12 @@ export const bottomStyles = {
pt: containerOffsetVertical,
} as const;

export const bottomStylesBefore = {
...beforeStyles,
height: 24,
top: '-8px',
};

export const bottomStylesAfter = {
borderColor: 'currentColor',
borderWidth: '1px 0 0 1px',
Expand Down Expand Up @@ -104,6 +118,7 @@ export const toolTipAlignmentVariants = variant({
opacity: 0,
position: 'absolute',
visibility: 'hidden',

'&::after': {
content: '""',
display: 'block',
Expand Down
11 changes: 10 additions & 1 deletion packages/gamut/src/Tip/shared/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
bottomCenterStylesAfter,
bottomStyles,
bottomStylesAfter,
bottomStylesBefore,
centerStyles,
centerStylesAfter,
leftStyles,
Expand All @@ -14,6 +15,7 @@ import {
topCenterStylesAfter,
topStyles,
topStylesAfter,
topStylesBefore,
} from './styles';
import { TipPlacementComponentProps, TipWrapperProps } from './types';

Expand Down Expand Up @@ -62,13 +64,16 @@ export const getPopoverAlignment = ({
export const createToolTipVariantFromAlignment = (alignment: string) => {
let styleObject = {};
let styleObjectAfter = {};
let styleObjectBefore = {};

if (alignment.includes('top')) {
styleObject = { ...topStyles };
styleObjectAfter = { ...topStylesAfter };
styleObjectBefore = { ...topStylesBefore };
} else {
styleObject = { ...bottomStyles };
styleObjectAfter = { ...bottomStylesAfter };
styleObjectBefore = { ...bottomStylesBefore };
}

if (alignment.includes('center')) {
Expand All @@ -87,7 +92,11 @@ export const createToolTipVariantFromAlignment = (alignment: string) => {
styleObjectAfter = { ...styleObjectAfter, ...leftStylesAfter };
}

return { ...styleObject, '&::after': styleObjectAfter };
return {
...styleObject,
'&::after': styleObjectAfter,
'&::before': styleObjectBefore,
};
};

export const createVariantsFromAlignments = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export const Floating: Story = {
tip="Wonder at the majesty of the universe"
icon={SmileyStarEyesIcon}
tipProps={{ alignment: 'bottom-center', placement: 'floating' }}
onClick={() => {
console.log(
'This is a test, and will be deleted before the PR is merged'
);
}}
/>
),
};
Loading