# Header

> Get visitors to the right page at any width: plain links and panels of links, folding into a phone menu.

Page: https://uicontext.com/blocks/header

A screen in Marketing site. Preview it at https://uicontext.com/blocks/header/preview.

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/header
```

With npm: `npx shadcn@latest add checkfu/uicontext/header`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/header`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/header`.

## Components used

- [Sheet](https://uicontext.com/docs/components/sheet.md) (`sheet`): A panel that slides over the page from a side or the bottom.
- [Button](https://uicontext.com/docs/components/button.md) (`button`): A button, and a link that looks like one, in every tone and three sizes.

## Source

As written in the repository. `src/blocks/marketing/Nav.ts` is the screen; the other files are pieces it imports.

```ts title="src/blocks/marketing/Nav.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import { NavigationMenu } from "effect/ui/kit"
import * as stylex from "@stylexjs/stylex"
import { Schema } from "effect"
import { buttonStyle } from "../../Button.ts"
import { motionStyles } from "../../Motion.ts"
import { Sheet } from "../../Sheet.ts"
import { sx } from "../../Sx.ts"
import { color, corner, density, elevation, font, motion, space, stroke } from "../../tokens.stylex.ts"
import { Icon, isIconName } from "../saas/Icons.ts"
import { rhythm } from "./marketing.stylex.ts"
import { Action, BrandLink, SiteBrand, sectionStyles } from "./Section.ts"

// The site's header: the product's mark, its main links, and Sign in beside the main action. A
// link can open a panel of links instead (a mega menu): the arrow keys move along the bar, Down or
// Enter opens a panel, Tab walks into it, and Escape or a press outside closes it. The mouse opens
// a panel by resting on its link, and moves between panels at once while one is open.
//
// Below 768px of its own width the links fold into a sheet behind a Menu button: every link, the
// panels' links under their names, and the two actions at the bottom within a thumb's reach.

export const NavLink = Schema.TaggedStruct("Link", { label: Schema.String, href: Schema.String })

/** A link inside a panel, with a line that says what's there and an optional icon. */
export const NavPanelLink = Schema.Struct({
	label: Schema.String,
	href: Schema.String,
	description: Schema.optional(Schema.String),
	icon: Schema.optional(Schema.String),
})
export type NavPanelLink = typeof NavPanelLink.Type

/** A link on the bar that opens a panel of links, with an optional card at its end. */
export const NavGroup = Schema.TaggedStruct("Group", {
	/** names the panel: what `open` holds */
	value: Schema.String,
	label: Schema.String,
	links: Schema.Array(NavPanelLink),
	/** a card at the panel's end: a guide, the latest release */
	feature: Schema.optional(Schema.Struct({ title: Schema.String, description: Schema.String, action: Action })),
})
export type NavGroup = typeof NavGroup.Type

export const NavItem = Schema.Union([NavLink, NavGroup])
export type NavItem = typeof NavItem.Type

export const SiteNavProps = Schema.Struct({
	brand: SiteBrand,
	items: Schema.Array(NavItem),
	/** the quiet link at the end: "Sign in" */
	signIn: Schema.optional(Action),
	/** the main action: "Start free" */
	primary: Schema.optional(Action),
	/** the href of the page showing, marked as current */
	current: Schema.optional(Schema.String),
	/** stays at the top of the page as it scrolls */
	sticky: Schema.optional(Schema.Boolean),
	/** shows the phone layout, the Menu button and its sheet, at any width */
	compact: Schema.optional(Schema.Boolean),
})
export type SiteNavProps = typeof SiteNavProps.Type

export const SiteNavModel = Schema.Struct({
	/** the open panel's value */
	open: Schema.NullOr(Schema.String),
	/** the phone menu is open */
	sheet: Schema.Boolean,
})

export const SiteNavMessage = UiSchema.TaggedEnum({
	RequestedPanel: { value: Schema.String },
	ClosedPanel: {},
	OpenedSheet: {},
	ClosedSheet: {},
})

