Skip to content

A continuation of HomeBox the inventory and organization system built for the Home User

feat: improve sidebar for collections

tonyaelliecff8f7740abf
diff --git a/frontend/components/ui/collapsible/Collapsible.vue b/frontend/components/ui/collapsible/Collapsible.vue
new file mode 100644
index 00000000..77d575e8
--- /dev/null
+++ b/frontend/components/ui/collapsible/Collapsible.vue
@@ -0,0 +1,15 @@
+<script setup lang="ts">
+import type { CollapsibleRootEmits, CollapsibleRootProps } from "reka-ui"
+import { CollapsibleRoot, useForwardPropsEmits } from "reka-ui"
+
+const props = defineProps<CollapsibleRootProps>()
+const emits = defineEmits<CollapsibleRootEmits>()
+
+const forwarded = useForwardPropsEmits(props, emits)
+</script>
+
+<template>
+ <CollapsibleRoot v-slot="{ open }" v-bind="forwarded">
+ <slot :open="open" />
+ </CollapsibleRoot>
+</template>
diff --git a/frontend/components/ui/collapsible/CollapsibleContent.vue b/frontend/components/ui/collapsible/CollapsibleContent.vue
new file mode 100644
index 00000000..56fab10f
--- /dev/null
+++ b/frontend/components/ui/collapsible/CollapsibleContent.vue
@@ -0,0 +1,12 @@
+<script setup lang="ts">
+import type { CollapsibleContentProps } from "reka-ui"
+import { CollapsibleContent } from "reka-ui"
+
+const props = defineProps<CollapsibleContentProps>()
+</script>
+
+<template>
+ <CollapsibleContent v-bind="props" class="overflow-hidden transition-all data-[state=closed]:animate-collapsible-up data-[state=open]:animate-collapsible-down">
+ <slot />
+ </CollapsibleContent>
+</template>
diff --git a/frontend/components/ui/collapsible/CollapsibleTrigger.vue b/frontend/components/ui/collapsible/CollapsibleTrigger.vue
new file mode 100644
index 00000000..05bc3f1d
--- /dev/null
+++ b/frontend/components/ui/collapsible/CollapsibleTrigger.vue
@@ -0,0 +1,12 @@
+<script setup lang="ts">
+import type { CollapsibleTriggerProps } from "reka-ui"
+import { CollapsibleTrigger } from "reka-ui"
+
+const props = defineProps<CollapsibleTriggerProps>()
+</script>
+
+<template>
+ <CollapsibleTrigger v-bind="props">
+ <slot />
+ </CollapsibleTrigger>
+</template>
diff --git a/frontend/components/ui/collapsible/index.ts b/frontend/components/ui/collapsible/index.ts
new file mode 100644
index 00000000..86a031d5
--- /dev/null
+++ b/frontend/components/ui/collapsible/index.ts
@@ -0,0 +1,3 @@
+export { default as Collapsible } from "./Collapsible.vue"
+export { default as CollapsibleContent } from "./CollapsibleContent.vue"
+export { default as CollapsibleTrigger } from "./CollapsibleTrigger.vue"
diff --git a/frontend/layouts/default.vue b/frontend/layouts/default.vue
index 04a7db6c..5d52d171 100644
--- a/frontend/layouts/default.vue
+++ b/frontend/layouts/default.vue
@@ -65,19 +65,63 @@
<SidebarContent>
<SidebarGroup>
<SidebarMenu>
- <SidebarMenuItem v-for="n in nav" :key="n.id">
- <SidebarMenuLink
- :href="n.to"
- :class="{
- 'bg-accent text-accent-foreground': n.active?.value,
- 'text-nowrap': typeof locale === 'string' && locale.startsWith('zh-'),
- }"
- :tooltip="n.name.value"
- >
- <component :is="n.icon" />
- <span>{{ n.name.value }}</span>
- </SidebarMenuLink>
- </SidebarMenuItem>
+ <template v-for="n in nav" :key="n.id">
+ <SidebarMenuItem v-if="!n.collapsible" :key="n.id">
+ <SidebarMenuLink
+ :href="n.to"
+ :class="{
+ 'bg-accent text-accent-foreground': n.active?.value,
+ 'text-nowrap': typeof locale === 'string' && locale.startsWith('zh-'),
+ }"
+ :tooltip="n.name.value"
+ >
+ <component :is="n.icon" />
+ <span>{{ n.name.value }}</span>
+ </SidebarMenuLink>
+ </SidebarMenuItem>
+
+ <Collapsible v-else default-open class="group/collapsible">
+ <SidebarMenuItem>
+ <SidebarMenuItem class="flex gap-1">
+ <SidebarMenuLink
+ :href="n.to"
+ :class="{
+ 'bg-accent text-accent-foreground': n.active?.value,
+ 'text-nowrap': typeof locale === 'string' && locale.startsWith('zh-'),
+ }"
+ :tooltip="n.name.value"
+ >
+ <component :is="n.icon" />
+ <span>{{ n.name.value }}</span>
+ </SidebarMenuLink>
+ <CollapsibleTrigger as-child>
+ <SidebarMenuButton class="flex size-12 items-center justify-center">
+ <MdiChevronRight
+ class="transition-transform duration-200 group-data-[state=open]/collapsible:rotate-90"
+ />
+ </SidebarMenuButton>
+ </CollapsibleTrigger>
+ </SidebarMenuItem>
+ <CollapsibleContent>
+ <SidebarMenuSub>
+ <SidebarMenuSubItem v-for="c in n.collapsible" :key="c.id">
+ <SidebarMenuLink
+ :href="c.to"
+ :class="{
+ 'bg-accent text-accent-foreground': c.active?.value,
+ 'text-nowrap': typeof locale === 'string' && locale.startsWith('zh-'),
+ 'h-min py-0': true,
+ }"
+ :tooltip="c.name.value"
+ >
+ <span>{{ c.name.value }}</span>
+ </SidebarMenuLink>
+ </SidebarMenuSubItem>
+ </SidebarMenuSub>
+ </CollapsibleContent>
+ </SidebarMenuItem>
+ </Collapsible>
+ </template>
<!-- makes scanner accessible easily if using legacy header -->
<SidebarMenuItem v-if="preferences.displayLegacyHeader">
@@ -191,6 +235,7 @@
import MdiPlus from "~icons/mdi/plus";
import MdiLogout from "~icons/mdi/logout";
import MdiFileDocumentMultiple from "~icons/mdi/file-document-multiple";
+ import MdiChevronRight from "~icons/mdi/chevron-right";
import {
Sidebar,
@@ -201,6 +246,8 @@
SidebarHeader,
SidebarInset,
SidebarMenu,
+ SidebarMenuSub,
+ SidebarMenuSubItem,
SidebarMenuButton,
SidebarMenuItem,
SidebarMenuLink,
@@ -214,6 +261,7 @@
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
+ import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";
import { Shortcut } from "~/components/ui/shortcut";
import { useDialog } from "~/components/ui/dialog-provider";
import { Input } from "~/components/ui/input";
@@ -321,7 +369,19 @@
const route = useRoute();
- const nav = [
+ const nav: {
+ icon: Component;
+ active: ComputedRef<boolean>;
+ id: number;
+ name: ComputedRef<string>;
+ to: string;
+ collapsible?: {
+ active: ComputedRef<boolean>;
+ id: number;
+ name: ComputedRef<string>;
+ to: string;
+ }[];
+ }[] = [
{
icon: MdiHome,
active: computed(() => route.path === "/home"),
@@ -368,8 +428,40 @@
icon: MdiCog,
id: 6,
active: computed(() => route.path.includes("/collection")),
- name: computed(() => t("menu.collection_options")),
+ name: computed(() => t("menu.collection")),
to: "/collection/members",
+ collapsible: [
+ {
+ id: 61,
+ active: computed(() => route.path === "/collection/members"),
+ name: computed(() => t("collection.tabs.members")),
+ to: "/collection/members",
+ },
+ {
+ id: 62,
+ active: computed(() => route.path === "/collection/invites"),
+ name: computed(() => t("collection.tabs.invites")),
+ to: "/collection/invites",
+ },
+ {
+ id: 63,
+ active: computed(() => route.path === "/collection/notifiers"),
+ name: computed(() => t("collection.tabs.notifiers")),
+ to: "/collection/notifiers",
+ },
+ {
+ id: 64,
+ active: computed(() => route.path === "/collection/settings"),
+ name: computed(() => t("collection.tabs.settings")),
+ to: "/collection/settings",
+ },
+ {
+ id: 65,
+ active: computed(() => route.path === "/collection/tools"),
+ name: computed(() => t("collection.tabs.tools")),
+ to: "/collection/tools",
+ },
+ ],
},
];
diff --git a/frontend/locales/en.json b/frontend/locales/en.json
index f8a6fa94..5b74f422 100644
--- a/frontend/locales/en.json
+++ b/frontend/locales/en.json
@@ -660,7 +660,7 @@
"scanner": "Scanner",
"search": "Search",
"templates": "Templates",
- "collection_options": "Collection Options"
+ "collection": "Collection"
},
"pages": {
"templates": {