|
| 1 | +import { sanityFetch } from '@/lib/sanity'; |
| 2 | +import { VisualEditing } from '@/lib/visual-editing'; |
| 3 | +import appCss from '@/styles/app.css?url'; |
| 4 | +import { Footer } from '@/ui/footer'; |
| 5 | +import { MainNav } from '@/ui/main-nav'; |
| 6 | +import { GrunnmurenProvider } from '@obosbbl/grunnmuren-react'; |
| 7 | +import { |
| 8 | + type NavigateOptions, |
| 9 | + Outlet, |
| 10 | + ScrollRestoration, |
| 11 | + type ToOptions, |
| 12 | + createFileRoute, |
| 13 | + useRouter, |
| 14 | +} from '@tanstack/react-router'; |
| 15 | +import { defineQuery } from 'groq'; |
| 16 | + |
| 17 | +const COMPONENTS_NAVIGATION_QUERY = defineQuery( |
| 18 | + // make sure the slug is always a string so we don't have add fallback value in code just to make TypeScript happy |
| 19 | + `*[_type == "component"]{ _id, name, 'slug': coalesce(slug.current, '')} | order(name asc)`, |
| 20 | +); |
| 21 | + |
| 22 | +// This is the shared layout for all the Grunnmuren docs pages that are "public", ie not the Sanity studio |
| 23 | +export const Route = createFileRoute('/_docs')({ |
| 24 | + component: RootLayout, |
| 25 | + head: () => ({ |
| 26 | + links: [{ rel: 'stylesheet', href: appCss }], |
| 27 | + meta: [ |
| 28 | + { |
| 29 | + title: "Grunnmuren - OBOS' Design System", |
| 30 | + }, |
| 31 | + ], |
| 32 | + }), |
| 33 | + loader: () => sanityFetch({ query: COMPONENTS_NAVIGATION_QUERY }), |
| 34 | +}); |
| 35 | + |
| 36 | +function RootLayout() { |
| 37 | + const router = useRouter(); |
| 38 | + |
| 39 | + return ( |
| 40 | + <> |
| 41 | + <GrunnmurenProvider |
| 42 | + locale="nb" |
| 43 | + // This integrates RAC/Grunnmuren with TanStack router |
| 44 | + // Giving us typesafe routes |
| 45 | + // See https://react-spectrum.adobe.com/react-aria/routing.html#tanstack-router |
| 46 | + navigate={(to, options) => router.navigate({ to, ...options })} |
| 47 | + useHref={(to) => router.buildLocation({ to }).href} |
| 48 | + > |
| 49 | + <div className="grid min-h-screen lg:flex"> |
| 50 | + <div className="flex grow flex-col px-6"> |
| 51 | + <main className="grow"> |
| 52 | + <Outlet /> |
| 53 | + </main> |
| 54 | + <Footer /> |
| 55 | + </div> |
| 56 | + <MainNav /> |
| 57 | + </div> |
| 58 | + </GrunnmurenProvider> |
| 59 | + <ScrollRestoration /> |
| 60 | + <VisualEditing /> |
| 61 | + </> |
| 62 | + ); |
| 63 | +} |
| 64 | + |
| 65 | +// See comments on GrunnmurenProvider in <RootLayout /> |
| 66 | +declare module 'react-aria-components' { |
| 67 | + interface RouterConfig { |
| 68 | + href: ToOptions['to']; |
| 69 | + routerOptions: Omit<NavigateOptions, keyof ToOptions>; |
| 70 | + } |
| 71 | +} |
0 commit comments