import type { ReactNode } from 'react' import { Link } from 'react-router-dom' import PlaceControl from './PlaceControl' interface Props { /** The crumb link back to where the reader came from. */ backTo: string backLabel: string /** The page title: the page's `h1` when `titleAsH1`, otherwise plain text (the challenge's `h1` is on its cover). */ title: string titleAsH1?: boolean /** What the scope label sits after, for example "Data Center Story". */ scopeLead?: string /** Exactly what the data shows: "National", "Alabama", "Tuscaloosa, Alabama". */ label: string stateCode: string | undefined stateName: string | null city: string | null /** The short word of the screen in view (a category, never a number). */ current: string /** A sentence heading (the page's h1, its blanks are the controls); replaces the title and the Your place button. */ heading?: ReactNode /** Extra controls in the bar, before "Your place" (the challenge's sound switch). */ extra?: ReactNode /** The strip of progress pips along the bar's lower edge. */ progress?: ReactNode placeOpen: boolean onPlaceOpenChange: (open: boolean) => void onApply: (stateCode: string | null, city: string | null) => void /** The story's Close (×), top right (#1234): with it the bar drops the back crumb and the "Showing:" row; the title's * place control is the page's place switcher and Close its one exit. */ close?: ReactNode /** Why the story shows a wider place than the one asked (#1285): one line under the heading, in the sticky bar. */ note?: ReactNode } /** The sticky bar above the screens: where you are, the scope label with its broaden controls, and "Your place". */ export default function ScopeBar(p: Props) { return (
{p.heading ? (
{p.heading}
) : (
{p.backLabel} {p.titleAsH1 ?

{p.title}

: {p.title}}
)} {/* With the United States in the sentence blank, skip Showing: National (#959). Keep the back crumb and broaden controls when a place is set. */} {!p.close && (p.heading || p.stateName) && (

{p.heading && ( <> {p.backLabel} {p.stateName ? ' · ' : null} )} {p.stateName ? ( <> {p.scopeLead ? `${p.scopeLead} · showing:` : 'Showing:'} {p.label} {p.city && ( )} ) : null}

)} {/* Under the headline, in its column, never beside or over it. */} {p.note &&
{p.note}
}

{p.current}

{p.extra} {p.close} {p.progress} {!p.heading && }
) }