const styles = stylex.create({
	root: {
		containerType: "inline-size",
		boxSizing: "border-box",
		inlineSize: "100%",
		zIndex: 10,
		color: color.fg,
		fontFamily: font.sans,
		backgroundColor: `color-mix(in srgb, ${color.panel} 88%, transparent)`,
		backdropFilter: "saturate(1.4) blur(12px)",
		borderBlockEndWidth: stroke.hairline,
		borderBlockEndStyle: "solid",
		borderBlockEndColor: color.line,
	},
	sticky: { position: "sticky", insetBlockStart: 0 },
	bar: {
		boxSizing: "border-box",
		display: "flex",
		alignItems: "center",
		gap: space.xl,
		blockSize: `calc(${density.header} + 12px)`,
		maxInlineSize: `calc(${rhythm.page} + 2 * ${rhythm.gutter})`,
		marginInline: "auto",
		paddingInline: rhythm.gutter,
	},
	brand: { marginInlineEnd: { default: "auto", "@container (min-width: 768px)": space.lg } },
	// the bar's links and actions show from 768px; below, the Menu button stands for them
	wide: { display: { default: "none", "@container (min-width: 768px)": "flex" } },
	narrow: { display: { default: "inline-flex", "@container (min-width: 768px)": "none" } },
	compactHide: { display: "none" },
	compactShow: { display: "inline-flex" },
	compactBrand: { marginInlineEnd: "auto" },
	nav: { flexGrow: 1, minInlineSize: 0 },
	list: { display: "flex", alignItems: "center", gap: space.xxs, margin: 0, padding: 0, listStyle: "none" },
	item: { display: "flex" },
	barLink: {
		display: "inline-flex",
		alignItems: "center",
		gap: space.xs,
		blockSize: `calc(${density.control} + 4px)`,
		paddingInline: space.lg,
		borderWidth: 0,
		borderRadius: corner.control,
		backgroundColor: { default: "transparent", ":hover": { default: null, "@media (hover: hover) and (pointer: fine)": color.hover }, ":is([data-popup-open])": color.hover },
		color: { default: color.muted, ":hover": { default: null, "@media (hover: hover) and (pointer: fine)": color.fg }, ":is([data-popup-open], [aria-current=page])": color.fg },
		fontFamily: "inherit",
		fontSize: font.base,
		fontWeight: 500,
		textDecoration: "none",
		whiteSpace: "nowrap",
		cursor: "pointer",
		transitionProperty: "background-color, color",
		transitionDuration: motion.fast,
		outline: { default: "none", ":focus-visible": `2px solid ${color.focusRing}` },
		outlineOffset: -2,
	},
	chevron: {
		display: "inline-flex",
		color: color.faint,
		transitionProperty: "transform",
		transitionDuration: motion.base,
		transitionTimingFunction: motion.easeOut,
		transform: { default: "none", ":is([data-popup-open] > *)": "rotate(180deg)" },
	},
	actions: { alignItems: "center", gap: space.md, flexShrink: 0 },
	signIn: { textDecoration: "none" },
	// the main action stays on the bar from 560px, beside the Menu button
	primaryNarrow: { textDecoration: "none", display: { default: "none", "@container (min-width: 560px)": "inline-flex", "@container (min-width: 768px)": "none" } },
	primaryCompact: { textDecoration: "none", display: { default: "none", "@container (min-width: 560px)": "inline-flex" } },
	menuButton: { flexShrink: 0 },
	positioner: { zIndex: 20, outline: "none" },
	panel: {
		boxSizing: "border-box",
		display: "grid",
		gridTemplateColumns: "minmax(0, 1fr) 15rem",
		inlineSize: "min(44rem, calc(100vw - 2rem))",
		marginBlockStart: space.md,
		overflow: "hidden",
		borderWidth: stroke.hairline,
		borderStyle: "solid",
		borderColor: color.line,
		borderRadius: `calc(${corner.card} + 4px)`,
		backgroundColor: color.overlay,
		color: color.fg,
		boxShadow: elevation.menu,
		fontFamily: font.sans,
	},
	panelPlain: { gridTemplateColumns: "minmax(0, 1fr)", inlineSize: "min(28rem, calc(100vw - 2rem))" },
	panelLinks: { display: "grid", gridTemplateColumns: "repeat(2, minmax(0, 1fr))", gap: space.xxs, margin: 0, padding: space.md, listStyle: "none" },
	panelLink: {
		display: "grid",
		gridTemplateColumns: "auto minmax(0, 1fr)",
		columnGap: space.lg,
		rowGap: space.xxs,
		alignItems: "start",
		padding: space.lg,
		borderRadius: corner.card,
		color: color.fg,
		textDecoration: "none",
		backgroundColor: { default: "transparent", ":hover": { default: null, "@media (hover: hover) and (pointer: fine)": color.hover }, ":focus-visible": color.hover },
		outline: { default: "none", ":focus-visible": `2px solid ${color.focusRing}` },
		outlineOffset: -2,
	},
	panelIcon: {
		display: "grid",
		placeItems: "center",
		gridRow: "span 2",
		inlineSize: 32,
		blockSize: 32,
		borderRadius: corner.control,
		borderWidth: stroke.hairline,
		borderStyle: "solid",
		borderColor: color.line,
		backgroundColor: color.panel,
		color: color.fg,
	},
	panelLabel: { fontSize: font.base, fontWeight: 550, lineHeight: 1.3 },
	panelText: { fontSize: font.sm, lineHeight: 1.45, color: color.muted },
	feature: {
		display: "grid",
		alignContent: "end",
		gap: space.sm,
		padding: space.xxl,
		backgroundColor: color.raised,
		borderInlineStartWidth: stroke.hairline,
		borderInlineStartStyle: "solid",
		borderInlineStartColor: color.line,
	},
	featureTitle: { margin: 0, fontSize: font.base, fontWeight: 600, lineHeight: 1.35 },
	featureText: { margin: 0, fontSize: font.sm, lineHeight: 1.5, color: color.muted },
	featureLink: { fontSize: font.sm, marginBlockStart: space.sm },
	// the phone menu
	sheetGroups: { display: "grid", gap: space.xxl },
	sheetGroup: { display: "grid", gap: space.xs },
	sheetHeading: { margin: 0, paddingBlockEnd: space.xs, fontSize: font.xs, fontWeight: 600, letterSpacing: "0.04em", textTransform: "uppercase", color: color.muted },
	sheetLinks: { display: "grid", margin: 0, padding: 0, listStyle: "none" },
	sheetLink: {
		display: "flex",
		alignItems: "center",
		gap: space.lg,
		minBlockSize: `calc(${density.control} + 12px)`,
		paddingInline: space.md,
		marginInline: `calc(-1 * ${space.md})`,
		borderRadius: corner.control,
		color: color.fg,
		fontSize: font.lg,
		fontWeight: 500,
		textDecoration: "none",
		backgroundColor: { default: "transparent", ":hover": { default: null, "@media (hover: hover) and (pointer: fine)": { default: color.hover, ":active": color.selected } }, ":active": color.selected, ":is([aria-current=page])": color.selected },
		outline: { default: "none", ":focus-visible": `2px solid ${color.focusRing}` },
		outlineOffset: -2,
	},
	sheetIcon: { display: "inline-flex", color: color.muted },
	sheetFooter: { display: "grid", gap: space.md, inlineSize: "100%" },
	sheetAction: { inlineSize: "100%", textDecoration: "none" },
})

