Site
Site header
The site's header: the lockup, the links with their dropdown menus (products beside a live card, use cases beside a picture card, resources beside the docs card with the brand light), the sign-in and the one White key; on phones a sheet that reveals downward with the menus as disclosures. A Black ground and a hairline once the page scrolls.
Install
React apps get the React files; every other stack gets the web component.
npx spyglass-ds add site-header<script type="module" src="/spyglass-ds/elements/site-header.js"></script>Usage
The top of every website page. links entries with menu open the products, use cases or resources menu; menus carries their content (Acme by default, pictures only through picture and shots); hideKeyUntil holds the key back until a hero's actions scroll under the bar; variant centered shows the links from 1024, minimal keeps only the lockup and the key.
Never
- Two White buttons in the header
- Platform logos in the menus: platforms are named in words
- People's photos as default pictures: pass your own shots
- Menus that animate when opened from the keyboard
- Icons that move on hover
The menus open on hover, focus or click as on the site; from the keyboard they appear at once with focus on their first link, arrows move through them and Escape returns focus to their link. The phone sheet is a modal dialog: focus stays inside it and Escape returns it to the menu button. In menus, a products row's picture (a src or an image slot) takes the place of its scene on the live card, and a use case row's shots take srcs or image slots; the glyph and the empty tiles shown without them carry data-ds-placeholder.
Adds with it: ascii-drift, brand-light, button, creative-card, logo, product-visual
Props
The web component takes the same as attributes or properties (<spyglass-site-header>); title is heading there.
<SiteHeader>
| Prop | Type | Default |
|---|---|---|
links | HeaderLink[] The links; entries with `menu` (products, useCases, resources) open that menu. | headerNav |
menus | HeaderMenus The menus' content. | headerMenus |
cta | HeaderAction The White key on the right. | { label: 'Get a free API key', href: '#start', short: 'Get API key' } |
secondary | HeaderAction The sign-in before it. | { label: 'Sign in', href: '#sign-in' } |
homeHref | string Where the lockup links. | '/' |
label | string The lockup's accessible name. | 'Spyglass' |
variant | 'default' | 'centered' | 'minimal' default (links and menus from 1280), centered (from 1024) or minimal (the lockup and the key only). | 'default' |
hideKeyUntil | string Keep the key hidden until the element this selector finds has passed under the bar. | |
sticky | boolean Stay at the top while the page scrolls (sticky), or scroll away with it. | true |
labels | HeaderLabels | headerLabels |
className | string |
<NavMenus>
| Prop | Type | Default |
|---|---|---|
links | NavEntry[] The links; entries with `menu` open that menu. | |
menus | HeaderMenus | headerMenus |
label | string The nav's accessible name. | 'Main' |
from | number The width the links show from (1280 or 1024); hidden below it. | 1280 |
className | string |
<OfferRowBody>
| Prop | Type | Default |
|---|---|---|
item | OfferRow | SoonRow |
<UseCasesPanel>
| Prop | Type | Default |
|---|---|---|
menu | UseCasesMenu | headerMenus.useCases |
<ResourcesPanel>
| Prop | Type | Default |
|---|---|---|
menu | ResourcesMenu | headerMenus.resources |
<ProductsLivePanel>
| Prop | Type | Default |
|---|---|---|
menu | ProductsMenu | headerMenus.products |
<MenuSheet>
| Prop | Type | Default |
|---|---|---|
label | string The menu button's and the dialog's name. | 'Menu' |
closeLabel | string | 'Close menu' |
brand | ReactNode The lockup link in the sheet's bar. | |
action | ReactNode Beside the close button (the key). | |
foot | ReactNode Pinned at the foot (sign in, the key). | |
children | ReactNode | |
until | number The width it closes and hides at (1280 or 1024; the header shows its links from there). | 1280 |
className | string |
<SheetDisclosure>
| Prop | Type | Default |
|---|---|---|
label | string | |
children | ReactNode | |
defaultOpen | boolean | false |
className | string |
<NavIcon>
| Prop | Type | Default |
|---|---|---|
name | NavIconName | |
size | 20 | 24 20 or 24px. | 20 |
className | string |
<Chevron>
| Prop | Type | Default |
|---|---|---|
size | 12 | 16 | 12 |
className | string |
Examples
The same example in React and as web components; both render identically.
import { SiteHeader } from '@/react/components/site/SiteHeader'
// The header as the site sets it: Products, Use cases and Resources open their menus (Acme content), the sign-in and
// the key on the right; the phone sheet below 1280. The space under it leaves room for the menus.
export default function Default() {
return (
<div className="min-h-150 w-full">
<SiteHeader homeHref="#home" />
</div>
)
}<!-- The header as the site sets it: Products, Use cases and Resources open their menus (Acme content), the sign-in and
the key on the right; the phone sheet below 1280. The space under it leaves room for the menus. -->
<div class="min-h-150 w-full">
<spyglass-site-header home-href="#home"></spyglass-site-header>
</div>import { SiteHeader } from '@/react/components/site/SiteHeader'
// The links and menus from 1024, with plain links only.
const links = [{ label: 'Product', href: '#product', current: true }, { label: 'Customers', href: '#customers' }, { label: 'Pricing', href: '#pricing' }, { label: 'Docs', href: '#docs' }]
export default function Centered() {
return (
<div className="min-h-40 w-full">
<SiteHeader variant="centered" homeHref="#home" links={links} cta={{ label: 'Get started', href: '#start' }} />
</div>
)
}<!-- The links and menus from 1024, with plain links only. -->
<div class="min-h-40 w-full">
<spyglass-site-header variant="centered" home-href="#home" links='[{"label":"Product","href":"#product","current":true},{"label":"Customers","href":"#customers"},{"label":"Pricing","href":"#pricing"},{"label":"Docs","href":"#docs"}]' cta='{"label":"Get started","href":"#start"}'></spyglass-site-header>
</div>import { SiteHeader } from '@/react/components/site/SiteHeader'
// The minimal header for a checkout or a sign-in flow: the lockup and the one button.
export default function Minimal() {
return <SiteHeader variant="minimal" homeHref="#home" cta={{ label: 'Talk to us', href: '#contact' }} className="w-full" />
}<!-- The minimal header for a checkout or a sign-in flow: the lockup and the one button. -->
<spyglass-site-header variant="minimal" home-href="#home" cta='{"label":"Talk to us","href":"#contact"}' class="w-full"></spyglass-site-header>Source
'use client'
import { useEffect, useLayoutEffect, useState } from 'react'
import { BAR, MenuSheet } from '@/react/components/site/MenuSheet'
import { GLYPH } from '@/react/components/site/MenuPanels'
import { NAV_LINK, NavMenus } from '@/react/components/site/NavMenus'
import { NavIcon } from '@/react/components/site/NavIcon'
import { SHEET_LINK, SheetDisclosure } from '@/react/components/site/SheetDisclosure'
import { Button } from '@/react/components/ui/Button'
import { Logo } from '@/react/components/visuals/Logo'
import { headerLabels, headerMenus, headerNav, type HeaderLabels, type HeaderMenus, type NavEntry } from '@/lib/site-header'
import { cn } from '@/react/lib/cn'
import { homeLinkClick } from '@/lib/home-link'
// The site's header (site/Header: Header, HomeLink, ScrollGround, HeaderKey, NavMenus, MenuSheet): 64px, 72px from
// 1024, in the page's container; the lockup (20px) on the left, from 1280 the links and their menus centered (NavMenus)
// and on the right the sign-in in the links' style beside the White 36px key ("Get API key" under 424px, gone under
// 372). Below 1280 the links fold into the phone sheet (MenuSheet): its menus as disclosures of their rows, its other
// links, the sign-in and the key at its foot. Once the page scrolls 8px the bar takes a Black ground and a hairline
// (fading in, 160ms). With `hideKeyUntil` (a selector, a hero's actions) the key waits, hidden, until that element
// passes under the bar, then grows in and the sign-in slides aside for it. `variant`: default; centered (links and
// menus from 1024); minimal (the lockup and the key only). Menu content comes through `menus` (Acme by default).
export interface HeaderLink extends NavEntry {}
export interface HeaderAction {
label: string
href: string
/** A shorter label for the narrowest phones (the key). */
short?: string
}
export interface SiteHeaderProps {
/** The links; entries with `menu` (products, useCases, resources) open that menu. */
links?: HeaderLink[]
/** The menus' content. */
menus?: HeaderMenus
/** The White key on the right. */
cta?: HeaderAction
/** The sign-in before it. */
secondary?: HeaderAction
/** Where the lockup links. */
homeHref?: string
/** The lockup's accessible name. */
label?: string
/** default (links and menus from 1280), centered (from 1024) or minimal (the lockup and the key only). */
variant?: 'default' | 'centered' | 'minimal'
/** Keep the key hidden until the element this selector finds has passed under the bar. */
hideKeyUntil?: string
/** Stay at the top while the page scrolls (sticky), or scroll away with it. */
sticky?: boolean
labels?: HeaderLabels
className?: string
}
const GRID = { default: 'xl:grid xl:grid-cols-[1fr_auto_1fr]', centered: 'lg:grid lg:grid-cols-[1fr_auto_1fr]', minimal: '' }
const SIGN_IN = { default: 'hidden xl:flex', centered: 'hidden lg:flex', minimal: 'hidden' }
const FROM = { default: 1280, centered: 1024, minimal: 1280 }
function useScrolled() {
const [scrolled, setScrolled] = useState(false)
useEffect(() => {
const on = () => setScrolled(window.scrollY > 8)
on()
window.addEventListener('scroll', on, { passive: true })
return () => window.removeEventListener('scroll', on)
}, [])
return scrolled
}
function useKeyShown(selector?: string) {
const [shown, setShown] = useState<'shown' | 'hidden'>('shown')
const [instant, setInstant] = useState(true)
useLayoutEffect(() => {
const hero = selector ? document.querySelector(selector) : null
const bar = () => parseFloat(getComputedStyle(document.documentElement).getPropertyValue(window.matchMedia('(min-width: 1024px)').matches ? '--ds-size-header' : '--ds-header-bar-phone')) || 0
const state = (rect: DOMRectReadOnly | null, top: number) => (!rect || (!rect.width && !rect.height) || rect.top < top ? 'shown' : 'hidden')
setShown(state(hero?.getBoundingClientRect() ?? null, bar()))
setInstant(true)
let frame = requestAnimationFrame(() => setInstant(false))
if (!hero) return () => cancelAnimationFrame(frame)
let observer: IntersectionObserver | null = null
let top = -1
const watch = () => {
const next = bar()
if (next === top) return
top = next
observer?.disconnect()
observer = new IntersectionObserver(([entry]) => {
if (!entry) return
setShown(state(entry.boundingClientRect, top))
if (!frame) frame = requestAnimationFrame(() => setInstant(false))
}, { rootMargin: `-${top}px 0px 0px 0px`, threshold: [0, 1] })
observer.observe(hero)
}
watch()
window.addEventListener('resize', watch)
return () => {
window.removeEventListener('resize', watch)
observer?.disconnect()
cancelAnimationFrame(frame)
}
}, [selector])
return { shown, instant }
}
export function SiteHeader({
links = headerNav,
menus = headerMenus,
cta = { label: 'Get a free API key', href: '#start', short: 'Get API key' },
secondary = { label: 'Sign in', href: '#sign-in' },
homeHref = '/',
label = 'Spyglass',
variant = 'default',
hideKeyUntil,
sticky = true,
labels = headerLabels,
className,
}: SiteHeaderProps) {
const scrolled = useScrolled()
const { shown, instant } = useKeyShown(hideKeyUntil)
const hidden = shown === 'hidden'
const brand = (
<a href={homeHref} aria-label={label} data-home-link="" onClick={(e) => homeLinkClick(e.nativeEvent)} className="-ms-2 block flex-none rounded-ds-sm px-2 py-3 text-fg md:-ms-3 md:px-3 md:py-2 lg:py-3 xl:justify-self-start">
<Logo height={20} label={label} />
</a>
)
const key = () => cta ? (
<Button href={cta.href} size="xs" className="ds-key">
<span className="ds-key-full truncate">{cta.label}</span>
<span className="ds-key-short truncate">{cta.short ?? cta.label}</span>
</Button>
) : null
const sheetRows = (entry: NavEntry) => {
if (entry.menu === 'products') { const m = menus.products ?? headerMenus.products; return [...m.offers, ...(m.soon ? [m.soon] : [])].map((r) => ({ key: r.key, name: r.name, href: r.href, icon: r.icon })) }
if (entry.menu === 'useCases') return (menus.useCases ?? headerMenus.useCases).rows.map((r) => ({ key: r.key, name: r.name, href: r.href, icon: r.icon }))
return []
}
return (
<header data-ds="site-header" data-variant={variant} className={cn('ds-site-header z-20 text-fg', sticky ? 'sticky top-0' : 'relative', className)}>
<style href="ds-site-header" precedence="ds">{css}</style>
<span aria-hidden="true" data-on={scrolled || undefined} className="pointer-events-none absolute inset-0 border-b border-edge bg-surface opacity-0 transition-opacity duration-160 ease-out data-on:opacity-100" />
<div className={cn(BAR, GRID[variant])}>
{brand}
{variant !== 'minimal' ? <NavMenus links={links} menus={menus} label={labels.nav} from={FROM[variant]} /> : null}
<div className="ds-actions flex min-w-0 flex-[0_1_auto] items-center gap-1 md:gap-2 xl:min-w-auto xl:justify-self-end xl:gap-3">
<div data-key={shown} data-instant={instant || undefined} className="ds-key-slot relative flex min-w-0 flex-[0_1_auto]">
<div className="ds-key-room pointer-events-none absolute inset-0">
{secondary ? <a href={secondary.href} className={cn(NAV_LINK, SIGN_IN[variant], 'pointer-events-auto absolute inset-y-0 right-[calc(100%+var(--ds-space-md))] my-auto px-3 whitespace-nowrap')}>{secondary.label}</a> : null}
</div>
<div inert={hidden} aria-hidden={hidden || undefined} className="ds-key-box flex min-w-0">{key()}</div>
</div>
{variant !== 'minimal' ? (
<MenuSheet
label={labels.menu}
closeLabel={labels.close}
until={FROM[variant]}
brand={brand}
action={<div className="flex min-w-0 flex-[0_1_auto]">{key()}</div>}
foot={
<>
{secondary ? <Button href={secondary.href} variant="secondary" className="w-full">{secondary.label}</Button> : null}
{cta ? <div className="contents md:hidden"><Button href={cta.href} className="w-full">{cta.label}</Button></div> : null}
</>
}
>
<nav aria-label={labels.nav} className="mx-auto w-full max-w-[calc(var(--ds-layout-content)+2*var(--ds-layout-gutter))] px-(--ds-layout-gutter)">
<ul>
{links.map((entry) => (
<li key={entry.label} className="flex flex-col border-t border-edge first:border-t-0 last:border-b">
{entry.menu && entry.menu !== 'resources' ? (
<SheetDisclosure label={entry.label}>
<ul className="grid gap-x-4 pb-2 md:grid-cols-2">
{sheetRows(entry).map((row) => (
<li key={row.key}>
<a href={row.href} className="-mx-2 flex min-h-12 items-center gap-3 rounded-control px-2 type-body text-fg transition-[color] duration-160 ease-out outline-offset-[calc(-1*var(--ds-space-xs))] hover:text-fg-soft active:text-fg-soft">
<span className={cn(GLYPH, 'size-8 rounded-ds-sm')}><NavIcon name={row.icon} /></span>
{row.name}
</a>
</li>
))}
</ul>
</SheetDisclosure>
) : (
<a href={entry.menu === 'resources' ? (menus.resources ?? headerMenus.resources).all.href : entry.href} aria-current={entry.current ? 'page' : undefined} className={SHEET_LINK}>{entry.label}</a>
)}
</li>
))}
</ul>
</nav>
</MenuSheet>
) : null}
</div>
</div>
</header>
)
}
export default SiteHeader
const css = `
.ds-key-box { transition: opacity var(--ds-duration-entrance) var(--ds-easing-out) var(--ds-duration-slow), transform var(--ds-duration-entrance) var(--ds-easing-out) var(--ds-duration-slow), visibility var(--ds-duration-instant) linear; }
.ds-key-room { transition: transform var(--ds-duration-slow) var(--ds-easing-out); }
.ds-key-slot[data-key="hidden"] .ds-key-box {
opacity: 0; transform: scale(var(--ds-menu-from-scale)); visibility: hidden; pointer-events: none;
transition: opacity var(--ds-duration-close) var(--ds-easing-out), transform var(--ds-duration-close) var(--ds-easing-out), visibility var(--ds-duration-instant) linear var(--ds-duration-close);
}
.ds-key-slot[data-instant] .ds-key-box, .ds-key-slot[data-instant] .ds-key-room { transition: none; }
.ds-key-short { display: none; }
@media (max-width: 423px) {
.ds-actions { gap: 0; }
.ds-key-full { display: none; }
.ds-key-short { display: block; }
}
@media (max-width: 371px) { .ds-key-slot .ds-key { display: none; } }
@media (min-width: 1024px) {
.ds-site-header[data-variant="centered"] .ds-key-slot[data-key="hidden"] .ds-key-room { transform: translateX(calc(100% + var(--ds-space-xl))); transition-delay: var(--ds-duration-close); }
}
@media (min-width: 1280px) {
.ds-site-header[data-variant="default"] .ds-key-slot[data-key="hidden"] .ds-key-room { transform: translateX(calc(100% + var(--ds-space-xl))); transition-delay: var(--ds-duration-close); }
}
@media (prefers-reduced-motion: reduce) {
.ds-key-box { transition: opacity var(--ds-duration-micro) var(--ds-easing-out), visibility var(--ds-duration-instant) linear; }
.ds-key-slot[data-key="hidden"] .ds-key-box { transform: none; transition: opacity var(--ds-duration-micro) var(--ds-easing-out), visibility var(--ds-duration-instant) linear var(--ds-duration-micro); }
.ds-key-room { transition: none; }
}
`'use client'
import { useEffect, useId, useRef, useState, type FocusEvent, type KeyboardEvent, type MouseEvent, type PointerEvent, type ReactNode } from 'react'
import { ResourcesPanel, UseCasesPanel } from '@/react/components/site/MenuPanels'
import { Chevron } from '@/react/components/site/NavIcon'
import { ProductsLivePanel } from '@/react/components/site/ProductsLivePanel'
import { headerMenus, headerNav, MENU_GRACE_MS, MENU_INTENT_MS, type HeaderMenus, type MenuKey, type NavEntry } from '@/lib/site-header'
import { cn } from '@/react/lib/cn'
// The site header's links and menus (site/Header NavMenus): DM Sans 14/20 links in the soft gray, 36px tall with 16px
// in, filling #262626 under the pointer; Products, Use cases and Resources open their panels 24px under the bar.
// Under a mouse a menu opens after a short pause (80ms) and, once one is open, moving to another swaps at once; leaving
// the links and the panel closes it after 240ms. A click opens it and keeps it open (a second click closes it); Enter,
// Space or ArrowDown open it with focus on its first link (ArrowUp on its last), arrows, Home and End move through its
// links, Escape closes it and gives focus back to its link, and a click or focus outside closes it. A panel opens by
// fading in, rising 8px and growing from 96% (240ms; 160ms out); from the keyboard, or swapping, it appears at once.
// Reduced motion keeps the fade.
export const NAV_LINK = 'relative flex h-control-xs items-center rounded-control px-4 type-ui text-fg-soft transition-[color,background-color] duration-160 ease-out after:absolute after:inset-x-0 after:-inset-y-1 hover:bg-surface-raised hover:text-fg focus-visible:text-fg active:text-fg aria-[current=page]:text-fg'
type Via = 'hover' | 'click'
const WIDTH: Record<MenuKey, string> = {
products: 'w-[min(var(--ds-header-menu-products-w),calc(100vw-2*var(--ds-layout-gutter)))]',
useCases: 'w-[min(var(--ds-header-menu-cases-w),calc(100vw-2*var(--ds-layout-gutter)))]',
resources: 'w-[min(var(--ds-header-menu-resources-w),calc(100vw-2*var(--ds-layout-gutter)))]',
}
function links(panel: HTMLElement | null | undefined) {
return panel ? [...panel.querySelectorAll<HTMLElement>('a[href]:not([tabindex="-1"])')].filter((a) => a.getClientRects().length > 0) : []
}
export interface NavMenusProps {
/** The links; entries with `menu` open that menu. */
links?: NavEntry[]
menus?: HeaderMenus
/** The nav's accessible name. */
label?: string
/** The width the links show from (1280 or 1024); hidden below it. */
from?: number
className?: string
}
export function NavMenus({ links: entries = headerNav, menus = headerMenus, label = 'Main', from = 1280, className }: NavMenusProps) {
const [open, setOpen] = useState<MenuKey | null>(null)
const [instant, setInstant] = useState(false)
const navRef = useRef<HTMLElement>(null)
const triggers = useRef<Partial<Record<MenuKey, HTMLButtonElement | null>>>({})
const panels = useRef<Partial<Record<MenuKey, HTMLDivElement | null>>>({})
const via = useRef<Via>('click')
const timer = useRef<number | undefined>(undefined)
const pendingFocus = useRef<'first' | 'last' | null>(null)
const openRef = useRef<MenuKey | null>(null)
const uid = useId()
const panelId = (key: MenuKey) => `${uid}-${key}`
const clearTimer = () => {
window.clearTimeout(timer.current)
timer.current = undefined
}
const show = (key: MenuKey, how: Via, keyboard = false) => {
clearTimer()
via.current = how
setInstant(keyboard || (openRef.current !== null && openRef.current !== key))
openRef.current = key
setOpen(key)
}
const hide = () => {
clearTimer()
openRef.current = null
setInstant(false)
setOpen(null)
}
useEffect(() => {
if (!open || !pendingFocus.current) return
const items = links(panels.current[open])
const target = pendingFocus.current === 'first' ? items[0] : items[items.length - 1]
pendingFocus.current = null
target?.focus()
}, [open])
useEffect(() => {
if (!open) return
const nav = navRef.current
const onKeyDown = (e: globalThis.KeyboardEvent) => {
if (e.key !== 'Escape') return
const hadFocus = nav?.contains(document.activeElement)
hide()
if (hadFocus) triggers.current[open]?.focus()
}
const onPointerDown = (e: globalThis.PointerEvent) => { if (nav && !nav.contains(e.target as Node)) hide() }
const wide = window.matchMedia(`(min-width: ${from}px)`)
const onNarrow = () => { if (!wide.matches) hide() }
document.addEventListener('keydown', onKeyDown)
document.addEventListener('pointerdown', onPointerDown)
wide.addEventListener('change', onNarrow)
return () => {
document.removeEventListener('keydown', onKeyDown)
document.removeEventListener('pointerdown', onPointerDown)
wide.removeEventListener('change', onNarrow)
}
}, [open, from])
useEffect(() => () => window.clearTimeout(timer.current), [])
const onTriggerClick = (key: MenuKey, e: MouseEvent<HTMLButtonElement>) => {
clearTimer()
const keyboard = e.detail === 0
if (open === key) {
if (via.current === 'hover' && !keyboard) {
via.current = 'click'
return
}
hide()
return
}
if (keyboard) pendingFocus.current = 'first'
show(key, 'click', keyboard)
}
const onTriggerKeyDown = (key: MenuKey, e: KeyboardEvent<HTMLButtonElement>) => {
if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return
e.preventDefault()
if (open === key) {
const items = links(panels.current[key])
;(e.key === 'ArrowDown' ? items[0] : items[items.length - 1])?.focus()
return
}
pendingFocus.current = e.key === 'ArrowDown' ? 'first' : 'last'
show(key, 'click', true)
}
const onTriggerEnter = (key: MenuKey, e: PointerEvent<HTMLButtonElement>) => {
if (e.pointerType !== 'mouse') return
clearTimer()
if (open) {
if (open !== key) show(key, 'hover')
return
}
timer.current = window.setTimeout(() => show(key, 'hover'), MENU_INTENT_MS)
}
const onTriggerLeave = (e: PointerEvent<HTMLButtonElement>) => { if (e.pointerType === 'mouse' && !open) clearTimer() }
const onNavEnter = (e: PointerEvent<HTMLElement>) => { if (e.pointerType === 'mouse' && open) clearTimer() }
const onNavLeave = (e: PointerEvent<HTMLElement>) => {
if (e.pointerType !== 'mouse') return
clearTimer()
if (open && via.current === 'hover') timer.current = window.setTimeout(hide, MENU_GRACE_MS)
}
const onNavBlur = (e: FocusEvent<HTMLElement>) => { if (open && !navRef.current?.contains(e.relatedTarget as Node | null)) hide() }
const onPanelKeyDown = (key: MenuKey, e: KeyboardEvent<HTMLDivElement>) => {
const items = links(panels.current[key])
const at = items.indexOf(document.activeElement as HTMLElement)
if (at < 0) return
let next = -1
if (e.key === 'ArrowDown' || e.key === 'ArrowRight') next = Math.min(at + 1, items.length - 1)
else if (e.key === 'ArrowUp' || e.key === 'ArrowLeft') next = Math.max(at - 1, 0)
else if (e.key === 'Home') next = 0
else if (e.key === 'End') next = items.length - 1
if (next < 0) return
e.preventDefault()
items[next]?.focus()
}
const panel = (key: MenuKey, body: ReactNode) => (
<div
ref={(el) => { panels.current[key] = el }}
id={panelId(key)}
data-open={open === key || undefined}
inert={open !== key}
onKeyDown={(e) => onPanelKeyDown(key, e)}
onClick={(e) => { if ((e.target as Element).closest('a')) hide() }}
className={cn('ds-menu-panel absolute top-[calc(100%+var(--ds-header-menu-gap))] left-1/2 z-20 rounded-control border border-edge bg-surface-subtle text-fg before:absolute before:inset-x-0 before:bottom-full before:h-(--ds-header-menu-gap)', WIDTH[key])}
>
{body}
</div>
)
const has = (key: MenuKey) => entries.some((e) => e.menu === key) && Boolean(menus[key] ?? headerMenus[key])
return (
<nav ref={navRef} data-ds="nav-menus" aria-label={label} data-instant={instant || undefined} onPointerEnter={onNavEnter} onPointerLeave={onNavLeave} onBlur={onNavBlur} className={cn('ds-nav-menus relative', from === 1024 ? 'hidden lg:block' : 'hidden xl:block', className)}>
<style href="ds-nav-menus" precedence="ds">{css}</style>
<ul className="flex gap-1">
{entries.map((item) => item.menu ? (
<li key={item.label} className={item.menu === 'resources' ? 'relative' : undefined}>
<button
ref={(el) => { triggers.current[item.menu!] = el }}
type="button"
aria-expanded={open === item.menu}
aria-controls={panelId(item.menu)}
onClick={(e) => onTriggerClick(item.menu!, e)}
onKeyDown={(e) => onTriggerKeyDown(item.menu!, e)}
onPointerEnter={(e) => onTriggerEnter(item.menu!, e)}
onPointerLeave={onTriggerLeave}
className={cn(NAV_LINK, 'cursor-pointer gap-1 aria-expanded:bg-surface-raised aria-expanded:text-fg')}
>
{item.label}
<Chevron className="ds-nav-chevron" />
</button>
{item.menu === 'resources' && has('resources') ? panel('resources', <ResourcesPanel menu={menus.resources ?? headerMenus.resources} />) : null}
</li>
) : (
<li key={item.label}><a className={NAV_LINK} href={item.href} aria-current={item.current ? 'page' : undefined}>{item.label}</a></li>
))}
</ul>
{has('products') ? panel('products', <ProductsLivePanel menu={menus.products ?? headerMenus.products} />) : null}
{has('useCases') ? panel('useCases', <UseCasesPanel menu={menus.useCases ?? headerMenus.useCases} />) : null}
</nav>
)
}
export default NavMenus
const css = `
.ds-menu-panel {
visibility: hidden; opacity: 0; transform-origin: top center;
transform: translate(-50%, calc(-1 * var(--ds-header-menu-rise))) scale(var(--ds-menu-from-scale));
transition: opacity var(--ds-duration-micro) var(--ds-easing-out), transform var(--ds-duration-micro) var(--ds-easing-out), visibility var(--ds-duration-instant) linear var(--ds-duration-micro);
}
.ds-menu-panel[data-open] {
visibility: visible; opacity: 1; transform: translate(-50%, 0);
transition: opacity var(--ds-duration-enter) var(--ds-easing-out), transform var(--ds-duration-enter) var(--ds-easing-out), visibility var(--ds-duration-instant);
}
.ds-nav-menus[data-instant] .ds-menu-panel { transition: none; }
.ds-nav-chevron { transition: transform var(--ds-duration-micro) var(--ds-easing-out); }
[aria-expanded="true"] > .ds-nav-chevron { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) {
.ds-menu-panel, .ds-menu-panel[data-open] { transform: translate(-50%, 0); }
.ds-nav-chevron { transition: none; }
}
`'use client'
import { useState } from 'react'
import { NavIcon } from '@/react/components/site/NavIcon'
import { BrandLight } from '@/react/components/visuals/BrandLight'
import { headerMenus, type OfferRow, type ResourcesMenu, type SoonRow, type UseCasesMenu } from '@/lib/site-header'
import { cn } from '@/react/lib/cn'
import { imageFit, toSlot } from '@/lib/image'
// The site header's menu panels (site/Header MenuPanels): the use cases (two columns of rows with a 40px glyph, the name
// over a muted line, and a card on the right that crossfades to the row under the pointer or focus: up to three
// pictures and a longer line), the resources (rows with a 32px glyph, a coming-soon row in the faint gray with its
// badge, and the docs card with the brand light drifting behind an install line) and the strip of quieter links at the
// foot. The active row fills #262626 and its glyph brightens; nothing moves but the light (still with reduced motion).
export const ROW = 'group/row flex gap-3 rounded-ds-sm p-3 transition-[background-color] duration-160 ease-out outline-offset-[calc(-1*var(--ds-border-focus))] hover:bg-surface-raised data-active:bg-surface-raised'
export const GLYPH = 'grid flex-none place-items-center border border-edge bg-surface transition-[border-color] duration-160 ease-out group-hover/row:border-edge-strong group-hover/row:[--glyph-body:var(--ds-color-neutral-7)] group-hover/row:[--glyph-lit:var(--ds-color-fg)] group-focus-visible/row:border-edge-strong group-focus-visible/row:[--glyph-body:var(--ds-color-neutral-7)] group-focus-visible/row:[--glyph-lit:var(--ds-color-fg)] group-data-active/row:border-edge-strong group-data-active/row:[--glyph-body:var(--ds-color-neutral-7)] group-data-active/row:[--glyph-lit:var(--ds-color-fg)] [&_path]:transition-[fill,stroke] [&_path]:duration-160 [&_path]:ease-out'
export const STRIP = 'flex items-center gap-2 border-t border-edge py-1 pr-1 pl-4'
export const STRIP_LINK = 'flex h-8 items-center rounded-ds-sm px-2 type-ui-strong text-fg transition-[background-color] duration-160 ease-out outline-offset-[calc(-1*var(--ds-border-focus))] hover:bg-surface-raised'
/** A products row's body: the glyph, the name and the line. */
export function OfferRowBody({ item }: { item: OfferRow | SoonRow }) {
return (
<>
<span className={cn(GLYPH, 'size-10 rounded-control')}><NavIcon name={item.icon} size={24} /></span>
<span className="flex min-w-0 flex-col">
<span className="type-ui-strong text-fg">{item.name}</span>
<span className="type-ui text-fg-muted">{item.line}</span>
</span>
</>
)
}
export function UseCasesPanel({ menu = headerMenus.useCases }: { menu?: UseCasesMenu }) {
const [active, setActive] = useState(0)
const rows = menu.rows
const current = rows[active] ?? rows[0]
return (
<div data-ds="menu-panels" className="contents">
<div className="flex gap-1 p-1">
<ul className="grid min-w-0 flex-1 grid-flow-col grid-cols-2 grid-rows-3 content-start gap-1">
{rows.map((item, i) => (
<li key={item.key}>
<a className={ROW} href={item.href} data-active={i === active || undefined} onPointerEnter={() => setActive(i)} onFocus={() => setActive(i)}>
<span className={cn(GLYPH, 'size-10 rounded-control')}><NavIcon name={item.icon} size={24} /></span>
<span className="flex min-w-0 flex-col">
<span className="type-ui-strong text-fg">{item.name}</span>
<span className="type-ui text-fg-muted">{item.line}</span>
</span>
</a>
</li>
))}
</ul>
{current ? (
<a href={current.href} tabIndex={-1} aria-hidden="true" className="relative grid w-72 flex-none overflow-hidden rounded-ds-sm bg-surface-raised p-2 [contain:size]">
{rows.map((item, i) => (
<span key={item.key} data-on={i === active || undefined} className="flex min-h-0 flex-col opacity-0 transition-opacity duration-160 ease-out [grid-area:1/1] data-on:opacity-100">
<span className="grid min-h-0 flex-none grid-cols-3 gap-1">
{[0, 1, 2].map((n) => {
const shot = toSlot(item.shots?.[n])
return (
<span key={n} data-ds-placeholder={shot.src ? undefined : ''} className="relative aspect-4/5 overflow-hidden rounded-ds-sm bg-surface-subtle">
{shot.src ? <img src={shot.src} alt={shot.alt ?? ''} loading="eager" className="absolute inset-0 size-full object-cover" style={imageFit(shot)} /> : null}
</span>
)
})}
</span>
<span className="flex min-w-0 flex-none flex-col px-1 pt-2 pb-1">
<span className="type-ui-strong text-fg">{item.name}</span>
<span className="line-clamp-2 type-ui text-fg-muted">{item.card ?? item.line}</span>
</span>
</span>
))}
</a>
) : null}
</div>
<div className={STRIP}>
<a className={STRIP_LINK} href={menu.all.href}>{menu.all.label}</a>
<ul className="flex gap-1">
{menu.more.map((link) => <li key={link.label}><a className={cn(STRIP_LINK, 'font-regular text-fg-muted')} href={link.href}>{link.label}</a></li>)}
</ul>
</div>
</div>
)
}
export function ResourcesPanel({ menu = headerMenus.resources }: { menu?: ResourcesMenu }) {
const docs = menu.feature
return (
<div data-ds="menu-panels" className="flex gap-1 p-1">
<style href="ds-menu-panels" precedence="ds">{css}</style>
<ul className="relative isolate flex w-64 flex-none flex-col gap-1">
{menu.rows.map((row) => (
<li key={row.key}>
{row.soon ? (
<span aria-disabled="true" className="group/row flex h-12 cursor-default items-center gap-3 rounded-ds-sm px-3 type-ui text-fg-faint">
<span className={cn(GLYPH, 'size-8 rounded-ds-sm [--glyph-body:var(--ds-color-neutral-4)] [--glyph-lit:var(--ds-color-fg-faint)]')}><NavIcon name={row.icon} /></span>
{row.title}
<span className="ml-auto inline-flex h-6 items-center rounded-ds-sm bg-surface-inset px-2 type-caption font-medium text-fg-soft">{menu.soonLabel}</span>
</span>
) : (
<a href={row.href} {...(row.external ? { target: '_blank', rel: 'noreferrer' } : {})} className="group/row flex h-12 items-center gap-3 rounded-ds-sm px-3 type-ui-strong text-fg transition-[background-color] duration-160 ease-out outline-offset-[calc(-1*var(--ds-border-focus))] hover:bg-surface-raised">
<span className={cn(GLYPH, 'size-8 rounded-ds-sm')}><NavIcon name={row.icon} /></span>
{row.title}
</a>
)}
</li>
))}
</ul>
<a href={docs.href} {...(docs.external ? { target: '_blank', rel: 'noreferrer' } : {})} className="relative flex min-w-0 flex-1 flex-col overflow-hidden rounded-ds-sm bg-surface-raised p-2 transition-[background-color] duration-160 ease-out outline-offset-[calc(-1*var(--ds-border-focus))] [contain:size] hover:bg-surface-hover">
<span aria-hidden="true" className="relative min-h-0 flex-1 overflow-hidden bg-surface">
<span className="ds-docs-wave absolute inset-0">
<span className="ds-docs-ribbon absolute -inset-6 translate-y-6"><BrandLight variant="curved-strip" ground={false} cover className="absolute inset-0" /></span>
</span>
<code className="absolute top-3 left-3 font-code text-(length:--ds-text-caption) leading-(--ds-text-caption-leading) whitespace-nowrap text-fg-soft"><span className="text-fg-faint">$</span> {docs.code}</code>
</span>
<span className="flex min-w-0 flex-none flex-col px-1 pt-3 pb-1">
<span className="type-ui-strong text-fg">{docs.title}</span>
<span className="type-ui text-fg-muted">{docs.line}</span>
</span>
</a>
</div>
)
}
export default UseCasesPanel
const css = `
.ds-docs-wave { animation: ds-docs-slide var(--ds-header-band-slide) var(--ds-easing-drift) infinite alternate; }
.ds-docs-ribbon > * { animation: ds-docs-bob var(--ds-header-band-bob) var(--ds-easing-drift) infinite alternate; }
@keyframes ds-docs-slide { from { transform: translateX(calc(-1 * var(--ds-space-xl))); } to { transform: translateX(var(--ds-space-xl)); } }
@keyframes ds-docs-bob { from { transform: translateY(calc(-1 * var(--ds-space-sm))) rotate(-2deg); } to { transform: translateY(var(--ds-space-sm)) rotate(2deg); } }
@media (prefers-reduced-motion: reduce) { .ds-docs-wave, .ds-docs-ribbon > * { animation: none; } }
`'use client'
import { useEffect, useRef, useState } from 'react'
import { GLYPH, OfferRowBody, ROW, STRIP, STRIP_LINK } from '@/react/components/site/MenuPanels'
import { NavIcon } from '@/react/components/site/NavIcon'
import { ProductVisual } from '@/react/components/site/ProductVisual'
import { asciiDriftStyleObject } from '@/lib/ascii-drift'
import { headerMenus, LIVE_CROSSFADE_MS, type ProductsMenu } from '@/lib/site-header'
import { cn } from '@/react/lib/cn'
import { imageFit, toSlot } from '@/lib/image'
// The site header's products menu (site/Header ProductsLivePanel, LiveVisual, ui/WarmPictures): a 320px list of the
// offers (a 40px glyph, the name over a muted line) and the "live soon" row, beside a 540px
// live card that crossfades (160ms) to the row under the pointer or focus: the product's looping scene (`visual`, a
// product-visual kind, at the menu's quicker reading pace) over the ASCII texture, or its `picture`, or the
// texture and its glyph, with where it is live in words in a chip at its corner; for the live soon row, its groups (platforms and integrations, in words). The pictures load
// ahead, hidden, so the card never waits. A strip of build links at the foot.
// The product's scene fills the card at the menu's quicker reading pace (site --dur-read-first-menu, -hold-menu).
const VISUAL = 'absolute inset-0 grid [--ds-read-first:var(--ds-read-first-menu)] [--ds-read-hold:var(--ds-read-hold-menu)]'
export function ProductsLivePanel({ menu = headerMenus.products }: { menu?: ProductsMenu }) {
const rows = [...menu.offers, ...(menu.soon ? [menu.soon] : [])]
const [active, setActive] = useState(0)
const [leaving, setLeaving] = useState<number | null>(null)
const timer = useRef(0)
useEffect(() => () => window.clearTimeout(timer.current), [])
const show = (i: number) => {
if (i === active) return
window.clearTimeout(timer.current)
setLeaving(active)
setActive(i)
timer.current = window.setTimeout(() => setLeaving(null), LIVE_CROSSFADE_MS)
}
const current = rows[active] ?? rows[0]
const groups = current && 'groups' in current ? current.groups : undefined
return (
<div data-ds="products-live-panel" className="contents">
<div className="flex gap-1 p-1">
<ul className="flex w-80 flex-none flex-col gap-1">
{rows.map((item, i) => (
<li key={item.key}>
<a className={ROW} href={item.href} data-active={i === active || undefined} onPointerEnter={() => show(i)} onFocus={() => show(i)}>
<OfferRowBody item={item} />
</a>
</li>
))}
</ul>
{current ? (
<a href={current.href} tabIndex={-1} aria-hidden="true" className="relative grid w-(--ds-header-live-card-w) flex-none overflow-hidden rounded-ds-sm bg-surface-raised">
{[leaving, active].map((i) => {
if (i === null || !rows[i]) return null
const item = rows[i]
const picture = toSlot('picture' in item ? item.picture : undefined)
const visual = 'visual' in item ? item.visual : undefined
const platforms = 'platforms' in item ? item.platforms : undefined
return (
<span key={item.key} data-on={i === active || undefined} className="ds-live-stage relative isolate grid h-full place-items-center overflow-hidden rounded-ds-sm bg-surface-raised opacity-0 [grid-area:1/1] data-on:z-1 data-on:opacity-100">
<span aria-hidden="true" className="pointer-events-none absolute inset-0 -z-1 select-none" style={asciiDriftStyleObject('mass', 'centre', 'faint')} />
{picture.src ? <img src={picture.src} alt={picture.alt ?? ''} className="absolute inset-0 size-full object-cover" style={imageFit(picture)} /> : visual ? <span className={VISUAL}><ProductVisual kind={visual} texture={false} fill /></span> : 'groups' in item ? null : <span data-ds-placeholder="" className={cn(GLYPH, 'size-16 rounded-control [--glyph-body:var(--ds-color-neutral-7)] [--glyph-lit:var(--ds-color-fg)]')}><NavIcon name={item.icon} size={24} /></span>}
{platforms?.length ? <span className="absolute top-3 left-3 z-2 flex rounded-ds-sm bg-surface px-2 py-1 type-caption text-fg-soft">{platforms.join(', ')}</span> : null}
</span>
)
})}
{groups ? (
<span aria-hidden="true" className="pointer-events-none absolute inset-0 z-2 grid place-items-center content-center gap-8">
{groups.map((g) => (
<span key={g.label} className="grid justify-items-center gap-4">
<span className="type-ui text-fg-soft">{g.label}</span>
<span className="flex flex-wrap justify-center gap-x-6 gap-y-2 px-6">{g.items.map((w) => <span key={w} className="type-body font-medium text-fg">{w}</span>)}</span>
</span>
))}
</span>
) : null}
</a>
) : null}
<div hidden aria-hidden="true" inert>
{rows.map((item) => ('picture' in item && toSlot(item.picture).src ? <img key={item.key} src={toSlot(item.picture).src} alt="" loading="eager" /> : null))}
</div>
</div>
<div className={STRIP}>
<span className="type-ui text-fg-muted">{menu.strip.label}</span>
<ul className="flex gap-1">
{menu.strip.links.map((link) => <li key={link.label}><a className={STRIP_LINK} href={link.href}>{link.label}</a></li>)}
</ul>
</div>
<style href="ds-products-live-panel" precedence="ds">{css}</style>
</div>
)
}
export default ProductsLivePanel
const css = `
.ds-live-stage { transition: opacity var(--ds-duration-micro) var(--ds-easing-out); }
@starting-style { .ds-live-stage[data-on] { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .ds-live-stage { transition: none; } }
`'use client'
import { useEffect, useId, useRef, useState, type MouseEvent, type ReactNode } from 'react'
import { cn } from '@/react/lib/cn'
// The site header's phone menu (site/Header MenuSheet): a 48px button with two 24px bars that cross into an X; the
// sheet is a modal dialog over the whole window, Black, revealed downward from the bar (clip-path, 240ms in, 160ms
// out) with the lockup, the key and the close button in the bar, the links scrolling in the middle (fading at their
// edges) and the foot pinned under a hairline. Focus moves into it (to the close button from the keyboard) and stays in
// it (Tab wraps); Escape or the close button closes it and gives focus back to the menu button; following a link closes
// it; the page under it does not scroll. Reduced motion: it appears and leaves at once.
export const BAR = 'relative mx-auto flex h-16 w-full max-w-[calc(var(--ds-layout-content)+2*var(--ds-layout-gutter))] items-center justify-between px-(--ds-layout-gutter) lg:h-header'
const MENU_BUTTON = 'ds-menu-button grid size-12 flex-none cursor-pointer place-items-center rounded-control -me-3 text-fg outline-offset-[calc(-1*var(--ds-space-xs))]'
export interface MenuSheetProps {
/** The menu button's and the dialog's name. */
label?: string
closeLabel?: string
/** The lockup link in the sheet's bar. */
brand?: ReactNode
/** Beside the close button (the key). */
action?: ReactNode
/** Pinned at the foot (sign in, the key). */
foot?: ReactNode
children?: ReactNode
/** The width it closes and hides at (1280 or 1024; the header shows its links from there). */
until?: number
className?: string
}
function lock(dialog: HTMLDialogElement) {
const root = document.documentElement
const bar = window.innerWidth - root.clientWidth
root.style.overflow = 'hidden'
root.style.paddingRight = `${bar}px`
dialog.style.setProperty('--scrollbar-w', `${bar}px`)
}
function unlock(dialog: HTMLDialogElement | null) {
const root = document.documentElement
root.style.overflow = ''
root.style.paddingRight = ''
dialog?.style.removeProperty('--scrollbar-w')
}
function Glyph() {
return (
<span aria-hidden="true" className="ds-menu-glyph relative block h-3 w-6">
<span /><span />
</span>
)
}
export function MenuSheet({ label = 'Menu', closeLabel = 'Close menu', brand, action, foot, children, until = 1280, className }: MenuSheetProps) {
const dialogRef = useRef<HTMLDialogElement>(null)
const triggerRef = useRef<HTMLButtonElement>(null)
const closeRef = useRef<HTMLButtonElement>(null)
const followed = useRef(false)
const [open, setOpen] = useState(false)
const id = useId()
const openMenu = (e: MouseEvent<HTMLButtonElement>) => {
const dialog = dialogRef.current
if (!dialog || dialog.open) return
followed.current = false
lock(dialog)
dialog.showModal()
if (e.detail === 0) closeRef.current?.focus()
else dialog.focus()
setOpen(true)
}
const closeMenu = () => {
unlock(dialogRef.current)
dialogRef.current?.close()
}
const onClose = () => {
unlock(dialogRef.current)
setOpen(false)
if (!followed.current) triggerRef.current?.focus({ preventScroll: true })
}
useEffect(() => {
const dialog = dialogRef.current
if (!dialog) return
const onClick = (e: globalThis.MouseEvent) => {
if (!(e.target as Element).closest('a')) return
followed.current = true
unlock(dialog)
dialog.close()
}
const onKeyDown = (e: KeyboardEvent) => {
if (e.key !== 'Tab') return
const stops = [...dialog.querySelectorAll<HTMLElement>('a[href], button')].filter((el) => el.getClientRects().length > 0 && !el.closest('[inert]'))
const first = stops[0]
const last = stops[stops.length - 1]
if (!first || !last) return
if (document.activeElement === dialog) {
e.preventDefault()
;(e.shiftKey ? last : first).focus()
} else if (e.shiftKey && document.activeElement === first) {
e.preventDefault()
last.focus()
} else if (!e.shiftKey && document.activeElement === last) {
e.preventDefault()
first.focus()
}
}
const wide = window.matchMedia(`(min-width: ${until}px)`)
const onWide = () => { if (wide.matches && dialog.open) closeMenu() }
dialog.addEventListener('click', onClick)
dialog.addEventListener('keydown', onKeyDown)
wide.addEventListener('change', onWide)
return () => {
dialog.removeEventListener('click', onClick)
dialog.removeEventListener('keydown', onKeyDown)
wide.removeEventListener('change', onWide)
unlock(dialog)
}
}, [until])
return (
<div data-ds="menu-sheet" className={cn('contents', until === 1024 ? 'lg:hidden' : 'xl:hidden', className)}>
<style href="ds-menu-sheet" precedence="ds">{css}</style>
<button ref={triggerRef} type="button" aria-haspopup="dialog" aria-expanded={open} aria-controls={id} onClick={openMenu} className={MENU_BUTTON}>
<span className="sr-only">{label}</span>
<Glyph />
</button>
<dialog ref={dialogRef} id={id} aria-label={label} tabIndex={-1} onClose={onClose} className="ds-sheet fixed inset-0 m-0 h-dvh max-h-none w-full max-w-none overflow-hidden border-0 bg-surface p-0 pe-(--scrollbar-w,0) text-fg outline-none">
<div className="flex h-full flex-col">
<div className={cn(BAR, 'flex-none after:absolute after:inset-x-0 after:bottom-0 after:border-t after:border-edge')}>
{brand}
<div className="flex min-w-0 flex-[0_1_auto] items-center gap-1 md:gap-2">
{action}
<button ref={closeRef} type="button" onClick={closeMenu} className={MENU_BUTTON}>
<span className="sr-only">{closeLabel}</span>
<Glyph />
</button>
</div>
</div>
<div className="fade-y flex min-h-0 flex-1 flex-col overflow-y-auto overscroll-contain">{children}</div>
<div className="relative mx-auto flex w-full max-w-[calc(var(--ds-layout-content)+2*var(--ds-layout-gutter))] flex-none flex-col gap-2 px-(--ds-layout-gutter) pt-4 pb-[max(var(--ds-space-lg),env(safe-area-inset-bottom))] before:absolute before:inset-x-0 before:top-0 before:border-t before:border-edge">{foot}</div>
</div>
</dialog>
</div>
)
}
export default MenuSheet
const css = `
.ds-menu-glyph { transition: transform var(--ds-duration-press) var(--ds-easing-out); }
.ds-menu-button:active .ds-menu-glyph { transform: scale(0.9); }
.ds-menu-glyph > span { position: absolute; inset-inline: 0; top: calc(50% - var(--ds-stroke) / 2); height: 0; border-top: var(--ds-stroke) solid currentColor; transition: transform var(--ds-duration-micro) var(--ds-easing-out); }
.ds-menu-glyph > span:first-child { transform: translateY(calc(-1 * var(--ds-space-xs))) rotate(0deg); }
.ds-menu-glyph > span:last-child { transform: translateY(var(--ds-space-xs)) rotate(0deg); }
.ds-sheet {
--sheet-bar: var(--ds-header-bar-phone);
clip-path: inset(0 0 calc(100% - var(--sheet-bar)) 0);
transition: clip-path var(--ds-duration-micro) var(--ds-easing-out), display var(--ds-duration-micro) allow-discrete, overlay var(--ds-duration-micro) allow-discrete;
}
.ds-sheet[open] { clip-path: inset(0 0 0 0); transition-duration: var(--ds-duration-enter); }
.ds-sheet::backdrop { background: transparent; }
.ds-sheet[open] .ds-menu-glyph > span { transition-duration: var(--ds-duration-enter); }
.ds-sheet[open] .ds-menu-glyph > span:first-child { transform: translateY(0) rotate(45deg); }
.ds-sheet[open] .ds-menu-glyph > span:last-child { transform: translateY(0) rotate(-45deg); }
@starting-style {
.ds-sheet[open] { clip-path: inset(0 0 calc(100% - var(--sheet-bar)) 0); }
.ds-sheet[open] .ds-menu-glyph > span:first-child { transform: translateY(calc(-1 * var(--ds-space-xs))) rotate(0deg); }
.ds-sheet[open] .ds-menu-glyph > span:last-child { transform: translateY(var(--ds-space-xs)) rotate(0deg); }
}
@media (min-width: 1024px) { .ds-sheet { --sheet-bar: var(--ds-size-header); } }
@media (prefers-reduced-motion: reduce) {
.ds-sheet, .ds-sheet[open], .ds-menu-glyph, .ds-menu-glyph > span, .ds-sheet[open] .ds-menu-glyph > span { transition: none; }
}
`'use client'
import { useId, useState, type ReactNode } from 'react'
import { Chevron } from '@/react/components/site/NavIcon'
import { cn } from '@/react/lib/cn'
// The phone sheet's disclosure (site/Header SheetDisclosure): a 48px row in Funnel Display 24/28 with a 16px chevron in
// the soft gray that turns over; its list opens to its height and fades in over 320ms (160ms closing), as the library's
// accordion rows do. Reduced motion keeps the fade.
export const SHEET_LINK = 'flex min-h-12 items-center rounded-control px-3 -mx-3 type-heading-3 text-fg transition-[color] duration-160 ease-out outline-offset-[calc(-1*var(--ds-space-xs))] hover:text-fg-soft active:text-fg-soft'
export interface SheetDisclosureProps {
label: string
children: ReactNode
defaultOpen?: boolean
className?: string
}
export function SheetDisclosure({ label, children, defaultOpen = false, className }: SheetDisclosureProps) {
const [open, setOpen] = useState(defaultOpen)
const id = useId()
return (
<div data-ds="sheet-disclosure" data-open={open || undefined} className={cn('flex flex-col', className)}>
<style href="ds-sheet-disclosure" precedence="ds">{css}</style>
<button type="button" aria-expanded={open} aria-controls={id} onClick={() => setOpen((was) => !was)} className={cn(SHEET_LINK, 'w-[calc(100%+2*var(--ds-space-md))] cursor-pointer justify-between text-start')}>
{label}
<Chevron size={16} className="ds-sheet-chevron size-4 text-fg-soft" />
</button>
<div id={id} inert={!open} data-open={open} className="ds-sheet-collapse">
<div><div className="ds-sheet-collapse-body">{children}</div></div>
</div>
</div>
)
}
export default SheetDisclosure
const css = `
.ds-sheet-collapse { display: grid; grid-template-rows: 0fr; transition: grid-template-rows var(--ds-duration-exit) var(--ds-easing-out); }
.ds-sheet-collapse[data-open="true"] { grid-template-rows: 1fr; transition-duration: var(--ds-duration-glide); }
.ds-sheet-collapse > div { min-height: 0; overflow: hidden; }
.ds-sheet-collapse-body { opacity: 0; transition: opacity var(--ds-duration-exit) var(--ds-easing-out); }
.ds-sheet-collapse[data-open="true"] .ds-sheet-collapse-body { opacity: 1; transition-duration: var(--ds-duration-glide); }
.ds-sheet-chevron { transition: transform var(--ds-duration-glide) var(--ds-easing-in-out); }
[aria-expanded="true"] > .ds-sheet-chevron { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) {
.ds-sheet-collapse, .ds-sheet-collapse[data-open="true"], .ds-sheet-chevron { transition: none; }
}
`import { CHEVRON_PATH, navIconPaths, type NavIconName } from '@/lib/site-header'
import { cn } from '@/react/lib/cn'
// The site's menu glyphs (site/Header NavIcon): two tones on a 24px grid, the body in the gray and the lit part in the
// soft gray, both brightening when the row they sit in is active (--glyph-body, --glyph-lit). And the menus' chevron.
export interface NavIconProps {
name: NavIconName
/** 20 or 24px. */
size?: 20 | 24
className?: string
}
export function NavIcon({ name, size = 20, className }: NavIconProps) {
return <svg data-ds="nav-icon" viewBox="0 0 24 24" width={size} height={size} aria-hidden="true" focusable="false" className={cn('block flex-none', className)} dangerouslySetInnerHTML={{ __html: navIconPaths(name) }} />
}
export function Chevron({ size = 12, className }: { size?: 12 | 16; className?: string }) {
return <svg viewBox="0 0 12 12" width={size} height={size} fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" focusable="false" className={cn('flex-none', className)} dangerouslySetInnerHTML={{ __html: CHEVRON_PATH }} />
}
export default NavIconimport type { ProductVisualKind } from '@/lib/product-visual-data'
import type { ImageSlot } from '@/lib/image'
// The site header's content and glyphs (site/Header, content/nav.ts, content/home.ts): the nav, the three menus and the
// menu icons, the same in both flavors. Copy is Acme's; platforms are named in words (never their logos); pictures come
// in through `picture` and `shots` (none by default, so no one's photo is shown unless you pass it).
export type NavIconName =
| 'brand' | 'creator' | 'media' | 'insights' | 'landing' | 'collabs' | 'comments' | 'tagged' | 'soon' | 'paid' | 'organic'
| 'creators' | 'monitor' | 'trend' | 'build' | 'research' | 'templates' | 'docs' | 'blog' | 'articles' | 'demos' | 'careers'
export type MenuKey = 'products' | 'useCases' | 'resources'
export interface NavEntry {
label: string
/** A plain link. */
href?: string
/** Opens this menu instead (from 1280; a disclosure in the phone sheet, resources a link to `resources.all`). */
menu?: MenuKey
/** The page being shown. */
current?: boolean
}
export interface MenuLink { label: string; href: string }
export interface OfferRow {
key: string
name: string
line: string
href: string
icon: NavIconName
/** Where it is live, in words: a chip on the live card. */
platforms?: string[]
/** The product's looping scene on the live card (a `product-visual` kind), as on the site. */
visual?: ProductVisualKind
/** A picture for the live card (a src or { src, alt, fit, position }; a product shot, never a person's photo by
* default); it takes the place of `visual`. Without either the card shows the product's glyph, marked as a placeholder. */
picture?: string | ImageSlot
}
export interface SoonRow {
key: string
name: string
line: string
href: string
icon: NavIconName
/** The live card's groups: a label over the platforms or integrations, in words. */
groups: { label: string; items: string[] }[]
}
export interface ProductsMenu { offers: OfferRow[]; soon?: SoonRow; strip: { label: string; links: MenuLink[] } }
export interface CaseRow {
key: string
name: string
line: string
href: string
icon: NavIconName
/** The card's longer line. */
card?: string
/** Up to three pictures for the card (4:5), each a src or { src, alt, fit, position }; empty tiles when left out. */
shots?: (string | ImageSlot)[]
}
export interface UseCasesMenu { rows: CaseRow[]; all: MenuLink; more: MenuLink[] }
export interface ResourceRow { key: string; title: string; href: string; icon: NavIconName; soon?: boolean; external?: boolean }
export interface ResourcesMenu {
rows: ResourceRow[]
all: MenuLink
feature: { title: string; line: string; href: string; code: string; external?: boolean }
soonLabel: string
}
export interface HeaderMenus { products?: ProductsMenu; useCases?: UseCasesMenu; resources?: ResourcesMenu }
export interface HeaderLabels { nav: string; menu: string; close: string; home: string }
export const headerNav: NavEntry[] = [
{ label: 'Products', menu: 'products' },
{ label: 'Use cases', menu: 'useCases' },
{ label: 'Enterprise', href: '#enterprise' },
{ label: 'Resources', menu: 'resources' },
{ label: 'Pricing', href: '#pricing' },
]
export const headerLabels: HeaderLabels = { nav: 'Main', menu: 'Menu', close: 'Close menu', home: 'Home' }
export const headerMenus: Required<HeaderMenus> = {
products: {
offers: [
{ key: 'brands-creators', name: 'Brands and creators', platforms: ['Meta', 'Instagram', 'TikTok'], line: 'Profiles, handles, reach and category', visual: 'add-account', icon: 'brand', href: '#brands' },
{ key: 'media-archive', name: 'Media archive', platforms: ['Meta', 'Instagram', 'TikTok'], line: 'Ads, posts, performance, comments', visual: 'media-mix', icon: 'media', href: '#media' },
{ key: 'collaborations', name: 'Collaborations', platforms: ['Meta', 'Instagram'], line: 'Who works with whom, since when', visual: 'collabs-timeline', icon: 'collabs', href: '#collabs' },
{ key: 'creative-insights', name: 'Creative insights', line: 'Hooks, angles, personas and formats', visual: 'patterns-switch', icon: 'insights', href: '#insights' },
{ key: 'search', name: 'Realtime search', line: 'Ask in plain words, across it all', visual: 'filter-narrow', icon: 'research', href: '#search' },
],
soon: {
key: 'coming-soon',
name: 'Coming soon',
line: 'New platforms on the way',
icon: 'soon',
href: '#soon',
groups: [
{ label: 'Ad libraries and social channels', items: ['Google Ads', 'LinkedIn', 'Pinterest', 'YouTube', 'X'] },
{ label: 'Direct integrations', items: ['Meta', 'Acme Analytics', 'Acme Attribution'] },
],
},
strip: { label: 'Build with', links: [{ label: 'API reference', href: '#api' }, { label: 'SDKs', href: '#sdks' }, { label: 'CLI', href: '#cli' }, { label: 'MCP', href: '#mcp' }] },
},
useCases: {
rows: [
{ key: 'build', name: 'Build your own', line: 'Agents, ad libraries and more', icon: 'build', href: '#build', card: 'Your own agents, ad libraries and tools, built on the Acme API and MCP server.' },
{ key: 'research', name: 'Creative research', line: 'Hooks, angles and formats that win', icon: 'research', href: '#research' },
{ key: 'paid', name: 'Paid ads', line: 'What brands run, and how long', icon: 'paid', href: '#paid' },
{ key: 'organic', name: 'Organic social', line: 'Posts and how they perform', icon: 'organic', href: '#organic' },
{ key: 'competitive', name: 'Competitive analysis', line: 'What competitors launch and test', icon: 'monitor', href: '#competitive' },
{ key: 'creators', name: 'Creator sourcing', line: 'Find creators and their collabs', icon: 'creators', href: '#creators' },
],
all: { label: 'All use cases', href: '#use-cases' },
more: [{ label: 'Consumer sentiment', href: '#sentiment' }, { label: 'Landing page development', href: '#landing' }, { label: '360-degree research', href: '#research-360' }],
},
resources: {
rows: [
{ key: 'templates', title: 'Templates', href: '#templates', icon: 'templates' },
{ key: 'case-studies', title: 'Case studies', href: '#case-studies', icon: 'insights' },
{ key: 'blog', title: 'Blog', href: '#blog', icon: 'blog' },
{ key: 'articles', title: 'Articles', href: '#articles', icon: 'articles' },
{ key: 'demos', title: 'Demos', href: '#demos', icon: 'demos', soon: true },
],
all: { label: 'All resources', href: '#resources' },
feature: { title: 'Docs', line: 'Set up the MCP server, call the REST API and use the SDKs.', href: '#docs', code: 'npm install -g @acme/cli' },
soonLabel: 'Coming soon',
},
}
// ----- The menu glyphs (site NavIcon): two tones on a 24px grid, a body in the gray and a lit part in the soft gray
// (White when the row is active), cut out of the ground. -----
type Tone = 'body' | 'lit' | 'cut' | 'hole'
type Part = { d: string; tone: Tone; line?: boolean; w?: number; t?: string }
const r = (x: number, y: number, w: number, h: number, k = 1) =>
k === 0
? `M${x} ${y}h${w}v${h}h-${w}Z`
: `M${x + k} ${y}h${w - 2 * k}a${k} ${k} 0 0 1 ${k} ${k}v${h - 2 * k}a${k} ${k} 0 0 1-${k} ${k}h-${w - 2 * k}a${k} ${k} 0 0 1-${k}-${k}v-${h - 2 * k}a${k} ${k} 0 0 1 ${k}-${k}Z`
const circle = (cx: number, cy: number, rad: number) => `M${cx - rad} ${cy}a${rad} ${rad} 0 1 0 ${2 * rad} 0a${rad} ${rad} 0 1 0-${2 * rad} 0Z`
const front = (d: string, t?: string): Part[] => [{ d, tone: 'cut', line: true, t }, { d, tone: 'lit', t }]
const TAG = 'M2.5 11.4V4a1.5 1.5 0 0 1 1.5-1.5h7.4a1.5 1.5 0 0 1 1.06.44l8.66 8.66a1.5 1.5 0 0 1 0 2.12l-7.4 7.4a1.5 1.5 0 0 1-2.12 0L2.94 12.46a1.5 1.5 0 0 1-.44-1.06Z'
const play = (x: number, y: number, k = 1) => {
const n = (v: number) => +(v * k).toFixed(3)
return `M${+(x - n(2.4)).toFixed(3)} ${+(y - n(3.3)).toFixed(3)}v${n(6.6)}a${n(0.6)} ${n(0.6)} 0 0 0 ${n(0.92)} ${n(0.5)}l${n(5.1)} ${-n(3.3)}a${n(0.6)} ${n(0.6)} 0 0 0 0 ${-n(1)}l${-n(5.1)} ${-n(3.3)}a${n(0.6)} ${n(0.6)} 0 0 0 ${-n(0.92)} ${n(0.5)}Z`
}
const shoulders = (x: number, top: number, half: number, bottom: number) => `M${x - half} ${bottom}c0-${(bottom - top) * 0.9} ${half * 0.55}-${bottom - top} ${half}-${bottom - top}s${half} ${(bottom - top) * 0.1} ${half} ${bottom - top}Z`
const ICONS: Record<NavIconName, Part[]> = {
brand: [{ d: TAG, tone: 'body', t: 'translate(.5 .5) scale(.8)' }, ...front(TAG, 'translate(4.3 4.3) scale(.8)'), { d: circle(7.5, 7.5, 2), tone: 'hole', t: 'translate(4.3 4.3) scale(.8)' }],
creator: [{ d: shoulders(12, 13.5, 8, 21.5), tone: 'body' }, ...front(circle(12, 7.5, 4.25))],
media: [{ d: r(8.5, 2, 13, 16, 2.5), tone: 'body' }, ...front(r(2.5, 6, 13, 16, 2.5)), { d: play(8.7, 14, 0.85), tone: 'hole' }],
insights: [{ d: `${r(2.5, 12, 5, 9.5, 1.5)}${r(16.5, 8, 5, 13.5, 1.5)}`, tone: 'body' }, { d: r(9.5, 2.5, 5, 19, 1.5), tone: 'lit' }],
landing: [{ d: r(2, 3, 20, 15, 2.5), tone: 'body' }, { d: `${circle(5.5, 6.5, 1)}${circle(8.5, 6.5, 1)}${circle(11.5, 6.5, 1)}`, tone: 'hole' }, ...front('M12.5 9.5v11.2l2.9-2.7 1.9 3.9 2-1-1.9-3.8h4Z')],
collabs: [{ d: `${circle(8.5, 6.5, 3.25)}${shoulders(8.5, 11.5, 6, 18)}`, tone: 'body' }, ...front(`${circle(15.5, 10, 3.5)}${shoulders(15.5, 15, 6.5, 22)}`)],
comments: [{ d: 'M2 4.5A2.5 2.5 0 0 1 4.5 2h9A2.5 2.5 0 0 1 16 4.5V10a2.5 2.5 0 0 1-2.5 2.5H8.5l-4 3v-3A2.5 2.5 0 0 1 2 10Z', tone: 'body' }, ...front('M8 11.5A2.5 2.5 0 0 1 10.5 9h9a2.5 2.5 0 0 1 2.5 2.5V17a2.5 2.5 0 0 1-2.5 2.5V22l-3.5-2.5h-5.5A2.5 2.5 0 0 1 8 17Z')],
tagged: [{ d: r(2, 2, 16, 16, 2.5), tone: 'body' }, ...front(TAG, 'translate(10 10) scale(.55)'), { d: circle(7.5, 7.5, 2), tone: 'hole', t: 'translate(10 10) scale(.55)' }],
soon: [{ d: circle(12, 12, 10), tone: 'body' }, { d: 'M12 6.5V12l3.5 2.5', tone: 'lit', line: true, w: 2 }],
research: [{ d: r(2.5, 2, 13, 17, 2.5), tone: 'body' }, { d: `${circle(14.5, 13.5, 4.25)}M17.6 16.6l3.9 3.9`, tone: 'cut', line: true, w: 4 }, { d: `${circle(14.5, 13.5, 4.25)}M17.6 16.6l3.9 3.9`, tone: 'lit', line: true, w: 2 }],
paid: [{ d: 'M3.5 8.5H7l7.1-4.3a.6.6 0 0 1 .9.51v14.58a.6.6 0 0 1-.9.51L7 15.5H3.5A1.5 1.5 0 0 1 2 14v-4a1.5 1.5 0 0 1 1.5-1.5Z', tone: 'body' }, { d: 'M18 9a4 4 0 0 1 0 6M20.5 6.5a7.6 7.6 0 0 1 0 11', tone: 'lit', line: true, w: 2 }],
organic: [{ d: r(2, 2, 15, 15, 2.5), tone: 'body' }, ...front('M16.5 21.5s-5-2.9-5-6.4a2.6 2.6 0 0 1 5-1 2.6 2.6 0 0 1 5 1c0 3.5-5 6.4-5 6.4Z')],
creators: [{ d: `${r(2, 6, 14, 12, 2.5)}M17 10.2l4.1-2.46a.6.6 0 0 1 .9.52v7.48a.6.6 0 0 1-.9.52L17 13.8Z`, tone: 'body' }, { d: circle(9, 12, 3), tone: 'lit' }],
monitor: [{ d: 'M1.5 12S5.5 4.5 12 4.5 22.5 12 22.5 12 18.5 19.5 12 19.5 1.5 12 1.5 12Z', tone: 'body' }, { d: circle(12, 12, 4.5), tone: 'lit' }, { d: circle(12, 12, 1.75), tone: 'hole' }],
trend: [{ d: 'M2 21.5V16.5l6-6 4 4 7-7H22v14Z', tone: 'body' }, { d: 'M2 16.5l6-6 4 4 8.5-8.5M15.5 6H21v5.5', tone: 'cut', line: true, w: 4 }, { d: 'M2 16.5l6-6 4 4 8.5-8.5M15.5 6H21v5.5', tone: 'lit', line: true, w: 2 }],
build: [{ d: r(2, 3.5, 20, 17, 2.5), tone: 'body' }, { d: 'M9 9l-3 3 3 3M15 9l3 3-3 3', tone: 'lit', line: true, w: 2 }],
templates: [{ d: `${r(3, 3, 18, 7, 1.5)}${r(14, 13, 7, 3, 1.5)}${r(14, 18, 5, 3, 1.5)}`, tone: 'body' }, { d: r(3, 13, 8, 8, 1.5), tone: 'lit' }],
docs: [{ d: 'M11.25 5.6C8.8 3.9 5.6 3.5 2 4.4v14.2c3.6-.9 6.8-.5 9.25 1.2Z', tone: 'body' }, { d: 'M12.75 5.6c2.45-1.7 5.65-2.1 9.25-1.2v14.2c-3.6-.9-6.8-.5-9.25 1.2Z', tone: 'lit' }],
blog: [{ d: 'M15 6l3 3L8 19l-4.3 1.3L5 16 15 6Z', tone: 'body' }, { d: 'M16.4 4.6l1.5-1.5a1.5 1.5 0 0 1 2.1 0l.9.9a1.5 1.5 0 0 1 0 2.1l-1.5 1.5Z', tone: 'lit' }],
articles: [{ d: 'M6.5 2h8L20 7.5v13A1.5 1.5 0 0 1 18.5 22h-12A1.5 1.5 0 0 1 5 20.5v-17A1.5 1.5 0 0 1 6.5 2Z', tone: 'body' }, { d: 'M8.5 12h7M8.5 15.5h7M8.5 19h4', tone: 'cut', line: true, w: 2 }, { d: 'M14.5 2v4a1.5 1.5 0 0 0 1.5 1.5h4Z', tone: 'lit' }],
demos: [{ d: circle(12, 12, 10), tone: 'body' }, { d: play(12.6, 12), tone: 'lit' }],
careers: [{ d: r(2, 7.5, 20, 13.5, 2.5), tone: 'body' }, { d: 'M9 7.5V5.5A1.5 1.5 0 0 1 10.5 4h3A1.5 1.5 0 0 1 15 5.5v2', tone: 'body', line: true, w: 2 }, { d: r(2, 12.5, 20, 2.5, 0), tone: 'lit' }],
}
const TONE: Record<Tone, string> = {
body: 'var(--glyph-body, var(--ds-color-neutral-6))',
lit: 'var(--glyph-lit, var(--ds-color-fg-soft))',
cut: 'var(--glyph-cut, var(--ds-color-surface))',
hole: 'var(--glyph-cut, var(--ds-color-surface))',
}
/** The glyph's paths as SVG markup (the svg's children), the same in both flavors. */
export function navIconPaths(name: NavIconName): string {
return (ICONS[name] ?? ICONS.soon)
.map((p) => {
const t = p.t ? ` transform="${p.t}"` : ''
return p.line
? `<path d="${p.d}"${t} fill="none" style="stroke: ${TONE[p.tone]}" stroke-width="${p.w ?? 3}" stroke-linecap="round" stroke-linejoin="round"></path>`
: `<path d="${p.d}"${t} style="fill: ${TONE[p.tone]}"></path>`
})
.join('')
}
/** The 12px chevron after a menu's label (and the 16px one in the phone sheet). */
export const CHEVRON_PATH = '<path d="M3 4.5 6 7.5 9 4.5"></path>'
/** The hover intent before a menu opens and the grace before it closes when the pointer leaves (site --dur-menu-*). */
export const MENU_INTENT_MS = 80
export const MENU_GRACE_MS = 240
/** The live card's crossfade (the leaving picture stays this long). */
export const LIVE_CROSSFADE_MS = 200// The site's home link (site/Header/HomeLink): pressed on the page it points to, it does not reload. The page jumps to
// the top at once (no smooth scroll: it is a reset, not a journey), any #hash is dropped from the address, and focus
// goes to the header's home link so the next Tab starts from the top. A press with a modifier key keeps the browser's
// own behavior (a new tab or window). Both flavors call it from the link's click.
export function homeLinkClick(event: MouseEvent) {
if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return
const link = event.currentTarget as HTMLAnchorElement | null
if (!link?.href) return
const target = new URL(link.href, window.location.href)
if (target.origin !== window.location.origin || target.pathname !== window.location.pathname) return
event.preventDefault()
window.scrollTo({ top: 0, behavior: 'instant' })
if (window.location.hash) window.history.replaceState(null, '', `${window.location.pathname}${window.location.search}`)
// The first home link on the page (the header's), even from inside a shadow root.
const root = link.getRootNode() as Document | ShadowRoot
const first = (root.querySelector?.('[data-home-link]') ?? document.querySelector('[data-home-link]')) as HTMLElement | null
if (first && first !== link) first.focus({ preventScroll: true })
}// Joins class names, skipping falsy ones: cn('a', on && 'b', ['c', undefined]). It does not merge conflicting
// utilities (no tailwind-merge), as Vue's class binding does not: the library's classes are written not to compete,
// and a className from the caller is appended after them, as Vue appends a fallthrough class.
export type ClassValue = string | false | null | undefined | 0 | ClassValue[]
export function cn(...values: ClassValue[]): string {
const out: string[] = []
for (const v of values) {
if (!v) continue
if (Array.isArray(v)) {
const s = cn(...v)
if (s) out.push(s)
}
else out.push(v)
}
return out.join(' ')
}import { html, nothing } from 'lit'
import { ifDefined } from 'lit/directives/if-defined.js'
import { DsElement, define, HostLayoutController } from '@/elements/lib/element'
import { BAR, menuSheetStyles } from '@/elements/components/site/menu-sheet'
import { GLYPH, menuPanelsStyles } from '@/elements/components/site/menu-panels'
import { NAV_LINK, navMenusStyles } from '@/elements/components/site/nav-menus'
import { navIcon, navIconStyles } from '@/elements/components/site/nav-icon'
import { SHEET_LINK, sheetDisclosureStyles } from '@/elements/components/site/sheet-disclosure'
import { headerLabels, headerMenus, headerNav, type HeaderLabels, type HeaderMenus, type NavEntry } from '@/lib/site-header'
import '@/elements/components/site/menu-sheet'
import '@/elements/components/site/nav-menus'
import '@/elements/components/site/sheet-disclosure'
import '@/elements/components/ui/button'
import '@/elements/components/visuals/logo'
import styles from 'virtual:tw'
import { homeLinkClick } from '@/lib/home-link'
// SiteHeader.tsx as <spyglass-site-header>: the site's header, 64px (72 from 1024) in the page's container: the lockup,
// from 1280 the links and their menus (<spyglass-nav-menus>), the sign-in beside the White key; below 1280 the phone
// sheet (<spyglass-menu-sheet>) with the menus as disclosures. The bar takes a Black ground and a hairline once the page
// scrolls 8px. `hide-key-until` (a selector) keeps the key hidden until that element passes under the bar. `links`,
// `menus`, `cta`, `secondary`, `labels` (JSON); `home-href`, `logo-label`, `variant` (default, centered, minimal),
// `sticky` (sticky="false" to scroll away).
export type HeaderLink = NavEntry
export interface HeaderAction { label: string; href: string; short?: string }
const GRID = { default: 'xl:grid xl:grid-cols-[1fr_auto_1fr]', centered: 'lg:grid lg:grid-cols-[1fr_auto_1fr]', minimal: '' }
const SIGN_IN = { default: 'hidden xl:flex', centered: 'hidden lg:flex', minimal: 'hidden' }
const FROM = { default: 1280, centered: 1024, minimal: 1280 }
/** @summary The website header: lockup, links with their dropdown menus, sign-in and the key; the phone sheet. */
export class SiteHeader extends DsElement {
static styles = [DsElement.styles, navIconStyles, menuPanelsStyles, navMenusStyles, sheetDisclosureStyles, menuSheetStyles, styles]
protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="site-header"]'))
static properties = {
links: { type: Array },
menus: { type: Object },
cta: { type: Object },
secondary: { type: Object },
homeHref: { attribute: 'home-href' },
label: { attribute: 'logo-label' },
variant: {},
hideKeyUntil: { attribute: 'hide-key-until' },
sticky: { type: Boolean, converter: { fromAttribute: (v: string | null) => v !== 'false' } },
labels: { type: Object },
scrolled: { state: true },
shown: { state: true },
instant: { state: true },
}
/** The links; entries with `menu` (products, useCases, resources) open that menu. */
links: HeaderLink[] = headerNav
menus: HeaderMenus = headerMenus
/** The White key ({ label, href, short? }). */
cta?: HeaderAction = { label: 'Get a free API key', href: '#start', short: 'Get API key' }
/** The sign-in before it ({ label, href }). */
secondary?: HeaderAction = { label: 'Sign in', href: '#sign-in' }
homeHref = '/'
/** The lockup's accessible name. */
label = 'Spyglass'
/** default (links and menus from 1280), centered (from 1024) or minimal (the lockup and the key only). */
variant: 'default' | 'centered' | 'minimal' = 'default'
/** Keep the key hidden until the element this selector finds has passed under the bar. */
hideKeyUntil?: string
sticky = true
labels: HeaderLabels = headerLabels
private scrolled = false
private shown: 'shown' | 'hidden' = 'shown'
private instant = true
private observer?: IntersectionObserver
private frame = 0
private top = -1
private onScroll = () => {
const next = window.scrollY > 8
if (next !== this.scrolled) this.scrolled = next
}
private bar() { return parseFloat(getComputedStyle(document.documentElement).getPropertyValue(window.matchMedia('(min-width: 1024px)').matches ? '--ds-size-header' : '--ds-header-bar-phone')) || 0 }
private state(rect: DOMRectReadOnly | null, top: number): 'shown' | 'hidden' { return !rect || (!rect.width && !rect.height) || rect.top < top ? 'shown' : 'hidden' }
private watch = () => {
const hero = this.hideKeyUntil ? document.querySelector(this.hideKeyUntil) : null
if (!hero) return
const next = this.bar()
if (next === this.top) return
this.top = next
this.observer?.disconnect()
this.observer = new IntersectionObserver(([entry]) => {
if (!entry) return
this.shown = this.state(entry.boundingClientRect, this.top)
if (!this.frame) this.frame = requestAnimationFrame(() => (this.instant = false))
}, { rootMargin: `-${this.top}px 0px 0px 0px`, threshold: [0, 1] })
this.observer.observe(hero)
}
connectedCallback() {
super.connectedCallback()
this.onScroll()
window.addEventListener('scroll', this.onScroll, { passive: true })
window.addEventListener('resize', this.watch)
const hero = this.hideKeyUntil ? document.querySelector(this.hideKeyUntil) : null
this.shown = this.state(hero?.getBoundingClientRect() ?? null, this.bar())
this.instant = true
this.frame = requestAnimationFrame(() => (this.instant = false))
this.top = -1
this.watch()
}
disconnectedCallback() {
super.disconnectedCallback()
window.removeEventListener('scroll', this.onScroll)
window.removeEventListener('resize', this.watch)
this.observer?.disconnect()
cancelAnimationFrame(this.frame)
}
private sheetRows(entry: NavEntry) {
const menus = this.menus ?? headerMenus
if (entry.menu === 'products') { const m = menus.products ?? headerMenus.products; return [...m.offers, ...(m.soon ? [m.soon] : [])].map((r) => ({ key: r.key, name: r.name, href: r.href, icon: r.icon })) }
if (entry.menu === 'useCases') return (menus.useCases ?? headerMenus.useCases).rows.map((r) => ({ key: r.key, name: r.name, href: r.href, icon: r.icon }))
return []
}
render() {
const variant = this.variant in GRID ? this.variant : 'default'
const links = this.links ?? headerNav
const menus = this.menus ?? headerMenus
const labels = this.labels ?? headerLabels
const hidden = this.shown === 'hidden'
const cta = this.cta
const secondary = this.secondary
const brand = (slot?: string) => html`<a slot=${ifDefined(slot)} href=${this.homeHref} aria-label=${this.label} data-home-link @click=${homeLinkClick} class="-ms-2 block flex-none rounded-ds-sm px-2 py-3 text-fg md:-ms-3 md:px-3 md:py-2 lg:py-3 xl:justify-self-start"><spyglass-logo height="20" aria-label=${this.label}></spyglass-logo></a>`
const key = () => (cta ? html`<spyglass-button href=${cta.href} size="xs" class="ds-key"><span class="ds-key-full truncate">${cta.label}</span><span class="ds-key-short truncate">${cta.short ?? cta.label}</span></spyglass-button>` : nothing)
return html`<header data-ds="site-header" data-variant=${variant} class=${`ds-site-header z-20 text-fg ${this.sticky ? 'sticky top-0' : 'relative'}`}><span aria-hidden="true" data-on=${ifDefined(this.scrolled ? '' : undefined)} class="pointer-events-none absolute inset-0 border-b border-edge bg-surface opacity-0 transition-opacity duration-160 ease-out data-on:opacity-100"></span><div class=${`${BAR} ${GRID[variant]}`.trim()}>${brand()}${variant !== 'minimal' ? html`<spyglass-nav-menus .links=${links} .menus=${menus} label=${labels.nav} from=${FROM[variant]}></spyglass-nav-menus>` : nothing}<div class="ds-actions flex min-w-0 flex-[0_1_auto] items-center gap-1 md:gap-2 xl:min-w-auto xl:justify-self-end xl:gap-3"><div data-key=${this.shown} data-instant=${ifDefined(this.instant ? '' : undefined)} class="ds-key-slot relative flex min-w-0 flex-[0_1_auto]"><div class="ds-key-room pointer-events-none absolute inset-0">${secondary ? html`<a href=${secondary.href} class=${`${NAV_LINK} ${SIGN_IN[variant]} pointer-events-auto absolute inset-y-0 right-[calc(100%+var(--ds-space-md))] my-auto px-3 whitespace-nowrap`}>${secondary.label}</a>` : nothing}</div><div ?inert=${hidden} aria-hidden=${ifDefined(hidden ? 'true' : undefined)} class="ds-key-box flex min-w-0">${key()}</div></div>${variant !== 'minimal' ? html`<spyglass-menu-sheet label=${labels.menu} close-label=${labels.close} until=${FROM[variant]}>${brand('brand')}<div slot="action" class="flex min-w-0 flex-[0_1_auto]">${key()}</div><nav aria-label=${labels.nav} class="mx-auto w-full max-w-[calc(var(--ds-layout-content)+2*var(--ds-layout-gutter))] px-(--ds-layout-gutter)"><ul>${links.map((entry) => html`<li class="flex flex-col border-t border-edge first:border-t-0 last:border-b">${entry.menu && entry.menu !== 'resources' ? html`<spyglass-sheet-disclosure label=${entry.label}><ul class="grid gap-x-4 pb-2 md:grid-cols-2">${this.sheetRows(entry).map((row) => html`<li><a href=${row.href} class="-mx-2 flex min-h-12 items-center gap-3 rounded-control px-2 type-body text-fg transition-[color] duration-160 ease-out outline-offset-[calc(-1*var(--ds-space-xs))] hover:text-fg-soft active:text-fg-soft"><span class=${`${GLYPH} size-8 rounded-ds-sm`}>${navIcon(row.icon)}</span>${row.name}</a></li>`)}</ul></spyglass-sheet-disclosure>` : html`<a href=${ifDefined(entry.menu === 'resources' ? (menus.resources ?? headerMenus.resources).all.href : entry.href)} aria-current=${ifDefined(entry.current ? 'page' : undefined)} class=${SHEET_LINK}>${entry.label}</a>`}</li>`)}</ul></nav>${secondary ? html`<spyglass-button slot="foot" href=${secondary.href} variant="secondary" class="w-full">${secondary.label}</spyglass-button>` : nothing}${cta ? html`<div slot="foot" class="contents md:hidden"><spyglass-button href=${cta.href} class="w-full">${cta.label}</spyglass-button></div>` : nothing}</spyglass-menu-sheet>` : nothing}</div></div></header>`
}
}
define('site-header', SiteHeader).ds-key-box { transition: opacity var(--ds-duration-entrance) var(--ds-easing-out) var(--ds-duration-slow), transform var(--ds-duration-entrance) var(--ds-easing-out) var(--ds-duration-slow), visibility var(--ds-duration-instant) linear; }
.ds-key-room { transition: transform var(--ds-duration-slow) var(--ds-easing-out); }
.ds-key-slot[data-key="hidden"] .ds-key-box {
opacity: 0; transform: scale(var(--ds-menu-from-scale)); visibility: hidden; pointer-events: none;
transition: opacity var(--ds-duration-close) var(--ds-easing-out), transform var(--ds-duration-close) var(--ds-easing-out), visibility var(--ds-duration-instant) linear var(--ds-duration-close);
}
.ds-key-slot[data-instant] .ds-key-box, .ds-key-slot[data-instant] .ds-key-room { transition: none; }
.ds-key-short { display: none; }
@media (max-width: 423px) {
.ds-actions { gap: 0; }
.ds-key-full { display: none; }
.ds-key-short { display: block; }
}
@media (max-width: 371px) { .ds-key-slot .ds-key { display: none; } }
@media (min-width: 1024px) {
.ds-site-header[data-variant="centered"] .ds-key-slot[data-key="hidden"] .ds-key-room { transform: translateX(calc(100% + var(--ds-space-xl))); transition-delay: var(--ds-duration-close); }
}
@media (min-width: 1280px) {
.ds-site-header[data-variant="default"] .ds-key-slot[data-key="hidden"] .ds-key-room { transform: translateX(calc(100% + var(--ds-space-xl))); transition-delay: var(--ds-duration-close); }
}
@media (prefers-reduced-motion: reduce) {
.ds-key-box { transition: opacity var(--ds-duration-micro) var(--ds-easing-out), visibility var(--ds-duration-instant) linear; }
.ds-key-slot[data-key="hidden"] .ds-key-box { transform: none; transition: opacity var(--ds-duration-micro) var(--ds-easing-out), visibility var(--ds-duration-instant) linear var(--ds-duration-micro); }
.ds-key-room { transition: none; }
}import { html, nothing, type TemplateResult } from 'lit'
import { ifDefined } from 'lit/directives/if-defined.js'
import { DsElement, define, HostLayoutController, uid } from '@/elements/lib/element'
import { chevron, navIconStyles } from '@/elements/components/site/nav-icon'
import { menuPanelsStyles, resourcesPanel, useCasesPanel } from '@/elements/components/site/menu-panels'
import { LiveState, productsLivePanelStyles, productsPanel } from '@/elements/components/site/products-live-panel'
import { headerMenus, headerNav, MENU_GRACE_MS, MENU_INTENT_MS, type HeaderMenus, type MenuKey, type NavEntry } from '@/lib/site-header'
import styles from 'virtual:tw'
// NavMenus.tsx as <spyglass-nav-menus>: the header's links and their three menus, in one shadow root. Under a mouse a
// menu opens after 80ms and swaps at once once one is open; leaving closes it after 240ms; a click opens and keeps it;
// Enter, Space or ArrowDown open it with focus on its first link (ArrowUp its last); arrows, Home and End move through
// it; Escape closes it and gives focus back; a click or focus outside closes it. From the keyboard or when swapping the
// panel appears at once. `links` and `menus` (JSON), `label`, `from` (the width it shows from).
export const navMenusStyles = styles
export const NAV_LINK = 'relative flex h-control-xs items-center rounded-control px-4 type-ui text-fg-soft transition-[color,background-color] duration-160 ease-out after:absolute after:inset-x-0 after:-inset-y-1 hover:bg-surface-raised hover:text-fg focus-visible:text-fg active:text-fg aria-[current=page]:text-fg'
const WIDTH: Record<MenuKey, string> = {
products: 'w-[min(var(--ds-header-menu-products-w),calc(100vw-2*var(--ds-layout-gutter)))]',
useCases: 'w-[min(var(--ds-header-menu-cases-w),calc(100vw-2*var(--ds-layout-gutter)))]',
resources: 'w-[min(var(--ds-header-menu-resources-w),calc(100vw-2*var(--ds-layout-gutter)))]',
}
type Via = 'hover' | 'click'
/** @summary The header's links and dropdown menus. */
export class NavMenus extends DsElement {
static styles = [DsElement.styles, navIconStyles, menuPanelsStyles, productsLivePanelStyles, styles]
protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="nav-menus"]'))
static properties = { links: { type: Array }, menus: { type: Object }, label: {}, from: { type: Number }, open: { state: true }, instant: { state: true }, cases: { state: true } }
/** The links; entries with `menu` open that menu. */
links: NavEntry[] = headerNav
menus: HeaderMenus = headerMenus
/** The nav's accessible name. */
label = 'Main'
/** The width the menus show from. */
from = 1280
private open: MenuKey | null = null
private instant = false
private cases = 0
private live = new LiveState(() => this.requestUpdate())
private via: Via = 'click'
private timer: number | undefined
private pendingFocus: 'first' | 'last' | null = null
private navId = uid('nav')
private wide?: MediaQueryList
private get nav() { return this.renderRoot.querySelector<HTMLElement>('nav') }
private panelEl(key: MenuKey) { return this.renderRoot.querySelector<HTMLElement>(`#${this.navId}-${key}`) }
private trigger(key: MenuKey) { return this.renderRoot.querySelector<HTMLButtonElement>(`[aria-controls="${this.navId}-${key}"]`) }
private deepActive() { return (this.renderRoot as ShadowRoot).activeElement as HTMLElement | null }
private items(key: MenuKey) {
const panel = this.panelEl(key)
return panel ? [...panel.querySelectorAll<HTMLElement>('a[href]:not([tabindex="-1"])')].filter((a) => a.getClientRects().length > 0) : []
}
private onKey = (e: KeyboardEvent) => {
if (e.key !== 'Escape' || !this.open) return
const key = this.open
const hadFocus = Boolean(this.deepActive())
this.hide()
if (hadFocus) this.trigger(key)?.focus()
}
private onDown = (e: PointerEvent) => { if (this.open && this.nav && !e.composedPath().includes(this.nav)) this.hide() }
private onNarrow = () => { if (this.wide && !this.wide.matches && this.open) this.hide() }
connectedCallback() {
super.connectedCallback()
document.addEventListener('keydown', this.onKey)
document.addEventListener('pointerdown', this.onDown)
this.wide = window.matchMedia(`(min-width: ${this.from}px)`)
this.wide.addEventListener('change', this.onNarrow)
}
disconnectedCallback() {
super.disconnectedCallback()
document.removeEventListener('keydown', this.onKey)
document.removeEventListener('pointerdown', this.onDown)
this.wide?.removeEventListener('change', this.onNarrow)
clearTimeout(this.timer)
this.live.stop()
}
protected updated(changed: Map<string, unknown>) {
super.updated(changed as never)
if (changed.has('open') && this.open && this.pendingFocus) {
const items = this.items(this.open)
const target = this.pendingFocus === 'first' ? items[0] : items[items.length - 1]
this.pendingFocus = null
target?.focus()
}
}
private clearTimer() {
clearTimeout(this.timer)
this.timer = undefined
}
private show(key: MenuKey, how: Via, keyboard = false) {
this.clearTimer()
this.via = how
this.instant = keyboard || (this.open !== null && this.open !== key)
this.open = key
}
private hide() {
this.clearTimer()
this.instant = false
this.open = null
}
private onTriggerClick(key: MenuKey, e: MouseEvent) {
this.clearTimer()
const keyboard = e.detail === 0
if (this.open === key) {
if (this.via === 'hover' && !keyboard) {
this.via = 'click'
return
}
this.hide()
return
}
if (keyboard) this.pendingFocus = 'first'
this.show(key, 'click', keyboard)
}
private onTriggerKeyDown(key: MenuKey, e: KeyboardEvent) {
if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return
e.preventDefault()
if (this.open === key) {
const items = this.items(key)
;(e.key === 'ArrowDown' ? items[0] : items[items.length - 1])?.focus()
return
}
this.pendingFocus = e.key === 'ArrowDown' ? 'first' : 'last'
this.show(key, 'click', true)
}
private onTriggerEnter(key: MenuKey, e: PointerEvent) {
if (e.pointerType !== 'mouse') return
this.clearTimer()
if (this.open) {
if (this.open !== key) this.show(key, 'hover')
return
}
this.timer = window.setTimeout(() => this.show(key, 'hover'), MENU_INTENT_MS)
}
private onTriggerLeave(e: PointerEvent) { if (e.pointerType === 'mouse' && !this.open) this.clearTimer() }
private onNavEnter(e: PointerEvent) { if (e.pointerType === 'mouse' && this.open) this.clearTimer() }
private onNavLeave(e: PointerEvent) {
if (e.pointerType !== 'mouse') return
this.clearTimer()
if (this.open && this.via === 'hover') this.timer = window.setTimeout(() => this.hide(), MENU_GRACE_MS)
}
private onNavBlur(e: FocusEvent) { if (this.open && !this.nav?.contains(e.relatedTarget as Node | null)) this.hide() }
private onPanelKeyDown(key: MenuKey, e: KeyboardEvent) {
const items = this.items(key)
const at = items.indexOf(this.deepActive() as HTMLElement)
if (at < 0) return
let next = -1
if (e.key === 'ArrowDown' || e.key === 'ArrowRight') next = Math.min(at + 1, items.length - 1)
else if (e.key === 'ArrowUp' || e.key === 'ArrowLeft') next = Math.max(at - 1, 0)
else if (e.key === 'Home') next = 0
else if (e.key === 'End') next = items.length - 1
if (next < 0) return
e.preventDefault()
items[next]?.focus()
}
private panel(key: MenuKey, body: TemplateResult) {
return html`<div id=${`${this.navId}-${key}`} data-open=${ifDefined(this.open === key ? '' : undefined)} ?inert=${this.open !== key} @keydown=${(e: KeyboardEvent) => this.onPanelKeyDown(key, e)} @click=${(e: MouseEvent) => { if (e.composedPath().some((n) => n instanceof HTMLAnchorElement)) this.hide() }} class=${`ds-menu-panel absolute top-[calc(100%+var(--ds-header-menu-gap))] left-1/2 z-20 rounded-control border border-edge bg-surface-subtle text-fg before:absolute before:inset-x-0 before:bottom-full before:h-(--ds-header-menu-gap) ${WIDTH[key]}`}>${body}</div>`
}
render() {
const entries = this.links ?? headerNav
const menus = this.menus ?? headerMenus
const has = (key: MenuKey) => entries.some((e) => e.menu === key) && Boolean(menus[key] ?? headerMenus[key])
return html`<nav data-ds="nav-menus" aria-label=${this.label} data-instant=${ifDefined(this.instant ? '' : undefined)} @pointerenter=${this.onNavEnter} @pointerleave=${this.onNavLeave} @focusout=${this.onNavBlur} class=${`ds-nav-menus relative ${this.from === 1024 ? 'hidden lg:block' : 'hidden xl:block'}`}><ul class="flex gap-1">${entries.map((item) => item.menu ? html`<li class=${ifDefined(item.menu === 'resources' ? 'relative' : undefined)}><button type="button" aria-expanded=${String(this.open === item.menu)} aria-controls=${`${this.navId}-${item.menu}`} @click=${(e: MouseEvent) => this.onTriggerClick(item.menu!, e)} @keydown=${(e: KeyboardEvent) => this.onTriggerKeyDown(item.menu!, e)} @pointerenter=${(e: PointerEvent) => this.onTriggerEnter(item.menu!, e)} @pointerleave=${this.onTriggerLeave} class=${`${NAV_LINK} cursor-pointer gap-1 aria-expanded:bg-surface-raised aria-expanded:text-fg`}>${item.label}${chevron(12, 'ds-nav-chevron')}</button>${item.menu === 'resources' && has('resources') ? this.panel('resources', resourcesPanel(menus.resources ?? headerMenus.resources)) : nothing}</li>` : html`<li><a class=${NAV_LINK} href=${ifDefined(item.href)} aria-current=${ifDefined(item.current ? 'page' : undefined)}>${item.label}</a></li>`)}</ul>${has('products') ? this.panel('products', productsPanel(menus.products ?? headerMenus.products, this.live.active, this.live.leaving, (i) => this.live.show(i))) : nothing}${has('useCases') ? this.panel('useCases', useCasesPanel(menus.useCases ?? headerMenus.useCases, this.cases, (i) => (this.cases = i))) : nothing}</nav>`
}
}
define('nav-menus', NavMenus).ds-menu-panel {
visibility: hidden; opacity: 0; transform-origin: top center;
transform: translate(-50%, calc(-1 * var(--ds-header-menu-rise))) scale(var(--ds-menu-from-scale));
transition: opacity var(--ds-duration-micro) var(--ds-easing-out), transform var(--ds-duration-micro) var(--ds-easing-out), visibility var(--ds-duration-instant) linear var(--ds-duration-micro);
}
.ds-menu-panel[data-open] {
visibility: visible; opacity: 1; transform: translate(-50%, 0);
transition: opacity var(--ds-duration-enter) var(--ds-easing-out), transform var(--ds-duration-enter) var(--ds-easing-out), visibility var(--ds-duration-instant);
}
.ds-nav-menus[data-instant] .ds-menu-panel { transition: none; }
.ds-nav-chevron { transition: transform var(--ds-duration-micro) var(--ds-easing-out); }
[aria-expanded="true"] > .ds-nav-chevron { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) {
.ds-menu-panel, .ds-menu-panel[data-open] { transform: translate(-50%, 0); }
.ds-nav-chevron { transition: none; }
}import { html, nothing } from 'lit'
import { ifDefined } from 'lit/directives/if-defined.js'
import { DsElement, define } from '@/elements/lib/element'
import { navIcon, navIconStyles } from '@/elements/components/site/nav-icon'
import { headerMenus, type OfferRow, type ResourcesMenu, type SoonRow, type UseCasesMenu } from '@/lib/site-header'
import '@/elements/components/visuals/brand-light'
import styles from 'virtual:tw'
import { imageFit, toSlot } from '@/lib/image'
import { styleMap } from 'lit/directives/style-map.js'
// MenuPanels.tsx as template functions (the header's nav renders them in its own shadow root, with these styles) and
// as <spyglass-menu-panels panel="use-cases|resources" menu='{...}'> on its own: the use cases panel (rows and the card
// crossfading to the active row) and the resources panel (rows, the coming-soon row, the docs card with the light).
export const ROW = 'group/row flex gap-3 rounded-ds-sm p-3 transition-[background-color] duration-160 ease-out outline-offset-[calc(-1*var(--ds-border-focus))] hover:bg-surface-raised data-active:bg-surface-raised'
export const GLYPH = 'grid flex-none place-items-center border border-edge bg-surface transition-[border-color] duration-160 ease-out group-hover/row:border-edge-strong group-hover/row:[--glyph-body:var(--ds-color-neutral-7)] group-hover/row:[--glyph-lit:var(--ds-color-fg)] group-focus-visible/row:border-edge-strong group-focus-visible/row:[--glyph-body:var(--ds-color-neutral-7)] group-focus-visible/row:[--glyph-lit:var(--ds-color-fg)] group-data-active/row:border-edge-strong group-data-active/row:[--glyph-body:var(--ds-color-neutral-7)] group-data-active/row:[--glyph-lit:var(--ds-color-fg)] [&_path]:transition-[fill,stroke] [&_path]:duration-160 [&_path]:ease-out'
export const STRIP = 'flex items-center gap-2 border-t border-edge py-1 pr-1 pl-4'
export const STRIP_LINK = 'flex h-8 items-center rounded-ds-sm px-2 type-ui-strong text-fg transition-[background-color] duration-160 ease-out outline-offset-[calc(-1*var(--ds-border-focus))] hover:bg-surface-raised'
export const menuPanelsStyles = styles
export const offerRowBody = (item: OfferRow | SoonRow) => html`<span class=${`${GLYPH} size-10 rounded-control`}>${navIcon(item.icon, 24)}</span><span class="flex min-w-0 flex-col"><span class="type-ui-strong text-fg">${item.name}</span><span class="type-ui text-fg-muted">${item.line}</span></span>`
export const useCasesPanel = (menu: UseCasesMenu, active: number, onActive: (i: number) => void) => {
const rows = menu.rows
const current = rows[active] ?? rows[0]
return html`<div data-ds="menu-panels" class="contents"><div class="flex gap-1 p-1"><ul class="grid min-w-0 flex-1 grid-flow-col grid-cols-2 grid-rows-3 content-start gap-1">${rows.map((item, i) => html`<li><a class=${ROW} href=${item.href} data-active=${ifDefined(i === active ? '' : undefined)} @pointerenter=${() => onActive(i)} @focus=${() => onActive(i)}><span class=${`${GLYPH} size-10 rounded-control`}>${navIcon(item.icon, 24)}</span><span class="flex min-w-0 flex-col"><span class="type-ui-strong text-fg">${item.name}</span><span class="type-ui text-fg-muted">${item.line}</span></span></a></li>`)}</ul>${current ? html`<a href=${current.href} tabindex="-1" aria-hidden="true" class="relative grid w-72 flex-none overflow-hidden rounded-ds-sm bg-surface-raised p-2 [contain:size]">${rows.map((item, i) => html`<span data-on=${ifDefined(i === active ? '' : undefined)} class="flex min-h-0 flex-col opacity-0 transition-opacity duration-160 ease-out [grid-area:1/1] data-on:opacity-100"><span class="grid min-h-0 flex-none grid-cols-3 gap-1">${[0, 1, 2].map((n) => { const shot = toSlot(item.shots?.[n]); return html`<span data-ds-placeholder=${ifDefined(shot.src ? undefined : '')} class="relative aspect-4/5 overflow-hidden rounded-ds-sm bg-surface-subtle">${shot.src ? html`<img src=${shot.src} alt=${shot.alt ?? ''} loading="eager" class="absolute inset-0 size-full object-cover" style=${styleMap(imageFit(shot) ?? {})}>` : nothing}</span>` })}</span><span class="flex min-w-0 flex-none flex-col px-1 pt-2 pb-1"><span class="type-ui-strong text-fg">${item.name}</span><span class="line-clamp-2 type-ui text-fg-muted">${item.card ?? item.line}</span></span></span>`)}</a>` : nothing}</div><div class=${STRIP}><a class=${STRIP_LINK} href=${menu.all.href}>${menu.all.label}</a><ul class="flex gap-1">${menu.more.map((link) => html`<li><a class=${`${STRIP_LINK} font-regular text-fg-muted`} href=${link.href}>${link.label}</a></li>`)}</ul></div></div>`
}
export const resourcesPanel = (menu: ResourcesMenu) => {
const docs = menu.feature
return html`<div data-ds="menu-panels" class="flex gap-1 p-1"><ul class="relative isolate flex w-64 flex-none flex-col gap-1">${menu.rows.map((row) => html`<li>${row.soon ? html`<span aria-disabled="true" class="group/row flex h-12 cursor-default items-center gap-3 rounded-ds-sm px-3 type-ui text-fg-faint"><span class=${`${GLYPH} size-8 rounded-ds-sm [--glyph-body:var(--ds-color-neutral-4)] [--glyph-lit:var(--ds-color-fg-faint)]`}>${navIcon(row.icon)}</span>${row.title}<span class="ml-auto inline-flex h-6 items-center rounded-ds-sm bg-surface-inset px-2 type-caption font-medium text-fg-soft">${menu.soonLabel}</span></span>` : html`<a href=${row.href} target=${ifDefined(row.external ? '_blank' : undefined)} rel=${ifDefined(row.external ? 'noreferrer' : undefined)} class="group/row flex h-12 items-center gap-3 rounded-ds-sm px-3 type-ui-strong text-fg transition-[background-color] duration-160 ease-out outline-offset-[calc(-1*var(--ds-border-focus))] hover:bg-surface-raised"><span class=${`${GLYPH} size-8 rounded-ds-sm`}>${navIcon(row.icon)}</span>${row.title}</a>`}</li>`)}</ul><a href=${docs.href} target=${ifDefined(docs.external ? '_blank' : undefined)} rel=${ifDefined(docs.external ? 'noreferrer' : undefined)} class="relative flex min-w-0 flex-1 flex-col overflow-hidden rounded-ds-sm bg-surface-raised p-2 transition-[background-color] duration-160 ease-out outline-offset-[calc(-1*var(--ds-border-focus))] [contain:size] hover:bg-surface-hover"><span aria-hidden="true" class="relative min-h-0 flex-1 overflow-hidden bg-surface"><span class="ds-docs-wave absolute inset-0"><span class="ds-docs-ribbon absolute -inset-6 translate-y-6"><spyglass-brand-light variant="curved-strip" ground="false" cover class="absolute inset-0"></spyglass-brand-light></span></span><code class="absolute top-3 left-3 font-code text-(length:--ds-text-caption) leading-(--ds-text-caption-leading) whitespace-nowrap text-fg-soft"><span class="text-fg-faint">$</span> ${docs.code}</code></span><span class="flex min-w-0 flex-none flex-col px-1 pt-3 pb-1"><span class="type-ui-strong text-fg">${docs.title}</span><span class="type-ui text-fg-muted">${docs.line}</span></span></a></div>`
}
/** @summary A header menu panel on its own: use cases or resources. */
export class MenuPanels extends DsElement {
static styles = [DsElement.styles, navIconStyles, styles]
static properties = { panel: {}, menu: { type: Object }, active: { state: true } }
/** use-cases or resources. */
panel: 'use-cases' | 'resources' = 'use-cases'
/** The menu's content (lib/site-header.ts headerMenus.useCases or .resources by default). */
menu?: UseCasesMenu | ResourcesMenu
private active = 0
render() {
return this.panel === 'resources'
? resourcesPanel((this.menu as ResourcesMenu) ?? headerMenus.resources)
: useCasesPanel((this.menu as UseCasesMenu) ?? headerMenus.useCases, this.active, (i) => (this.active = i))
}
}
define('menu-panels', MenuPanels).ds-docs-wave { animation: ds-docs-slide var(--ds-header-band-slide) var(--ds-easing-drift) infinite alternate; }
.ds-docs-ribbon > * { animation: ds-docs-bob var(--ds-header-band-bob) var(--ds-easing-drift) infinite alternate; }
@keyframes ds-docs-slide { from { transform: translateX(calc(-1 * var(--ds-space-xl))); } to { transform: translateX(var(--ds-space-xl)); } }
@keyframes ds-docs-bob { from { transform: translateY(calc(-1 * var(--ds-space-sm))) rotate(-2deg); } to { transform: translateY(var(--ds-space-sm)) rotate(2deg); } }
@media (prefers-reduced-motion: reduce) { .ds-docs-wave, .ds-docs-ribbon > * { animation: none; } }import { html, nothing } from 'lit'
import { ifDefined } from 'lit/directives/if-defined.js'
import { repeat } from 'lit/directives/repeat.js'
import { DsElement, define } from '@/elements/lib/element'
import { navIcon, navIconStyles } from '@/elements/components/site/nav-icon'
import { GLYPH, menuPanelsStyles, offerRowBody, ROW, STRIP, STRIP_LINK } from '@/elements/components/site/menu-panels'
import { asciiDriftStyle } from '@/lib/ascii-drift'
import { headerMenus, LIVE_CROSSFADE_MS, type OfferRow, type ProductsMenu, type SoonRow } from '@/lib/site-header'
import '@/elements/components/site/product-visual'
import styles from 'virtual:tw'
import { imageFit, toSlot } from '@/lib/image'
import { styleMap } from 'lit/directives/style-map.js'
// ProductsLivePanel.tsx as a template function (the header's nav renders it with these styles) and as
// <spyglass-products-live-panel menu='{...}'> on its own: the offers and the live soon row beside the live card that
// crossfades to the active row (its picture over the texture, or the texture and its glyph, or the live soon groups in
// words); the pictures load ahead, hidden; the build strip at the foot.
export const productsLivePanelStyles = styles
export const productsPanel = (menu: ProductsMenu, active: number, leaving: number | null, onShow: (i: number) => void) => {
const rows: (OfferRow | SoonRow)[] = [...menu.offers, ...(menu.soon ? [menu.soon] : [])]
const current = rows[active] ?? rows[0]
const groups = current && 'groups' in current ? current.groups : undefined
return html`<div data-ds="products-live-panel" class="contents"><div class="flex gap-1 p-1"><ul class="flex w-80 flex-none flex-col gap-1">${rows.map((item, i) => html`<li><a class=${ROW} href=${item.href} data-active=${ifDefined(i === active ? '' : undefined)} @pointerenter=${() => onShow(i)} @focus=${() => onShow(i)}>${offerRowBody(item)}</a></li>`)}</ul>${current ? html`<a href=${current.href} tabindex="-1" aria-hidden="true" class="relative grid w-(--ds-header-live-card-w) flex-none overflow-hidden rounded-ds-sm bg-surface-raised">${repeat([leaving, active].filter((i): i is number => i !== null && Boolean(rows[i])), (i) => rows[i].key, (i) => {
const item = rows[i]
const picture = toSlot('picture' in item ? item.picture : undefined)
const visual = 'visual' in item ? item.visual : undefined
const platforms = 'platforms' in item ? item.platforms : undefined
return html`<span data-on=${ifDefined(i === active ? '' : undefined)} class="ds-live-stage relative isolate grid h-full place-items-center overflow-hidden rounded-ds-sm bg-surface-raised opacity-0 [grid-area:1/1] data-on:z-1 data-on:opacity-100"><span aria-hidden="true" class="pointer-events-none absolute inset-0 -z-1 select-none" style=${asciiDriftStyle('mass', 'centre', 'faint')}></span>${picture.src ? html`<img src=${picture.src} alt=${picture.alt ?? ''} class="absolute inset-0 size-full object-cover" style=${styleMap(imageFit(picture) ?? {})}>` : visual ? html`<span class=${VISUAL}><spyglass-product-visual kind=${visual} texture="none" fill class="h-full"></spyglass-product-visual></span>` : 'groups' in item ? nothing : html`<span data-ds-placeholder="" class=${`${GLYPH} size-16 rounded-control [--glyph-body:var(--ds-color-neutral-7)] [--glyph-lit:var(--ds-color-fg)]`}>${navIcon(item.icon, 24)}</span>`}${platforms?.length ? html`<span class="absolute top-3 left-3 z-2 flex rounded-ds-sm bg-surface px-2 py-1 type-caption text-fg-soft">${platforms.join(', ')}</span>` : nothing}</span>`
})}${groups ? html`<span aria-hidden="true" class="pointer-events-none absolute inset-0 z-2 grid place-items-center content-center gap-8">${groups.map((g) => html`<span class="grid justify-items-center gap-4"><span class="type-ui text-fg-soft">${g.label}</span><span class="flex flex-wrap justify-center gap-x-6 gap-y-2 px-6">${g.items.map((w) => html`<span class="type-body font-medium text-fg">${w}</span>`)}</span></span>`)}</span>` : nothing}</a>` : nothing}<div hidden aria-hidden="true" inert>${rows.map((item) => ('picture' in item && toSlot(item.picture).src ? html`<img src=${toSlot(item.picture).src} alt="" loading="eager">` : nothing))}</div></div><div class=${STRIP}><span class="type-ui text-fg-muted">${menu.strip.label}</span><ul class="flex gap-1">${menu.strip.links.map((link) => html`<li><a class=${STRIP_LINK} href=${link.href}>${link.label}</a></li>`)}</ul></div></div>`
}
// The product's scene fills the card at the menu's quicker reading pace (site --dur-read-first-menu, -hold-menu).
const VISUAL = 'absolute inset-0 grid [--ds-read-first:var(--ds-read-first-menu)] [--ds-read-hold:var(--ds-read-hold-menu)]'
/** A controller for the live card's active row and its crossfade, shared by the panel and the header's nav. */
export class LiveState {
active = 0
leaving: number | null = null
private timer = 0
constructor(private readonly update: () => void) {}
show(i: number) {
if (i === this.active) return
clearTimeout(this.timer)
this.leaving = this.active
this.active = i
this.update()
this.timer = window.setTimeout(() => {
this.leaving = null
this.update()
}, LIVE_CROSSFADE_MS)
}
stop() {
clearTimeout(this.timer)
}
}
/** @summary The header's products menu on its own: offers beside the live card. */
export class ProductsLivePanel extends DsElement {
static styles = [DsElement.styles, navIconStyles, menuPanelsStyles, styles]
static properties = { menu: { type: Object } }
/** The menu's content (lib/site-header.ts headerMenus.products by default). */
menu: ProductsMenu = headerMenus.products
private live = new LiveState(() => this.requestUpdate())
disconnectedCallback() {
super.disconnectedCallback()
this.live.stop()
}
render() {
return productsPanel(this.menu ?? headerMenus.products, this.live.active, this.live.leaving, (i) => this.live.show(i))
}
}
define('products-live-panel', ProductsLivePanel).ds-live-stage { transition: opacity var(--ds-duration-micro) var(--ds-easing-out); }
@starting-style { .ds-live-stage[data-on] { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .ds-live-stage { transition: none; } }import { html } from 'lit'
import { DsElement, define, uid } from '@/elements/lib/element'
import styles from 'virtual:tw'
// MenuSheet.tsx as <spyglass-menu-sheet>: the 48px menu button and the phone sheet, a modal dialog revealed downward from
// the bar, with the `brand`, `action` and close button in its bar, the default slot scrolling in the middle and the
// `foot` pinned under a hairline. Focus moves in (to the close button from the keyboard) and Tab wraps inside; Escape
// or the close button closes it and gives focus back; following a link closes it; the page does not scroll under it.
// `label`, `close-label`, `until` (1280 or 1024: it hides and closes from there).
export const menuSheetStyles = styles
export const BAR = 'relative mx-auto flex h-16 w-full max-w-[calc(var(--ds-layout-content)+2*var(--ds-layout-gutter))] items-center justify-between px-(--ds-layout-gutter) lg:h-header'
const MENU_BUTTON = 'ds-menu-button grid size-12 flex-none cursor-pointer place-items-center rounded-control -me-3 text-fg outline-offset-[calc(-1*var(--ds-space-xs))]'
const glyph = html`<span aria-hidden="true" class="ds-menu-glyph relative block h-3 w-6"><span></span><span></span></span>`
function unlock(dialog: HTMLDialogElement | null) {
const root = document.documentElement
root.style.overflow = ''
root.style.paddingRight = ''
dialog?.style.removeProperty('--scrollbar-w')
}
/**
* @summary The phone menu: a button that opens the sheet.
* @slot brand - The lockup link in the sheet's bar.
* @slot action - Beside the close button.
* @slot - The links.
* @slot foot - Pinned at the foot.
*/
export class MenuSheet extends DsElement {
static styles = [DsElement.styles, styles]
static properties = { label: {}, closeLabel: { attribute: 'close-label' }, until: { type: Number }, open: { state: true } }
label = 'Menu'
closeLabel = 'Close menu'
/** The width it hides and closes at (1280 or 1024). */
until = 1280
private open = false
private sheetId = uid('sheet')
private followed = false
private wide?: MediaQueryList
private get dialog() { return this.renderRoot.querySelector<HTMLDialogElement>('dialog') }
private get trigger() { return this.renderRoot.querySelector<HTMLButtonElement>('[aria-haspopup]') }
private get closer() { return this.renderRoot.querySelector<HTMLButtonElement>('[data-close]') }
private onWide = () => { if (this.wide?.matches && this.dialog?.open) this.closeMenu() }
connectedCallback() {
super.connectedCallback()
this.wide = window.matchMedia(`(min-width: ${this.until}px)`)
this.wide.addEventListener('change', this.onWide)
}
disconnectedCallback() {
super.disconnectedCallback()
this.wide?.removeEventListener('change', this.onWide)
unlock(this.dialog)
}
private openMenu(e: MouseEvent) {
const dialog = this.dialog
if (!dialog || dialog.open) return
this.followed = false
const root = document.documentElement
const bar = window.innerWidth - root.clientWidth
root.style.overflow = 'hidden'
root.style.paddingRight = `${bar}px`
dialog.style.setProperty('--scrollbar-w', `${bar}px`)
dialog.showModal()
if (e.detail === 0) this.closer?.focus()
else dialog.focus()
this.open = true
}
private closeMenu() {
unlock(this.dialog)
this.dialog?.close()
}
private onClose() {
unlock(this.dialog)
this.open = false
if (!this.followed) this.trigger?.focus({ preventScroll: true })
}
private onClick(e: MouseEvent) {
if (!e.composedPath().some((n) => n instanceof HTMLAnchorElement)) return
this.followed = true
this.closeMenu()
}
// The focusable stops in the order they show: what is slotted in the bar, the close button, the links (a closed
// disclosure gives only its own button), the foot. Elements that draw their control in a shadow root give that.
private stops() {
const out: HTMLElement[] = []
const walk = (el: Element) => {
if (!(el instanceof HTMLElement)) return
if (el.localName.endsWith('-sheet-disclosure')) {
const toggle = el.shadowRoot?.querySelector<HTMLElement>('button')
if (toggle) out.push(toggle)
if (el.hasAttribute('open')) for (const c of el.children) walk(c)
return
}
if (el.shadowRoot && el.localName.endsWith('-button')) {
const inner = el.shadowRoot.querySelector<HTMLElement>('a[href], button')
if (inner) out.push(inner)
return
}
if (el.matches('a[href], button')) {
out.push(el)
return
}
for (const c of el.children) walk(c)
}
const from = (name: string) => {
const slot = this.renderRoot.querySelector<HTMLSlotElement>(name ? `slot[name="${name}"]` : 'slot:not([name])')
for (const el of slot?.assignedElements({ flatten: true }) ?? []) walk(el)
}
from('brand')
from('action')
if (this.closer) out.push(this.closer)
from('')
from('foot')
return out.filter((el) => el.getClientRects().length > 0)
}
private deepActive() {
let a: Element | null = document.activeElement
while (a?.shadowRoot?.activeElement) a = a.shadowRoot.activeElement
return a
}
private onKeyDown(e: KeyboardEvent) {
if (e.key !== 'Tab') return
const stops = this.stops()
const first = stops[0]
const last = stops[stops.length - 1]
if (!first || !last) return
const active = this.deepActive()
if (active === this.dialog) {
e.preventDefault()
;(e.shiftKey ? last : first).focus()
} else if (e.shiftKey && active === first) {
e.preventDefault()
last.focus()
} else if (!e.shiftKey && active === last) {
e.preventDefault()
first.focus()
}
}
render() {
return html`<div data-ds="menu-sheet" class=${`contents ${this.until === 1024 ? 'lg:hidden' : 'xl:hidden'}`}><button type="button" aria-haspopup="dialog" aria-expanded=${String(this.open)} aria-controls=${this.sheetId} @click=${this.openMenu} class=${MENU_BUTTON}><span class="sr-only">${this.label}</span>${glyph}</button><dialog id=${this.sheetId} aria-label=${this.label} tabindex="-1" @close=${this.onClose} @click=${this.onClick} @keydown=${this.onKeyDown} class="ds-sheet fixed inset-0 m-0 h-dvh max-h-none w-full max-w-none overflow-hidden border-0 bg-surface p-0 pe-(--scrollbar-w,0) text-fg outline-none"><div class="flex h-full flex-col"><div class=${`${BAR} flex-none after:absolute after:inset-x-0 after:bottom-0 after:border-t after:border-edge`}><slot name="brand"></slot><div class="flex min-w-0 flex-[0_1_auto] items-center gap-1 md:gap-2"><slot name="action"></slot><button data-close type="button" @click=${this.closeMenu} class=${MENU_BUTTON}><span class="sr-only">${this.closeLabel}</span>${glyph}</button></div></div><div class="fade-y flex min-h-0 flex-1 flex-col overflow-y-auto overscroll-contain"><slot></slot></div><div class="relative mx-auto flex w-full max-w-[calc(var(--ds-layout-content)+2*var(--ds-layout-gutter))] flex-none flex-col gap-2 px-(--ds-layout-gutter) pt-4 pb-[max(var(--ds-space-lg),env(safe-area-inset-bottom))] before:absolute before:inset-x-0 before:top-0 before:border-t before:border-edge"><slot name="foot"></slot></div></div></dialog></div>`
}
}
define('menu-sheet', MenuSheet).ds-menu-glyph { transition: transform var(--ds-duration-press) var(--ds-easing-out); }
.ds-menu-button:active .ds-menu-glyph { transform: scale(0.9); }
.ds-menu-glyph > span { position: absolute; inset-inline: 0; top: calc(50% - var(--ds-stroke) / 2); height: 0; border-top: var(--ds-stroke) solid currentColor; transition: transform var(--ds-duration-micro) var(--ds-easing-out); }
.ds-menu-glyph > span:first-child { transform: translateY(calc(-1 * var(--ds-space-xs))) rotate(0deg); }
.ds-menu-glyph > span:last-child { transform: translateY(var(--ds-space-xs)) rotate(0deg); }
.ds-sheet {
--sheet-bar: var(--ds-header-bar-phone);
clip-path: inset(0 0 calc(100% - var(--sheet-bar)) 0);
transition: clip-path var(--ds-duration-micro) var(--ds-easing-out), display var(--ds-duration-micro) allow-discrete, overlay var(--ds-duration-micro) allow-discrete;
}
.ds-sheet[open] { clip-path: inset(0 0 0 0); transition-duration: var(--ds-duration-enter); }
.ds-sheet::backdrop { background: transparent; }
.ds-sheet[open] .ds-menu-glyph > span { transition-duration: var(--ds-duration-enter); }
.ds-sheet[open] .ds-menu-glyph > span:first-child { transform: translateY(0) rotate(45deg); }
.ds-sheet[open] .ds-menu-glyph > span:last-child { transform: translateY(0) rotate(-45deg); }
@starting-style {
.ds-sheet[open] { clip-path: inset(0 0 calc(100% - var(--sheet-bar)) 0); }
.ds-sheet[open] .ds-menu-glyph > span:first-child { transform: translateY(calc(-1 * var(--ds-space-xs))) rotate(0deg); }
.ds-sheet[open] .ds-menu-glyph > span:last-child { transform: translateY(var(--ds-space-xs)) rotate(0deg); }
}
@media (min-width: 1024px) { .ds-sheet { --sheet-bar: var(--ds-size-header); } }
@media (prefers-reduced-motion: reduce) {
.ds-sheet, .ds-sheet[open], .ds-menu-glyph, .ds-menu-glyph > span, .ds-sheet[open] .ds-menu-glyph > span { transition: none; }
}import { html } from 'lit'
import { ifDefined } from 'lit/directives/if-defined.js'
import { DsElement, define, uid } from '@/elements/lib/element'
import { chevron, navIconStyles } from '@/elements/components/site/nav-icon'
import styles from 'virtual:tw'
// SheetDisclosure.tsx as <spyglass-sheet-disclosure label>: the phone sheet's 48px Funnel Display row whose list (the
// default slot) opens to its height and fades in; the chevron turns over. `open` reflects.
export const sheetDisclosureStyles = styles
export const SHEET_LINK = 'flex min-h-12 items-center rounded-control px-3 -mx-3 type-heading-3 text-fg transition-[color] duration-160 ease-out outline-offset-[calc(-1*var(--ds-space-xs))] hover:text-fg-soft active:text-fg-soft'
/**
* @summary A disclosure row in the phone menu.
* @slot - The list it opens.
*/
export class SheetDisclosure extends DsElement {
static styles = [DsElement.styles, navIconStyles, styles]
static properties = { label: {}, open: { type: Boolean, reflect: true } }
label = ''
open = false
private panelId = uid('disclosure')
render() {
return html`<div data-ds="sheet-disclosure" data-open=${ifDefined(this.open ? '' : undefined)} class="flex flex-col"><button type="button" aria-expanded=${String(this.open)} aria-controls=${this.panelId} @click=${() => (this.open = !this.open)} class=${`${SHEET_LINK} w-[calc(100%+2*var(--ds-space-md))] cursor-pointer justify-between text-start`}>${this.label}${chevron(16, 'ds-sheet-chevron size-4 text-fg-soft')}</button><div id=${this.panelId} ?inert=${!this.open} data-open=${String(this.open)} class="ds-sheet-collapse"><div><div class="ds-sheet-collapse-body"><slot></slot></div></div></div></div>`
}
}
define('sheet-disclosure', SheetDisclosure).ds-sheet-collapse { display: grid; grid-template-rows: 0fr; transition: grid-template-rows var(--ds-duration-exit) var(--ds-easing-out); }
.ds-sheet-collapse[data-open="true"] { grid-template-rows: 1fr; transition-duration: var(--ds-duration-glide); }
.ds-sheet-collapse > div { min-height: 0; overflow: hidden; }
.ds-sheet-collapse-body { opacity: 0; transition: opacity var(--ds-duration-exit) var(--ds-easing-out); }
.ds-sheet-collapse[data-open="true"] .ds-sheet-collapse-body { opacity: 1; transition-duration: var(--ds-duration-glide); }
.ds-sheet-chevron { transition: transform var(--ds-duration-glide) var(--ds-easing-in-out); }
[aria-expanded="true"] > .ds-sheet-chevron { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) {
.ds-sheet-collapse, .ds-sheet-collapse[data-open="true"], .ds-sheet-chevron { transition: none; }
}import { html, svg } from 'lit'
import { unsafeSVG } from 'lit/directives/unsafe-svg.js'
import { DsElement, define } from '@/elements/lib/element'
import { CHEVRON_PATH, navIconPaths, type NavIconName } from '@/lib/site-header'
import styles from 'virtual:tw'
// NavIcon.tsx as <spyglass-nav-icon name size>: the site's two-tone menu glyphs. The header renders the same markup
// through `navIcon()` and `chevron()`, so its menus live in one shadow root.
export const navIcon = (name: NavIconName, size: 20 | 24 = 20, cls = '') => html`<svg data-ds="nav-icon" viewBox="0 0 24 24" width=${size} height=${size} aria-hidden="true" focusable="false" class=${`block flex-none ${cls}`.trim()}>${svg`${unsafeSVG(navIconPaths(name))}`}</svg>`
export const navIconStyles = styles
export const chevron = (size: 12 | 16 = 12, cls = '') => html`<svg viewBox="0 0 12 12" width=${size} height=${size} fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" class=${`flex-none ${cls}`.trim()}>${svg`${unsafeSVG(CHEVRON_PATH)}`}</svg>`
/** @summary A two-tone menu glyph. */
export class NavIcon extends DsElement {
static styles = [DsElement.styles, styles]
static properties = { name: {}, size: { type: Number } }
name: NavIconName = 'soon'
/** 20 or 24px. */
size: 20 | 24 = 20
render() {
return navIcon(this.name, this.size)
}
}
define('nav-icon', NavIcon)Reference: Site site/Header (Header, NavMenus, MenuPanels, ProductsLivePanel, LiveVisual, HeaderKey, HomeLink, NavIcon, ScrollGround, MenuSheet, SheetDisclosure, Header.module.css) and ui/WarmPictures: 64/72px bar in the container, grid 1fr auto 1fr from 1280; links 36px, 16px in, --text-2, --surface under the pointer; panels 24px under the links on --raised in a --line hairline with an 8px corner, 874, 944 and 556px wide, rising 8px from scale 0.96 over --dur (--dur-fast out), opening after 80ms of hover and closing 240ms after the pointer leaves; rows 12px in, a 40px glyph tile, 14/20 Medium names over --text-3 lines; the live card 540px crossfading in 200ms; the strip 32px links over a hairline; the key --control-xs, Get API key under 424px; the sheet a modal dialog clipped open from the bar, 24/28 Funnel Display rows under hairlines, the foot pinned. The library names platforms in words, takes pictures through props, and opens menus at once from the keyboard.