shells.ts
This file
Path
apps/web/src/features/shared/shell/shells.ts
28 lines · 988 bytes · TypeScript
Last changed by
Merge project/drop-proposals into mainoscabrielbefore adoptionb4ed08b
History of this fileTake it
Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 1–2why, one step back1/**2 * The four frames a page is drawn in (ADR 0041). A route names its own inMerge project/drop-proposals into mainoscabrielbefore adoptionb4ed08b
lines 3–4why, one step back3 * `staticData.shell`; the deepest route that names one wins, so a page can4 * be focused inside routes that name another frame.Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 5–28why, one step back5 */6import { useMatches } from "@tanstack/react-router";7import { createContext, useContext } from "react";89export type ShellName = "docs" | "focus" | "project" | "site";1011declare module "@tanstack/react-router" {12 interface StaticDataRouteOption {13 readonly shell?: ShellName;14 }15}1617/** A path no route matched is drawn in the site's frame. */18export const useShellName = (): ShellName =>19 useMatches({20 select: (matches) =>21 matches.findLast(({ staticData }) => staticData.shell !== undefined)22 ?.staticData.shell ?? "site",23 });2425/** Outside a shell (a view's own test) a page draws as it would in the site. */26export const ShellNameContext = createContext<ShellName>("site");2728export const useShellFrame = (): ShellName => useContext(ShellNameContext);