tabs.tsx 894 B

123456789101112131415161718192021222324252627282930313233
  1. import * as React from "react";
  2. import { cn } from "@/lib/utils";
  3. export function Tabs({
  4. tabs,
  5. value,
  6. onChange,
  7. }: {
  8. tabs: Array<{ value: string; label: string; content: React.ReactNode }>;
  9. value: string;
  10. onChange: (value: string) => void;
  11. }) {
  12. const active = tabs.find((tab) => tab.value === value) ?? tabs[0];
  13. return (
  14. <div>
  15. <div className="flex rounded-md border border-border bg-muted/40 p-1">
  16. {tabs.map((tab) => (
  17. <button
  18. key={tab.value}
  19. className={cn(
  20. "flex-1 rounded-sm px-3 py-1.5 text-sm text-muted-foreground transition",
  21. value === tab.value && "bg-muted text-foreground",
  22. )}
  23. onClick={() => onChange(tab.value)}
  24. >
  25. {tab.label}
  26. </button>
  27. ))}
  28. </div>
  29. <div className="mt-4">{active?.content}</div>
  30. </div>
  31. );
  32. }