docs-sidebar.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. "use client";
  2. import Link from "next/link";
  3. import { usePathname } from "next/navigation";
  4. import { cn } from "@/lib/utils";
  5. import { docsNavigation } from "@/lib/docs-navigation";
  6. export function DocsSidebar() {
  7. const pathname = usePathname();
  8. return (
  9. <nav className="space-y-6 pb-8">
  10. {docsNavigation.map((section) => (
  11. <div key={section.title}>
  12. <h4 className="text-xs font-normal text-muted-foreground/50 uppercase tracking-wider mb-2">
  13. {section.title}
  14. </h4>
  15. <ul className="space-y-1">
  16. {section.items.map((item) => {
  17. const isActive = pathname === item.href;
  18. const isExternal = item.external;
  19. return (
  20. <li key={item.href}>
  21. <Link
  22. href={item.href}
  23. {...(isExternal && {
  24. target: "_blank",
  25. rel: "noopener noreferrer",
  26. })}
  27. className={cn(
  28. "text-sm transition-colors block py-1",
  29. isActive
  30. ? "text-primary font-medium"
  31. : "text-muted-foreground hover:text-foreground",
  32. isExternal && "inline-flex items-center gap-1",
  33. )}
  34. >
  35. {item.title}
  36. {isExternal && (
  37. <svg
  38. className="w-3 h-3"
  39. fill="none"
  40. stroke="currentColor"
  41. viewBox="0 0 24 24"
  42. >
  43. <path
  44. strokeLinecap="round"
  45. strokeLinejoin="round"
  46. strokeWidth={2}
  47. d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"
  48. />
  49. </svg>
  50. )}
  51. </Link>
  52. </li>
  53. );
  54. })}
  55. </ul>
  56. </div>
  57. ))}
  58. </nav>
  59. );
  60. }