-
-
Notifications
You must be signed in to change notification settings - Fork 225
Expand file tree
/
Copy pathTabBar.jsx
More file actions
53 lines (49 loc) · 1.69 KB
/
Copy pathTabBar.jsx
File metadata and controls
53 lines (49 loc) · 1.69 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
import { useLocation } from 'preact-iso';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
export default function TabBar({ tabs, activeTab, onTabChange, basePath, className = '' }) {
const location = useLocation();
const handleTabClick = (tabId, event) => {
if (basePath) {
event.preventDefault();
location.route(`${basePath}/${tabId}`);
} else if (onTabChange) {
onTabChange(tabId);
}
};
return (
<div className={`w-full overflow-x-auto scrollbar-none ${className}`}>
<div
role="tablist"
className="tabs tabs-border min-w-full px-1 flex-nowrap"
>
{tabs.map((tab) => {
const isActive = tab.id === activeTab;
const href = basePath ? `${basePath}/${tab.id}` : '#';
return (
<a
key={tab.id}
href={href}
onClick={(e) => handleTabClick(tab.id, e)}
onMouseEnter={() => tab.preload?.()}
onTouchStart={() => tab.preload?.()}
role="tab"
aria-selected={isActive}
aria-controls={`panel-${tab.id}`}
id={`tab-${tab.id}`}
className={`tab h-12 flex flex-row items-center justify-center gap-2 text-sm font-medium transition-all duration-150 whitespace-nowrap ${
isActive
? 'tab-active text-primary'
: 'text-base-content/60 hover:text-base-content/85'
}`}
>
{tab.icon && (
<FontAwesomeIcon icon={tab.icon} className="h-4 w-4 shrink-0" />
)}
{tab.label}
</a>
);
})}
</div>
</div>
);
}