header.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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({ className }: { className?: string }) {
  20. return (
  21. <a
  22. href="https://github.com/vercel-labs/json-render"
  23. target="_blank"
  24. rel="noopener noreferrer"
  25. className={cn(
  26. "flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors",
  27. className,
  28. )}
  29. >
  30. <svg
  31. viewBox="0 0 16 16"
  32. className="h-4 w-4"
  33. fill="currentColor"
  34. aria-hidden="true"
  35. >
  36. <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" />
  37. </svg>
  38. <span>12k</span>
  39. </a>
  40. );
  41. }
  42. export function Header() {
  43. const pathname = usePathname();
  44. const [mobileOpen, setMobileOpen] = useState(false);
  45. const isActive = (href: string) => {
  46. if (href === "/playground") {
  47. return pathname === "/playground";
  48. }
  49. if (href === "/examples") {
  50. return pathname.startsWith("/examples");
  51. }
  52. if (href === "/docs") {
  53. return pathname.startsWith("/docs");
  54. }
  55. return false;
  56. };
  57. return (
  58. <header className="sticky top-0 z-50 bg-background">
  59. <div className="flex h-14 items-center justify-between px-4 gap-6">
  60. <div className="flex items-center gap-2">
  61. <Link href="https://vercel.com" title="Made with love by Vercel">
  62. <svg
  63. data-testid="geist-icon"
  64. height="18"
  65. strokeLinejoin="round"
  66. viewBox="0 0 16 16"
  67. width="18"
  68. style={{ color: "currentcolor" }}
  69. >
  70. <path
  71. fillRule="evenodd"
  72. clipRule="evenodd"
  73. d="M8 1L16 15H0L8 1Z"
  74. fill="currentColor"
  75. ></path>
  76. </svg>
  77. </Link>
  78. <span className="text-(--ds-gray-500)">
  79. <svg
  80. data-testid="geist-icon"
  81. height="16"
  82. strokeLinejoin="round"
  83. viewBox="0 0 16 16"
  84. width="16"
  85. style={{ color: "currentcolor" }}
  86. >
  87. <path
  88. fillRule="evenodd"
  89. clipRule="evenodd"
  90. 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"
  91. fill="currentColor"
  92. ></path>
  93. </svg>
  94. </span>
  95. <Link href="/">
  96. <span className="font-medium tracking-tight text-lg font-(family-name:--font-geist-pixel-square)">
  97. json-render
  98. </span>
  99. </Link>
  100. </div>
  101. {/* Desktop nav */}
  102. <nav className="hidden sm:flex items-center gap-4">
  103. {navLinks.map((link) => (
  104. <Link
  105. key={link.href}
  106. href={link.href}
  107. className={cn(
  108. "text-sm transition-colors",
  109. isActive(link.href)
  110. ? "text-primary"
  111. : "text-muted-foreground hover:text-foreground",
  112. )}
  113. >
  114. {link.label}
  115. </Link>
  116. ))}
  117. <Search />
  118. <GitHubLink />
  119. <ThemeToggle />
  120. </nav>
  121. {/* Mobile nav */}
  122. <div className="flex sm:hidden items-center gap-3">
  123. <Search />
  124. <GitHubLink />
  125. <Sheet open={mobileOpen} onOpenChange={setMobileOpen}>
  126. <SheetTrigger
  127. className="flex items-center justify-center"
  128. aria-label="Open menu"
  129. >
  130. <svg
  131. xmlns="http://www.w3.org/2000/svg"
  132. width="20"
  133. height="20"
  134. viewBox="0 0 24 24"
  135. fill="none"
  136. stroke="currentColor"
  137. strokeWidth="2"
  138. strokeLinecap="round"
  139. strokeLinejoin="round"
  140. className="text-muted-foreground"
  141. >
  142. <line x1="4" x2="20" y1="12" y2="12" />
  143. <line x1="4" x2="20" y1="6" y2="6" />
  144. <line x1="4" x2="20" y1="18" y2="18" />
  145. </svg>
  146. </SheetTrigger>
  147. <SheetContent side="right" className="overflow-y-auto p-6">
  148. <SheetTitle className="mb-6">Menu</SheetTitle>
  149. <nav className="flex flex-col gap-1">
  150. {navLinks.map((link) => (
  151. <Link
  152. key={link.href}
  153. href={link.href}
  154. onClick={() => setMobileOpen(false)}
  155. className={cn(
  156. "block py-2.5 text-sm transition-colors",
  157. isActive(link.href)
  158. ? "text-primary"
  159. : "text-muted-foreground hover:text-foreground",
  160. )}
  161. >
  162. {link.label}
  163. </Link>
  164. ))}
  165. <div className="my-3 border-t border-border" />
  166. <div className="flex items-center justify-between py-2.5">
  167. <span className="text-sm text-muted-foreground">Theme</span>
  168. <ThemeToggle />
  169. </div>
  170. </nav>
  171. </SheetContent>
  172. </Sheet>
  173. </div>
  174. </div>
  175. </header>
  176. );
  177. }