Skip to content

Commit 2b98c2c

Browse files
jonrohaniansan5653dependabot[bot]hectahertzjoshblack
authored
chore(TooltipV2): Remove the CSS modules feature flag from the TooltipV2 component (#5872)
Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Ian Sanders <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Hector Garcia <[email protected]> Co-authored-by: Josh Black <[email protected]> Co-authored-by: Marie Lucca <[email protected]> Co-authored-by: Emily Brick <[email protected]> Co-authored-by: Marie Lucca <[email protected]> Co-authored-by: Lukas Oppermann <[email protected]> Co-authored-by: Tyler Jones <[email protected]> Co-authored-by: Mike Perrotti <[email protected]>
1 parent 02ed196 commit 2b98c2c

File tree

3 files changed

+15
-353
lines changed

3 files changed

+15
-353
lines changed

.changeset/petite-women-notice.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': minor
3+
---
4+
5+
Remove the CSS modules feature flag from the TooltipV2 component

packages/react/src/TooltipV2/Tooltip.tsx

Lines changed: 8 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,17 @@
11
import React, {Children, useEffect, useRef, useState, useMemo} from 'react'
22
import type {SxProp} from '../sx'
3-
import sx from '../sx'
43
import {useId, useProvidedRefOrCreate, useOnEscapePress, useIsMacOS} from '../hooks'
54
import {invariant} from '../utils/invariant'
65
import {warning} from '../utils/warning'
7-
import styled from 'styled-components'
8-
import {get} from '../constants'
96
import {getAnchoredPosition} from '@primer/behaviors'
107
import type {AnchorSide, AnchorAlignment} from '@primer/behaviors'
118
import {isSupported, apply} from '@oddbird/popover-polyfill/fn'
12-
import {toggleStyledComponent} from '../internal/utils/toggleStyledComponent'
139
import {clsx} from 'clsx'
1410
import classes from './Tooltip.module.css'
15-
import {useFeatureFlag} from '../FeatureFlags'
1611
import {getAccessibleKeybindingHintString, KeybindingHint, type KeybindingHintProps} from '../KeybindingHint'
1712
import VisuallyHidden from '../_VisuallyHidden'
1813
import useSafeTimeout from '../hooks/useSafeTimeout'
19-
20-
const CSS_MODULE_FEATURE_FLAG = 'primer_react_css_modules_ga'
21-
22-
const animationStyles = `
23-
animation-name: tooltip-appear;
24-
animation-duration: 0.1s;
25-
animation-fill-mode: forwards;
26-
animation-timing-function: ease-in;
27-
animation-delay: 0s;
28-
`
29-
30-
const StyledTooltip = toggleStyledComponent(
31-
CSS_MODULE_FEATURE_FLAG,
32-
'span',
33-
styled.span`
34-
/* Overriding the default popover styles */
35-
display: none;
36-
&[popover] {
37-
position: absolute;
38-
padding: 0.5em 0.75em;
39-
width: max-content;
40-
margin: auto;
41-
clip: auto;
42-
white-space: normal;
43-
font: normal normal 11px/1.5 ${get('fonts.normal')};
44-
-webkit-font-smoothing: subpixel-antialiased;
45-
color: var(--tooltip-fgColor, ${get('colors.fg.onEmphasis')});
46-
text-align: center;
47-
word-wrap: break-word;
48-
background: var(--tooltip-bgColor, ${get('colors.neutral.emphasisPlus')});
49-
border-radius: ${get('radii.2')};
50-
border: 0;
51-
opacity: 0;
52-
max-width: 250px;
53-
inset: auto;
54-
/* for scrollbar */
55-
overflow: visible;
56-
}
57-
/* class name in chrome is :popover-open */
58-
&[popover]:popover-open {
59-
display: block;
60-
}
61-
/* class name in firefox and safari is \:popover-open */
62-
&[popover].\\:popover-open {
63-
display: block;
64-
}
65-
66-
@media (forced-colors: active) {
67-
outline: 1px solid transparent;
68-
}
69-
70-
// This is needed to keep the tooltip open when the user leaves the trigger element to hover tooltip
71-
&::after {
72-
position: absolute;
73-
display: block;
74-
right: 0;
75-
left: 0;
76-
height: var(--overlay-offset, 0.25rem);
77-
content: '';
78-
}
79-
80-
/* South, East, Southeast, Southwest after */
81-
&[data-direction='n']::after,
82-
&[data-direction='ne']::after,
83-
&[data-direction='nw']::after {
84-
top: 100%;
85-
}
86-
&[data-direction='s']::after,
87-
&[data-direction='se']::after,
88-
&[data-direction='sw']::after {
89-
bottom: 100%;
90-
}
91-
92-
&[data-direction='w']::after {
93-
position: absolute;
94-
display: block;
95-
height: 100%;
96-
width: 8px;
97-
content: '';
98-
bottom: 0;
99-
left: 100%;
100-
}
101-
/* East before and after */
102-
&[data-direction='e']::after {
103-
position: absolute;
104-
display: block;
105-
height: 100%;
106-
width: 8px;
107-
content: '';
108-
bottom: 0;
109-
right: 100%;
110-
margin-left: -8px;
111-
}
112-
113-
/* Animation definition */
114-
@keyframes tooltip-appear {
115-
from {
116-
opacity: 0;
117-
}
118-
to {
119-
opacity: 1;
120-
}
121-
}
122-
/* Animation styles */
123-
&:popover-open,
124-
&:popover-open::before {
125-
${animationStyles}
126-
}
127-
128-
/* Animation styles */
129-
&.\\:popover-open,
130-
&.\\:popover-open::before {
131-
${animationStyles}
132-
}
133-
134-
${sx};
135-
`,
136-
)
14+
import {toggleSxComponent} from '../internal/utils/toggleSxComponent'
13715

13816
export type TooltipDirection = 'nw' | 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w'
13917
export type TooltipProps = React.PropsWithChildren<
@@ -203,6 +81,10 @@ const isInteractive = (element: HTMLElement) => {
20381
}
20482
export const TooltipContext = React.createContext<{tooltipId?: string}>({})
20583

84+
const BaseComponent = toggleSxComponent('span') as React.ComponentType<
85+
SxProp & React.HTMLAttributes<HTMLElement> & React.RefAttributes<HTMLSpanElement>
86+
>
87+
20688
export const Tooltip = React.forwardRef(
20789
(
20890
{direction = 's', text, type = 'description', children, id, className, keybindingHint, ...rest}: TooltipProps,
@@ -212,7 +94,6 @@ export const Tooltip = React.forwardRef(
21294
const child = Children.only(children)
21395
const triggerRef = useProvidedRefOrCreate(forwardedRef as React.RefObject<HTMLElement>)
21496
const tooltipElRef = useRef<HTMLDivElement>(null)
215-
const enabled = useFeatureFlag(CSS_MODULE_FEATURE_FLAG)
21697

21798
const [calculatedDirection, setCalculatedDirection] = useState<TooltipDirection>(direction)
21899

@@ -407,8 +288,8 @@ export const Tooltip = React.forwardRef(
407288
child.props.onMouseLeave?.(event)
408289
},
409290
})}
410-
<StyledTooltip
411-
className={clsx(className, {[classes.Tooltip]: enabled})}
291+
<BaseComponent
292+
className={clsx(className, classes.Tooltip)}
412293
ref={tooltipElRef}
413294
data-direction={calculatedDirection}
414295
{...rest}
@@ -440,7 +321,7 @@ export const Tooltip = React.forwardRef(
440321
) : (
441322
text
442323
)}
443-
</StyledTooltip>
324+
</BaseComponent>
444325
</>
445326
</TooltipContext.Provider>
446327
)

0 commit comments

Comments
 (0)