import * as React from "react"; import { hasSlot, isBadgeData, isLinkData, renderActions, renderBadge, renderLink, type ActionData, type BadgeData, type LinkData, } from "./data-slots"; import { cn } from "../lib/cn"; type MetaData = string | BadgeData | LinkData; export interface PageHeaderProps { overline?: React.ReactNode; title: React.ReactNode; description?: React.ReactNode; /** Under the description: elements, or data (strings, badges as * `{ tone, label }`, links as `{ label, href, external }`). */ meta?: React.ReactNode | MetaData[]; /** On the right: the page's buttons, main one last, as elements or * `ActionData`. Children go there too. */ actions?: React.ReactNode | ActionData | ActionData[]; children?: React.ReactNode; /** 1 by default: the page's one h1. */ headingLevel?: 1 | 2 | 3; className?: string; } function renderMeta(item: React.ReactNode | MetaData) { if (item == null || item === false) return null; if (isBadgeData(item)) return renderBadge(item); if (isLinkData(item)) return renderLink(item); if (React.isValidElement(item)) return item; // A fact given as `{ label }` with no address: plain words. if (typeof item === "object" && "label" in item) { return {(item as { label: React.ReactNode }).label}; } return {item as React.ReactNode}; } // The design system's PageHeader: an overline, the page's title, a line of // description, a row of facts and the page's actions. One per page: it is the // one that carries the `h1`. The actions sit beside the title, aligned to its // last line, and wrap under it when they do not fit. function PageHeader({ overline, title, description, meta, actions, headingLevel = 1, className, children, }: PageHeaderProps) { const Heading = `h${headingLevel}` as "h1" | "h2" | "h3"; const hasMeta = hasSlot(meta); const hasActions = hasSlot(actions) || hasSlot(children); return (
{overline}
)} {/* `wrap-anywhere` here and below: the title of the overview is the site's domain, one long word that would widen the page. */}{description}
)} {hasMeta && (