Something went wrong. Try again.
source code of sayemon10.com sayemon10.com
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182<script lang="ts"> import { page } from '$app/state'; import { haptic, supportsHaptic } from '#lib/haptic/haptic.js';
const tabs = [ { name: 'Home', path: '/' }, { name: 'About', path: '/about' }, { name: 'Blog', path: '/blog' }, { name: 'Uses', path: '/uses' }, { name: 'Contact', path: '/contact' } ];
let hoveredIndex = $state<number | null>(null); let hoverStyle = $state({ left: '0px', width: '0px' }); let activeStyle = $state({ left: '0px', width: '0px' }); let tabRefs: HTMLAnchorElement[] = $state([]);
$effect(() => { if (hoveredIndex !== null) { const hoveredElement = tabRefs[hoveredIndex]; if (hoveredElement) { const { offsetLeft, offsetWidth } = hoveredElement; hoverStyle = { left: `${offsetLeft + (window.innerWidth <= 640 ? 16 : 0)}px`, width: `${offsetWidth}px` }; } } });
$effect(() => { const activeIndex = tabs.findIndex((tab) => tab.path === page.url.pathname); if (activeIndex !== -1) { const activeElement = tabRefs[activeIndex]; if (activeElement) { const { offsetLeft, offsetWidth } = activeElement; activeStyle = { left: `${offsetLeft + (window.innerWidth <= 640 ? 16 : 0)}px`, width: `${offsetWidth}px` }; } } });</script>
<div class="relative mx-auto mb-12 max-w-xl px-4 sm:px-0"> <!-- Hover Highlight --> <div class="absolute flex h-7.5 items-center rounded-[6px] bg-[#0e0f1114] transition-all duration-300 ease-out dark:bg-[#ffffff1a]" style:left={hoverStyle.left} style:width={hoverStyle.width} style:opacity={hoveredIndex !== null ? 1 : 0} ></div>
<!-- Active Indicator --> <div class="absolute -bottom-1.5 h-0.5 bg-[#0e0f11] transition-all duration-300 ease-out dark:bg-white" style:left={activeStyle.left} style:width={activeStyle.width} ></div>
<!-- Tabs --> <div class="relative flex items-center space-x-1.5"> {#each tabs as tab, index (tab.path)} {@const isActive = tab.path === page.url.pathname} <a bind:this={tabRefs[index]} href={tab.path} class="flex h-7.5 cursor-pointer items-center justify-center px-3 py-2 text-base leading-5 whitespace-nowrap transition-colors duration-300 {isActive ? 'text-black dark:text-white' : 'text-black/80 dark:text-white/80'}" title={tab.name} onmouseenter={() => (hoveredIndex = index)} onmouseleave={() => (hoveredIndex = null)} onclick={() => supportsHaptic && haptic()} > {tab.name} </a> {/each} </div></div>