header.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. "use client";
  2. import { useState } from "react";
  3. import Link from "next/link";
  4. import { usePathname } from "next/navigation";
  5. import { ThemeToggle } from "./theme-toggle";
  6. import { Search } from "./search";
  7. import {
  8. Sheet,
  9. SheetTrigger,
  10. SheetContent,
  11. SheetTitle,
  12. } from "@/components/ui/sheet";
  13. import { cn } from "@/lib/utils";
  14. const navLinks = [
  15. { href: "/playground", label: "Playground" },
  16. { href: "/examples", label: "Examples" },
  17. { href: "/docs", label: "Docs" },
  18. ];
  19. function GitHubLink({
  20. className,
  21. stars,
  22. }: {
  23. className?: string;
  24. stars?: string;
  25. }) {
  26. return (
  27. <a
  28. href="https://github.com/vercel-labs/json-render"
  29. target="_blank"
  30. rel="noopener noreferrer"
  31. className={cn(
  32. "flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors",
  33. className,
  34. )}
  35. >
  36. <svg
  37. viewBox="0 0 16 16"
  38. className="h-4 w-4"
  39. fill="currentColor"
  40. aria-hidden="true"
  41. >
  42. <path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z" />
  43. </svg>
  44. {stars && <span>{stars}</span>}
  45. </a>
  46. );
  47. }
  48. export function Header({ stars }: { stars?: string }) {
  49. const pathname = usePathname();
  50. const [mobileOpen, setMobileOpen] = useState(false);
  51. const isActive = (href: string) => {
  52. if (href === "/playground") {
  53. return pathname === "/playground";
  54. }
  55. if (href === "/examples") {
  56. return pathname.startsWith("/examples");
  57. }
  58. if (href === "/docs") {
  59. return pathname.startsWith("/docs");
  60. }
  61. return false;
  62. };
  63. return (
  64. <header className="sticky top-0 z-50 bg-background">
  65. <div className="flex h-14 items-center justify-between px-4 gap-6">
  66. <div className="flex items-center gap-2">
  67. <Link href="https://vercel.com" title="Made with love by Vercel">
  68. <svg
  69. data-testid="geist-icon"
  70. height="18"
  71. strokeLinejoin="round"
  72. viewBox="0 0 16 16"
  73. width="18"
  74. style={{ color: "currentcolor" }}
  75. >
  76. <path
  77. fillRule="evenodd"
  78. clipRule="evenodd"
  79. d="M8 1L16 15H0L8 1Z"
  80. fill="currentColor"
  81. ></path>
  82. </svg>
  83. </Link>
  84. <span className="text-(--ds-gray-500)">
  85. <svg
  86. data-testid="geist-icon"
  87. height="16"
  88. strokeLinejoin="round"
  89. viewBox="0 0 16 16"
  90. width="16"
  91. style={{ color: "currentcolor" }}
  92. >
  93. <path
  94. fillRule="evenodd"
  95. clipRule="evenodd"
  96. d="M4.01526 15.3939L4.3107 14.7046L10.3107 0.704556L10.6061 0.0151978L11.9849 0.606077L11.6894 1.29544L5.68942 15.2954L5.39398 15.9848L4.01526 15.3939Z"
  97. fill="currentColor"
  98. ></path>
  99. </svg>
  100. </span>
  101. <Link href="/">
  102. <span className="font-medium tracking-tight text-lg font-(family-name:--font-geist-pixel-square)">
  103. json-render
  104. </span>
  105. </Link>
  106. </div>
  107. {/* Desktop nav */}
  108. <nav className="hidden sm:flex items-center gap-4">
  109. {navLinks.map((link) => (
  110. <Link
  111. key={link.href}
  112. href={link.href}
  113. className={cn(
  114. "text-sm transition-colors",
  115. isActive(link.href)
  116. ? "text-primary"
  117. : "text-muted-foreground hover:text-foreground",
  118. )}
  119. >
  120. {link.label}
  121. </Link>
  122. ))}
  123. <Search />
  124. <GitHubLink stars={stars} />
  125. <ThemeToggle />
  126. </nav>
  127. {/* Mobile nav */}
  128. <div className="flex sm:hidden items-center gap-3">
  129. <Search />
  130. <GitHubLink stars={stars} />
  131. <Sheet open={mobileOpen} onOpenChange={setMobileOpen}>
  132. <SheetTrigger
  133. className="flex items-center justify-center"
  134. aria-label="Open menu"
  135. >
  136. <svg
  137. xmlns="http://www.w3.org/2000/svg"
  138. width="20"
  139. height="20"
  140. viewBox="0 0 24 24"
  141. fill="none"
  142. stroke="currentColor"
  143. strokeWidth="2"
  144. strokeLinecap="round"
  145. strokeLinejoin="round"
  146. className="text-muted-foreground"
  147. >
  148. <line x1="4" x2="20" y1="12" y2="12" />
  149. <line x1="4" x2="20" y1="6" y2="6" />
  150. <line x1="4" x2="20" y1="18" y2="18" />
  151. </svg>
  152. </SheetTrigger>
  153. <SheetContent side="right" className="overflow-y-auto p-6">
  154. <SheetTitle className="mb-6">Menu</SheetTitle>
  155. <nav className="flex flex-col gap-1">
  156. {navLinks.map((link) => (
  157. <Link
  158. key={link.href}
  159. href={link.href}
  160. onClick={() => setMobileOpen(false)}
  161. className={cn(
  162. "block py-2.5 text-sm transition-colors",
  163. isActive(link.href)
  164. ? "text-primary"
  165. : "text-muted-foreground hover:text-foreground",
  166. )}
  167. >
  168. {link.label}
  169. </Link>
  170. ))}
  171. <div className="my-3 border-t border-border" />
  172. <div className="flex items-center justify-between py-2.5">
  173. <span className="text-sm text-muted-foreground">Theme</span>
  174. <ThemeToggle />
  175. </div>
  176. </nav>
  177. </SheetContent>
  178. </Sheet>
  179. </div>
  180. </div>
  181. </header>
  182. );
  183. }