Skip to content
refs
History
98 lines · 4.3 KBRaw
1import { ArrowLeftIcon, ArrowRightIcon } from "@refs/design-system/icons";
2import { data, Link } from "react-router";
3import type { Route } from "./+types/docs";
4import { SiteHeader } from "../components/landing";
5import { refs } from "../lib/session";
6import { DOC_SECTIONS, docPage, type DocLink, type DocSection } from "../lib/docs.server";
7
8export const meta: Route.MetaFunction = ({ loaderData }) =>
9 loaderData ? [{ title: `${loaderData.page.title} · refs docs` }, { name: "description", content: loaderData.page.summary }] : [{ title: "Docs · refs" }];
10
11export function loader({ params, context }: Route.LoaderArgs) {
12 const found = docPage(params.page ?? "overview");
13 if (!found) throw data(null, { status: 404 });
14 return { ...found, sections: DOC_SECTIONS, signedIn: Boolean(refs(context).viewer.person) };
15}
16
17function PageList({ sections, current }: { sections: readonly DocSection[]; current: string }) {
18 return (
19 <div className="flex flex-col gap-6">
20 {sections.map((section) => (
21 <div key={section.title} className="flex flex-col gap-1">
22 <span className="caption px-3 pb-1 text-faint">{section.title}</span>
23 {section.pages.map((page) => (
24 <Link
25 key={page.slug}
26 to={page.slug === "overview" ? "/docs" : `/docs/${page.slug}`}
27 aria-current={page.slug === current ? "page" : undefined}
28 className={`rounded-control px-3 py-1.5 text-compact ${page.slug === current ? "bg-hover font-medium text-ink" : "text-muted hover:bg-hover hover:text-ink"}`}
29 >
30 {page.title}
31 </Link>
32 ))}
33 </div>
34 ))}
35 </div>
36 );
37}
38
39function Neighbour({ link, direction }: { link: DocLink; direction: "previous" | "next" }) {
40 const next = direction === "next";
41 return (
42 <Link
43 to={link.slug === "overview" ? "/docs" : `/docs/${link.slug}`}
44 className={`flex min-w-0 flex-1 flex-col gap-1 rounded-panel bg-raised px-4 py-3 shadow-card hover:bg-hover ${next ? "items-end text-right" : ""}`}
45 >
46 <span className="flex items-center gap-1.5 text-xs text-muted">
47 {!next && <ArrowLeftIcon size={12} />}
48 {next ? "Next" : "Previous"}
49 {next && <ArrowRightIcon size={12} />}
50 </span>
51 <span className="text-compact font-medium">{link.title}</span>
52 </Link>
53 );
54}
55
56export default function Docs({ loaderData }: Route.ComponentProps) {
57 const { page, previous, next, sections, signedIn } = loaderData;
58 return (
59 <div className="min-h-svh bg-ground">
60 <SiteHeader wide signedIn={signedIn} />
61 <div className="mx-auto grid max-w-[1280px] gap-8 px-4 py-8 md:px-8 lg:grid-cols-[200px_minmax(0,1fr)] lg:gap-12 xl:grid-cols-[200px_minmax(0,1fr)_180px]">
62 <nav aria-label="Docs" className="max-lg:hidden">
63 <div className="sticky top-[76px]">
64 <PageList sections={sections} current={page.slug} />
65 </div>
66 </nav>
67 <details className="rounded-panel bg-raised shadow-card lg:hidden">
68 <summary className="cursor-pointer px-4 py-3 text-compact font-medium">Docs pages</summary>
69 <div className="px-1 pb-3">
70 <PageList sections={sections} current={page.slug} />
71 </div>
72 </details>
73 <main className="min-w-0">
74 <h1 className="m-0 text-title font-semibold tracking-[-0.02em]">{page.title}</h1>
75 <article className="markdown docs-article mt-6" dangerouslySetInnerHTML={{ __html: page.html }} />
76 {(previous || next) && (
77 <nav aria-label="Previous and next page" className="mt-12 flex max-w-[74ch] flex-wrap gap-3">
78 {previous && <Neighbour link={previous} direction="previous" />}
79 {next && <Neighbour link={next} direction="next" />}
80 </nav>
81 )}
82 </main>
83 {page.headings.length > 1 && (
84 <nav aria-label="On this page" className="max-xl:hidden">
85 <div className="sticky top-[76px] flex flex-col gap-1">
86 <span className="caption pb-1 text-faint">On this page</span>
87 {page.headings.map((heading) => (
88 <a key={heading.id} href={`#${heading.id}`} className="py-1 text-xs text-muted hover:text-ink">
89 {heading.text}
90 </a>
91 ))}
92 </div>
93 </nav>
94 )}
95 </div>
96 </div>
97 );
98}