generated from gsoc2/open-sauced
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtab-list.tsx
82 lines (74 loc) · 2.38 KB
/
tab-list.tsx
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import React from "react";
import Link from "next/link";
import clsx from "clsx";
import TabListItem from "./tab-list-item";
type TabItem = {
name: string;
path: string;
};
interface TabListProps {
tabList: TabItem[];
selectedTab: string;
pageId?: string;
}
interface SubTabsListProps extends TabListProps {
label: string;
textSize?: "small" | "regular";
onSelect?: (tab: TabItem) => void;
}
const TabList = ({ tabList, pageId, selectedTab }: TabListProps) => {
return (
<nav
role="tablist"
aria-orientation="horizontal"
aria-label="Browse the tools"
className="tool-list-nav flex w-full overflow-x-auto overflow-y-hidden gap-2"
>
{tabList.map((tab, index) => (
<div
role="tab"
aria-selected={selectedTab === tab.name.toLowerCase() ? "true" : "false"}
data-state={selectedTab === tab.name.toLowerCase() ? "active" : "inactive"}
tabIndex={-1}
key={index}
className={`tool-list-item border-b-2 transition-all ease-in-out ${
selectedTab === tab.name.toLowerCase()
? "border-orange-500"
: "border-transparent hover:border-light-slate-8"
}`}
>
<TabListItem tab={tab} pageLink={`${pageId ? `${pageId}/` : ""}${tab.path}`} selectedTab={selectedTab} />
</div>
))}
</nav>
);
};
export const SubTabsList = ({ tabList, pageId, selectedTab, label, textSize, onSelect }: SubTabsListProps) => {
return (
<nav
role="tablist"
aria-label={label}
className={clsx(
"flex items-center w-max overflow-x-auto overflow-y-hidden gap-2 bg-light-slate-3 p-1 rounded",
textSize === "small" && "text-sm"
)}
>
{tabList.map((tab, index) => {
const isSelected = selectedTab === tab.name.toLowerCase();
return (
<div
role="tab"
aria-selected={isSelected ? "true" : "false"}
data-state={isSelected ? "active" : "inactive"}
key={index}
className={clsx(isSelected && "bg-white shadow", "rounded py-1 px-2", !isSelected && "text-light-slate-11")}
onClick={onSelect ? () => onSelect(tab) : undefined}
>
{onSelect ? tab.name : <Link href={`${pageId ? `${pageId}/` : ""}${tab.path}`}>{tab.name}</Link>}
</div>
);
})}
</nav>
);
};
export default TabList;