flotilla/src/lib/components/PrimaryNavItem.svelte

44 lines
1.1 KiB
Svelte
Raw Normal View History

2024-08-05 21:45:16 +00:00
<script lang="ts">
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"
const {
children,
onclick = undefined,
title = "",
href = "",
prefix = "",
notification = false,
...restProps
} = $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 {onclick} data-tip={title} class={className}>
{@render children?.()}
{#if !active && notification}
<div class="absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-primary text-primary-content">
</div>
{/if}
</Button>
{:else}
<Link {href} data-tip={title} class={className}>
{@render children?.()}
{#if !active && notification}
<div class="absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-primary text-primary-content">
</div>
{/if}
</Link>
{/if}