const iconOf = (name: string | undefined) => (name !== undefined && isIconName(name) ? name : undefined)

export const SiteNav = Html.component({
	name: "SiteNav",
	props: SiteNavProps,
	model: SiteNavModel,
	message: SiteNavMessage,
	restore: false,
}).make({
	init: () => ({ open: null, sheet: false }),
	update: {
		RequestedPanel: ($, { value }) => $.evolve({ open: value }),
		ClosedPanel: ($) => $.evolve({ open: null }),
		OpenedSheet: ($) => $.evolve({ sheet: true, open: null }),
		ClosedSheet: ($) => $.evolve({ sheet: false }),
	},
	view: (h, model) => {
		const props = h.props
		const compact = props.compact === true
		const wide = compact ? styles.compactHide : styles.wide
		const groups = props.items.filter((item): item is NavGroup => item._tag === "Group")
		const links = props.items.filter((item) => item._tag === "Link")
		return h.header.attrs(sx(styles.root, props.sticky === true && styles.sticky)).children(
			h.div.attrs(sx(styles.bar)).children(
				BrandLink(h, props.brand, compact ? styles.compactBrand : styles.brand),
				NavigationMenu(h, {
					props: { value: model.open, side: "bottom", align: "start", sideOffset: 4, collisionPadding: 16 },
					onEmit: {
						RequestedOpen: ({ value }) => SiteNavMessage.RequestedPanel({ value }),
						RequestedClose: () => SiteNavMessage.ClosedPanel(),
						Settled: () => undefined,
					},
					view: (menu) => {
						// the panel the menu shows, which stays through its exit so focus can go home
						const openGroup = groups.find((group) => group.value === menu.value)
						return menu.root(h.nav.attrs({ "aria-label": "Main", ...sx(styles.nav, wide) })).children(
							menu.list(h.ul.attrs(sx(styles.list))).children(
								props.items.map((item) =>
									menu.item(h.li.key(item.label).attrs(sx(styles.item))).children(
										item._tag === "Group"
											? menu.trigger({ element: h.button.attrs(sx(styles.barLink)), value: item.value }).children(
													item.label,
													h.span.attrs(sx(styles.chevron)).children(Icon(h, "chevronDown", 14)),
												)
											: menu.link({ element: h.a.attrs({ href: item.href, ...sx(styles.barLink) }), active: item.href === props.current }).children(item.label),
									),
								),
							),
							menu.portal(h.div)?.children(
								menu.positioner(h.div.attrs(sx(styles.positioner))).children(
									menu.popup(h.div.attrs(sx(motionStyles.popup))).children(
										menu.viewport(h.div).children(
											openGroup !== undefined && h.div.attrs(sx(styles.panel, openGroup.feature === undefined && styles.panelPlain)).children(
												h.ul.attrs({ "aria-label": openGroup.label, ...sx(styles.panelLinks) }).children(
													openGroup.links.map((item) => {
														const icon = iconOf(item.icon)
														return h.li.key(item.href).children(
															menu.link({ element: h.a.attrs({ href: item.href, ...sx(styles.panelLink) }), active: item.href === props.current, closeOnClick: true }).children(
																icon !== undefined && h.span.attrs(sx(styles.panelIcon)).children(Icon(h, icon, 16)),
																h.span.attrs(sx(styles.panelLabel)).children(item.label),
																item.description !== undefined && h.span.attrs(sx(styles.panelText)).children(item.description),
															),
														)
													}),
												),
												openGroup.feature !== undefined && h.div.attrs(sx(styles.feature)).children(
													h.p.attrs(sx(styles.featureTitle)).children(openGroup.feature.title),
													h.p.attrs(sx(styles.featureText)).children(openGroup.feature.description),
													menu.link({ element: h.a.attrs({ href: openGroup.feature.action.href, ...sx(sectionStyles.textLink, sectionStyles.focus, styles.featureLink) }), closeOnClick: true }).children(
														openGroup.feature.action.label,
														h.span.attrs(sx(sectionStyles.arrowFlip)).children(Icon(h, "arrowRight", 14)),
													),
												),
											),
										),
									),
								),
							),
						)
					},
				}),
				h.div.attrs(sx(styles.actions, wide)).children(
					props.signIn !== undefined && h.a.attrs({ href: props.signIn.href, ...sx(...buttonStyle({ emphasis: "ghost" }), styles.signIn) }).children(props.signIn.label),
					props.primary !== undefined && h.a.attrs({ href: props.primary.href, ...sx(...buttonStyle({ tone: "primary" }), styles.signIn) }).children(props.primary.label),
				),
				props.primary !== undefined && h.a.attrs({ href: props.primary.href, ...sx(...buttonStyle({ tone: "primary" }), compact ? styles.primaryCompact : styles.primaryNarrow) }).children(props.primary.label),
				Sheet(h, {
					key: "site-menu",
					open: model.sheet,
					side: "right",
					size: "sm",
					title: "Menu",
					onOpenChange: (open) => (open ? SiteNavMessage.OpenedSheet() : SiteNavMessage.ClosedSheet()),
					trigger: (sheet) =>
						sheet.trigger(h.button).attrs({
							type: "button",
							"aria-label": "Menu",
							...sx(...buttonStyle({ emphasis: "ghost", iconOnly: true }), styles.menuButton, compact ? styles.compactShow : styles.narrow),
						}).children(Icon(h, "menu", 20)),
					children: [h.div.attrs(sx(styles.sheetGroups)).children(
						links.length > 0 && h.nav.attrs({ "aria-label": "Main", ...sx(styles.sheetGroup) }).children(
							h.ul.attrs(sx(styles.sheetLinks)).children(links.map((link) => h.li.key(link.href).children(SheetLink(h, link, props.current)))),
						),
						groups.map((group) =>
							h.nav.key(group.value).attrs({ "aria-labelledby": `site-menu-${group.value}`, ...sx(styles.sheetGroup) }).children(
								h.h3.attrs({ id: `site-menu-${group.value}`, ...sx(styles.sheetHeading) }).children(group.label),
								h.ul.attrs(sx(styles.sheetLinks)).children(group.links.map((link) => h.li.key(link.href).children(SheetLink(h, link, props.current)))),
							),
						),
					)],
					footer: [h.div.attrs(sx(styles.sheetFooter)).children(
						props.primary !== undefined && h.a.attrs({ href: props.primary.href, ...sx(...buttonStyle({ tone: "primary", size: "lg" }), styles.sheetAction) }).on("click", SiteNavMessage.ClosedSheet()).children(props.primary.label),
						props.signIn !== undefined && h.a.attrs({ href: props.signIn.href, ...sx(...buttonStyle({ size: "lg" }), styles.sheetAction) }).on("click", SiteNavMessage.ClosedSheet()).children(props.signIn.label),
					)],
				}),
			),
		)
	},
})

