"use client" /** * Tokens secondary navigation — the body of the `tokens` panel. * * Same shape as `LibrarySecondaryNav` but simpler — flat list of * categories. URL scope: `?category=color|gradient|radius|…` (default = `all`). * * Compact mode (icon rail) and expanded mode share the same active-state * logic. Clicking the active row while already on the same href reopens the * panel (in case it was collapsed) — matching the Library "All * questions" reopen behavior. */ import * as React from "react" import { Link } from "@/lib/router-compat" import { usePathname, useSearchParams } from "@/lib/router-compat" import { Tip } from "@/components/ui/tip" import { cn } from "@/lib/utils" import { useSecondaryPanel } from "@/components/sidebar" import { CATEGORY_TABS, CATEGORY_COUNTS, TOKENS_INDEX, type TokenCategory, } from "@/components/tokens-themes-section" /** * URL value for "show everything". Centralized so consumers (panel + client + * page header subtitle) all agree on the canonical default. */ export const TOKENS_ALL_CATEGORY = "all" as const export type TokensCategoryParam = "all" | TokenCategory /** Read the active category from a `URLSearchParams`. Falls back to `"all"`. */ export function readTokensCategory(params: URLSearchParams | null): TokensCategoryParam { const raw = (params?.get("category") ?? "").toLowerCase() if (raw === TOKENS_ALL_CATEGORY) return TOKENS_ALL_CATEGORY const match = CATEGORY_TABS.find((c) => c.id === raw) return match ? (match.id as TokenCategory) : TOKENS_ALL_CATEGORY } interface CategoryEntry { id: TokensCategoryParam label: string icon: string count: number } const CATEGORY_ENTRIES: CategoryEntry[] = [ { id: TOKENS_ALL_CATEGORY, label: "All tokens", icon: "fa-grid-2", count: TOKENS_INDEX.tokenCount, }, ...CATEGORY_TABS.filter((c) => CATEGORY_COUNTS[c.id] > 0).map((c) => ({ id: c.id as TokensCategoryParam, label: c.label, icon: c.icon, count: CATEGORY_COUNTS[c.id], })), ] /** Build `?category=…` URL preserving the current pathname (tokens hub). */ function tokensCategoryHref(pathname: string, id: TokensCategoryParam): string { if (id === TOKENS_ALL_CATEGORY) return pathname return `${pathname}?category=${encodeURIComponent(id)}` } function CategoryRow({ entry, active, onActiveClick, }: { entry: CategoryEntry active: boolean onActiveClick: () => void }) { const pathname = usePathname() const href = tokensCategoryHref(pathname, entry.id) return (
  • { if (active) onActiveClick() }} aria-current={active ? "page" : undefined} className={cn( "flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset", active ? "bg-sidebar-accent font-medium text-sidebar-accent-foreground" : "text-sidebar-foreground hover:bg-sidebar-accent/50", )} >