flotilla/src/lib/components/SecondaryNavItem.svelte

64 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(--radius-2xl);
2024-08-16 17:50:38 +00:00
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(0.97);
2024-08-16 17:50:38 +00:00
}
</style>
2024-08-05 21:45:16 +00:00
<script lang="ts">
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"
const {children, href = "", title = "", notification = false, ...restProps} = $props()
2024-08-06 22:46:37 +00:00
2025-02-04 00:37:14 +00:00
const active = $derived($page.url.pathname === href)
const wrapperClass = $derived(
cx(
restProps.class,
"secondary-nav__nav-item relative flex shrink-0 items-center gap-3 text-left transition-all",
{
"secondary-nav__nav-item--active": active,
"tip tip-right": title,
},
),
)
2024-08-05 21:45:16 +00:00
</script>
2024-08-16 17:50:38 +00:00
{#if href}
<a {href} {...restProps} data-tip={title} class={wrapperClass}>
{@render children?.()}
2026-02-27 20:25:16 +00:00
{#if notification}
<div
class="absolute right-[1.15rem] top-5 h-2 w-2 rounded-full bg-primary text-primary-content"
transition:fade>
2026-04-06 16:09:01 +00:00
</div>
2024-11-14 18:53:13 +00:00
{/if}
2024-08-16 17:50:38 +00:00
</a>
{:else}
<button {...restProps} data-tip={title} class={wrapperClass}>
2026-02-27 20:25:16 +00:00
{#if notification}
<div
class="absolute right-[1.15rem] top-5 h-2 w-2 rounded-full bg-primary text-primary-content"
transition:fade>
2026-04-06 16:09:01 +00:00
</div>
2024-11-14 18:53:13 +00:00
{/if}
{@render children?.()}
2024-08-16 17:50:38 +00:00
</button>
{/if}