Skip to content

Production-ready animations, transitions, backgrounds, and scenes for Remotion

feat: added separated docs

dev_wandry947cc531a196
diff --git a/app/docs/layout.tsx b/app/docs/layout.tsx
index e914783a..5c4a3d40 100644
--- a/app/docs/layout.tsx
+++ b/app/docs/layout.tsx
@@ -1,61 +1,31 @@
-import { DocsLayout } from "fumadocs-ui/layouts/docs";
import type { ReactNode } from "react";
import { DocsHeader } from "@/components/docs/docs-header";
-import { baseOptions } from "@/lib/layout.shared";
+import { DocsShell } from "@/components/docs/docs-shell";
+import { DocsTabsBar } from "@/components/docs/docs-tabs-bar";
+import { splitDocsTree } from "@/lib/docs-tabs";
import { withNewBadges } from "@/lib/with-new-badges";
import { source } from "@/source";
export default async function Layout({ children }: { children: ReactNode }) {
+ // Decorate the shared page tree with the animated "NEW" sidebar badge (see
+ // `withNewBadges`), then split it into the Components / Primitives tab trees
+ // (see `splitDocsTree`). Both run on the server; `DocsShell` picks the tree
+ // matching the active tab by pathname so each tab owns its own sidebar.
+ const { components, primitives } = splitDocsTree(
+ withNewBadges(source.pageTree),
+ );
+
return (
<>
- {/* Custom remocn chrome owns the only top nav. Static (non-sticky) and
- content-aligned so the bar tracks the docs grid: logo over the
- sidebar, nav starting at the article column's left edge. */}
+ {/* Custom remocn chrome: the main header (logo + site nav + actions), then
+ a thin bar holding the Components/Primitives switcher. Both are static
+ (non-sticky) and content-aligned so they track the docs grid — logo
+ over the sidebar, tabs starting at the article column's left edge. */}
<DocsHeader />
- <DocsLayout
- // Decorate the shared page tree with the animated "NEW" sidebar badge
- // for pages listed in `NEW_BADGE_PATHS` (immutable copy — see
- // `withNewBadges`). Everything else passes through untouched.
- tree={withNewBadges(source.pageTree)}
- {...baseOptions()}
- // Suppress the Fumadocs default top nav so there is no double header —
- // `SiteHeader` above is the single top bar. Verified against
- // fumadocs-ui 16.7 `NavOptions.enabled` (layouts/shared) and the
- // `navEnabled && jsx(slots.header)` guard in layouts/docs/client.
- nav={{ enabled: false }}
- // Render the search field in the sidebar header. fumadocs-ui 16.7
- // builds `slots.searchTrigger` only when `searchToggle.enabled` is
- // truthy (layouts/shared/client.js), and the sidebar slot renders
- // `slots.searchTrigger.full` — the large search bar — at the top of
- // the rail (layouts/docs/slots/sidebar.js). Search itself is already
- // wired: `RootProvider` enables it by default and `app/api/search`
- // serves the index.
- searchToggle={{ enabled: true }}
- // Remove the sidebar footer. fumadocs-ui 16.7 renders the footer block
- // only when `languageSelect || iconLinks.length || themeSwitch || footer`
- // is truthy (layouts/docs/slots/sidebar.js). This app has no i18n
- // (single locale → no languageSelect), no nav `links`/`githubUrl` (→ no
- // iconLinks), and passes no `footer`, so the theme switch is the only
- // thing populating it — disabling it drops the whole footer.
- themeSwitch={{ enabled: false }}
- // Remove the sidebar hide/collapse button: fumadocs-ui 16.7 renders the
- // collapse trigger only under `collapsible && <SidebarCollapseTrigger>`
- // (slots/sidebar.js), so `collapsible: false` drops it (and the floating
- // re-expand trigger, since the rail can no longer collapse).
- sidebar={{ collapsible: false }}
- >
- {/* `relative isolate` scopes the decorative grid to the content column so
- it sits behind the page body but above the base background — the same
- dotted-grid backdrop used behind the landing hero, for visual
- continuity when crossing from the landing into the docs. */}
- <div className="relative isolate">
- <div
- aria-hidden
- className="pointer-events-none absolute inset-x-0 top-0 -z-10 h-[360px] bg-grid-fade"
- />
- {children}
- </div>
- </DocsLayout>
+ <DocsTabsBar />
+ <DocsShell componentsTree={components} primitivesTree={primitives}>
+ {children}
+ </DocsShell>
</>
);
}
diff --git a/components/docs/docs-header.tsx b/components/docs/docs-header.tsx
index 8dad7198..dd99e2f2 100644
--- a/components/docs/docs-header.tsx
+++ b/components/docs/docs-header.tsx
@@ -16,7 +16,8 @@ import { NAV_LINKS } from "@/config/site";
* block's right edge. The CSS vars are redeclared here because this header
* renders above (outside) DocsLayout, so its variables aren't in scope. `-ml-4`
* pulls the first nav item's label flush with the article text while its
- * ghost-button background bleeds back into the gutter.
+ * ghost-button background bleeds back into the gutter. The Components/Primitives
+ * switcher lives in the thin `DocsTabsBar` rendered directly below this header.
*
* The 1400px / 268px literals mirror fumadocs-ui 16.7 defaults — the docs grid
* sets `[--fd-layout-width:1400px]` and `md:layout:[--fd-sidebar-width:268px]`
diff --git a/components/docs/docs-shell.tsx b/components/docs/docs-shell.tsx
new file mode 100644
index 00000000..38671623
--- /dev/null
+++ b/components/docs/docs-shell.tsx
@@ -0,0 +1,70 @@
+"use client";
+
+import type { Root } from "fumadocs-core/page-tree";
+import { DocsLayout } from "fumadocs-ui/layouts/docs";
+import { usePathname } from "next/navigation";
+import type { ReactNode } from "react";
+import { getActiveDocsTab } from "@/lib/docs-tabs";
+import { baseOptions } from "@/lib/layout.shared";
+
+/**
+ * Renders the Fumadocs `DocsLayout` with the sidebar tree that matches the
+ * active docs tab. Both trees are built once on the server (in `app/docs/layout`)
+ * and handed down; this client shell only picks between them by pathname, so the
+ * Components and Primitives tabs each get their own sidebar without moving any
+ * files or changing URLs. The page body arrives as server-rendered `children`,
+ * so the RSC boundary stays intact — only the layout chrome is client-rendered.
+ *
+ * The `DocsLayout` props mirror the previous server layout: the custom
+ * `DocsHeader` above owns the only top nav (`nav` disabled), search renders in
+ * the sidebar header, and the theme switch / collapse trigger / sidebar footer
+ * are suppressed. The decorative grid scopes a dotted backdrop to the content
+ * column for visual continuity with the landing hero.
+ *
+ * `containerProps` pins two layout vars on the DocsLayout grid:
+ * - `--fd-layout-width: 1400px` matches the chrome's width (DocsHeader/DocsTabsBar
+ * use 1400; the grid otherwise falls back to 97rem). Unifying them makes the
+ * sidebar's left edge coincide with the chrome's, so the tab bar's tabs line up
+ * exactly with the sidebar at every viewport width.
+ * - `--fd-banner-height: 2.75rem` is the sticky `DocsTabsBar` height. fumadocs
+ * derives `--fd-docs-row-1: var(--fd-banner-height, 0px)` and sticks the sidebar/
+ * TOC at `top-(--fd-docs-row-1)`, dropping them just below the pinned tab bar
+ * instead of letting the bar overlap the sidebar top.
+ */
+export function DocsShell({
+ componentsTree,
+ primitivesTree,
+ children,
+}: {
+ componentsTree: Root;
+ primitivesTree: Root;
+ children: ReactNode;
+}) {
+ const pathname = usePathname();
+ const tree =
+ getActiveDocsTab(pathname) === "primitives"
+ ? primitivesTree
+ : componentsTree;
+
+ return (
+ <DocsLayout
+ tree={tree}
+ {...baseOptions()}
+ nav={{ enabled: false }}
+ searchToggle={{ enabled: true }}
+ themeSwitch={{ enabled: false }}
+ sidebar={{ collapsible: false }}
+ containerProps={{
+ className: "[--fd-layout-width:1400px] [--fd-banner-height:2.75rem]",
+ }}
+ >
+ <div className="relative isolate">
+ <div
+ aria-hidden
+ className="pointer-events-none absolute inset-x-0 top-0 -z-10 h-[360px] bg-grid-fade"
+ />
+ {children}
+ </div>
+ </DocsLayout>
+ );
+}
diff --git a/components/docs/docs-tabs-bar.tsx b/components/docs/docs-tabs-bar.tsx
new file mode 100644
index 00000000..66876814
--- /dev/null
+++ b/components/docs/docs-tabs-bar.tsx
@@ -0,0 +1,28 @@
+import { DocsTabs } from "@/components/docs/docs-tabs";
+
+/**
+ * Thin secondary bar sitting directly below {@link DocsHeader}, holding the
+ * Components | Primitives switcher. It is `sticky top-0` so it stays pinned to
+ * the top while the page scrolls; the (non-sticky) main header scrolls away
+ * above it, and the bar pins exactly as the header scrolls out. `DocsShell` sets
+ * the DocsLayout `--fd-banner-height` to this bar's height so the sticky sidebar
+ * lands just below the pinned bar instead of under it.
+ *
+ * The tabs sit at the far left, aligned with the sidebar's content padding: the
+ * centered block carries `px-4` (the sidebar's `p-4` = 16px) and `-ml-3` cancels
+ * the first tab's own `px-3` so its label lands flush at 16px — directly above
+ * the sidebar content's left edge. `items-stretch` lets the tabs fill the bar's
+ * height so the active underline lands on its bottom border.
+ *
+ * The 1400px literal mirrors fumadocs-ui 16.7's docs-grid width, kept in sync
+ * with `DocsHeader` (Tailwind JIT can't read JS constants).
+ */
+export function DocsTabsBar() {
+ return (
+ <div className="sticky top-0 z-30 h-11 w-full border-b border-border bg-background/70 backdrop-blur-xl">
+ <div className="mx-auto flex h-11 w-full max-w-(--fd-layout-width) items-stretch px-4 [--fd-layout-width:1400px]">
+ <DocsTabs className="-ml-3" />
+ </div>
+ </div>
+ );
+}
diff --git a/components/docs/docs-tabs.tsx b/components/docs/docs-tabs.tsx
new file mode 100644
index 00000000..7e3fde5c
--- /dev/null
+++ b/components/docs/docs-tabs.tsx
@@ -0,0 +1,49 @@
+"use client";
+
+import Link from "next/link";
+import { usePathname } from "next/navigation";
+import { DOCS_TABS, getActiveDocsTab } from "@/lib/docs-tabs";
+import { cn } from "@/lib/utils";
+
+/**
+ * Tab switcher for the docs: Components | Primitives. Rendered inside the thin
+ * `DocsTabsBar` below the main header. The active tab is derived from the current
+ * path (the ui section maps to Primitives, see {@link getActiveDocsTab}) and
+ * carries an underline pinned to the bar's bottom border via `bottom-0`. The nav
+ * stretches to its parent's height (no hardcoded height), so the underline tracks
+ * whatever bar it sits in. Each tab is a plain link; switching navigates to that
+ * tab's landing page and `DocsShell` swaps the sidebar tree for the new path.
+ */
+export function DocsTabs({ className }: { className?: string }) {
+ const pathname = usePathname();
+ const active = getActiveDocsTab(pathname);
+
+ return (
+ <nav className={cn("flex items-stretch gap-1", className)}>
+ {DOCS_TABS.map((tab) => {
+ const isActive = tab.id === active;
+ return (
+ <Link
+ key={tab.id}
+ href={tab.href}
+ aria-current={isActive ? "page" : undefined}
+ className={cn(
+ "relative flex items-center px-3 text-sm font-medium transition-colors focus-visible:text-foreground focus-visible:outline-none",
+ isActive
+ ? "text-foreground"
+ : "text-muted-foreground hover:text-foreground",
+ )}
+ >
+ {tab.label}
+ {isActive && (
+ <span
+ aria-hidden
+ className="absolute inset-x-3 bottom-0 h-0.5 rounded-full bg-foreground"
+ />
+ )}
+ </Link>
+ );
+ })}
+ </nav>
+ );
+}
diff --git a/lib/docs-tabs.ts b/lib/docs-tabs.ts
new file mode 100644
index 00000000..b8fe0d89
--- /dev/null
+++ b/lib/docs-tabs.ts
@@ -0,0 +1,84 @@
+import type { Node, Root } from "fumadocs-core/page-tree";
+
+/**
+ * The docs are split into two top-level tabs surfaced in `DocsHeader`. Each tab
+ * owns its own sidebar tree (see {@link splitDocsTree}): "Primitives" holds only
+ * the remocn-ui section (`/docs/ui/*`); "Components" holds everything else,
+ * unchanged from the flat docs structure. No files move and no URLs change —
+ * the split is purely a view over the existing Fumadocs page tree.
+ */
+export type DocsTabId = "components" | "primitives";
+
+export type DocsTab = {
+ id: DocsTabId;
+ label: string;
+ /** Landing page when the tab is clicked from the other tab. */
+ href: string;
+};
+
+export const DOCS_TABS: DocsTab[] = [
+ {
+ id: "components",
+ label: "Components",
+ href: "/docs/getting-started/introduction",
+ },
+ { id: "primitives", label: "Primitives", href: "/docs/ui" },
+];
+
+/** URL prefix that backs the Primitives tab (the remocn-ui section). */
+const PRIMITIVES_PREFIX = "/docs/ui";
+
+/** A pathname belongs to Primitives when it is the ui index or any ui page. */
+function isPrimitivesPath(pathname: string): boolean {
+ return (
+ pathname === PRIMITIVES_PREFIX ||
+ pathname.startsWith(`${PRIMITIVES_PREFIX}/`)
+ );
+}
+
+export function getActiveDocsTab(pathname: string): DocsTabId {
+ return isPrimitivesPath(pathname) ? "primitives" : "components";
+}
+
+/** True for the root-level folder node that holds the remocn-ui (ui) section. */
+function isPrimitivesNode(node: Node): boolean {
+ if (node.type !== "folder") return false;
+ if (node.index?.url === PRIMITIVES_PREFIX) return true;
+ return node.children.some(
+ (child) =>
+ child.type === "page" &&
+ child.url.startsWith(`${PRIMITIVES_PREFIX}/`),
+ );
+}
+
+/**
+ * Splits the Fumadocs page tree into the two tab trees. Immutable — the source
+ * `Root` (shared across requests) is never mutated; each branch is a shallow
+ * copy with a filtered `children` list, so order is preserved within each tab.
+ * Compose after {@link withNewBadges} so the badge decoration survives the split.
+ *
+ * Each branch gets a DISTINCT, stable `$id`. This is load-bearing: fumadocs'
+ * `TreeContextProvider` memoizes the active tree with
+ * `useMemo(() => rawTree, [rawTree.$id ?? rawTree])`. The source root's `$id` is
+ * the literal "root", so two plain shallow copies would share it — the memo dep
+ * would never change when `DocsShell` swaps trees on a tab switch, freezing the
+ * sidebar on the first tab until a full page reload. Distinct ids make the dep
+ * differ per tab so the sidebar updates client-side.
+ */
+export function splitDocsTree(tree: Root): {
+ components: Root;
+ primitives: Root;
+} {
+ return {
+ components: {
+ ...tree,
+ $id: "docs-tab-components",
+ children: tree.children.filter((node) => !isPrimitivesNode(node)),
+ },
+ primitives: {
+ ...tree,
+ $id: "docs-tab-primitives",
+ children: tree.children.filter(isPrimitivesNode),
+ },
+ };
+}