import { Dialog as BaseDialog } from "@base-ui/react/dialog"; import { RobotIcon, BuildingsIcon, CaretUpDownIcon, ChartLineUpIcon, CheckSquareIcon, GitBranchIcon, HouseIcon, KeyIcon, ListIcon, LockIcon, PlusIcon, SidebarIcon, SignOutIcon, TagIcon, UserIcon, UsersIcon, XIcon, type Icon } from "../icons"; import type { NamespaceRef, Person } from "@refs/backend/contract"; import { useEffect, useState, type ReactNode } from "react"; import { Link } from "../provider"; import { Button, LinkButton } from "../ui/button"; import { cn } from "../ui/cn"; import { Banner } from "../ui/feedback"; import { ThemeChoices, ThemeMenu, useRailHidden } from "../theme"; import { Tooltip } from "../ui/overlay"; import { AuthGraphic } from "./auth-graphic"; import { DropdownMenu } from "../ui/overlay"; import { Avatar, LogoMark, Wordmark } from "./brand"; export interface Crumb { label: string; href: string; } export interface ShellState { org: string; namespace: string | null; namespaces: readonly NamespaceRef[]; user: Person | null; showMembers: boolean; showSecrets: boolean; showLabels: boolean; showAdmin: boolean; pathname: string; onSignOut: () => void; onSwitchNamespace: (slug: string) => void; } /** The shared page column: the header, the tabs and the content all align to it, at the full width of every page. */ const column = "w-full px-4 sm:px-6"; function RailLink({ href, icon: Glyph, active, children }: { href: string; icon: Icon; active: boolean; children: ReactNode }) { return ( {children} ); } function NamespaceSwitcher({ current, label, namespaces, onSwitch }: { current: string | null; label: string; namespaces: readonly NamespaceRef[]; onSwitch: (slug: string) => void }) { const kind = namespaces.find((namespace) => namespace.slug === current)?.kind; const Glyph = kind === "org" ? BuildingsIcon : UserIcon; const face = ( {label} {kind === "org" ? "Organization" : "Personal"} ); if (namespaces.length < 2) return
{face}
; return ( {face} {namespaces.map((namespace) => ( : } onClick={() => onSwitch(namespace.slug)}> {namespace.name} {namespace.kind === "user" ? "Personal" : "Organization"} ))} }> New organization ); } function Rail({ state }: { state: ShellState }) { const { pathname, namespace } = state; const home = namespace ? `/${namespace}` : "/"; const inTasks = pathname === "/tasks" || pathname === "/tasks/new" || /^\/[^/]+\/[^/]+\/tasks(\/|$)/.test(pathname); const inOverview = pathname === "/" || pathname === home; return (
); } function MobileRail({ state }: { state: ShellState }) { const [open, setOpen] = useState(false); useEffect(() => setOpen(false), [state.pathname]); return ( }> }> ); } /** Lets a keyboard user jump past the rail and the header. It shows only when it has focus. */ function SkipLink() { return ( Skip to content ); } /** Hides or shows the rail on wide screens, like the sidebar button of a desktop app. Narrow screens use the drawer. */ function RailToggle() { const [hidden, toggle] = useRailHidden(); const label = hidden ? "Show sidebar" : "Hide sidebar"; return ( }> ); } function UserMenu({ user, showMembers, showAdmin, onSignOut }: { user: Person; showMembers: boolean; showAdmin: boolean; onSignOut: () => void }) { return (
{user.name} {user.email}
}> Access tokens {showMembers && ( }> Members )} {showAdmin && ( }> Admin )} } onClick={onSignOut}> Sign out
); } function CreateMenu() { return ( } aria-label="Create new" />}>New }> New repository }> New task }> New organization ); } function Crumbs({ trail }: { trail: Crumb[] }) { return ( ); } /** * The header floats over the page as a translucent material. Its hairline is a scroll edge when the header * stands alone, and a fixed divider when it carries tabs. */ function Header({ subnav, children }: { subnav?: ReactNode; children: ReactNode }) { return (
{children}
{subnav &&
{subnav}
}
); } /** * The signed-in frame: a quiet rail on the left, the floating header with location and actions, then the page. * `full` removes the bottom space, for a canvas such as the code map. */ export function AppShell({ state, crumbs = [], subnav, full = false, children }: { state: ShellState; crumbs?: Crumb[]; subnav?: ReactNode; full?: boolean; children: ReactNode }) { const { user } = state; const trail: Crumb[] = [...(state.org ? [{ label: state.org, href: state.namespace ? `/${state.namespace}` : "/" }] : []), ...crumbs]; if (!user) { return ( <>
{trail.length > 0 && }
Docs Sign in
{children}
); } return (
Docs
{children}
); } export function PageHeader({ title, description, actions }: { title: ReactNode; description?: ReactNode; actions?: ReactNode }) { return (

{title}

{description &&

{description}

}
{actions &&
{actions}
}
); } /** A sign-in or sign-up page: the form on one side, the product at work on the other. */ export function AuthPage({ subtitle, error, children }: { subtitle: string; error?: string; children: ReactNode }) { return (

{subtitle}

{error && } {children}
); }