type Msg = typeof SiteNavMessage.Type

const SheetLink = (h: Html.H<Msg>, link: { readonly label: string; readonly href: string; readonly icon?: string | undefined }, current: string | undefined) => {
	const icon = iconOf(link.icon)
	return h.a
		.attrs({ href: link.href, "aria-current": link.href === current ? "page" : undefined, ...sx(styles.sheetLink) })
		.on("click", SiteNavMessage.ClosedSheet())
		.children(icon !== undefined && h.span.attrs(sx(styles.sheetIcon)).children(Icon(h, icon, 18)), link.label)
}
```

```ts title="src/blocks/marketing/Section.ts"
import { Mount, type View } from "effect/ui"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Effect, Schema, Stream } from "effect"
import { buttonStyle } from "../../Button.ts"
import { type Style, sx } from "../../Sx.ts"
import { color, corner, density, elevation, font, motion, space, stroke, typography } from "../../tokens.stylex.ts"
import { Icon } from "../saas/Icons.ts"
import { rhythm, type } from "./marketing.stylex.ts"

// What the marketing sections share: the section frame (a container, so every section lays itself
// out by its own width), a header with an optional eyebrow, links drawn as buttons, the product's
// mark, and the frame that shows a real screen of the product, scaled down.

/** A link a section offers: "Start free" to /signup. */
export const Action = Schema.Struct({ label: Schema.String, href: Schema.String })
export type Action = typeof Action.Type

