From ef20f76a85a7ef05e5f29e677f244e7414d6a0c4 Mon Sep 17 00:00:00 2001 From: not-nullptr Date: Sat, 16 Nov 2024 11:51:41 +0000 Subject: [PATCH] feat: sliding navbar --- src/lib/components/functional/Navbar.svelte | 74 +++++++++++++++------ src/routes/convert/+page.svelte | 36 ++++++++++ 2 files changed, 88 insertions(+), 22 deletions(-) diff --git a/src/lib/components/functional/Navbar.svelte b/src/lib/components/functional/Navbar.svelte index dc00da6..41b2f5f 100644 --- a/src/lib/components/functional/Navbar.svelte +++ b/src/lib/components/functional/Navbar.svelte @@ -7,6 +7,8 @@ import { theme } from "$lib/store/index.svelte"; import { blur, duration } from "$lib/animation"; import { quintOut } from "svelte/easing"; + import { browser } from "$app/environment"; + import type { SvelteComponent } from "svelte"; type Props = { items: { @@ -19,17 +21,32 @@ }; let { items }: Props = $props(); + + let links = $state([]); + let container = $state(); + let containerRect = $derived(container?.getBoundingClientRect()); + $effect(() => { + $inspect(containerRect); + }); + + const linkRects = $derived(links.map((l) => l.getBoundingClientRect())); + + const selectedIndex = $derived( + items.findIndex((i) => i.activeMatch($page.url.pathname)), + ); -{#snippet link(item: (typeof items)[0])} +{#snippet link(item: (typeof items)[0], index: number)} {@const Icon = item.icon} @@ -117,23 +134,36 @@ {/snippet} - -
-
- +
+ + {#if linkRects[selectedIndex]} +
+ {/if} +
+
+ +
-
- {#each items as item (item.url)} - {@render link(item)} - {/each} -
- - + {#each items as item, i (item.url)} + {@render link(item, i)} + {/each} +
+ + +
diff --git a/src/routes/convert/+page.svelte b/src/routes/convert/+page.svelte index 7e54015..fe4f587 100644 --- a/src/routes/convert/+page.svelte +++ b/src/routes/convert/+page.svelte @@ -1,6 +1,8 @@ {#snippet fileItem(file: VertFile, index: number)} @@ -107,3 +110,36 @@ {/if}
+ +
+ {#if files.files.length === 1} +
+ {files.files[0].name} +
+ +
+
+ {/if} +