Skip to content
Myr

app-shell.tsx

This file

Path

apps/web/src/features/shared/shell/app-shell.tsx

175 lines · 5.7 KiB · TypeScript

Last changed by

Merge web/ruled-frame into mainoscabrielbefore adoption07f14ad

History of this file

Take it

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 1–2why, one step back
1import { useHydrated, useLocation } from "@tanstack/react-router";
2import { cn } from "cn";

Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e

lines 3–7why, one step back
3import { Suspense, useCallback, useMemo, useState } from "react";
4import type { ReactNode } from "react";56import { KeysProvider } from "../keys.tsx";7import { SkipLink } from "../layout.tsx";

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 8why, one step back
8import { docsPath } from "../paths.ts";

Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e

lines 9–10why, one step back
9import { ShellContext, ShellReadsContext } from "./context.ts";
10import type { Overlay, ShellReads } from "./context.ts";

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 11–13why, one step back
11import { DocsNav } from "./docs-nav.tsx";
12import { Footer } from "./footer.tsx";13import { GUTTER } from "./gutter.ts";

Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e

line 14why, one step back
14import { LazyOverlays } from "./lazy-overlays.ts";

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 15–16why, one step back
15import { ShellNameContext, useShellName } from "./shells.ts";
16import type { ShellName } from "./shells.ts";

Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e

lines 17–18why, one step back
17import { TopBar } from "./top-bar.tsx";
18

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 19–27why, one step back
19/**
20 * The project's container. A project's own pages draw their header and21 * side column inside it, from the project's route (`ProjectFrame`).22 */23const ProjectContainer = ({ children }: { readonly children: ReactNode }) => (24 <div className="max-w-project mx-auto flex w-full flex-1 flex-col">25 {children}26 </div>27);

Merge build/1300-w13-foundation into mainoscabrielbefore adoption0e29c37

line 28why, one step back
28

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 29why, one step back
29/**

Merge web/ruled-frame into mainoscabrielbefore adoption07f14ad

lines 30–32why, one step back
30 * The article first, so it is read first; from `columns` the tree stands to
31 * its left, parted by a rule the article's full height. Below `columns` the32 * index shows no tree under itself: the index already lists every page.

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 33–36why, one step back
33 */
34const DocsFrame = ({ children }: { readonly children: ReactNode }) => {35 const index = useLocation({36 select: ({ pathname }) => pathname.replace(/\/$/u, "") === docsPath(),

Merge build/1300-w13-foundation into mainoscabrielbefore adoption0e29c37

lines 37–38why, one step back
37 });
38

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 39why, one step back
39 return (

Merge web/ruled-frame into mainoscabrielbefore adoption07f14ad

lines 40–46why, one step back
40 <div className="columns:grid columns:grid-cols-[var(--column-docs-nav)_minmax(0,1fr)] flex w-full flex-1 flex-col">
41 <div42 className={cn(43 "columns:col-start-2 columns:row-start-1 border-rule flex min-w-0 flex-col",44 index ? undefined : "columns:border-l"45 )}46 >

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 47–65why, one step back
47 {children}
48 </div>49 <div50 className={cn(51 "border-rule columns:col-start-1 columns:row-start-1 columns:sticky columns:top-(--top-bar) columns:self-start columns:max-h-[calc(100dvh-var(--top-bar))] columns:overflow-y-auto columns:block columns:border-t-0 border-t py-6",52 index && "hidden",53 GUTTER54 )}55 data-docs-tree={index ? "index" : "page"}56 >57 <DocsNav />58 </div>59 </div>60 );61};6263const FRAMES = {64 docs: DocsFrame,65 focus: ({ children }: { readonly children: ReactNode }) => (

Merge web/ruled-frame into mainoscabrielbefore adoption07f14ad

line 66why, one step back
66 <div className="flex w-full flex-1 flex-col pb-16">{children}</div>

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 67–69why, one step back
67 ),
68 project: ProjectContainer,69 site: ({ children }: { readonly children: ReactNode }) => (

Merge web/ruled-frame into mainoscabrielbefore adoption07f14ad

line 70why, one step back
70 <div className="flex w-full flex-1 flex-col">{children}</div>

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 71–90why, one step back
71 ),
72} as const satisfies Record<73 ShellName,74 (props: { readonly children: ReactNode }) => ReactNode75>;7677/**78 * Each shell's gutter, from DESIGN.md's shell table, as the variable every79 * `GUTTER` inside it reads: the site's for the site, the docs and a focused80 * page, the project's for a project.81 */82export const SHELL_GUTTERS = {83 docs: "[--shell-gutter:var(--gutter-site)]",84 focus: "[--shell-gutter:var(--gutter-site)]",85 project: "[--shell-gutter:var(--gutter-project)]",86 site: "[--shell-gutter:var(--gutter-site)]",87} as const satisfies Record<ShellName, string>;8889const FOOTED: ReadonlySet<ShellName> = new Set(["docs", "site"]);90