/** The product's name and mark. `letter` draws the mark when there's no logo file. */
export const SiteBrand = Schema.Struct({ name: Schema.String, letter: Schema.String, href: Schema.String })
export type SiteBrand = typeof SiteBrand.Type

export const sectionStyles = stylex.create({
	root: {
		containerType: "inline-size",
		boxSizing: "border-box",
		inlineSize: "100%",
		color: color.fg,
		fontFamily: font.sans,
		backgroundColor: color.panel,
	},
	muted: { backgroundColor: color.app },
	inner: {
		boxSizing: "border-box",
		display: "grid",
		gap: rhythm.header,
		maxInlineSize: `calc(${rhythm.page} + 2 * ${rhythm.gutter})`,
		marginInline: "auto",
		paddingInline: rhythm.gutter,
		paddingBlock: rhythm.section,
	},
	header: { display: "grid", gap: space.lg, justifyItems: "start", maxInlineSize: "44rem" },
	headerCenter: { justifyItems: "center", textAlign: "center", marginInline: "auto" },
	eyebrow: { margin: 0, fontSize: font.sm, fontWeight: 600, color: color.brand, letterSpacing: "0.01em" },
	// headlines take the theme's display face and weight, so a design language carries its own voice
	title: {
		margin: 0,
		fontFamily: typography.displayFamily,
		fontSize: type.title,
		lineHeight: 1.12,
		fontWeight: typography.displayWeight,
		letterSpacing: type.tight,
		textWrap: "balance",
	},
	display: {
		margin: 0,
		fontFamily: typography.displayFamily,
		fontSize: type.display,
		lineHeight: 1.04,
		fontWeight: typography.displayWeight,
		letterSpacing: "-0.035em",
		textWrap: "balance",
	},
	lede: {
		margin: 0,
		maxInlineSize: "38rem",
		fontSize: type.lede,
		lineHeight: 1.55,
		color: color.muted,
		textWrap: "pretty",
	},
	heading: { margin: 0, fontSize: type.heading, lineHeight: 1.3, fontWeight: 600, letterSpacing: "-0.015em", textWrap: "balance" },
	body: { margin: 0, fontSize: font.base, lineHeight: 1.6, color: color.muted, textWrap: "pretty" },
	actions: { display: "flex", flexWrap: "wrap", gap: space.lg, alignItems: "center" },
	actionsCenter: { justifyContent: "center" },
	// marketing buttons sit a step above the app's largest, and stretch to the width on a phone
	action: {
		height: `calc(${density.control} + 12px)`,
		paddingInline: 20,
		fontSize: 15,
		textDecoration: "none",
		flexGrow: { default: 1, "@container (min-width: 560px)": 0 },
	},
	list: { margin: 0, padding: 0, listStyle: "none" },
	srOnly: { position: "absolute", width: 1, height: 1, overflow: "hidden", clipPath: "inset(50%)", whiteSpace: "nowrap" },
	focus: { outline: { default: "none", ":focus-visible": `2px solid ${color.focusRing}` }, outlineOffset: 2, borderRadius: corner.tag },
	textLink: {
		display: "inline-flex",
		alignItems: "center",
		gap: space.xs,
		minBlockSize: { default: null, "@media (pointer: coarse)": density.control },
		fontSize: font.base,
		fontWeight: 550,
		color: color.brand,
		textDecoration: { default: "none", ":hover": { default: null, "@media (hover: hover) and (pointer: fine)": "underline" } },
		textUnderlineOffset: 4,
		textDecorationThickness: 1,
	},
	arrow: {
		display: "inline-flex",
		transitionProperty: "transform",
		transitionDuration: motion.fast,
		transitionTimingFunction: motion.easeOut,
		transform: {
			default: null,
			":is(:hover > *)": { default: null, "@media (hover: hover) and (pointer: fine)": `translateX(${motion.shift})` },
		},
	},
	arrowFlip: { display: "inline-flex", transform: { default: null, ":dir(rtl)": "scaleX(-1)" } },
	brand: {
		display: "inline-flex",
		alignItems: "center",
		gap: space.md,
		minBlockSize: 40,
		color: color.fg,
		textDecoration: "none",
		fontSize: font.lg,
		fontWeight: 650,
		letterSpacing: "-0.02em",
		whiteSpace: "nowrap",
	},
	mark: {
		display: "grid",
		placeItems: "center",
		flexShrink: 0,
		inlineSize: 28,
		blockSize: 28,
		borderRadius: corner.control,
		backgroundColor: color.fg,
		color: color.panel,
		fontSize: font.base,
		fontWeight: 700,
		letterSpacing: 0,
	},
})

