Review fixes for 1203
Before adoption: this commit came in with the history the project adopted, so no landing records it.
- AppLink escapes a path's $ and braces (literalPath) before the router sees them: a path built whole is a name, and the router was filling routes/$project/$.tsx from the page's own params (it became routes/datekit/...) and dropping {-$x}. The router decodes them back when it reads a page's params. Test: shell.test.tsx, inside the router and with none around it. - The rail's Keys and Menu buttons take their muted colour from a wrapper (Quiet): the kit's class merger reads an unknown text-* as a colour, so a colour in a Button's className dropped text-ui and the buttons drew at 16 px. The keys dialog's caps drop their colour class for the same reason (they drew at 14 px, not the 13 px label). Tests: every rail button carries text-ui; every key cap carries text-label. - The project switcher keeps a row's open count beside its posture at the row's end (two ml-auto split the row). The sheet loses its soft shadow: flat paper and a hairline, one elevation. - One doc comment on ProjectRow (two were stacked); root.test.tsx asserts the router's pending, error and not-found components are the shell's own, not merely defined. - ASSUMPTION: the same merger collision inside the kit's own base classes (muted colour dropped beside text-ui in DialogDescription, Kbd and others) is the kit's to fix, not the shell's; recorded for 1204.
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+144 added−38 removed
- tests:+83 added−3 removed
- other:+61 added−35 removed
Provenance
- Commit
950d5e0- Tree
1b9c279- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent
ddbd51e
8 files changed+144 added−38 removed
modified:apps/web/src/components/ui/sheet.tsx+3 added-2 removed
2 unmodified lines3456778910111214 unmodified lines2728293030313233343551 unmodified lines2 unmodified lines/** * A sheet: Base UI's dialog drawn against an edge of the screen. It slides * in over 200 ms (none under reduced motion, which the stylesheet's switch * turns off), traps focus while open, and closes on Escape, a press outside * or its Close button. The page behind dims in ink, without blur. * or its Close button. The page behind dims in ink, without blur; the * sheet itself is flat paper parted from it by a hairline, with no shadow. */import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";import { cva } from "class-variance-authority";import { cn } from "cn";14 unmodified lines return <DialogPrimitive.Close data-slot="sheet-close" {...props} />;}
const sheetVariants = cva( "bg-background text-foreground border-rule fixed z-50 flex flex-col overflow-hidden shadow-[0_8px_32px_-8px_color-mix(in_oklch,var(--foreground)_28%,transparent)] transition-transform duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] outline-none", "bg-background text-foreground border-rule fixed z-50 flex flex-col overflow-hidden transition-transform duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] outline-none", { variants: { side: { bottom:51 unmodified linesmodified:apps/web/src/features/shared/shell/overlays.tsx+5 added-3 removed
115 unmodified lines116 return (117 <ComboboxItem className="h-10 gap-3" key={name} value={name}>118 <span className="min-w-0 truncate font-medium">{name}</span>119 {listing === undefined ? null : (120- <>121- <span className="text-muted-foreground text-label ml-auto tabular-nums">120+ // One group at the row's end, so the count sits beside121+ // the posture rather than midway along the row.122+ <span className="ml-auto flex shrink-0 items-center gap-3">123+ <span className="text-muted-foreground text-label tabular-nums">124 {listing.openAsks} open125 </span>126 <PostureMark posture={listing.posture} />125- </>127+ </span>128 )}129 </ComboboxItem>130 );131 }}130 unmodified linesmodified:apps/web/src/features/shared/shell/rail.tsx+40 added-27 removed
150 unmodified lines151 </span>152 );153 };154 155-/** A project's row: its name, and its posture once the list has it. */156-/** The current project's row: in ink at 600, unfilled, so the page being read (a section under it) is the one filled row. */157-const PROJECT_ROW = RAIL_BASE;158-155+/**156+ * A project's row: its name, and its posture once the list has it. The157+ * current project's is in ink at 600 but unfilled, so the page being read158+ * (a section under it) is the one filled row.159+ */160 const ProjectRow = ({161 current,162 listing,163 project,4 unmodified lines168 }) => (169 <AppLink170 activeOptions={EXACT}171 aria-current={current ? "true" : undefined}171- className={PROJECT_ROW}172+ className={RAIL_BASE}173 data-project={project}174 to={`/${project}`}175 >176 <span className="min-w-0 truncate">{project}</span>117 unmodified lines294 </div>295 );296 };297 298+/**299+ * A ghost button set in muted text, ink on hover. The colour comes from300+ * around the button, not through its `className`: the kit merges classes,301+ * reads an unknown `text-*` as a colour, and would drop the button's302+ * `text-ui` size for a colour given there.303+ */304+const Quiet = ({ children }: { readonly children: ReactNode }) => (305+ <span className="text-muted-foreground flex shrink-0">{children}</span>306+);307+308 /** The rail's foot: the session, and the Keys button that opens the `?` dialog. */309 export const RailFoot = () => {310 const { open } = useShell();311 312 return (313 <div className="border-rule flex min-h-12 shrink-0 items-center justify-between gap-2 border-t py-1.5 pr-1.5 pl-3">314 <SessionSlot layout="rail" />304- <Button305- className="text-muted-foreground shrink-0"306- onClick={() => {307- open("keys");308- }}309- size="sm"310- variant="ghost"311- >312- <Keyboard aria-hidden="true" strokeWidth={1.75} />313- Keys314- </Button>315+ <Quiet>316+ <Button317+ onClick={() => {318+ open("keys");319+ }}320+ size="sm"321+ variant="ghost"322+ >323+ <Keyboard aria-hidden="true" strokeWidth={1.75} />324+ Keys325+ </Button>326+ </Quiet>327 </div>328 );329 };330 64 unmodified lines395 >396 <div className="border-rule flex h-11 shrink-0 items-center justify-between gap-2 border-b pr-1.5 pl-4">397 <Wordmark />398 {slotted ? (387- <Button388- className="text-muted-foreground"389- onClick={() => {390- open("menu");391- }}392- size="sm"393- variant="ghost"394- >395- <Menu aria-hidden="true" strokeWidth={1.75} />396- Menu397- </Button>399+ <Quiet>400+ <Button401+ onClick={() => {402+ open("menu");403+ }}404+ size="sm"405+ variant="ghost"406+ >407+ <Menu aria-hidden="true" strokeWidth={1.75} />408+ Menu409+ </Button>410+ </Quiet>411 ) : null}412 </div>413 {slotted ? (414 <>12 unmodified linesmodified:apps/web/src/features/shared/keys.tsx+1 added-1 removed
156 unmodified lines157 <span className="text-muted-foreground" key={key}>158 to159 </span>160 ) : (161- <Kbd className="text-foreground font-mono" key={key}>161+ <Kbd className="font-mono" key={key}>162 {key}163 </Kbd>164 )165 )}451 unmodified linesmodified:apps/web/src/features/shared/link.tsx+12 added-2 removed
47 unmodified lines48495051525354555657585960616263646566675868697071727 unmodified lines8081828374848586878812 unmodified lines47 unmodified lines /** Keep each pane's scroll where it is (a selection in a list). */ readonly resetScroll?: boolean;}
/** * `path` with the router's own marks escaped: a `$` (a param, or the splat) * and the braces of an optional segment are, in a path built whole, part of * a name (a file at `routes/$project/$.tsx`), never a param for the router * to fill from the page being read. Escaped, they reach the address as * written, and the router decodes them back when it reads the page's params. */export const literalPath = (path: string): string => path.replaceAll("$", "%24").replaceAll("{", "%7B").replaceAll("}", "%7D");
/** The address an `AppLink` names, as the router would write it. */export const hrefOf = ({ hash, search, to,}: Pick<AppLinkProps, "hash" | "search" | "to">): string => `${to}${ `${literalPath(to)}${ search === undefined || Object.keys(search).length === 0 ? "" : defaultStringifySearch(search) }${hash === undefined ? "" : `#${hash}`}`;7 unmodified linesexport const AppLink = (props: AppLinkProps): ReactNode => { const router = useRouter({ warn: false });
if (Predicate.isNotNullish(router)) { return <PathLink {...props} />; return <PathLink {...props} to={literalPath(props.to)} />; }
// A router is always there in the app; only a view rendered alone has none. const {12 unmodified linesmodified:apps/web/test/keys.test.tsx+8 added
159 unmodified lines160 expect(markup).toMatch(161 /<button\b[^>]*aria-pressed="false"[^>]*>On<\/button>/u162 );163 164+ // Each key cap at the label size, whatever face it is set in.165+ expect(166+ [...markup.matchAll(/<kbd\b[^>]*class="(?<classes>[^"]*)"/gu)].filter(167+ ({ groups }) =>168+ groups?.classes?.split(" ").includes("text-label") !== true169+ )170+ ).toStrictEqual([]);171+172 for (const key of ["?", "j", "k", "J", "K", "1", "9", "Esc"]) {173 expect(markup).toContain(`<kbd`);174 expect(text).toContain(key);175 }2 unmodified linesmodified:apps/web/test/root.test.tsx+8 added-3 removed
5 unmodified lines6 */7 import { describe, expect, it } from "@effect/vitest";8 import { renderToStaticMarkup } from "react-dom/server";9 10+import {11+ NotFoundPage,12+ PendingPage,13+ RouteError,14+} from "../src/features/shared/pending.tsx";15 import { themeColors } from "../src/features/shared/theme.ts";16 import { getRouter } from "../src/router.tsx";17 import { rootHead, ThemeColors } from "../src/routes/__root.tsx";18 77 unmodified lines96 });97 98 it("waits 300 ms before drawing a page as pending, so a quick move never flashes", () => {99 expect(options.defaultPendingMs).toBe(300);95- expect(options.defaultPendingComponent).toBeDefined();100+ expect(options.defaultPendingComponent).toBe(PendingPage);101 });102 103 it("draws a failure and a missing page in the shell, never the router's own", () => {99- expect(options.defaultErrorComponent).toBeDefined();100- expect(options.defaultNotFoundComponent).toBeDefined();104+ expect(options.defaultErrorComponent).toBe(RouteError);105+ expect(options.defaultNotFoundComponent).toBe(NotFoundPage);106 });107 108 it("scrolls each new page's main pane back to its top", () => {109 expect(options.scrollRestoration).toBeTruthy();3 unmodified linesmodified:apps/web/test/shell.test.tsx+67 added
17 unmodified lines18 import { Effect } from "effect";19 import { renderToStaticMarkup } from "react-dom/server";20 21 import { PageShell } from "../src/features/shared/layout.tsx";22+import { AppLink } from "../src/features/shared/link.tsx";23 import { RouteError } from "../src/features/shared/pending.tsx";24 import { AppShell } from "../src/features/shared/shell/app-shell.tsx";25 import { RailSlot } from "../src/features/shared/shell/rail-slot.tsx";26 import { Workspace } from "../src/features/shared/shell/workspace.tsx";259 unmodified lines286 })287 );288 });289 290+describe("the shell's controls", () => {291+ // A colour given to a kit button must not cost it the UI size: the292+ // class merger reads an unknown `text-*` as a colour, so a colour class293+ // drops `text-ui` and the button falls back to the body's 16 px.294+ it.effect("set every button in the rail at the UI size", () =>295+ Effect.gen(function* () {296+ const rail = elementOf(297+ yield* renderAt("/datekit/tree/main", ledgerPage(false), {298+ rail: Tree,299+ }),300+ "nav",301+ 'aria-label="Site"'302+ );303+304+ const buttons = [305+ ...rail.matchAll(/<button\b[^>]*class="(?<classes>[^"]*)"/gu),306+ ].map(({ groups }) => groups?.classes?.split(" ") ?? []);307+308+ expect(buttons.length).toBeGreaterThanOrEqual(2);309+ expect(310+ buttons.filter((classes) => !classes.includes("text-ui"))311+ ).toStrictEqual([]);312+ })313+ );314+});315+316+describe(AppLink, () => {317+ // A path is built whole, and a file's path may hold the router's own318+ // marks (`routes/$project/route.tsx`, `{-$x}`): they are the file's319+ // name, never a param to fill from the page being read.320+ it.effect("leads to a path holding $ or braces as written", () =>321+ Effect.gen(function* () {322+ const markup = yield* renderAt(323+ "/datekit/ledger",324+ <p>325+ <AppLink to="/datekit/blob/main/src/routes/$project/$.tsx">326+ route327+ </AppLink>328+ <AppLink to="/datekit/blob/main/src/{-$x}.ts">optional</AppLink>329+ </p>330+ );331+332+ const hrefs = linksOf(markup).map(({ href }) => href);333+334+ expect(hrefs.map((href) => decodeURIComponent(href ?? ""))).toStrictEqual(335+ [336+ "/datekit/blob/main/src/routes/$project/$.tsx",337+ "/datekit/blob/main/src/{-$x}.ts",338+ ]339+ );340+ })341+ );342+343+ it("draws the same address with no router around it", () => {344+ expect(345+ renderToStaticMarkup(346+ <AppLink to="/datekit/blob/main/src/routes/$project/$.tsx">347+ route348+ </AppLink>349+ )350+ ).toMatch(351+ /href="\/datekit\/blob\/main\/src\/routes\/(?:\$|%24)project\/(?:\$|%24)\.tsx"/u352+ );353+ });354+});355+356 describe("the shell's sources", () => {357 // Keys only: the sources as text.358 const sources: Readonly<Record<string, string>> = import.meta.glob(359 "../src/features/shared/shell/*.tsx",70 unmodified lines