Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
feat: prev/next arrows and vim keys on docs pages
kapishdima6030c216abfa
diff --git a/app/docs/[[...slug]]/page.tsx b/app/docs/[[...slug]]/page.tsxindex 7fc3c750..e5b429b3 100644--- a/app/docs/[[...slug]]/page.tsx+++ b/app/docs/[[...slug]]/page.tsx@@ -1,5 +1,6 @@import { notFound } from "next/navigation";import { DocsRail, RailCards } from "@/components/docs/shell/docs-rail";+import { KeyboardNav } from "@/components/docs/shell/keyboard-nav";import { MobilePageBar } from "@/components/docs/shell/mobile-page-bar";import { getPageContext } from "@/components/docs/shell/page-context";import { PageFooter } from "@/components/docs/shell/page-footer";@@ -27,12 +28,15 @@ export default async function Page(props: {return (<><MobilePageBar crumbs={crumbs} />+ <KeyboardNav previous={previous} next={next} /><div className="flex flex-1"><article className="flex min-w-0 flex-1 flex-col px-5 pt-7 pb-14 lg:px-10 lg:pt-9 lg:pb-16 xl:mx-auto xl:w-full xl:max-w-(--docs-article-max) xl:px-(--docs-article-pad)"><PageHeadertitle={data.title}description={data.description}links={links}+ previous={previous}+ next={next}/><div className="typeset typeset-docs mt-6 flex-1 lg:mt-8 [&_:is(h2,h3,h4)[id]]:scroll-mt-20 xl:[&_:is(h2,h3,h4)[id]]:scroll-mt-6"><MDX components={getMDXComponents()} />diff --git a/components/docs/copy-markdown-button.tsx b/components/docs/copy-markdown-button.tsxindex b93a96d4..f8c71816 100644--- a/components/docs/copy-markdown-button.tsx+++ b/components/docs/copy-markdown-button.tsx@@ -68,7 +68,11 @@ export function CopyMarkdownButton({onClick={handleCopy}aria-busy={state === "loading"}className={cn(- "inline-flex h-11 w-fit shrink-0 items-center gap-2 rounded-control-sm bg-secondary pr-3.5 pl-3 text-[15px] leading-5 text-foreground outline-none transition-colors hover:bg-[#dcdde0] focus-visible:ring-2 focus-visible:ring-ring dark:hover:bg-[#33363b] lg:h-8 lg:gap-[7px] lg:rounded-[10px] lg:pr-3 lg:pl-[11px] lg:text-small",+ "inline-flex w-fit shrink-0 items-center outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring",+ // Below `lg`: a solid 44px button. From `lg`: a 32px tile inside the+ // switcher-style capsule `PageActions` draws around it.+ "max-lg:h-11 max-lg:gap-2 max-lg:rounded-control-sm max-lg:bg-secondary max-lg:pr-3.5 max-lg:pl-3 max-lg:text-[15px] max-lg:leading-5 max-lg:text-foreground max-lg:hover:bg-[#dcdde0] max-lg:dark:hover:bg-[#33363b]",+ "lg:h-8 lg:gap-[7px] lg:rounded-tile lg:px-2.5 lg:text-small lg:text-muted-foreground lg:hover:bg-surface/60 lg:hover:text-foreground lg:dark:hover:bg-secondary/60",className,)}>diff --git a/components/docs/shell/keyboard-nav.tsx b/components/docs/shell/keyboard-nav.tsxnew file mode 100644index 00000000..e5fc9a46--- /dev/null+++ b/components/docs/shell/keyboard-nav.tsx@@ -0,0 +1,54 @@+"use client";++import { usePathname, useRouter } from "next/navigation";+import { useEffect } from "react";+import { DOCS_TABS, getActiveDocsTab } from "@/lib/docs-tabs";+import type { PageNeighbour } from "./page-context";++/** Focus inside these owns its letter keys (typing, menu typeahead). */+const OWNS_KEYS =+ 'input, textarea, select, [contenteditable], [role="menu"], [role="listbox"], [role="combobox"], [role="dialog"]';++/**+ * Vim-style docs navigation: `j` / `k` step to the next / previous page (the+ * arrows above the title), `h` / `l` to the previous / next library (the+ * sidebar switcher). Neither wraps around, matching the arrows' dead ends.+ */+export function KeyboardNav({+ previous,+ next,+}: {+ previous?: PageNeighbour;+ next?: PageNeighbour;+}) {+ const router = useRouter();+ const pathname = usePathname();++ useEffect(() => {+ const tabIndex = DOCS_TABS.findIndex(+ (tab) => tab.id === getActiveDocsTab(pathname),+ );+ const targets: Record<string, string | undefined> = {+ j: next?.url,+ k: previous?.url,+ h: DOCS_TABS[tabIndex - 1]?.href,+ l: DOCS_TABS[tabIndex + 1]?.href,+ };++ const onKey = (event: KeyboardEvent) => {+ if (event.defaultPrevented || event.repeat) return;+ if (event.metaKey || event.ctrlKey || event.altKey || event.shiftKey)+ return;+ const href = targets[event.key];+ if (!href) return;+ const target = event.target as HTMLElement | null;+ if (target?.closest(OWNS_KEYS)) return;+ event.preventDefault();+ router.push(href);+ };+ window.addEventListener("keydown", onKey);+ return () => window.removeEventListener("keydown", onKey);+ }, [router, pathname, previous?.url, next?.url]);++ return null;+}diff --git a/components/docs/shell/page-actions.tsx b/components/docs/shell/page-actions.tsxindex 4dabf98b..88153555 100644--- a/components/docs/shell/page-actions.tsx+++ b/components/docs/shell/page-actions.tsx@@ -46,8 +46,9 @@ function useAlignToIsland(enabled: boolean) {/*** "Copy page" with a menu beside it: the button copies the page's markdown,* the chevron opens the agent hand-offs (Open in Claude / ChatGPT, View as- * Markdown). 32px on the breadcrumb row from `lg`, 44px under the- * description below it.+ * Markdown). From `lg` it sits on the row above the title as a 40px capsule+ * matching the sidebar's library switcher; below it, 44px under the+ * description.*/export function PageActions({links,@@ -64,20 +65,20 @@ export function PageActions({<divref={ref}className={cn(- "inline-flex w-fit shrink-0 items-stretch",+ "inline-flex w-fit shrink-0 items-stretch lg:h-10 lg:items-center lg:gap-0.5 lg:rounded-control-sm lg:bg-capsule lg:p-1",alignToHeader && "xl:translate-x-[9px]",className,)}><CopyMarkdownButtonurl={links.markdown}- className="rounded-r-none lg:rounded-r-none"+ className="max-lg:rounded-r-none"/>- <span aria-hidden="true" className="w-px bg-foreground/10" />+ <span aria-hidden="true" className="w-px bg-foreground/10 lg:hidden" /><Menu.Root><Menu.Triggeraria-label="More page actions"- className="group flex w-10 items-center justify-center rounded-r-control-sm bg-secondary text-foreground outline-none transition-colors hover:bg-[#dcdde0] focus-visible:ring-2 focus-visible:ring-ring data-popup-open:bg-[#dcdde0] lg:w-7 lg:rounded-r-[10px] dark:hover:bg-[#33363b] dark:data-popup-open:bg-[#33363b]"+ className="group flex items-center justify-center outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring max-lg:w-10 max-lg:rounded-r-control-sm max-lg:bg-secondary max-lg:text-foreground max-lg:hover:bg-[#dcdde0] max-lg:data-popup-open:bg-[#dcdde0] max-lg:dark:hover:bg-[#33363b] max-lg:dark:data-popup-open:bg-[#33363b] lg:size-8 lg:rounded-tile lg:text-muted-foreground lg:hover:bg-surface/60 lg:hover:text-foreground lg:data-popup-open:bg-surface/60 lg:data-popup-open:text-foreground lg:dark:hover:bg-secondary/60 lg:dark:data-popup-open:bg-secondary/60"><ChevronIcon className="size-3.5 rotate-90 transition-[rotate] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] group-data-popup-open:-rotate-90 motion-reduce:transition-none" /></Menu.Trigger>diff --git a/components/docs/shell/page-header.tsx b/components/docs/shell/page-header.tsxindex dc07b0fa..e522d78d 100644--- a/components/docs/shell/page-header.tsx+++ b/components/docs/shell/page-header.tsx@@ -1,25 +1,47 @@import { PageActions } from "./page-actions";+import type { PageNeighbour } from "./page-context";import type { PageLinks } from "./page-links";+import { PageNav } from "./page-nav";/**- * Article head: the page actions ("Copy page" + agent menu) above the title- * on desktop, the title and the description. Below `lg` the actions drop- * under the description.+ * Article head: the row above the title (previous / next arrows on the left,+ * the page actions — "Copy page" + agent menu — on the right from `lg`), the+ * title and the description. Below `lg` the actions drop under the+ * description. From `lg` the row is pulled up so its 40px capsules share a+ * top edge with the sidebar's library switcher.*/export function PageHeader({title,description,links,+ previous,+ next,}: {title: string;description?: string;links?: PageLinks;+ previous?: PageNeighbour;+ next?: PageNeighbour;}) {+ const hasNav = Boolean(previous || next);return (<header className="flex flex-col gap-3 lg:gap-3.5 lg:pb-3">- {links && (- <div className="hidden min-h-8 justify-end lg:flex">- <PageActions links={links} alignToHeader />+ {(hasNav || links) && (+ <div+ className={+ hasNav+ ? "flex items-center justify-between gap-3 lg:-mt-3"+ : "hidden justify-end lg:-mt-3 lg:flex"+ }+ >+ {hasNav && <PageNav previous={previous} next={next} />}+ {links && (+ <PageActions+ links={links}+ alignToHeader+ className="max-lg:hidden"+ />+ )}</div>)}<h1 className="text-[34px] leading-9 font-medium tracking-heading text-balance text-foreground lg:text-h3 lg:leading-[52px]">diff --git a/components/docs/shell/page-nav.tsx b/components/docs/shell/page-nav.tsxnew file mode 100644index 00000000..1da1981b--- /dev/null+++ b/components/docs/shell/page-nav.tsx@@ -0,0 +1,71 @@+import Link from "next/link";+import { cn } from "@/lib/utils";+import { ArrowIcon } from "./docs-icons";+import type { PageNeighbour } from "./page-context";++const tile = "flex size-8 items-center justify-center rounded-tile";++function NavArrow({+ page,+ direction,+}: {+ page?: PageNeighbour;+ direction: "previous" | "next";+}) {+ const next = direction === "next";+ const icon = (+ <ArrowIcon direction={next ? "right" : "left"} className="size-4" />+ );++ // The end of the library keeps its slot so the pair never changes width.+ if (!page) {+ return (+ <span aria-hidden="true" className={cn(tile, "text-muted-foreground/40")}>+ {icon}+ </span>+ );+ }++ return (+ <Link+ href={page.url}+ aria-label={`${next ? "Next" : "Previous"}: ${page.name}`}+ title={`${page.name} (${next ? "j" : "k"})`}+ aria-keyshortcuts={next ? "j" : "k"}+ className={cn(+ tile,+ "text-muted-foreground outline-none hover:bg-surface/60 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring dark:hover:bg-secondary/60",+ )}+ >+ {icon}+ </Link>+ );+}++/**+ * Previous / next arrows above the title: the same neighbours as the footer+ * cards, one click away without scrolling to the bottom of the page. Drawn+ * as the sidebar's library switcher capsule so the two rows read as one.+ */+export function PageNav({+ previous,+ next,+ className,+}: {+ previous?: PageNeighbour;+ next?: PageNeighbour;+ className?: string;+}) {+ return (+ <nav+ aria-label="Previous and next page"+ className={cn(+ "flex h-10 w-fit shrink-0 items-center gap-0.5 rounded-control-sm bg-capsule p-1",+ className,+ )}+ >+ <NavArrow page={previous} direction="previous" />+ <NavArrow page={next} direction="next" />+ </nav>+ );+}