1- import styled from 'styled-components'
21import type { ComponentPropsWithRef , ReactElement } from 'react'
32import React , { useEffect , useRef } from 'react'
43import useLayoutEffect from '../utils/useIsomorphicLayoutEffect'
@@ -8,17 +7,14 @@ import type {TouchOrMouseEvent} from '../hooks'
87import { useOverlay } from '../hooks'
98import Portal from '../Portal'
109import type { SxProp } from '../sx'
11- import sx from '../sx'
1210import { useRefObjectAsForwardedRef } from '../hooks/useRefObjectAsForwardedRef'
1311import type { AnchorSide } from '@primer/behaviors'
1412import { useTheme } from '../ThemeProvider'
1513import type { ForwardRefComponent as PolymorphicForwardRefComponent } from '../utils/polymorphic'
1614import { useFeatureFlag } from '../FeatureFlags'
17- import { toggleStyledComponent } from '../internal/utils/toggleStyledComponent'
1815import classes from './Overlay.module.css'
1916import { clsx } from 'clsx'
20-
21- const CSS_MODULES_FLAG = 'primer_react_css_modules_ga'
17+ import { BoxWithFallback } from '../internal/components/BoxWithFallback'
2218
2319type StyledOverlayProps = {
2420 width ?: keyof typeof widthMap
@@ -65,60 +61,6 @@ function getSlideAnimationStartingVector(anchorSide?: AnchorSide): {x: number; y
6561 return { x : 0 , y : 0 }
6662}
6763
68- const StyledOverlay = toggleStyledComponent (
69- CSS_MODULES_FLAG ,
70- 'div' ,
71- styled . div < StyledOverlayProps > `
72- background-color: ${ get ( 'colors.canvas.overlay' ) } ;
73- box-shadow: ${ get ( 'shadows.overlay.shadow' ) } ;
74- position: absolute;
75- min-width: 192px;
76- max-width: ${ props => props . maxWidth && widthMap [ props . maxWidth ] } ;
77- height: ${ props => heightMap [ props . height || 'auto' ] } ;
78- max-height: ${ props => ( props . maxHeight ? heightMap [ props . maxHeight ] : '100vh' ) } ;
79- width: ${ props => widthMap [ props . width || 'auto' ] } ;
80- border-radius: 12px;
81- overflow: ${ props => ( props . overflow ? props . overflow : 'hidden' ) } ;
82- animation: overlay-appear ${ animationDuration } ms ${ get ( 'animation.easeOutCubic' ) } ;
83-
84- @keyframes overlay-appear {
85- 0% {
86- opacity: 0;
87- }
88- 100% {
89- opacity: 1;
90- }
91- }
92- visibility: var(--styled-overlay-visibility);
93- :focus {
94- outline: none;
95- }
96-
97- @media (forced-colors: active) {
98- /* Support for Windows high contrast https://sarahmhigley.com/writing/whcm-quick-tips */
99- outline: solid 1px transparent;
100- }
101-
102- &[data-reflow-container='true'] {
103- max-width: calc(100vw - 2rem);
104- }
105-
106- &:where([data-responsive='fullscreen']) {
107- @media screen and (max-width: calc(768px - 0.02px)) {
108- position: fixed;
109- top: 0;
110- left: 0;
111- width: 100vw;
112- height: 100vh;
113- margin: 0;
114- border-radius: unset;
115- }
116- }
117-
118- ${ sx } ;
119- ` ,
120- )
121-
12264type BaseOverlayProps = {
12365 visibility ?: 'visible' | 'hidden'
12466 'data-test-id' ?: unknown
@@ -167,57 +109,31 @@ export const BaseOverlay = React.forwardRef<HTMLDivElement, OwnOverlayProps>(
167109 } ,
168110 forwardedRef ,
169111 ) : ReactElement => {
170- const cssModulesEnabled = useFeatureFlag ( CSS_MODULES_FLAG )
171-
172- if ( cssModulesEnabled ) {
173- return (
174- < StyledOverlay
175- { ...rest }
176- ref = { forwardedRef }
177- style = {
178- {
179- left,
180- right,
181- top,
182- bottom,
183- position,
184- ...styleFromProps ,
185- } as React . CSSProperties
186- }
187- { ...{
188- [ `data-width-${ width } ` ] : '' ,
189- [ `data-max-width-${ maxWidth } ` ] : maxWidth ? '' : undefined ,
190- [ `data-height-${ height } ` ] : '' ,
191- [ `data-max-height-${ maxHeight } ` ] : maxHeight ? '' : undefined ,
192- [ `data-visibility-${ visibility } ` ] : '' ,
193- } }
194- className = { clsx ( className , classes . Overlay ) }
195- />
196- )
197- } else {
198- return (
199- < StyledOverlay
200- height = { height }
201- width = { width }
202- maxHeight = { maxHeight }
203- maxWidth = { maxWidth }
204- { ...rest }
205- ref = { forwardedRef }
206- style = {
207- {
208- left,
209- right,
210- top,
211- bottom,
212- position,
213- '--styled-overlay-visibility' : visibility ,
214- ...styleFromProps ,
215- } as React . CSSProperties
216- }
217- className = { className }
218- />
219- )
220- }
112+ return (
113+ < BoxWithFallback
114+ as = "div"
115+ { ...rest }
116+ ref = { forwardedRef }
117+ style = {
118+ {
119+ left,
120+ right,
121+ top,
122+ bottom,
123+ position,
124+ ...styleFromProps ,
125+ } as React . CSSProperties
126+ }
127+ { ...{
128+ [ `data-width-${ width } ` ] : '' ,
129+ [ `data-max-width-${ maxWidth } ` ] : maxWidth ? '' : undefined ,
130+ [ `data-height-${ height } ` ] : '' ,
131+ [ `data-max-height-${ maxHeight } ` ] : maxHeight ? '' : undefined ,
132+ [ `data-visibility-${ visibility } ` ] : '' ,
133+ } }
134+ className = { clsx ( className , classes . Overlay ) }
135+ />
136+ )
221137 } ,
222138) as PolymorphicForwardRefComponent < 'div' , OwnOverlayProps >
223139
0 commit comments