// a shot in a narrow frame (a phone's) shows the screen's first 520 by 420px, so its text stays legible
const roomy = "@container (min-width: 560px)"
const cropWidth = 520
const cropHeight = 420

const shotStyles = stylex.create({
	frame: {
		position: "relative",
		containerType: "inline-size",
		overflow: "hidden",
		inlineSize: "100%",
		borderWidth: stroke.hairline,
		borderStyle: "solid",
		borderColor: color.lineStrong,
		borderRadius: { default: corner.card, "@container (min-width: 768px)": `calc(${corner.card} + 4px)` },
		backgroundColor: color.app,
		boxShadow: elevation.menu,
		// the screen's own type, whatever the section sets
		fontSize: font.base,
		lineHeight: "normal",
		textAlign: "start",
	},
	bare: { boxShadow: "none", borderRadius: corner.card },
	// a tall screen is cut at the size's height; a short one keeps its own
	clip: { overflow: "hidden" },
	clipDesktop: { maxBlockSize: { default: `calc(100cqi * ${cropHeight} / ${cropWidth})`, [roomy]: "calc(100cqi * 800 / 1280)" } },
	clipLaptop: { maxBlockSize: { default: `calc(100cqi * ${cropHeight} / ${cropWidth})`, [roomy]: "calc(100cqi * 720 / 1024)" } },
	clipTablet: { maxBlockSize: { default: `calc(100cqi * ${cropHeight} / ${cropWidth})`, [roomy]: "calc(100cqi * 680 / 820)" } },
	// the screen laid out at the width it was designed for, then zoomed to the frame: 100cqi over
	// that width. Zoom, unlike a transform, shrinks its box too, so the frame fits the screen. In a
	// frame narrower than 560px the whole screen would shrink past reading, so the frame shows its
	// start instead, at a scale that keeps its text legible. Not every engine divides lengths this way
	// (Safari 26 drops it), so FitScreen measures the frame and sets the zoom the same way.
	screen: { pointerEvents: "none", userSelect: "none" },
	screenDesktop: { inlineSize: 1280, zoom: { default: `tan(atan2(100cqi, ${cropWidth}px))`, [roomy]: "tan(atan2(100cqi, 1280px))" } },
	screenLaptop: { inlineSize: 1024, zoom: { default: `tan(atan2(100cqi, ${cropWidth}px))`, [roomy]: "tan(atan2(100cqi, 1024px))" } },
	screenTablet: { inlineSize: 820, zoom: { default: `tan(atan2(100cqi, ${cropWidth}px))`, [roomy]: "tan(atan2(100cqi, 820px))" } },
})

