-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTabs.tsx
More file actions
58 lines (54 loc) · 1.41 KB
/
Tabs.tsx
File metadata and controls
58 lines (54 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import clsx from 'clsx';
import { Button } from '@/components/ui/button';
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from '@/components/ui/tooltip';
type TabsProps = {
currentTab: number;
onTabChange: (index: number) => void;
tabLabels: string[];
disabledTabs?: number[];
disabledReasons?: Record<number, string>;
};
export function Tabs({
currentTab,
onTabChange,
tabLabels,
disabledTabs = [],
disabledReasons = {},
}: TabsProps) {
return (
<div className="-mb-2 flex items-center gap-6 overflow-x-auto pb-2">
{tabLabels.map((label, index) => {
const isDisabled = disabledTabs.includes(index);
const reason = disabledReasons[index];
const button = (
<Button
key={label}
variant={
currentTab === index
? 'gradient-outline-active'
: 'gradient-outline'
}
onClick={() => {
if (!isDisabled) onTabChange(index);
}}
className={clsx(isDisabled && 'cursor-not-allowed opacity-50')}
>
{label.toUpperCase()}
</Button>
);
return isDisabled && reason ? (
<Tooltip key={label}>
<TooltipTrigger asChild>{button}</TooltipTrigger>
<TooltipContent>{reason}</TooltipContent>
</Tooltip>
) : (
button
);
})}
</div>
);
}