Merge web/ruled-frame into mainoscabrielbefore adoption07f14ad

lines 91–103why, one step back
91/**
92 * The rails: from `tablet`, a hairline down each edge of the container, the93 * page's full height, with the top bar's box, the frame and the footer94 * between them (DESIGN.md "Rails"). The site and the docs are ruled at the95 * site's container, a focused page at its card's; a project is full-bleed.96 */97const RAILS = {98 docs: "max-w-site border-rule tablet:border-x mx-auto w-full",99 focus: "max-w-focus border-rule tablet:border-x mx-auto w-full",100 project: "",101 site: "max-w-site border-rule tablet:border-x mx-auto w-full",102} as const satisfies Record<ShellName, string>;103

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 104–105why, one step back
104const NO_READS: ShellReads = {};
105

Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e

lines 106–107why, one step back
106export const AppShell = ({
107 children,

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 108–112why, one step back
108 reads = NO_READS,
109}: {110 readonly children: ReactNode;111 readonly reads?: ShellReads;112}) => {

Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e

lines 113–114why, one step back
113 const pathname = useLocation({ select: (location) => location.pathname });
114 const hydrated = useHydrated();

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 115–116why, one step back
115 const shell = useShellName();
116 const Frame = FRAMES[shell];

Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e

line 117why, one step back
117

Merge build/comments-web-features into mainoscabrielbefore adoption74bfc72

lines 118–119why, one step back
118 // An overlay belongs to the address it opened on: it is gone from the next
119 // page.

Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e

lines 120–141why, one step back
120 const [opened, setOpened] = useState<{
121 readonly at: string;122 readonly overlay: Overlay;123 }>();124125 const overlay = opened?.at === pathname ? opened.overlay : undefined;126127 const open = useCallback(128 (next: Overlay) => {129 setOpened({ at: pathname, overlay: next });130 },131 [pathname]132 );133134 const close = useCallback(() => {135 setOpened(undefined);136 }, []);137138 const openDialog = useCallback(() => {139 open("keys");140 }, [open]);141

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 142why, one step back
142 const controls = useMemo(() => ({ open }), [open]);

Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e

lines 143–144why, one step back
143
144 return (

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 145why, one step back
145 <ShellContext value={controls}>

Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e

line 146why, one step back
146 <ShellReadsContext value={reads}>

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 147–150why, one step back
147 <ShellNameContext value={shell}>
148 <KeysProvider openDialog={openDialog}>149 <SkipLink />150 <div

Merge web/ruled-frame into mainoscabrielbefore adoption07f14ad

lines 151–154why, one step back
151 className={cn(
152 "flex min-h-dvh flex-col",153 shell === "project" ? "" : "tablet:px-(--frame-inset)"154 )}

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 155why, one step back
155 >

Merge web/ruled-frame into mainoscabrielbefore adoption07f14ad

lines 156–163why, one step back
156 <div
157 className={`flex flex-1 flex-col ${SHELL_GUTTERS[shell]} ${RAILS[shell]}`}158 data-shell={shell}159 >160 <TopBar shell={shell} />161 <Frame>{children}</Frame>162 {FOOTED.has(shell) ? <Footer /> : null}163 </div>

Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e

line 164why, one step back
164 </div>

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 165–171why, one step back
165 {hydrated && LazyOverlays !== undefined ? (
166 <Suspense fallback={null}>167 <LazyOverlays onClose={close} overlay={overlay} />168 </Suspense>169 ) : null}170 </KeysProvider>171 </ShellNameContext>

Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e

lines 172–175why, one step back
172 </ShellReadsContext>
173 </ShellContext>174 );175};