export type ShotSize = "desktop" | "laptop" | "tablet"

const designWidth = { desktop: 1280, laptop: 1024, tablet: 820 } as const

/** Zooms the screen to its frame: the frame's width over the width the screen was designed at. */
const FitScreen = Mount.makeStream("ProductShot.FitScreen", { args: { width: Schema.Number } }, (node: HTMLElement, args) =>
	Stream.callback<never>(() =>
		Effect.acquireRelease(
			Effect.sync(() => {
				const frame = node.parentElement
				if (frame === null) return () => undefined
				// only a change in width rezooms: the zoom changes the frame's height, which would call this again
				let width = -1
				const sized = new ResizeObserver(([entry]) => {
					if (entry === undefined || entry.contentRect.width === width) return
					width = entry.contentRect.width
					// as the styles above: under 560px the frame shows the screen's start, 520px of it
					node.style.zoom = String(width / (width < 560 ? cropWidth : args.width))
				})
				sized.observe(frame)
				return () => sized.disconnect()
			}),
			(cleanup) => Effect.sync(cleanup),
		),
	),
)

const screenSize = { desktop: shotStyles.screenDesktop, laptop: shotStyles.screenLaptop, tablet: shotStyles.screenTablet }
const clipSize = { desktop: shotStyles.clipDesktop, laptop: shotStyles.clipLaptop, tablet: shotStyles.clipTablet }

export interface ProductShotOptions<M, C extends View.Input<M>> {
	/** What the picture shows, read in place of the screen: "The issue list, with a filter applied". */
	readonly label: string
	/**
	 * The width the screen is laid out at before it's scaled to fit, and the most of its height that
	 * shows: `desktop` 1280 by 800 (by default), `laptop` 1024 by 720, `tablet` 820 by 680. Its
	 * layout is the one people see at that size.
	 */
	readonly size?: ShotSize
	/** No shadow, for a shot inside a card. */
	readonly bare?: boolean
	/** The screen: a live component, or an image with its width and height. */
	readonly children: C
	readonly style?: Style
}

/**
 * A screen of the product at the size it was designed for, scaled down to the frame's width, so a
 * hero or a feature shows the real thing at any width. The screen can't be focused or clicked, and
 * is read as one picture by its label.
 */
export const ProductShot = <M, C extends View.Input<M>>(h: Html.H<M>, options: ProductShotOptions<M, C>) => {
	const size = options.size ?? "desktop"
	return h.div.attrs({ role: "img", "aria-label": options.label, ...sx(shotStyles.frame, options.bare === true && shotStyles.bare, options.style) }).children(
		h.div.attrs(sx(shotStyles.clip, clipSize[size])).children(
			h.div.attrs({ inert: "", "aria-hidden": "true", ...sx(shotStyles.screen, screenSize[size]) }).onMount(FitScreen({ width: designWidth[size] })).children(options.children),
		),
	)
}

