flotilla/src/lib/components/PrimaryNavItem.svelte

56 lines
1.4 KiB
Svelte
Raw Normal View History

2024-08-05 21:45:16 +00:00
<script lang="ts">
import type {Snippet} from "svelte"
import cx from "classnames"
2024-10-09 23:15:09 +00:00
import {page} from "$app/stores"
import Link from "@lib/components/Link.svelte"
2024-08-09 23:22:09 +00:00
import Button from "@lib/components/Button.svelte"
type Props = {
children?: Snippet
onclick?: (event: Event) => unknown
title?: string
href?: string
prefix?: string
notification?: boolean
class?: string
"aria-label"?: string
}
const {
children,
onclick,
title = "",
href = "",
prefix = "",
notification = false,
...restProps
}: Props = $props()
2024-10-09 21:19:27 +00:00
2025-02-04 00:37:14 +00:00
const active = $derived($page.url?.pathname?.startsWith(prefix || href || "bogus"))
const className = $derived(
cx(restProps.class, "primary-nav__nav-item", {
"primary-nav__nav-item--active": active,
"tip tip-right": title,
}),
)
2024-08-05 21:45:16 +00:00
</script>
{#if onclick}
<Button {...restProps} {onclick} data-tip={title} class={className}>
{@render children?.()}
{#if notification}
<div class="absolute right-1 top-1 h-2 w-2 rounded-full bg-primary text-primary-content">
</div>
{/if}
</Button>
{:else}
<Link {...restProps} {href} data-tip={title} class={className}>
{@render children?.()}
{#if notification}
<div class="absolute right-1 top-1 h-2 w-2 rounded-full bg-primary text-primary-content">
</div>
{/if}
</Link>
{/if}