-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* vf-177 create tab component * vf-171 style tab bar * vf-171 rezise header * vf-171 add hjem to bar and remove logo button * vf-177 style login button * vf-177 center navbar * vf-177 lighten up header/tab bar and resize * vf-177 darkmode styling * vf-177 adjust to mobile view
- Loading branch information
1 parent
1c5fc40
commit 471eed9
Showing
3 changed files
with
72 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { useEffect, useRef, useState } from "react"; | ||
import routes from "@/pages/public/routes"; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
export const Tab = () => { | ||
const tabsRef = useRef<(HTMLElement | null)[]>([]); | ||
const [activeTabIndex, setActiveTabIndex] = useState<number | null>(null); | ||
const [tabUnderlineWidth, setTabUnderlineWidth] = useState(0); | ||
const [tabUnderlineLeft, setTabUnderlineLeft] = useState(0); | ||
const navigate = useNavigate(); | ||
|
||
useEffect(() => { | ||
if (activeTabIndex === null) { | ||
return; | ||
} | ||
|
||
const setTabPosition = () => { | ||
const currentTab = tabsRef.current[activeTabIndex] as HTMLElement; | ||
setTabUnderlineLeft(currentTab?.offsetLeft ?? 0); | ||
setTabUnderlineWidth(currentTab?.clientWidth ?? 0); | ||
}; | ||
|
||
setTabPosition(); | ||
}, [activeTabIndex]); | ||
|
||
return ( | ||
<div className="flew-row relative mx-auto flex h-11 rounded-full px-0.5"> | ||
<span | ||
className="absolute bottom-0 top-0 z-10 flex overflow-hidden rounded-full py-1.5 transition-all duration-300" | ||
style={{ left: tabUnderlineLeft, width: tabUnderlineWidth }} | ||
> | ||
<span className="h-full w-full rounded-full bg-vektor-blue shadow-sm" /> | ||
</span> | ||
{routes.map((route, index) => { | ||
const isActive = activeTabIndex === index; | ||
return ( | ||
<button | ||
type="button" | ||
key={route.name} | ||
ref={(el) => (tabsRef.current[index] = el)} | ||
className={`${isActive ? `text-black` : `hover:text-black text-neutral-700 dark:text-vektor-blue dark:hover:text-vektor-bg`} z-20 text-sm my-auto cursor-pointer select-none rounded-full px-4 text-center font-medium`} | ||
Check failure on line 41 in src/components/Header/Tab.tsx GitHub Actions / code-quality
|
||
onClick={() => { | ||
setActiveTabIndex(index); | ||
navigate(route.path ?? ""); | ||
}} | ||
> | ||
{route.name} | ||
</button> | ||
); | ||
})} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Tab; |