export interface SectionOptions<M, C extends View.Input<M>> {
	/** The id of the heading that names the section. */
	readonly labelledBy?: string
	/** The section's name, when it has no heading of its own. */
	readonly label?: string
	/** The page's background in place of the panel's, to set one section apart from the next. */
	readonly muted?: boolean
	readonly id?: string
	readonly children: C
	/** StyleX styles for the section. */
	readonly style?: Style
	/** StyleX styles for the column inside it. */
	readonly innerStyle?: Style
}

/** A page section: a container with the page's gutters and the space above and below. */
export const Section = <M, C extends View.Input<M>>(h: Html.H<M>, options: SectionOptions<M, C>) =>
	h.section
		.attrs({
			id: options.id,
			"aria-labelledby": options.labelledBy,
			"aria-label": options.labelledBy === undefined ? options.label : undefined,
			...sx(sectionStyles.root, options.muted === true && sectionStyles.muted, options.style),
		})
		.children(h.div.attrs(sx(sectionStyles.inner, options.innerStyle)).children(options.children))

export interface SectionHeaderOptions<M> {
	/** The heading's id, which the section points at. */
	readonly id: string
	/** A short line above the headline that says what part of the product this is: "Automations". */
	readonly eyebrow?: string
	readonly title: string
	readonly lede?: string
	/** Centered, or at the start; at the start by default. */
	readonly align?: "start" | "center"
	/** 1 for the page's headline (a hero), 2 by default. */
	readonly level?: 1 | 2
	/** Links under the lede. */
	readonly actions?: View.Content<M> | null
	readonly style?: Style
}

export const SectionHeader = <M>(h: Html.H<M>, options: SectionHeaderOptions<M>) => {
	const center = options.align === "center"
	const heading = options.level === 1 ? h.h1 : h.h2
	return h.header.attrs(sx(sectionStyles.header, center && sectionStyles.headerCenter, options.style)).children(
		options.eyebrow !== undefined && h.p.attrs(sx(sectionStyles.eyebrow)).children(options.eyebrow),
		heading.attrs({ id: options.id, ...sx(options.level === 1 ? sectionStyles.display : sectionStyles.title) }).children(options.title),
		options.lede !== undefined && h.p.attrs(sx(sectionStyles.lede)).children(options.lede),
		options.actions,
	)
}

/** A link drawn as a large button: the section's call to action. */
export const ActionLink = <M>(h: Html.H<M>, action: Action, options: { readonly primary?: boolean; readonly style?: Style } = {}) =>
	h.a
		.attrs({
			href: action.href,
			...sx(...buttonStyle({ size: "lg", tone: options.primary === true ? "primary" : "neutral" }), sectionStyles.action, options.style),
		})
		.children(action.label)

/** One or two links as buttons, the main one first. */
export const Actions = <M>(h: Html.H<M>, options: { readonly primary?: Action | undefined; readonly secondary?: Action | undefined; readonly center?: boolean; readonly style?: Style }) =>
	options.primary === undefined && options.secondary === undefined
		? null
		: h.div.attrs(sx(sectionStyles.actions, options.center === true && sectionStyles.actionsCenter, options.style)).children(
				options.primary !== undefined && ActionLink(h, options.primary, { primary: true }),
				options.secondary !== undefined && ActionLink(h, options.secondary),
			)

/** "Read the changelog →": a link in a sentence's place. */
export const ArrowLink = <M>(h: Html.H<M>, action: Action, style?: Style) =>
	h.a.attrs({ href: action.href, ...sx(sectionStyles.textLink, sectionStyles.focus, style) }).children(
		action.label,
		h.span.attrs(sx(sectionStyles.arrow)).children(h.span.attrs(sx(sectionStyles.arrowFlip)).children(Icon(h, "arrowRight", 16))),
	)

/** The product's mark and name, linking home. */
export const BrandLink = <M>(h: Html.H<M>, brand: SiteBrand, style?: Style) =>
	h.a.attrs({ href: brand.href, ...sx(sectionStyles.brand, sectionStyles.focus, style) }).children(
		h.span.attrs({ "aria-hidden": "true", ...sx(sectionStyles.mark) }).children(brand.letter),
		brand.name,
	)
```
