Create navbar dropdown menu
This commit is contained in:
parent
160c8a626d
commit
45d97388ee
9 changed files with 170 additions and 36 deletions
|
|
@ -1,15 +1,11 @@
|
|||
<script setup lang="ts">
|
||||
import { RiArrowDropDownLine, RiSettings3Fill } from "@remixicon/vue";
|
||||
import { RiSettings3Fill } from "@remixicon/vue";
|
||||
import NavbarDropdown from "./NavbarDropdown.vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex justify-between bg-black p-2 text-white">
|
||||
<div
|
||||
class="cursor-default rounded-md bg-neutral-800 pl-2 text-lg hover:bg-neutral-700 active:bg-neutral-500"
|
||||
>
|
||||
GedächtNAS
|
||||
<RiArrowDropDownLine class="inline" />
|
||||
</div>
|
||||
<NavbarDropdown />
|
||||
<div
|
||||
class="flex items-center rounded-md bg-neutral-800 px-1 hover:bg-neutral-700 active:bg-neutral-500"
|
||||
>
|
||||
|
|
|
|||
69
gdn-app/src/components/NavbarDropdown.vue
Normal file
69
gdn-app/src/components/NavbarDropdown.vue
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<script setup lang="ts">
|
||||
import { useReposStore } from "@/stores/repos";
|
||||
import { offset, useFloating } from "@floating-ui/vue";
|
||||
import {
|
||||
RiAddLine,
|
||||
RiArrowDropDownLine,
|
||||
RiArrowDropUpLine,
|
||||
} from "@remixicon/vue";
|
||||
import { ref, useTemplateRef } from "vue";
|
||||
import NavbarDropdownEntry from "./NavbarDropdownEntry.vue";
|
||||
|
||||
const repos = useReposStore();
|
||||
|
||||
const open = ref(false);
|
||||
|
||||
// https://floating-ui.com/docs/vue
|
||||
const reference = useTemplateRef("reference");
|
||||
const floating = useTemplateRef("floating");
|
||||
const { floatingStyles } = useFloating(reference, floating, {
|
||||
placement: "bottom-start",
|
||||
middleware: [offset(4)],
|
||||
});
|
||||
|
||||
function onAddNewRepo() {
|
||||
repos.addRepo({ id: "test", name: "test" });
|
||||
console.log(repos.selectedRepo);
|
||||
open.value = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- Navbar entry -->
|
||||
<div
|
||||
ref="reference"
|
||||
class="relative cursor-default rounded-md bg-neutral-800 pl-2 text-lg font-light hover:bg-neutral-700 active:bg-neutral-500"
|
||||
@click="open = !open"
|
||||
>
|
||||
<span v-if="repos.selectedRepo">{{ repos.selectedRepo.name }}</span>
|
||||
<span v-else class="italic">no repo selected</span>
|
||||
|
||||
<RiArrowDropUpLine v-if="open" class="inline" />
|
||||
<RiArrowDropDownLine v-else class="inline" />
|
||||
</div>
|
||||
|
||||
<!-- Close dropdown when clicking outside it -->
|
||||
<div
|
||||
v-if="open"
|
||||
class="fixed left-0 top-0 h-screen w-screen"
|
||||
@click="open = false"
|
||||
></div>
|
||||
|
||||
<!-- Dropdown -->
|
||||
<div
|
||||
v-if="open"
|
||||
ref="floating"
|
||||
class="absolute left-0 top-0 w-fit min-w-48 rounded-md bg-neutral-800 font-light"
|
||||
:style="floatingStyles"
|
||||
>
|
||||
<NavbarDropdownEntry
|
||||
v-for="repo of repos.reposByName"
|
||||
:class="{ 'font-medium': repo.id === repos.selectedRepoId }"
|
||||
>{{ repo.name }}</NavbarDropdownEntry
|
||||
>
|
||||
<hr v-if="repos.reposByName.length > 0" class="m-1 text-neutral-700" />
|
||||
<NavbarDropdownEntry class="italic" @click="onAddNewRepo">
|
||||
<RiAddLine class="-ml-2 inline h-4" />add new repo
|
||||
</NavbarDropdownEntry>
|
||||
</div>
|
||||
</template>
|
||||
7
gdn-app/src/components/NavbarDropdownEntry.vue
Normal file
7
gdn-app/src/components/NavbarDropdownEntry.vue
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<template>
|
||||
<div class="m-1">
|
||||
<div class="cursor-pointer select-none rounded px-2 hover:bg-neutral-700">
|
||||
<slot></slot>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
<script setup lang="ts">
|
||||
import { useFooStore } from "@/stores/foo";
|
||||
|
||||
const foo = useFooStore();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
Foo is {{ foo.name }}.
|
||||
<button @click="foo.setName('bar')">Change to bar.</button>
|
||||
</template>
|
||||
Loading…
Add table
Add a link
Reference in a new issue