mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
Add a dismissible bar above the www nav that promotes Launch Week 16 (December 7-11) and links to /launch-week. Hide the bar on /launch-week pages. Hide it on /state-of-startups too because the fixed nav on that page would cover it. ## Banner polish Adds shared animated dot artwork, a link CTA, and responsive spacing and alignment. Reduced-motion preferences keep the dots static. Studio uses this artwork in the dependent #54512. | After | | --- | | <img width="500" height="584" alt="31035" src="https://github.com/user-attachments/assets/7ebad641-158e-47ea-a8be-3097ecc5c0ae" /> | | <img width="500" height="584" alt="18287" src="https://github.com/user-attachments/assets/02c87481-1dbe-4576-afc0-bdc9f22fc893" /> | | <img width="995" height="584" alt="89244" src="https://github.com/user-attachments/assets/aad4b608-71f1-484f-bbf4-54c725800f52" /> | | <img width="995" height="584" alt="99848" src="https://github.com/user-attachments/assets/a8b50942-1ecd-4c63-91b3-a6b4847d8830" /> | ## Review instructions 1. Open the www homepage on the preview in light and dark mode. Check the centred desktop message, link hover, and close button. 2. At a phone width, check the left-aligned copy and artwork on the right. Open the mobile menu and close it; the banner should return. 3. Dismiss the banner and reload. It should stay dismissed. Validation: scoped ESLint, formatting, and ui-patterns typecheck pass. --------- Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com>
293 lines
12 KiB
TypeScript
293 lines
12 KiB
TypeScript
'use client'
|
|
|
|
import { LaunchWeek16Banner } from 'components/Announcement/LaunchWeek16Banner'
|
|
import ScrollProgress from 'components/ScrollProgress'
|
|
import { getMenu } from 'data/nav'
|
|
import { DevToolbarTrigger } from 'dev-tools'
|
|
import { useSendTelemetryEvent } from 'lib/telemetry'
|
|
import { usePathname } from 'next/navigation'
|
|
import React, { useRef, useState } from 'react'
|
|
import {
|
|
Button,
|
|
buttonVariants,
|
|
cn,
|
|
FloatingPlate,
|
|
NavigationMenu,
|
|
NavigationMenuContent,
|
|
NavigationMenuItem,
|
|
NavigationMenuLink,
|
|
NavigationMenuList,
|
|
NavigationMenuTrigger,
|
|
NavigationMenuViewport,
|
|
} from 'ui'
|
|
import { SignedInSwitch } from 'ui-patterns/SignedInSwitch/SignedInSwitch'
|
|
import { TopNavMenuToggle } from 'ui-patterns/TopNav/TopNavMenuToggle'
|
|
|
|
import { AccountMenu } from './AccountMenu'
|
|
import GitHubButton from './GitHubButton'
|
|
import MenuItem from './MenuItem'
|
|
import { MobileMenu } from './MobileMenu'
|
|
import RightClickBrandLogo from './RightClickBrandLogo'
|
|
import { DASHBOARD_SIGN_IN_URL, DASHBOARD_SIGN_UP_URL } from '@/lib/dashboard-links'
|
|
|
|
interface Props {
|
|
hideNavbar: boolean
|
|
stickyNavbar?: boolean
|
|
}
|
|
|
|
const Nav = ({ hideNavbar, stickyNavbar = true }: Props) => {
|
|
const pathname = usePathname()
|
|
const [open, setOpen] = useState(false)
|
|
const menuButtonRef = useRef<HTMLButtonElement>(null)
|
|
const [activeDropdown, setActiveDropdown] = useState('')
|
|
const [visibleDropdown, setVisibleDropdown] = useState('')
|
|
const [isSwitchingDropdown, setIsSwitchingDropdown] = useState(false)
|
|
const [openedDropdowns, setOpenedDropdowns] = useState<string[]>([])
|
|
const handleDropdownChange = (value: string) => {
|
|
// animate card height between two open menus only
|
|
setIsSwitchingDropdown(value !== '' && activeDropdown !== '')
|
|
setActiveDropdown(value)
|
|
if (value === '') return
|
|
setVisibleDropdown(value)
|
|
if (!openedDropdowns.includes(value)) setOpenedDropdowns([...openedDropdowns, value])
|
|
}
|
|
const menu = getMenu()
|
|
const dropdownTitles: string[] = menu.primaryNav
|
|
.filter((menuItem) => menuItem.hasDropdown)
|
|
.map((menuItem) => menuItem.title)
|
|
const getDropdownSide = (title: string) => {
|
|
if (title === visibleDropdown) return 'active'
|
|
return dropdownTitles.indexOf(title) < dropdownTitles.indexOf(visibleDropdown) ? 'start' : 'end'
|
|
}
|
|
const sendTelemetryEvent = useSendTelemetryEvent()
|
|
|
|
const isGAWeekSection = pathname?.startsWith('/ga-week')
|
|
const isStateOfStartupsPage = pathname?.startsWith('/state-of-startups')
|
|
const hideLaunchWeekBanner = isStateOfStartupsPage || pathname?.startsWith('/launch-week')
|
|
const disableStickyNav = isGAWeekSection || !stickyNavbar
|
|
const showLaunchWeekNavMode = isGAWeekSection && !open
|
|
|
|
const [scrolled, setScrolled] = React.useState(false)
|
|
React.useEffect(() => {
|
|
if (!isStateOfStartupsPage) return
|
|
const handleScroll = () => setScrolled(window.scrollY > 50)
|
|
window.addEventListener('scroll', handleScroll)
|
|
return () => window.removeEventListener('scroll', handleScroll)
|
|
}, [isStateOfStartupsPage])
|
|
|
|
const isTransparent = isStateOfStartupsPage && !scrolled && !open
|
|
|
|
const handleMenuToggle = () => setOpen(!open)
|
|
const handleMenuClose = () => setOpen(false)
|
|
|
|
if (hideNavbar) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<>
|
|
{!hideLaunchWeekBanner && (
|
|
<div className={cn(open && 'hidden')}>
|
|
<LaunchWeek16Banner />
|
|
</div>
|
|
)}
|
|
<div
|
|
className={cn(
|
|
'sticky top-0 z-40 transform',
|
|
disableStickyNav && 'relative',
|
|
isStateOfStartupsPage && 'fixed left-0 right-0'
|
|
)}
|
|
style={{ transform: 'translate3d(0,0,999px)' }}
|
|
data-nav-transparent={isTransparent ? '' : undefined}
|
|
>
|
|
<div
|
|
className={cn(
|
|
'absolute inset-0 h-full w-full bg-background/90 dark:bg-background/95 transition-all duration-300',
|
|
!showLaunchWeekNavMode && !isTransparent && 'opacity-100!',
|
|
showLaunchWeekNavMode && 'bg-transparent! dark:bg-black!',
|
|
isGAWeekSection && 'dark:bg-alternative!',
|
|
isTransparent && 'bg-transparent! dark:bg-transparent! opacity-100!'
|
|
)}
|
|
/>
|
|
<nav
|
|
className={cn(
|
|
`relative z-40 border-default border-b backdrop-blur-xs transition-all duration-300`,
|
|
showLaunchWeekNavMode && 'border-muted border-b bg-transparent',
|
|
isTransparent && 'border-transparent backdrop-blur-none'
|
|
)}
|
|
>
|
|
<div className="section-container relative flex justify-between h-16">
|
|
<div className="flex items-center flex-1 sm:items-stretch justify-between">
|
|
<div className="flex items-center">
|
|
<div className="flex items-center shrink-0">
|
|
<RightClickBrandLogo />
|
|
</div>
|
|
<NavigationMenu
|
|
delayDuration={0}
|
|
value={activeDropdown}
|
|
onValueChange={handleDropdownChange}
|
|
renderViewport={false}
|
|
className="static hidden pl-8 lg:flex h-16 items-stretch"
|
|
>
|
|
<NavigationMenuList className="h-full space-x-0 items-stretch">
|
|
{menu.primaryNav.map((menuItem) =>
|
|
menuItem.hasDropdown ? (
|
|
<NavigationMenuItem
|
|
className="text-sm font-medium"
|
|
key={menuItem.title}
|
|
value={menuItem.title}
|
|
>
|
|
<NavigationMenuTrigger
|
|
className={cn(
|
|
buttonVariants({ variant: 'text', size: 'small' }),
|
|
'bg-transparent! hover:text-primary data-open:text-primary! focus-ring focus-visible:text-foreground px-2.5 h-full'
|
|
)}
|
|
>
|
|
{menuItem.title}
|
|
</NavigationMenuTrigger>
|
|
<NavigationMenuContent
|
|
forceMount
|
|
inert={visibleDropdown !== menuItem.title}
|
|
data-active={visibleDropdown === menuItem.title}
|
|
data-side={getDropdownSide(menuItem.title)}
|
|
className={cn(
|
|
'md:w-full data-[motion^=from-]:animate-none! data-[motion^=to-]:animate-none!',
|
|
'data-[active=false]:pointer-events-none data-[active=false]:opacity-0',
|
|
'data-[side=start]:-translate-x-4 data-[side=end]:translate-x-4',
|
|
'motion-safe:group-data-[switching=true]/viewport:transition-[opacity,translate]',
|
|
'motion-safe:group-data-[switching=true]/viewport:duration-250',
|
|
'motion-safe:group-data-[switching=true]/viewport:ease-in-out'
|
|
)}
|
|
>
|
|
{openedDropdowns.includes(menuItem.title) ? menuItem.dropdown : null}
|
|
</NavigationMenuContent>
|
|
</NavigationMenuItem>
|
|
) : (
|
|
<NavigationMenuItem className="text-sm font-medium" key={menuItem.title}>
|
|
<NavigationMenuLink asChild>
|
|
<MenuItem
|
|
href={menuItem.url}
|
|
title={menuItem.title}
|
|
className="group-hover:bg-transparent text-foreground focus-visible:text-primary px-2.5 h-full"
|
|
hoverColor="brand"
|
|
/>
|
|
</NavigationMenuLink>
|
|
</NavigationMenuItem>
|
|
)
|
|
)}
|
|
</NavigationMenuList>
|
|
<NavigationMenuViewport
|
|
forceMount
|
|
data-open={activeDropdown !== ''}
|
|
data-switching={isSwitchingDropdown}
|
|
// The wrapper keeps the last menu's height while closed, so it must
|
|
// not capture pointer events over the page below the nav.
|
|
containerProps={{ className: 'inset-x-0 pointer-events-none' }}
|
|
className={cn(
|
|
'group/viewport pointer-events-auto origin-top scale-100 rounded-xl bg-surface-75 md:w-[960px]',
|
|
'data-[state=open]:animate-none! data-[state=closed]:animate-none!',
|
|
'data-[state=open]:duration-200 data-[state=open]:ease-out data-[state=closed]:duration-200',
|
|
'data-[open=false]:invisible data-[open=false]:scale-[0.97] data-[open=false]:opacity-0',
|
|
'data-[open=false]:pointer-events-none',
|
|
'motion-safe:transition-[opacity,scale,visibility]',
|
|
'motion-safe:data-[switching=true]:transition-[height,opacity,scale,visibility]',
|
|
'motion-reduce:transition-none'
|
|
)}
|
|
/>
|
|
</NavigationMenu>
|
|
</div>
|
|
<div className="flex items-center gap-2 opacity-0 animate-fade-in scale-100! delay-300">
|
|
<DevToolbarTrigger />
|
|
<GitHubButton />
|
|
<SignedInSwitch
|
|
signedIn={
|
|
<>
|
|
{isStateOfStartupsPage ? (
|
|
<FloatingPlate rounded="md" className="hidden lg:inline-flex">
|
|
<Button asChild>
|
|
<a href="/dashboard/projects">Dashboard</a>
|
|
</Button>
|
|
</FloatingPlate>
|
|
) : (
|
|
<Button className="hidden lg:inline-flex" asChild>
|
|
<a href="/dashboard/projects">Dashboard</a>
|
|
</Button>
|
|
)}
|
|
<AccountMenu />
|
|
</>
|
|
}
|
|
signedOut={
|
|
<>
|
|
{isStateOfStartupsPage ? (
|
|
<FloatingPlate rounded="md" className="hidden lg:inline-flex">
|
|
<Button asChild>
|
|
<a
|
|
href={DASHBOARD_SIGN_IN_URL}
|
|
onClick={() =>
|
|
sendTelemetryEvent({
|
|
action: 'sign_in_button_clicked',
|
|
properties: { buttonLocation: 'Header Nav' },
|
|
})
|
|
}
|
|
>
|
|
Sign in
|
|
</a>
|
|
</Button>
|
|
</FloatingPlate>
|
|
) : (
|
|
<Button className="hidden lg:inline-flex" asChild>
|
|
<a
|
|
href={DASHBOARD_SIGN_IN_URL}
|
|
onClick={() =>
|
|
sendTelemetryEvent({
|
|
action: 'sign_in_button_clicked',
|
|
properties: { buttonLocation: 'Header Nav' },
|
|
})
|
|
}
|
|
>
|
|
Sign in
|
|
</a>
|
|
</Button>
|
|
)}
|
|
<Button variant="primary" className="hidden lg:inline-flex" asChild>
|
|
<a
|
|
href={DASHBOARD_SIGN_UP_URL}
|
|
onClick={() =>
|
|
sendTelemetryEvent({
|
|
action: 'start_project_button_clicked',
|
|
properties: { buttonLocation: 'Header Nav' },
|
|
})
|
|
}
|
|
>
|
|
Start your project
|
|
</a>
|
|
</Button>
|
|
</>
|
|
}
|
|
/>
|
|
</div>
|
|
</div>
|
|
<TopNavMenuToggle
|
|
ref={menuButtonRef}
|
|
isOpen={open}
|
|
onClick={handleMenuToggle}
|
|
className="self-center lg:hidden"
|
|
/>
|
|
</div>
|
|
</nav>
|
|
|
|
<ScrollProgress />
|
|
</div>
|
|
<MobileMenu
|
|
open={open}
|
|
menu={menu}
|
|
toggleRef={menuButtonRef}
|
|
onLinkClick={handleMenuClose}
|
|
className="lg:hidden [--header-height:--spacing(16)]"
|
|
/>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default Nav
|