summaryrefslogblamecommitdiffstatshomepage
path: root/frontend/src/lib/navigation/Link.svelte
blob: 9c7e218d54dfc416307aa98190a7320019838aef (plain) (tree)
1
2
3
4
5
6
                  
                                          
                                                                    

                                                                    
 















                                                                                           


                                                                                   
                                                                                                      
                                      
                                              


                      
<script lang="ts">
	import { page } from '$app/state';
	import { accelerator, type Shortcut } from '$lib/Shortcuts';
	import type { Snippet } from 'svelte';
	import type { HTMLAnchorAttributes } from 'svelte/elements';

	interface Props extends Pick<HTMLAnchorAttributes, 'title' | 'target'> {
		href: string;
		accel: Shortcut;
		matchExact?: boolean;
		children?: Snippet;
	}

	let { href, title, accel, matchExact = false, target, children }: Props = $props();

	let active = $derived.by(() => {
		if (matchExact) {
			return page.url.pathname === href;
		} else {
			return page.url.pathname.startsWith(href);
		}
	});
</script>

<li class:active class="items-center hover:bg-indigo-700 [&.active]:bg-indigo-700">
	<a class="focus-background flex items-center" {target} {title} {href} use:accelerator={accel}>
		<div class="flex p-3">
			{@render children?.()}
		</div>
	</a>
</li>