Spaces:
Sleeping
Sleeping
Create frontend/src/components/ui/tabs.jsx
Browse files
frontend/src/components/ui/tabs.jsx
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { createContext, useContext } from "react";
|
| 2 |
+
import { cn } from "@/lib/utils";
|
| 3 |
+
|
| 4 |
+
const TabsContext = createContext(null);
|
| 5 |
+
|
| 6 |
+
export function Tabs({ value, onValueChange, children, className }) {
|
| 7 |
+
return (
|
| 8 |
+
<TabsContext.Provider value={{ value, onValueChange }}>
|
| 9 |
+
<div className={className}>{children}</div>
|
| 10 |
+
</TabsContext.Provider>
|
| 11 |
+
);
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
export function TabsList({ className, ...props }) {
|
| 15 |
+
return (
|
| 16 |
+
<div
|
| 17 |
+
className={cn(
|
| 18 |
+
"inline-flex items-center justify-center rounded-lg bg-slate-100 p-0.5",
|
| 19 |
+
className
|
| 20 |
+
)}
|
| 21 |
+
{...props}
|
| 22 |
+
/>
|
| 23 |
+
);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
export function TabsTrigger({ value, className, children, ...props }) {
|
| 27 |
+
const ctx = useContext(TabsContext);
|
| 28 |
+
const selected = ctx?.value === value;
|
| 29 |
+
|
| 30 |
+
return (
|
| 31 |
+
<button
|
| 32 |
+
type="button"
|
| 33 |
+
onClick={() => ctx?.onValueChange && ctx.onValueChange(value)}
|
| 34 |
+
data-state={selected ? "active" : "inactive"}
|
| 35 |
+
className={cn(
|
| 36 |
+
"inline-flex items-center justify-center rounded-md px-3 py-1.5 text-xs font-medium text-slate-600 transition-colors",
|
| 37 |
+
"data-[state=active]:bg-white data-[state=active]:text-slate-900",
|
| 38 |
+
className
|
| 39 |
+
)}
|
| 40 |
+
{...props}
|
| 41 |
+
>
|
| 42 |
+
{children}
|
| 43 |
+
</button>
|
| 44 |
+
);
|
| 45 |
+
}
|