flotilla/src/lib/components/SecondaryNavItem.svelte

66 lines
1.6 KiB
Svelte
Raw Normal View History

2024-08-16 17:50:38 +00:00
<style>
a,
button {
padding: 12px 16px;
display: flex;
border-radius: var(--rounded-btn, 0.5rem);
cursor: pointer;
animation: nav-button-pop 200ms ease-out;
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 150ms;
}
a:active:hover,
a:active:focus,
button:active:hover,
button:active:focus {
animation: button-pop 0s ease-out;
transform: scale(var(--btn-focus-scale, 0.97));
}
</style>
2024-08-05 21:45:16 +00:00
<script lang="ts">
2024-08-16 17:50:38 +00:00
import cx from "classnames"
2024-11-14 18:53:13 +00:00
import {fade} from "@lib/transition"
2024-08-06 22:46:37 +00:00
import {page} from "$app/stores"
2024-08-16 17:50:38 +00:00
export let href: string = ""
2024-11-14 18:53:13 +00:00
export let notification = false
2024-08-06 22:46:37 +00:00
2024-08-16 19:42:00 +00:00
$: active = $page.url.pathname === href
2024-08-05 21:45:16 +00:00
</script>
2024-08-16 17:50:38 +00:00
{#if href}
<a
{...$$props}
{href}
on:click
class={cx(
$$props.class,
2024-11-14 18:53:13 +00:00
"relative flex items-center gap-3 text-left transition-all hover:bg-base-100 hover:text-base-content",
2024-08-16 17:50:38 +00:00
)}
class:text-base-content={active}
class:bg-base-100={active}>
2024-08-05 21:45:16 +00:00
<slot />
2024-11-14 18:53:13 +00:00
{#if !active && notification}
2025-02-03 23:01:42 +00:00
<div class="absolute right-2 top-5 h-2 w-2 rounded-full bg-primary" transition:fade></div>
2024-11-14 18:53:13 +00:00
{/if}
2024-08-16 17:50:38 +00:00
</a>
{:else}
<button
{...$$props}
on:click
class={cx(
$$props.class,
2024-11-14 18:53:13 +00:00
"relative flex w-full items-center gap-3 text-left transition-all hover:bg-base-100 hover:text-base-content",
2024-08-16 17:50:38 +00:00
)}
class:text-base-content={active}
class:bg-base-100={active}>
2024-11-14 18:53:13 +00:00
{#if !active && notification}
2025-02-03 23:01:42 +00:00
<div class="absolute right-2 top-5 h-2 w-2 rounded-full bg-primary" transition:fade></div>
2024-11-14 18:53:13 +00:00
{/if}
2024-08-16 17:50:38 +00:00
<slot />
</button>
{/if}