55 *
66 * Copyright Oxide Computer Company
77 */
8+ import cn from 'classnames'
89import { useState , type ReactNode } from 'react'
910
1011import { Info16Icon , NextArrow12Icon } from '@oxide/design-system/icons/react'
@@ -26,36 +27,40 @@ function ExternalLink({ href, children }: { href: string; children: ReactNode })
2627 )
2728}
2829
29- type Props = {
30- /**
31- * HACK to avoid the user opening the modal while on the loading skeleton
32- * -- it immediately closes when the page finishes loading because the
33- * banner is dropped when the HydrateFallback unmounts and re-rendered in
34- * RootLayout. A more ideal solution would be to render the banner outside
35- * the RouterProvider and therefore have it be the same banner in both the
36- * HydrateFallback and normal page situations, but it's a lot more work to
37- * get the layout right in that case with respect to things like the loading
38- * bar. When we switch to framework mode, we can manage all this in the root
39- * route using the Layout export. In the meantime, this is tolerable and only
40- * applies to the preview deploys, and only burdens someone who manages to
41- * click the Learn More button in the half second before the content loads.
42- */
43- disableButton ?: boolean
30+ /**
31+ * Renders the preview banner (when enabled at build time) and sets
32+ * `--preview-banner-height` for the rest of the app. The banner is `fixed`, so
33+ * it can't push anything down through normal flow. Instead, the fixed-position
34+ * chrome (top bar, sidebar) and viewport-height calcs consume the variable to
35+ * offset themselves, the same way they use `--top-bar-height`. When the banner
36+ * is off, the variable stays at its 0px default (set in index.css) and the
37+ * offsets collapse to nothing, so consumers don't need their own conditionals.
38+ *
39+ * Rendered once in main.tsx, outside the router, so the same banner instance
40+ * persists across hydration (skeleton to real page) and error states.
41+ */
42+ export function PreviewBannerLayout ( { children } : { children : ReactNode } ) {
43+ return (
44+ < div
45+ className = { cn ( 'h-full' , process . env . MSW_BANNER && '[--preview-banner-height:2.5rem]' ) }
46+ >
47+ { process . env . MSW_BANNER ? < MswBanner /> : null }
48+ { children }
49+ </ div >
50+ )
4451}
4552
46- export function MswBanner ( { disableButton } : Props ) {
53+ function MswBanner ( ) {
4754 const [ isOpen , setIsOpen ] = useState ( false )
4855 const closeModal = ( ) => setIsOpen ( false )
4956 return (
5057 < >
51- { /* The [&+*]:pt-10 style is to ensure the page container isn't pushed out of screen as it uses 100vh for layout */ }
52- < aside className = "text-sans-md text-info bg-info absolute z-(--z-top-bar) flex h-10 w-full items-center justify-center [&+*]:pt-10" >
58+ < aside className = "text-sans-md text-info bg-info fixed top-0 z-(--z-top-bar) flex h-(--preview-banner-height) w-full items-center justify-center" >
5359 < Info16Icon className = "mr-2" /> This is a technical preview.
5460 < button
5561 type = "button"
5662 className = "text-sans-md hover:text-info ml-2 flex items-center gap-0.5"
5763 onClick = { ( ) => setIsOpen ( true ) }
58- disabled = { disableButton }
5964 >
6065 Learn more < NextArrow12Icon />
6166 </ button >
0 commit comments