docs-view.tsx
This file
Path
apps/web/src/features/docs/docs-view.tsx
184 lines · 5.9 KiB · TypeScript
Last changed by
Merge redesign into mainoscabrielbefore adoptioncaedd21
History of this fileTake it
Merge build/1313-docs into mainoscabrielbefore adoption9000f4e
line 1why, one step back1import type { DocPage, DocPart } from "@repo/agent-kit/docs/index";Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 2–3why, one step back2import { cn } from "cn";3import { Check, Copy, FileText } from "lucide-react";Merge build/1313-docs into mainoscabrielbefore adoption9000f4e
line 4why, one step back4Merge redesign into mainoscabrielbefore adoptioncaedd21
line 5why, one step back5import { Button, buttonVariants } from "../../components/ui/button.tsx";Merge build/1313-docs into mainoscabrielbefore adoption9000f4e
line 6why, one step back6import { SiteMarkdown } from "../markdown/markdown.tsx";Merge redesign into mainoscabrielbefore adoptioncaedd21
line 7why, one step back7import { useCopy } from "../shared/copy-action.tsx";Merge build/1313-docs into mainoscabrielbefore adoption9000f4e
lines 8–9why, one step back8import { AppLink } from "../shared/link.tsx";9import { docsPath } from "../shared/paths.ts";Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 10–11why, one step back10import { ContextBar } from "../shared/shell/context-bar.tsx";11import { GUTTER } from "../shared/shell/gutter.ts";Merge build/1313-docs into mainoscabrielbefore adoption9000f4e
line 12why, one step back12import { Workspace } from "../shared/shell/workspace.tsx";Merge redesign into mainoscabrielbefore adoptioncaedd21
line 13why, one step back13import { docBody, docHeadings } from "./article.ts";Merge build/1313-docs into mainoscabrielbefore adoption9000f4e
lines 14–54why, one step back14import { docsMarkdownPath } from "./head.ts";1516const PARTS = [17 { part: "guide", title: "Guides" },18 { part: "reference", title: "Reference" },19] as const satisfies readonly { part: DocPart; title: string }[];2021const LINK =22 "decoration-rule hover:decoration-foreground underline underline-offset-4";2324export const DocsIndexView = ({25 pages,26}: {27 readonly pages: readonly DocPage[];28}) => (29 <Workspace title="Docs">30 {PARTS.map(({ part, title }) => (31 <section aria-labelledby={`docs-${part}`} className="mb-8" key={part}>32 <h2 className="text-title mb-3 font-semibold" id={`docs-${part}`}>33 {title}34 </h2>35 <ul className="border-rule divide-rule divide-y border-y">36 {pages37 .filter((page) => page.part === part)38 .map(({ slug, summary, title: pageTitle }) => (39 <li className="flex flex-col gap-0.5 py-3" key={slug}>40 <AppLink41 className={`text-want font-medium ${LINK}`}42 to={docsPath(slug)}43 >44 {pageTitle}45 </AppLink>46 <p className="text-ui text-muted-foreground">{summary}</p>47 </li>48 ))}49 </ul>50 </section>51 ))}52 </Workspace>53);54Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 55–99why, one step back55const PART_TITLE = {56 guide: "Guides",57 reference: "Reference",58} as const satisfies Record<DocPart, string>;5960const CONTENTS_LINK =61 "text-ui text-muted-foreground hover:text-foreground flex min-h-8 items-center py-1 no-underline transition-colors duration-[120ms]";6263/** Merged, so the outline's control border wins over the base's transparent one. */64const MARKDOWN_LINK = cn(65 buttonVariants({ variant: "outline" }),66 "justify-start no-underline"67);6869const CopyMarkdown = ({ markdown }: { readonly markdown: string }) => {70 const { copied, copy } = useCopy(markdown);7172 return (73 <Button74 className="justify-start"75 onClick={copy}76 type="button"77 variant="outline"78 >79 {copied ? (80 <Check aria-hidden="true" strokeWidth={1.75} />81 ) : (82 <Copy aria-hidden="true" strokeWidth={1.75} />83 )}84 <span aria-live="polite">{copied ? "Copied" : "Copy as Markdown"}</span>85 </Button>86 );87};8889type Headings = ReturnType<typeof docHeadings>;9091const Contents = ({ headings }: { readonly headings: Headings }) => (92 <ul className="flex flex-col">93 {headings.map(({ id, text }) => (94 <li key={id}>95 {/* An anchor in this page, not a page of its own. */}96 <a className={CONTENTS_LINK} href={`#${id}`}>97 {text}98 </a>99 </li>Merge build/1313-docs into mainoscabrielbefore adoption9000f4e
line 100why, one step back100 ))}Merge redesign into mainoscabrielbefore adoptioncaedd21
line 101why, one step back101 </ul>Merge build/1313-docs into mainoscabrielbefore adoption9000f4e
lines 102–103why, one step back102);103Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 104–116why, one step back104/**105 * Below `columns` the headings fold into a disclosure above the article, so a106 * reader meets them before what they link to, not after.107 */108const ContentsAhead = ({ headings }: { readonly headings: Headings }) =>109 headings.length === 0 ? null : (110 <details className="border-rule columns:hidden mb-6 border-y py-2">111 <summary className="text-ui flex min-h-8 cursor-pointer items-center font-semibold">112 On this page113 </summary>114 <Contents headings={headings} />115 </details>116 );Merge build/1313-docs into mainoscabrielbefore adoption9000f4e
line 117why, one step back117Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 118–120why, one step back118/** The page's headings and its Markdown, beside the article from `columns`; below, its Markdown under it. */119const OnThisPage = ({120 headings,Merge build/1313-docs into mainoscabrielbefore adoption9000f4e
lines 121–122why, one step back121 page,122}: {Merge redesign into mainoscabrielbefore adoptioncaedd21
line 123why, one step back123 readonly headings: Headings;Merge build/1313-docs into mainoscabrielbefore adoption9000f4e
lines 124–125why, one step back124 readonly page: DocPage;125}) => (Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 126–129why, one step back126 <aside127 aria-label="On this page"128 className="border-rule columns:sticky columns:top-[calc(var(--top-bar)+1.5rem)] columns:self-start columns:border-t-0 columns:pt-0 columns:mt-0 mt-8 flex min-w-0 flex-col gap-6 border-t pt-6"129 data-column="toc"Merge build/1313-docs into mainoscabrielbefore adoption9000f4e
line 130why, one step back130 >Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 131–145why, one step back131 {headings.length === 0 ? null : (132 <div className="max-columns:hidden flex flex-col gap-1">133 <h2 className="text-ui font-semibold">On this page</h2>134 <Contents headings={headings} />135 </div>136 )}137 <div className="flex flex-col gap-2">138 <CopyMarkdown markdown={page.markdown} />139 {/* A server route, not a page of the app. */}140 <a className={MARKDOWN_LINK} href={docsMarkdownPath(page.slug)}>141 <FileText aria-hidden="true" strokeWidth={1.75} />142 View as .md143 </a>144 </div>145 </aside>Merge build/1313-docs into mainoscabrielbefore adoption9000f4e
line 146why, one step back146);Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 147–184why, one step back147148/**149 * The docs shell's main column: the article at the measure, then "On this150 * page", which stands to its right from `columns`.151 */152export const DocsPageView = ({ page }: { readonly page: DocPage }) => {153 const headings = docHeadings(page);154155 return (156 <main157 className="flex min-w-0 flex-1 flex-col outline-none"158 data-scroll-restoration-id="main"159 id="main"160 tabIndex={-1}161 >162 <ContextBar163 crumbs={[164 { label: "Docs", to: docsPath() },165 { label: PART_TITLE[page.part] },166 { label: page.title },167 ]}168 />169 <div170 className={`columns:grid columns:grid-cols-[minmax(0,1fr)_var(--column-docs-toc)] columns:gap-x-14 flex flex-col pt-6 pb-16 ${GUTTER}`}171 >172 <article className="max-w-(--measure) min-w-0" data-doc={page.slug}>173 <h1 className="text-headline text-balance break-words">174 {page.title}175 </h1>176 <p className="text-want mt-3 mb-6 font-normal">{page.summary}</p>177 <ContentsAhead headings={headings} />178 <SiteMarkdown source={docBody(page)} />179 </article>180 <OnThisPage headings={headings} page={page} />181 </div>182 </main>183 );184};