From c6a7dd798ea36a5eb1c6f2628937eda550713af5 Mon Sep 17 00:00:00 2001 From: Dean Sallinen <7519573+deansallinen@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:29:10 -0800 Subject: [PATCH] feat: mobile page menu --- .../components/navigation/pillgroup.svelte | 63 ++++++++++++++++--- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/src/lib/components/navigation/pillgroup.svelte b/src/lib/components/navigation/pillgroup.svelte index 0a665f760..a792ea10e 100644 --- a/src/lib/components/navigation/pillgroup.svelte +++ b/src/lib/components/navigation/pillgroup.svelte @@ -2,9 +2,12 @@ import Button from '$lib/components/button/button.svelte'; import { page } from '$app/stores'; import { cn } from '$lib/utils'; - import type { ComponentProps } from 'svelte'; + import { createSelect, melt } from '@melt-ui/svelte'; + import { fade } from 'svelte/transition'; + import { ChevronDown } from 'lucide-svelte'; - interface Option extends Omit, 'children'> { + interface Option { + href: string; text: string; } @@ -13,19 +16,31 @@ class?: string; } - const { class: className, ...props }: Props = $props(); + const { class: className, options, ...props }: Props = $props(); let pathWithoutLanguageTag = $derived($page.url.pathname.slice(3)); - const isCurrent = (option: Option) => pathWithoutLanguageTag === option.href; + const isCurrent = (href: string) => pathWithoutLanguageTag === href; + + const { + elements: { trigger, menu, option }, + states: { selectedLabel, open } + } = createSelect({ + forceVisible: true, + positioning: { + placement: 'bottom', + fitViewport: true, + sameWidth: true + } + }); - - {#each props.options as option} + + {#each options as option}
  • {/each}
    + +
    + + + {#if $open} + + {#each options as { href, text }} +
  • + + {text} + +
  • + {/each} +
    + {/if} +