Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): redesign docs shell navigation and search

Richie McIlroyb40109c781cd
diff --git a/apps/web/app/(docs)/docs/_components/DocsBreadcrumbs.tsx b/apps/web/app/(docs)/docs/_components/DocsBreadcrumbs.tsx
index 21f10affd..9d203a271 100644
--- a/apps/web/app/(docs)/docs/_components/DocsBreadcrumbs.tsx
+++ b/apps/web/app/(docs)/docs/_components/DocsBreadcrumbs.tsx
@@ -1,43 +1,26 @@
-import { ChevronRight } from "lucide-react";
-import Link from "next/link";
import { getBreadcrumbs } from "../docs-config";
interface DocsBreadcrumbsProps {
currentSlug: string;
+ pageTitle?: string;
}
-export function DocsBreadcrumbs({ currentSlug }: DocsBreadcrumbsProps) {
+export function DocsBreadcrumbs({
+ currentSlug,
+ pageTitle,
+}: DocsBreadcrumbsProps) {
const breadcrumbs = getBreadcrumbs(currentSlug);
+ const group =
+ breadcrumbs.length > 1 ? breadcrumbs[breadcrumbs.length - 2] : null;
- return (
- <nav
- className="flex items-center gap-1 text-sm mb-6"
- aria-label="Breadcrumb"
- >
- {breadcrumbs.map((crumb, index) => {
- const isLast = index === breadcrumbs.length - 1;
+ if (!group) return null;
+ if (pageTitle && group.title.toLowerCase() === pageTitle.toLowerCase()) {
+ return null;
+ }
- return (
- <span
- key={crumb.slug + crumb.title}
- className="flex items-center gap-1"
- >
- {index > 0 && (
- <ChevronRight className="w-3.5 h-3.5 text-gray-300 shrink-0" />
- )}
- {isLast ? (
- <span className="text-gray-700 font-medium">{crumb.title}</span>
- ) : (
- <Link
- href={crumb.slug ? `/docs/${crumb.slug}` : "/docs"}
- className="text-gray-400 hover:text-gray-600 transition-colors"
- >
- {crumb.title}
- </Link>
- )}
- </span>
- );
- })}
- </nav>
+ return (
+ <p className="mb-2.5 text-[13px] font-medium leading-5 text-blue-11">
+ {group.title}
+ </p>
);
}
diff --git a/apps/web/app/(docs)/docs/_components/DocsHeader.tsx b/apps/web/app/(docs)/docs/_components/DocsHeader.tsx
index 0cdac1085..4b9aace7d 100644
--- a/apps/web/app/(docs)/docs/_components/DocsHeader.tsx
+++ b/apps/web/app/(docs)/docs/_components/DocsHeader.tsx
@@ -1,28 +1,37 @@
"use client";
import { Logo } from "@cap/ui";
-import { ExternalLink, Menu, Search } from "lucide-react";
+import { Menu, Search } from "lucide-react";
import Link from "next/link";
import { useEffect, useState } from "react";
-function useOS() {
+function useIsMac() {
const [isMac, setIsMac] = useState(true);
useEffect(() => {
setIsMac(navigator.platform.toUpperCase().indexOf("MAC") >= 0);
}, []);
- return { isMac };
+ return isMac;
+}
+
+function isTypingTarget(target: EventTarget | null) {
+ if (!(target instanceof HTMLElement)) return false;
+ return (
+ target.tagName === "INPUT" ||
+ target.tagName === "TEXTAREA" ||
+ target.isContentEditable
+ );
}
export function DocsHeader() {
- const { isMac } = useOS();
+ const isMac = useIsMac();
- const handleSearchClick = () => {
+ const openSearch = () => {
window.dispatchEvent(new CustomEvent("open-docs-search"));
};
- const handleMobileMenuClick = () => {
+ const openMobileMenu = () => {
window.dispatchEvent(new CustomEvent("open-docs-mobile-menu"));
};
@@ -31,6 +40,17 @@ export function DocsHeader() {
if ((e.metaKey || e.ctrlKey) && e.key === "k") {
e.preventDefault();
window.dispatchEvent(new CustomEvent("open-docs-search"));
+ return;
+ }
+ if (
+ e.key === "/" &&
+ !e.metaKey &&
+ !e.ctrlKey &&
+ !e.altKey &&
+ !isTypingTarget(e.target)
+ ) {
+ e.preventDefault();
+ window.dispatchEvent(new CustomEvent("open-docs-search"));
}
};
window.addEventListener("keydown", handleKeyDown);
@@ -39,79 +59,81 @@ export function DocsHeader() {
return (
<header
- className="fixed top-0 left-0 right-0 z-50 flex items-center justify-between h-14 px-4 bg-white border-b border-gray-200"
+ className="fixed inset-x-0 top-0 z-50 border-b border-gray-3 bg-gray-1/90 backdrop-blur-md"
style={{
- paddingRight: "calc(1rem + var(--scrollbar-compensation, 0px))",
+ paddingRight: "var(--scrollbar-compensation, 0px)",
}}
>
- <div className="flex items-center gap-3">
- <button
- type="button"
- onClick={handleMobileMenuClick}
- className="lg:hidden flex items-center justify-center w-8 h-8 rounded-md text-gray-500 hover:text-gray-900 hover:bg-gray-100 transition-colors"
- aria-label="Open menu"
- >
- <Menu className="w-5 h-5" />
- </button>
- <Link href="/" className="flex items-center">
- <Logo className="h-5 w-auto" />
- </Link>
- <span className="text-sm font-semibold text-gray-400">/</span>
- <Link
- href="/docs"
- className="text-sm font-semibold text-gray-900 hover:text-gray-700 transition-colors"
- >
- Docs
- </Link>
- </div>
-
- <button
- type="button"
- onClick={handleSearchClick}
- className="hidden sm:flex items-center gap-2 h-8 px-3 rounded-lg border border-gray-200 bg-gray-50 text-sm text-gray-500 hover:border-gray-300 hover:bg-gray-100 transition-colors cursor-pointer min-w-[240px]"
- >
- <Search className="w-3.5 h-3.5 text-gray-400" />
- <span className="flex-1 text-left">Search docs...</span>
- <kbd className="hidden md:inline-flex items-center gap-0.5 rounded bg-white border border-gray-200 px-1.5 py-0.5 text-[11px] font-medium text-gray-400">
- {isMac ? "\u2318" : "Ctrl"}K
- </kbd>
- </button>
+ <div className="mx-auto flex h-14 max-w-[1408px] items-center justify-between gap-4 px-4 sm:px-6">
+ <div className="flex min-w-0 items-center gap-3">
+ <button
+ type="button"
+ onClick={openMobileMenu}
+ className="flex size-8 items-center justify-center rounded-lg text-gray-11 transition-colors hover:bg-gray-3 hover:text-gray-12 lg:hidden"
+ aria-label="Open navigation"
+ >
+ <Menu className="size-5" />
+ </button>
+ <Link href="/" className="flex shrink-0 items-center">
+ <Logo className="h-5 w-auto" />
+ </Link>
+ <span aria-hidden="true" className="h-4 w-px rotate-12 bg-gray-6" />
+ <Link
+ href="/docs"
+ className="text-sm font-medium text-gray-12 transition-colors hover:text-gray-11"
+ >
+ Docs
+ </Link>
+ </div>
- <div className="flex items-center gap-3">
<button
type="button"
- onClick={handleSearchClick}
- className="sm:hidden flex items-center justify-center w-8 h-8 rounded-md text-gray-500 hover:text-gray-900 hover:bg-gray-100 transition-colors"
- aria-label="Search"
+ onClick={openSearch}
+ className="hidden h-9 w-[300px] items-center gap-2.5 rounded-full border border-gray-4 bg-gray-2 px-3.5 text-[13px] text-gray-10 transition-colors hover:border-gray-5 hover:bg-gray-3 md:flex"
>
- <Search className="w-4 h-4" />
+ <Search className="size-3.5 shrink-0 text-gray-9" />
+ <span className="flex-1 truncate text-left">
+ Search or ask a question...
+ </span>
+ <kbd className="hidden items-center gap-0.5 rounded-md border border-gray-5 bg-gray-1 px-1.5 py-0.5 text-[11px] font-medium text-gray-10 lg:inline-flex">
+ {isMac ? "⌘" : "Ctrl"} K
+ </kbd>
</button>
- <Link
- href="https://cap.so"
- target="_blank"
- rel="noopener noreferrer"
- className="hidden sm:flex items-center gap-1 text-sm text-gray-500 hover:text-gray-900 transition-colors"
- >
- cap.so
- <ExternalLink className="w-3 h-3" />
- </Link>
- <Link
- href="https://github.com/CapSoftware/Cap"
- target="_blank"
- rel="noopener noreferrer"
- className="flex items-center text-gray-500 hover:text-gray-900 transition-colors"
- >
- <svg
- viewBox="0 0 24 24"
- fill="currentColor"
- className="w-5 h-5"
- role="img"
- aria-label="GitHub"
+
+ <div className="flex items-center gap-1.5">
+ <button
+ type="button"
+ onClick={openSearch}
+ className="flex size-8 items-center justify-center rounded-lg text-gray-11 transition-colors hover:bg-gray-3 hover:text-gray-12 md:hidden"
+ aria-label="Search or ask a question"
+ >
+ <Search className="size-4" />
+ </button>
+ <Link
+ href="https://github.com/CapSoftware/Cap"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="flex size-8 items-center justify-center rounded-lg text-gray-11 transition-colors hover:bg-gray-3 hover:text-gray-12"
+ aria-label="Cap on GitHub"
+ >
+ <svg
+ viewBox="0 0 24 24"
+ fill="currentColor"
+ className="size-[18px]"
+ role="img"
+ aria-label="GitHub"
+ >
+ <title>GitHub</title>
+ <path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z" />
+ </svg>
+ </Link>
+ <Link
+ href="/download"
+ className="ml-1 hidden h-8 items-center rounded-full bg-gray-12 px-3.5 text-[13px] font-medium text-gray-1 transition-colors hover:bg-gray-11 sm:flex"
>
- <title>GitHub</title>
- <path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z" />
- </svg>
- </Link>
+ Download
+ </Link>
+ </div>
</div>
</header>
);
diff --git a/apps/web/app/(docs)/docs/_components/DocsMobileMenu.tsx b/apps/web/app/(docs)/docs/_components/DocsMobileMenu.tsx
index f4429b4b4..f003234e3 100644
--- a/apps/web/app/(docs)/docs/_components/DocsMobileMenu.tsx
+++ b/apps/web/app/(docs)/docs/_components/DocsMobileMenu.tsx
@@ -1,27 +1,37 @@
"use client";
+import { Logo } from "@cap/ui";
import { X } from "lucide-react";
-import Link from "next/link";
import { usePathname } from "next/navigation";
import { useEffect, useRef, useState } from "react";
-import { docsConfig, type SidebarGroup } from "../docs-config";
+import { DocsSidebarNav } from "./DocsSidebarNav";
export function DocsMobileMenu() {
const [isOpen, setIsOpen] = useState(false);
+ const [isAnimating, setIsAnimating] = useState(false);
const pathname = usePathname();
- const prevPathname = useRef(pathname);
useEffect(() => {
- const handleOpen = () => setIsOpen(true);
+ const handleOpen = () => {
+ setIsOpen(true);
+ requestAnimationFrame(() => setIsAnimating(true));
+ };
window.addEventListener("open-docs-mobile-menu", handleOpen);
return () =>
window.removeEventListener("open-docs-mobile-menu", handleOpen);
}, []);
+ const close = () => {
+ setIsAnimating(false);
+ setTimeout(() => setIsOpen(false), 200);
+ };
+
+ const prevPathname = useRef(pathname);
useEffect(() => {
if (prevPathname.current !== pathname) {
- setIsOpen(false);
prevPathname.current = pathname;
+ setIsAnimating(false);
+ setIsOpen(false);
}
}, [pathname]);
@@ -36,63 +46,40 @@ export function DocsMobileMenu() {
};
}, [isOpen]);
- const isActive = (slug: string) => {
- return pathname === `/docs/${slug}` || pathname === `/docs/${slug}/`;
- };
-
if (!isOpen) return null;
return (
- <div className="fixed inset-0 z-50 lg:hidden">
+ <div className="fixed inset-0 z-[60] lg:hidden">
<button
type="button"
- className="absolute inset-0 bg-black/40 cursor-default"
- onClick={() => setIsOpen(false)}
- aria-label="Close menu"
+ className={`absolute inset-0 cursor-default bg-black-transparent-40 transition-opacity duration-200 ${
+ isAnimating ? "opacity-100" : "opacity-0"
+ }`}
+ onClick={close}
+ aria-label="Close navigation"
+ tabIndex={-1}
/>
- <div className="absolute top-0 left-0 bottom-0 w-[280px] bg-white shadow-xl overflow-y-auto">
- <div className="flex items-center justify-between h-14 px-4 border-b border-gray-200">
- <span className="text-sm font-semibold text-gray-900">
- Documentation
- </span>
+ <div
+ className={`absolute inset-y-0 left-0 w-[300px] overflow-y-auto border-r border-gray-3 bg-gray-1 shadow-xl transition-transform duration-200 ease-out ${
+ isAnimating ? "translate-x-0" : "-translate-x-full"
+ }`}
+ role="dialog"
+ aria-modal="true"
+ aria-label="Documentation navigation"
+ >
+ <div className="sticky top-0 flex h-14 items-center justify-between border-b border-gray-3 bg-gray-1 px-5">
+ <Logo className="h-5 w-auto" />
<button
type="button"
- onClick={() => setIsOpen(false)}
- className="flex items-center justify-center w-8 h-8 rounded-md text-gray-500 hover:text-gray-900 hover:bg-gray-100 transition-colors"
- aria-label="Close menu"
+ onClick={close}
+ className="flex size-8 items-center justify-center rounded-lg text-gray-11 transition-colors hover:bg-gray-3 hover:text-gray-12"
+ aria-label="Close navigation"
>
- <X className="w-5 h-5" />
+ <X className="size-5" />
</button>
</div>
- <nav className="px-4 py-6">
- <div className="flex flex-col gap-6">
- {docsConfig.sidebar.map((group: SidebarGroup) => (
- <div key={group.title}>
- <h4 className="px-3 mb-2 text-[11px] font-semibold uppercase tracking-wider text-gray-400">
- {group.title}
- </h4>
- <ul className="flex flex-col gap-0.5">
- {group.items.map((item) => {
- const active = isActive(item.slug);
- return (
- <li key={item.slug}>
- <Link
- href={`/docs/${item.slug}`}
- className={`block text-[13px] font-medium py-1.5 px-3 rounded-md transition-colors ${
- active
- ? "text-blue-500 bg-blue-50 border-l-2 border-blue-500"
- : "text-gray-600 hover:text-gray-900 hover:bg-gray-50"
- }`}
- >
- {item.title}
- </Link>
- </li>
- );
- })}
- </ul>
- </div>
- ))}
- </div>
+ <nav aria-label="Documentation" className="px-5 py-6">
+ <DocsSidebarNav />
</nav>
</div>
</div>
diff --git a/apps/web/app/(docs)/docs/_components/DocsPrevNext.tsx b/apps/web/app/(docs)/docs/_components/DocsPrevNext.tsx
index e41482a4b..50cc31875 100644
--- a/apps/web/app/(docs)/docs/_components/DocsPrevNext.tsx
+++ b/apps/web/app/(docs)/docs/_components/DocsPrevNext.tsx
@@ -1,4 +1,4 @@
-import { ChevronLeft, ChevronRight } from "lucide-react";
+import { ArrowLeft, ArrowRight } from "lucide-react";
import Link from "next/link";
import { getAdjacentDocs } from "../docs-config";
@@ -12,43 +12,37 @@ export function DocsPrevNext({ currentSlug }: DocsPrevNextProps) {
if (!prev && !next) return null;
return (
- <div className="flex items-stretch justify-between gap-4 mt-12 pt-6 border-t border-gray-200">
+ <div className="mt-14 grid grid-cols-1 gap-3 border-t border-gray-3 pt-8 sm:grid-cols-2">
{prev ? (
<Link
href={`/docs/${prev.slug}`}
- className="group flex items-center gap-3 flex-1 px-4 py-3 rounded-lg border border-gray-200 hover:border-gray-300 hover:bg-gray-50 transition-colors"
+ className="group flex flex-col gap-1 rounded-xl border border-gray-4 p-4 transition-colors hover:border-gray-6 hover:bg-gray-2"
>
- <ChevronLeft className="w-4 h-4 text-gray-400 group-hover:text-gray-600 transition-colors shrink-0" />
- <div className="flex flex-col">
- <span className="text-[11px] font-medium text-gray-400 uppercase tracking-wide">
- Previous
- </span>
- <span className="text-sm font-medium text-gray-700 group-hover:text-gray-900 transition-colors">
- {prev.title}
- </span>
- </div>
+ <span className="flex items-center gap-1 text-xs text-gray-10">
+ <ArrowLeft className="size-3 transition-transform group-hover:-translate-x-0.5" />
+ Previous
+ </span>
+ <span className="text-sm font-medium text-gray-12 transition-colors group-hover:text-blue-11">
+ {prev.title}
+ </span>
</Link>
) : (
- <div className="flex-1" />
+ <div className="hidden sm:block" />
)}
{next ? (
<Link
href={`/docs/${next.slug}`}
- className="group flex items-center justify-end gap-3 flex-1 px-4 py-3 rounded-lg border border-gray-200 hover:border-gray-300 hover:bg-gray-50 transition-colors text-right"
+ className="group flex flex-col items-end gap-1 rounded-xl border border-gray-4 p-4 text-right transition-colors hover:border-gray-6 hover:bg-gray-2 sm:col-start-2"
>
- <div className="flex flex-col items-end">
- <span className="text-[11px] font-medium text-gray-400 uppercase tracking-wide">
- Next
- </span>
- <span className="text-sm font-medium text-gray-700 group-hover:text-gray-900 transition-colors">
- {next.title}
- </span>
- </div>
- <ChevronRight className="w-4 h-4 text-gray-400 group-hover:text-gray-600 transition-colors shrink-0" />
+ <span className="flex items-center gap-1 text-xs text-gray-10">
+ Next
+ <ArrowRight className="size-3 transition-transform group-hover:translate-x-0.5" />
+ </span>
+ <span className="text-sm font-medium text-gray-12 transition-colors group-hover:text-blue-11">
+ {next.title}
+ </span>
</Link>
- ) : (
- <div className="flex-1" />
- )}
+ ) : null}
</div>
);
}
diff --git a/apps/web/app/(docs)/docs/_components/DocsSearch.tsx b/apps/web/app/(docs)/docs/_components/DocsSearch.tsx
index 5fdc28716..09e2d3d27 100644
--- a/apps/web/app/(docs)/docs/_components/DocsSearch.tsx
+++ b/apps/web/app/(docs)/docs/_components/DocsSearch.tsx
@@ -1,6 +1,13 @@
"use client";
-import { FileText, Search } from "lucide-react";
+import {
+ ArrowLeft,
+ CornerDownLeft,
+ FileText,
+ MessageCircle,
+ Search,
+} from "lucide-react";
+import dynamic from "next/dynamic";
import { useRouter } from "next/navigation";
import {
useCallback,
@@ -11,6 +18,8 @@ import {
useState,
} from "react";
+const DocsAskAnswer = dynamic(() => import("./DocsAskAnswer"), { ssr: false });
+
interface SearchItem {
slug: string;
title: string;
@@ -23,41 +32,45 @@ interface DocsSearchProps {
searchIndex: SearchItem[];
}
-interface GroupedResults {
- group: string;
- items: SearchItem[];
-}
+type PaletteItem =
+ | { type: "ask"; question: string }
+ | { type: "doc"; doc: SearchItem };
-function groupResults(items: SearchItem[]): GroupedResults[] {
- const map = new Map<string, SearchItem[]>();
- for (const item of items) {
- const existing = map.get(item.group);
- if (existing) {
- existing.push(item);
- } else {
- map.set(item.group, [item]);
- }
- }
- return Array.from(map.entries()).map(([group, items]) => ({
- group,
- items,
- }));
+interface AskTurn {
+ question: string;
+ answer: string;
+ status: "streaming" | "done" | "error";
+ error?: string;
}
-function truncateSummary(text: string, maxLength = 120): string {
- if (text.length <= maxLength) return text;
- return `${text.slice(0, maxLength).trimEnd()}...`;
-}
+const EXAMPLE_QUESTIONS = [
+ "How do I set up Cap in Claude Code?",
+ "Can my agent record my screen and share a link?",
+ "How do I self-host Cap with my own S3 bucket?",
+];
+
+const QUICK_LINK_SLUGS = [
+ "introduction",
+ "agents",
+ "agents/setup",
+ "api/rest-api",
+];
+
+const MAX_RESULTS = 10;
export function DocsSearch({ searchIndex }: DocsSearchProps) {
const [isOpen, setIsOpen] = useState(false);
+ const [isAnimating, setIsAnimating] = useState(false);
+ const [mode, setMode] = useState<"search" | "ask">("search");
const [query, setQuery] = useState("");
const [activeIndex, setActiveIndex] = useState(0);
- const [isAnimating, setIsAnimating] = useState(false);
+ const [turns, setTurns] = useState<AskTurn[]>([]);
const router = useRouter();
const inputRef = useRef<HTMLInputElement>(null);
- const resultsRef = useRef<HTMLDivElement>(null);
+ const conversationRef = useRef<HTMLDivElement>(null);
const activeItemRef = useRef<HTMLButtonElement>(null);
+ const abortRef = useRef<AbortController | null>(null);
+ const stickToBottomRef = useRef(true);
const instanceId = useId();
const resultsId = `${instanceId}-docs-search-results`;
const prevQueryRef = useRef(query);
@@ -66,37 +79,68 @@ export function DocsSearch({ searchIndex }: DocsSearchProps) {
const filteredResults = useMemo(() => {
if (!query.trim()) return [];
const lowerQuery = query.toLowerCase();
- return searchIndex.filter(
- (item) =>
- item.title.toLowerCase().includes(lowerQuery) ||
- item.summary.toLowerCase().includes(lowerQuery) ||
- item.content.toLowerCase().includes(lowerQuery),
- );
+ return searchIndex
+ .filter(
+ (item) =>
+ item.title.toLowerCase().includes(lowerQuery) ||
+ item.summary.toLowerCase().includes(lowerQuery) ||
+ item.content.toLowerCase().includes(lowerQuery),
+ )
+ .slice(0, MAX_RESULTS);
}, [query, searchIndex]);
- const grouped = useMemo(
- () => groupResults(filteredResults),
- [filteredResults],
+ const quickLinks = useMemo(
+ () =>
+ QUICK_LINK_SLUGS.flatMap((slug) => {
+ const doc = searchIndex.find((item) => item.slug === slug);
+ return doc ? [doc] : [];
+ }),
+ [searchIndex],
);
- const flatResults = useMemo(() => grouped.flatMap((g) => g.items), [grouped]);
+ const flatItems = useMemo<PaletteItem[]>(() => {
+ if (query.trim()) {
+ return [
+ { type: "ask", question: query.trim() },
+ ...filteredResults.map((doc): PaletteItem => ({ type: "doc", doc })),
+ ];
+ }
+ return [
+ ...EXAMPLE_QUESTIONS.map(
+ (question): PaletteItem => ({ type: "ask", question }),
+ ),
+ ...quickLinks.map((doc): PaletteItem => ({ type: "doc", doc })),
+ ];
+ }, [query, filteredResults, quickLinks]);
- const open = useCallback(() => {
+ const lastTurn = turns[turns.length - 1];
+ const isStreaming = lastTurn?.status === "streaming";
+
+ const open = useCallback((detail?: { mode?: string }) => {
setIsOpen(true);
setQuery("");
setActiveIndex(0);
- requestAnimationFrame(() => {
+ setMode(detail?.mode === "ask" ? "ask" : "search");
+ }, []);
+
+ useEffect(() => {
+ if (!isOpen) return;
+ const frame = requestAnimationFrame(() => {
setIsAnimating(true);
inputRef.current?.focus();
});
- }, []);
+ return () => cancelAnimationFrame(frame);
+ }, [isOpen]);
const close = useCallback(() => {
+ abortRef.current?.abort();
setIsAnimating(false);
const timeout = setTimeout(() => {
setIsOpen(false);
setQuery("");
setActiveIndex(0);
+ setMode("search");
+ setTurns([]);
}, 150);
return () => clearTimeout(timeout);
}, []);
@@ -109,51 +153,202 @@ export function DocsSearch({ searchIndex }: DocsSearchProps) {
[close, router],
);
+ const patchLastTurn = useCallback((patch: Partial<AskTurn>) => {
+ setTurns((prev) =>
+ prev.map((turn, index) =>
+ index === prev.length - 1 ? { ...turn, ...patch } : turn,
+ ),
+ );
+ }, []);
+
+ const streamAnswer = useCallback(
+ async (
+ question: string,
+ history: Array<{ role: "user" | "assistant"; content: string }>,
+ ) => {
+ abortRef.current?.abort();
+ const controller = new AbortController();
+ abortRef.current = controller;
+
+ try {
+ const response = await fetch("/api/docs/ask", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ question, history }),
+ signal: controller.signal,
+ });
+
+ if (!response.ok || !response.body) {
+ let message =
+ "Ask AI is unavailable right now. Try searching instead.";
+ try {
+ const data = (await response.json()) as { error?: unknown };
+ if (typeof data.error === "string") message = data.error;
+ } catch {
+ message = "Ask AI is unavailable right now. Try searching instead.";
+ }
+ patchLastTurn({ status: "error", error: message });
+ return;
+ }
+
+ const reader = response.body.getReader();
+ const decoder = new TextDecoder();
+ while (true) {
+ const { done, value } = await reader.read();
+ if (done) break;
+ const chunk = decoder.decode(value, { stream: true });
+ if (chunk) {
+ setTurns((prev) =>
+ prev.map((turn, index) =>
+ index === prev.length - 1
+ ? { ...turn, answer: turn.answer + chunk }
+ : turn,
+ ),
+ );
+ }
+ }
+ patchLastTurn({ status: "done" });
+ } catch {
+ if (!controller.signal.aborted) {
+ patchLastTurn({
+ status: "error",
+ error: "Connection lost. Try asking again.",
+ });
+ }
+ }
+ },
+ [patchLastTurn],
+ );
+
+ const startAsk = useCallback(
+ (question: string) => {
+ const trimmed = question.trim();
+ if (trimmed.length < 3 || isStreaming) return;
+ const history = turns
+ .filter((turn) => turn.status === "done")
+ .flatMap((turn) => [
+ { role: "user" as const, content: turn.question },
+ { role: "assistant" as const, content: turn.answer },
+ ])
+ .slice(-6);
+ setMode("ask");
+ setQuery("");
+ stickToBottomRef.current = true;
+ setTurns((prev) => [
+ ...prev,
+ { question: trimmed, answer: "", status: "streaming" },
+ ]);
+ inputRef.current?.focus();
+ void streamAnswer(trimmed, history);
+ },
+ [isStreaming, turns, streamAnswer],
+ );
+
+ const goBackToSearch = useCallback(() => {
+ if (isStreaming) {
+ abortRef.current?.abort();
+ setTurns((prev) => {
+ const last = prev[prev.length - 1];
+ if (last && last.status === "streaming") {
+ return last.answer
+ ? prev.map((turn, index) =>
+ index === prev.length - 1
+ ? { ...turn, status: "done" as const }
+ : turn,
+ )
+ : prev.slice(0, -1);
+ }
+ return prev;
+ });
+ }
+ setMode("search");
+ setActiveIndex(0);
+ inputRef.current?.focus();
+ }, [isStreaming]);
+
+ const selectItem = useCallback(
+ (item: PaletteItem) => {
+ if (item.type === "ask") {
+ startAsk(item.question);
+ } else {
+ navigateTo(item.doc.slug);
+ }
+ },
+ [startAsk, navigateTo],
+ );
+
+ const retryLastTurn = useCallback(() => {
+ const failed = turns[turns.length - 1];
+ if (!failed || failed.status !== "error") return;
+ setTurns((prev) => prev.slice(0, -1));
+ startAsk(failed.question);
+ }, [turns, startAsk]);
+
useEffect(() => {
- const handleCustomEvent = () => open();
- window.addEventListener("open-docs-search", handleCustomEvent);
+ const handleOpenEvent = (event: Event) => {
+ open((event as CustomEvent<{ mode?: string }>).detail ?? undefined);
+ };
+ window.addEventListener("open-docs-search", handleOpenEvent);
return () =>
- window.removeEventListener("open-docs-search", handleCustomEvent);
+ window.removeEventListener("open-docs-search", handleOpenEvent);
}, [open]);
useEffect(() => {
if (!isOpen) return;
const handleKeyDown = (e: KeyboardEvent) => {
+ if (e.isComposing) return;
+
if (e.key === "Escape") {
e.preventDefault();
- close();
+ if (mode === "ask") {
+ goBackToSearch();
+ } else {
+ close();
+ }
+ return;
+ }
+
+ if (mode === "ask") {
+ if (e.key === "Enter") {
+ e.preventDefault();
+ startAsk(query);
+ }
return;
}
if (e.key === "ArrowDown") {
e.preventDefault();
- setActiveIndex((prev) =>
- prev < flatResults.length - 1 ? prev + 1 : 0,
- );
+ setActiveIndex((prev) => (prev < flatItems.length - 1 ? prev + 1 : 0));
return;
}
if (e.key === "ArrowUp") {
e.preventDefault();
- setActiveIndex((prev) =>
- prev > 0 ? prev - 1 : flatResults.length - 1,
- );
+ setActiveIndex((prev) => (prev > 0 ? prev - 1 : flatItems.length - 1));
return;
}
if (e.key === "Enter") {
e.preventDefault();
- const selected = flatResults[activeIndex];
- if (selected) {
- navigateTo(selected.slug);
- }
+ const selected = flatItems[activeIndex];
+ if (selected) selectItem(selected);
}
};
window.addEventListener("keydown", handleKeyDown);
return () => window.removeEventListener("keydown", handleKeyDown);
- }, [isOpen, flatResults, activeIndex, close, navigateTo]);
+ }, [
+ isOpen,
+ mode,
+ query,
+ flatItems,
+ activeIndex,
+ close,
+ goBackToSearch,
+ startAsk,
+ selectItem,
+ ]);
if (prevQueryRef.current !== query) {
prevQueryRef.current = query;
@@ -165,6 +360,14 @@ export function DocsSearch({ searchIndex }: DocsSearchProps) {
activeItemRef.current?.scrollIntoView({ block: "nearest" });
}
+ useEffect(() => {
+ if (mode !== "ask" || turns.length === 0) return;
+ const el = conversationRef.current;
+ if (el && stickToBottomRef.current) {
+ el.scrollTop = el.scrollHeight;
+ }
+ }, [mode, turns]);
+
useEffect(() => {
if (isOpen) {
const scrollbarWidth =
@@ -189,145 +392,257 @@ export function DocsSearch({ searchIndex }: DocsSearchProps) {
if (!isOpen) return null;
- let flatIndex = -1;
+ const showAskIntro = mode === "ask" && turns.length === 0;
return (
- <div className="fixed inset-0 z-[60] flex items-start justify-center pt-[min(20vh,120px)]">
+ <div className="fixed inset-0 z-[70] flex items-start justify-center px-4 pt-[min(14vh,120px)]">
<button
type="button"
- className={`absolute inset-0 bg-black/30 transition-opacity duration-150 cursor-default ${
+ className={`absolute inset-0 cursor-default bg-black-transparent-40 transition-opacity duration-150 ${
isAnimating ? "opacity-100" : "opacity-0"
}`}
onClick={close}
- aria-label="Close search"
+ aria-label="Close"
tabIndex={-1}
/>
<div
- className={`relative w-full max-w-xl mx-4 bg-white rounded-xl shadow-2xl overflow-hidden transition-all duration-150 ${
+ className={`relative flex max-h-[min(620px,78vh)] w-full max-w-[640px] flex-col overflow-hidden rounded-2xl border border-gray-3 bg-gray-1 shadow-2xl transition-all duration-150 ${
isAnimating
- ? "opacity-100 scale-100 translate-y-0"
- : "opacity-0 scale-[0.98] -translate-y-2"
+ ? "translate-y-0 scale-100 opacity-100"
+ : "-translate-y-2 scale-[0.98] opacity-0"
}`}
role="dialog"
aria-modal="true"
- aria-label="Search documentation"
+ aria-label={
+ mode === "ask" ? "Ask about the docs" : "Search documentation"
+ }
>
- <div className="flex items-center gap-3 px-4 border-b border-gray-200">
- <Search className="w-4.5 h-4.5 text-gray-400 shrink-0" />
+ <div className="flex shrink-0 items-center gap-2.5 border-b border-gray-3 px-4">
+ {mode === "ask" ? (
+ <button
+ type="button"
+ onClick={goBackToSearch}
+ className="flex size-7 shrink-0 items-center justify-center rounded-md text-gray-10 transition-colors hover:bg-gray-3 hover:text-gray-12"
+ aria-label="Back to search"
+ >
+ <ArrowLeft className="size-4" />
+ </button>
+ ) : (
+ <Search className="size-4 shrink-0 text-gray-9" />
+ )}
<input
ref={inputRef}
type="text"
value={query}
onChange={(e) => setQuery(e.target.value)}
- placeholder="Search documentation..."
- className="flex-1 h-14 text-base text-gray-900 placeholder-gray-400 outline-none bg-transparent"
- aria-label="Search documentation"
+ placeholder={
+ mode === "ask"
+ ? turns.length > 0
+ ? "Ask a follow-up..."
+ : "Ask a question about Cap..."
+ : "Search docs or ask a question..."
+ }
+ className="h-[52px] flex-1 bg-transparent text-[15px] text-gray-12 outline-none placeholder:text-gray-9"
+ aria-label={
+ mode === "ask"
+ ? "Ask a question about Cap"
+ : "Search documentation"
+ }
aria-autocomplete="list"
- aria-controls={resultsId}
+ aria-controls={mode === "search" ? resultsId : undefined}
aria-activedescendant={
- flatResults[activeIndex]
- ? `${instanceId}-item-${flatResults[activeIndex].slug}`
+ mode === "search" && flatItems[activeIndex]
+ ? `${instanceId}-item-${activeIndex}`
: undefined
}
/>
- <kbd className="shrink-0 inline-flex items-center rounded bg-gray-100 border border-gray-200 px-1.5 py-0.5 text-[11px] font-medium text-gray-400 select-none">
- ESC
+ <kbd className="shrink-0 rounded-md border border-gray-4 bg-gray-2 px-1.5 py-0.5 text-[11px] font-medium text-gray-9 select-none">
+ Esc
</kbd>
</div>
- <div
- ref={resultsRef}
- id={resultsId}
- role="listbox"
- className="max-h-[400px] overflow-y-auto overscroll-contain"
- >
- {!query.trim() && (
- <div className="flex flex-col items-center justify-center py-12 px-4">
- <Search className="w-8 h-8 text-gray-300 mb-3" />
- <p className="text-sm text-gray-400">Start typing to search...</p>
- </div>
- )}
-
- {query.trim() && flatResults.length === 0 && (
- <div className="flex flex-col items-center justify-center py-12 px-4">
- <Search className="w-8 h-8 text-gray-300 mb-3" />
- <p className="text-sm text-gray-500">
- No results found for &ldquo;{query}&rdquo;
+ {mode === "search" ? (
+ <div
+ id={resultsId}
+ role="listbox"
+ className="flex-1 overflow-y-auto overscroll-contain py-2 [scrollbar-width:thin]"
+ >
+ {query.trim() && filteredResults.length === 0 && (
+ <p className="px-4 pb-1 pt-3 text-[13px] text-gray-9">
+ No pages match &ldquo;{query}&rdquo; — ask the docs instead:
</p>
- </div>
- )}
-
- {grouped.map((group) => (
- <div key={group.group} className="py-2">
- <div className="px-4 py-1.5">
- <span className="text-[11px] font-semibold uppercase tracking-wider text-gray-400">
- {group.group}
- </span>
- </div>
- {group.items.map((item) => {
- flatIndex++;
- const isActive = flatIndex === activeIndex;
- const currentIndex = flatIndex;
- return (
+ )}
+ {!query.trim() && (
+ <p className="px-4 pb-1.5 pt-2 text-xs font-medium text-gray-9">
+ Ask the docs
+ </p>
+ )}
+ {flatItems.map((item, index) => {
+ const isActive = index === activeIndex;
+ const isFirstQuickLink =
+ !query.trim() &&
+ item.type === "doc" &&
+ flatItems[index - 1]?.type === "ask";
+ return (
+ <div
+ key={
+ item.type === "ask" ? `ask-${item.question}` : item.doc.slug
+ }
+ >
+ {isFirstQuickLink && (
+ <p className="px-4 pb-1.5 pt-3 text-xs font-medium text-gray-9">
+ Popular pages
+ </p>
+ )}
<button
- key={item.slug}
ref={isActive ? activeItemRef : undefined}
- id={`${instanceId}-item-${item.slug}`}
+ id={`${instanceId}-item-${index}`}
role="option"
aria-selected={isActive}
type="button"
- className={`w-full flex items-start gap-3 px-4 py-2.5 text-left transition-colors duration-75 cursor-pointer ${
- isActive ? "bg-blue-50" : "hover:bg-gray-50"
+ className={`mx-2 flex w-[calc(100%-1rem)] items-center gap-3 rounded-lg px-2.5 py-2.5 text-left transition-colors duration-75 ${
+ isActive ? "bg-gray-3" : "hover:bg-gray-2"
}`}
- onClick={() => navigateTo(item.slug)}
- onMouseEnter={() => setActiveIndex(currentIndex)}
+ onClick={() => selectItem(item)}
+ onMouseEnter={() => setActiveIndex(index)}
>
- <FileText
- className={`w-4 h-4 mt-0.5 shrink-0 ${
- isActive ? "text-blue-500" : "text-gray-400"
- }`}
- />
- <div className="min-w-0 flex-1">
- <div
- className={`text-sm font-medium truncate ${
- isActive ? "text-blue-900" : "text-gray-900"
- }`}
- >
- {item.title}
- </div>
- {item.summary && (
- <div className="text-xs text-gray-500 mt-0.5 truncate">
- {truncateSummary(item.summary)}
+ {item.type === "ask" ? (
+ <MessageCircle className="size-4 shrink-0 text-gray-9" />
+ ) : (
+ <FileText className="size-4 shrink-0 text-gray-9" />
+ )}
+ <span className="min-w-0 flex-1 truncate text-sm text-gray-12">
+ {item.type === "ask" ? (
+ query.trim() ? (
+ <>
+ Ask the docs about{" "}
+ <span className="font-medium">
+ &ldquo;{item.question}&rdquo;
+ </span>
+ </>
+ ) : (
+ item.question
+ )
+ ) : (
+ item.doc.title
+ )}
+ </span>
+ {item.type === "doc" && (
+ <span className="shrink-0 text-xs text-gray-8">
+ {item.doc.group}
+ </span>
+ )}
+ {isActive && (
+ <CornerDownLeft className="size-3.5 shrink-0 text-gray-8" />
+ )}
+ </button>
+ </div>
+ );
+ })}
+ </div>
+ ) : (
+ <div
+ ref={conversationRef}
+ onScroll={(e) => {
+ const el = e.currentTarget;
+ stickToBottomRef.current =
+ el.scrollHeight - el.scrollTop - el.clientHeight < 80;
+ }}
+ className="flex-1 overflow-y-auto overscroll-contain px-5 py-4 [scrollbar-width:thin]"
+ >
+ {showAskIntro ? (
+ <div className="py-2">
+ <p className="text-sm font-medium text-gray-12">
+ Ask anything about Cap
+ </p>
+ <p className="mt-1 text-[13px] leading-5 text-gray-10">
+ Get instant answers from the documentation, with links to the
+ right pages.
+ </p>
+ <div className="mt-4 flex flex-col items-start gap-1.5">
+ {EXAMPLE_QUESTIONS.map((question) => (
+ <button
+ key={question}
+ type="button"
+ onClick={() => startAsk(question)}
+ className="rounded-full border border-gray-4 bg-gray-2 px-3 py-1.5 text-[13px] text-gray-11 transition-colors hover:border-gray-5 hover:text-gray-12"
+ >
+ {question}
+ </button>
+ ))}
+ </div>
+ </div>
+ ) : (
+ <div className="flex flex-col gap-6">
+ {turns.map((turn, index) => (
+ <div key={`${index}-${turn.question}`}>
+ <p className="text-sm font-medium leading-6 text-gray-12">
+ {turn.question}
+ </p>
+ <div className="mt-2">
+ {turn.status === "error" ? (
+ <div className="flex flex-wrap items-center gap-2">
+ <p className="text-sm text-red-400">{turn.error}</p>
+ <button
+ type="button"
+ onClick={retryLastTurn}
+ className="text-sm font-medium text-blue-11 underline-offset-[3px] hover:underline"
+ >
+ Try again
+ </button>
+ </div>
+ ) : turn.answer ? (
+ <>
+ <DocsAskAnswer
+ answer={turn.answer}
+ onNavigate={close}
+ />
+ {turn.status === "streaming" && (
+ <span className="mt-1 inline-block h-4 w-1.5 animate-pulse rounded-sm bg-blue-9" />
+ )}
+ </>
+ ) : (
+ <div className="flex items-center gap-1.5 py-1">
+ <span className="size-1.5 animate-pulse rounded-full bg-gray-8" />
+ <span className="size-1.5 animate-pulse rounded-full bg-gray-8 [animation-delay:150ms]" />
+ <span className="size-1.5 animate-pulse rounded-full bg-gray-8 [animation-delay:300ms]" />
</div>
)}
</div>
- </button>
- );
- })}
- </div>
- ))}
- </div>
-
- {flatResults.length > 0 && (
- <div className="flex items-center gap-4 px-4 py-2.5 border-t border-gray-200 bg-gray-50">
- <span className="flex items-center gap-1.5 text-[11px] text-gray-400">
- <kbd className="inline-flex items-center justify-center w-5 h-5 rounded bg-white border border-gray-200 text-[10px] font-medium">
- ↑
- </kbd>
- <kbd className="inline-flex items-center justify-center w-5 h-5 rounded bg-white border border-gray-200 text-[10px] font-medium">
- ↓
- </kbd>
- <span>to navigate</span>
- </span>
- <span className="flex items-center gap-1.5 text-[11px] text-gray-400">
- <kbd className="inline-flex items-center justify-center h-5 px-1.5 rounded bg-white border border-gray-200 text-[10px] font-medium">
- ↵
- </kbd>
- <span>to select</span>
- </span>
+ </div>
+ ))}
+ </div>
+ )}
</div>
)}
+
+ <div className="flex shrink-0 items-center gap-4 border-t border-gray-3 bg-gray-2 px-4 py-2.5">
+ {mode === "search" ? (
+ <>
+ <span className="flex items-center gap-1.5 text-[11px] text-gray-9">
+ <kbd className="flex h-5 w-5 items-center justify-center rounded border border-gray-4 bg-gray-1 text-[10px] font-medium">
+ ↑
+ </kbd>
+ <kbd className="flex h-5 w-5 items-center justify-center rounded border border-gray-4 bg-gray-1 text-[10px] font-medium">
+ ↓
+ </kbd>
+ navigate
+ </span>
+ <span className="flex items-center gap-1.5 text-[11px] text-gray-9">
+ <kbd className="flex h-5 items-center rounded border border-gray-4 bg-gray-1 px-1.5 text-[10px] font-medium">
+ ↵
+ </kbd>
+ select
+ </span>
+ </>
+ ) : (
+ <span className="text-[11px] text-gray-9">
+ Powered by Claude. Check important details against the linked
+ docs.
+ </span>
+ )}
+ </div>
</div>
</div>
);
diff --git a/apps/web/app/(docs)/docs/_components/DocsSidebar.tsx b/apps/web/app/(docs)/docs/_components/DocsSidebar.tsx
index 1e028a3e2..7d95be709 100644
--- a/apps/web/app/(docs)/docs/_components/DocsSidebar.tsx
+++ b/apps/web/app/(docs)/docs/_components/DocsSidebar.tsx
@@ -1,46 +1,12 @@
-"use client";
-
-import Link from "next/link";
-import { usePathname } from "next/navigation";
-import { docsConfig, type SidebarGroup } from "../docs-config";
+import { DocsSidebarNav } from "./DocsSidebarNav";
export function DocsSidebar() {
- const pathname = usePathname();
-
- const isActive = (slug: string) => {
- return pathname === `/docs/${slug}` || pathname === `/docs/${slug}/`;
- };
-
return (
- <nav className="sticky top-14 h-[calc(100vh-56px)] w-[260px] shrink-0 overflow-y-auto border-r border-gray-200 px-4 py-6">
- <div className="flex flex-col gap-6">
- {docsConfig.sidebar.map((group: SidebarGroup) => (
- <div key={group.title}>
- <h4 className="px-3 mb-2 text-[11px] font-semibold uppercase tracking-wider text-gray-400">
- {group.title}
- </h4>
- <ul className="flex flex-col gap-0.5">
- {group.items.map((item) => {
- const active = isActive(item.slug);
- return (
- <li key={item.slug}>
- <Link
- href={`/docs/${item.slug}`}
- className={`block text-[13px] font-medium py-1.5 px-3 rounded-md transition-colors ${
- active
- ? "text-blue-500 bg-blue-50 border-l-2 border-blue-500"
- : "text-gray-600 hover:text-gray-900 hover:bg-gray-50"
- }`}
- >
- {item.title}
- </Link>
- </li>
- );
- })}
- </ul>
- </div>
- ))}
- </div>
+ <nav
+ aria-label="Documentation"
+ className="sticky top-14 h-[calc(100vh-3.5rem)] w-full overflow-y-auto py-10 pr-8 [scrollbar-width:thin]"
+ >
+ <DocsSidebarNav />
</nav>
);
}
diff --git a/apps/web/app/(docs)/docs/_components/DocsTableOfContents.tsx b/apps/web/app/(docs)/docs/_components/DocsTableOfContents.tsx
index 7a677ed83..48f890fb4 100644
--- a/apps/web/app/(docs)/docs/_components/DocsTableOfContents.tsx
+++ b/apps/web/app/(docs)/docs/_components/DocsTableOfContents.tsx
@@ -1,5 +1,6 @@
"use client";
+import { AlignLeft } from "lucide-react";
import { useEffect, useState } from "react";
interface Heading {
@@ -18,9 +19,8 @@ export function DocsTableOfContents({ headings }: DocsTableOfContentsProps) {
useEffect(() => {
if (headings.length === 0) return;
- const slugs = headings.map((h) => h.slug);
- const elements = slugs
- .map((slug) => document.getElementById(slug))
+ const elements = headings
+ .map((h) => document.getElementById(h.slug))
.filter(Boolean) as HTMLElement[];
if (elements.length === 0) return;
@@ -38,7 +38,7 @@ export function DocsTableOfContents({ headings }: DocsTableOfContentsProps) {
}
},
{
- rootMargin: "-80px 0px -60% 0px",
+ rootMargin: "-72px 0px -65% 0px",
threshold: 0,
},
);
@@ -57,21 +57,25 @@ export function DocsTableOfContents({ headings }: DocsTableOfContentsProps) {
if (filteredHeadings.length === 0) return null;
return (
- <div className="hidden xl:block sticky top-[80px] w-[200px] shrink-0 max-h-[calc(100vh-100px)] overflow-y-auto">
- <h4 className="text-[11px] font-semibold uppercase tracking-wider text-gray-400 mb-3">
+ <nav
+ aria-label="On this page"
+ className="sticky top-14 max-h-[calc(100vh-3.5rem)] overflow-y-auto py-10 [scrollbar-width:thin]"
+ >
+ <p className="mb-3 flex items-center gap-1.5 text-[13px] font-medium text-gray-12">
+ <AlignLeft className="size-3.5 text-gray-9" />
On this page
- </h4>
- <ul className="flex flex-col gap-1">
+ </p>
+ <ul className="flex flex-col">
{filteredHeadings.map((heading, index) => (
<li key={`${heading.slug}-${index}`}>
<a
href={`#${heading.slug}`}
- className={`block text-[13px] py-1 transition-colors ${
- heading.level === 3 ? "pl-3" : ""
+ className={`block py-[5px] text-[13px] leading-5 transition-colors ${
+ heading.level === 3 ? "pl-3.5" : ""
} ${
activeSlug === heading.slug
- ? "text-blue-500 font-medium"
- : "text-gray-500 hover:text-gray-700"
+ ? "font-medium text-blue-11"
+ : "text-gray-10 hover:text-gray-12"
}`}
>
{heading.text}
@@ -79,6 +83,6 @@ export function DocsTableOfContents({ headings }: DocsTableOfContentsProps) {
</li>
))}
</ul>
- </div>
+ </nav>
);
}
diff --git a/apps/web/app/(docs)/docs/layout.tsx b/apps/web/app/(docs)/docs/layout.tsx
index 854ba586a..12f82c596 100644
--- a/apps/web/app/(docs)/docs/layout.tsx
+++ b/apps/web/app/(docs)/docs/layout.tsx
@@ -10,15 +10,15 @@ export default function DocsLayout(props: PropsWithChildren) {
const searchIndex = getDocSearchIndex(docsConfig.sidebar);
return (
- <div className="min-h-screen bg-white">
+ <div className="min-h-screen bg-gray-1 text-gray-12">
<DocsHeader />
<DocsSearch searchIndex={searchIndex} />
- <div className="flex pt-14">
- <aside className="hidden lg:block w-[260px] shrink-0">
+ <DocsMobileMenu />
+ <div className="mx-auto flex max-w-[1408px] px-4 pt-14 sm:px-6">
+ <aside className="hidden w-[264px] shrink-0 lg:block">
<DocsSidebar />
</aside>
- <DocsMobileMenu />
- <main className="flex-1 min-w-0">{props.children}</main>
+ <main className="min-w-0 flex-1">{props.children}</main>
</div>
</div>
);