Update mobile subnavigation to indicate the active item

This commit is contained in:
Ramon Wenger 2024-10-26 20:57:48 +02:00
parent 6c6bbb9e22
commit 0c1a2b3151
2 changed files with 39 additions and 13 deletions

View File

@ -18,7 +18,13 @@ const isExternalLink = computed(() => {
</script> </script>
<template> <template>
<a v-if="isExternalLink" v-bind="$attrs" :href="to" target="_blank"> <a
v-if="isExternalLink"
class="flex items-center gap-2"
v-bind="$attrs"
:href="to"
target="_blank"
>
<slot /> <slot />
<it-icon-external-link /> <it-icon-external-link />
</a> </a>

View File

@ -7,10 +7,10 @@ import {
COMPETENCES_ROUTE, COMPETENCES_ROUTE,
SELF_EVALUATION_ROUTE, SELF_EVALUATION_ROUTE,
} from "@/router/names"; } from "@/router/names";
import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from "@headlessui/vue"; import { Listbox, ListboxOption, ListboxOptions } from "@headlessui/vue";
import { useTranslation } from "i18next-vue"; import { useTranslation } from "i18next-vue";
import * as log from "loglevel"; import * as log from "loglevel";
import { computed, onMounted } from "vue"; import { computed, onMounted, ref } from "vue";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
log.debug("CompetenceParentPage created"); log.debug("CompetenceParentPage created");
@ -64,31 +64,38 @@ const items = [
{ id: 3, name: t("a.Handlungskompetenzen"), route: competencesRoute }, { id: 3, name: t("a.Handlungskompetenzen"), route: competencesRoute },
{ {
id: 3, id: 4,
name: "MS Teams", name: "MS Teams",
iconName: "it-icon-external-link", iconName: "it-icon-external-link",
route: "https://iterativ.ch", route: "https://iterativ.ch",
}, },
{ {
id: 3, id: 5,
name: "Vorschau Teilnehmer", name: "Vorschau Teilnehmer",
iconName: "it-icon-external-link", iconName: "it-icon-external-link",
route: "https://iterativ.ch", route: "https://iterativ.ch",
}, },
// { id: 4, name: "Vorschau Teilnehmer", iconName: "it-icon-external-link" },
]; ];
const currentRouteName = computed(() => { const currentRouteName = computed(() => {
return items.find((item) => isCurrentRoute(item.route))?.name || ""; return items.find((item) => isCurrentRoute(item.route))?.name || "";
}); });
const open = ref<boolean>(false);
const currentRoute = ref(items.find((item) => isCurrentRoute(item.route)));
const selectRoute = (current) => {
// we use this to mimic VueRouter's active flag
open.value = false;
currentRoute.value = current;
};
</script> </script>
<template> <template>
<div class="bg-gray-200"> <div class="bg-gray-200">
<nav class="border-b bg-white px-4 lg:px-8"> <nav class="border-b bg-white px-4 lg:px-8">
<Listbox as="div"> <Listbox as="div" :model-value="currentRoute" by="id">
<div class="relative w-full"> <div class="relative w-full py-2 lg:hidden">
<ListboxButton <button
class="relative flex w-full cursor-default flex-row items-center border bg-white py-3 pl-5 pr-10 text-left" class="relative flex w-full cursor-default flex-row items-center border bg-white py-3 pl-5 pr-10 text-left"
@click="open = !open"
> >
{{ currentRouteName }} {{ currentRouteName }}
<span <span
@ -96,15 +103,28 @@ const currentRouteName = computed(() => {
> >
<it-icon-arrow-down class="h-5 w-5" aria-hidden="true" /> <it-icon-arrow-down class="h-5 w-5" aria-hidden="true" />
</span> </span>
</ListboxButton> </button>
<ListboxOptions <ListboxOptions
class="absolute top-14 flex w-full cursor-default flex-col rounded-xl border-0 bg-white text-left shadow-lg" v-if="open"
class="absolute top-14 z-50 flex w-full cursor-default flex-col rounded-xl border-0 bg-white text-left shadow-lg"
static
> >
<ListboxOption v-for="item in items" :key="item.id"> <ListboxOption
v-for="item in items"
:key="item.id"
v-slot="{ selected }"
:value="item"
class="relative w-full border-b py-3 pl-10 pr-10 last:border-b-0"
>
<SubNavItem <SubNavItem
class="flex w-full items-center gap-2 border-b py-3 pl-5 pr-10 last:border-b-0"
:to="item.route" :to="item.route"
class="flex items-center gap-2"
@click="selectRoute(item)"
> >
<it-icon-check
v-if="selected"
class="absolute left-2 top-1/2 w-8 -translate-y-1/2"
/>
{{ item.name }} {{ item.name }}
</SubNavItem> </SubNavItem>
</ListboxOption> </ListboxOption>