Skip to content

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

feat: tag icon selector

tonyaellie0c9a09ff8bc1
diff --git a/frontend/components/Form/IconSelector.vue b/frontend/components/Form/IconSelector.vue
new file mode 100644
index 00000000..c613d45f
--- /dev/null
+++ b/frontend/components/Form/IconSelector.vue
@@ -0,0 +1,56 @@
+<script setup lang="ts">
+ import { Label } from "~/components/ui/label";
+ import { Button } from "~/components/ui/button";
+ import { availableIcons } from "~/lib/icons";
+
+ const props = defineProps({
+ modelValue: {
+ type: String,
+ required: false,
+ default: "",
+ },
+ label: {
+ type: String,
+ default: "",
+ },
+ });
+
+ const emits = defineEmits(["update:modelValue"]);
+
+ const id = useId();
+
+ const value = useVModel(props, "modelValue", emits);
+
+ function selectIcon(iconName: string) {
+ if (value.value === iconName) {
+ value.value = "";
+ } else {
+ value.value = iconName;
+ }
+ }
+</script>
+
+<template>
+ <div class="flex w-full flex-col gap-1.5">
+ <Label :for="id" class="flex w-full px-1">
+ <span>{{ label }}</span>
+ </Label>
+ <div class="flex flex-col gap-1">
+ <!-- Grid of icon buttons -->
+ <div class="grid w-fit grid-cols-4 gap-1">
+ <Button
+ v-for="icon in availableIcons"
+ :key="icon.name"
+ type="button"
+ :variant="value === icon.name ? 'default' : 'outline'"
+ size="sm"
+ class="flex size-10 items-center justify-center p-0"
+ :aria-label="`Select ${icon.name} icon`"
+ @click="selectIcon(icon.name)"
+ >
+ <component :is="icon.component" class="size-5" />
+ </Button>
+ </div>
+ </div>
+ </div>
+</template>
diff --git a/frontend/components/Tag/CreateModal.vue b/frontend/components/Tag/CreateModal.vue
index 637b01c7..8b77a127 100644
--- a/frontend/components/Tag/CreateModal.vue
+++ b/frontend/components/Tag/CreateModal.vue
@@ -20,6 +20,7 @@
:name="$t('components.tag.create_modal.tag_parent')"
/>
<ColorSelector v-model="form.color" :label="$t('components.tag.create_modal.tag_color')" :show-hex="true" />
+ <IconSelector v-model="form.icon" :label="$t('components.tag.create_modal.tag_icon')" />
<div class="mt-4 flex flex-row-reverse">
<ButtonGroup>
<Button :disabled="loading" type="submit">{{ $t("global.create") }}</Button>
@@ -39,6 +40,7 @@
import BaseModal from "@/components/App/CreateModal.vue";
import { useDialog, useDialogHotkey } from "~/components/ui/dialog-provider";
import ColorSelector from "@/components/Form/ColorSelector.vue";
+ import IconSelector from "@/components/Form/IconSelector.vue";
import FormTextField from "~/components/Form/TextField.vue";
import FormTextArea from "~/components/Form/TextArea.vue";
import { Button, ButtonGroup } from "~/components/ui/button";
@@ -59,6 +61,7 @@
name: "",
description: "",
color: "",
+ icon: "",
parentTag: null as TagOut | null,
});
@@ -74,6 +77,7 @@
form.name = "";
form.description = "";
form.color = "";
+ form.icon = "";
form.parentTag = null;
focused.value = false;
loading.value = false;
@@ -100,7 +104,7 @@
name: form.name,
description: form.description,
color: form.color,
- icon: "",
+ icon: form.icon,
parentId: form.parentTag?.id,
});
diff --git a/frontend/lib/icons.ts b/frontend/lib/icons.ts
new file mode 100644
index 00000000..eabd4eed
--- /dev/null
+++ b/frontend/lib/icons.ts
@@ -0,0 +1,65 @@
+import MdiHome from "~icons/mdi/home";
+import MdiRoomService from "~icons/mdi/room-service";
+import MdiChair from "~icons/mdi/chair";
+import MdiLaptop from "~icons/mdi/laptop";
+import MdiWrench from "~icons/mdi/wrench";
+import MdiBook from "~icons/mdi/book";
+import MdiFileCabinet from "~icons/mdi/file-cabinet";
+import MdiDumbbell from "~icons/mdi/dumbbell";
+import MdiBasketball from "~icons/mdi/basketball";
+import MdiGamepad from "~icons/mdi/gamepad";
+import MdiToolbox from "~icons/mdi/toolbox";
+import MdiLightbulb from "~icons/mdi/lightbulb";
+import MdiPlug from "~icons/mdi/plug";
+import MdiCloset from "~icons/mdi/closet";
+import MdiMicrowave from "~icons/mdi/microwave";
+import MdiCoffee from "~icons/mdi/coffee";
+import MdiPackageVariant from "~icons/mdi/package-variant";
+
+export type IconName =
+ | "home"
+ | "room-service"
+ | "chair"
+ | "laptop"
+ | "wrench"
+ | "book"
+ | "file-cabinet"
+ | "dumbbell"
+ | "basketball"
+ | "gamepad"
+ | "toolbox"
+ | "lightbulb"
+ | "plug"
+ | "closet"
+ | "microwave"
+ | "coffee";
+
+export const availableIcons = [
+ { name: "home", component: MdiHome },
+ { name: "room-service", component: MdiRoomService },
+ { name: "chair", component: MdiChair },
+ { name: "laptop", component: MdiLaptop },
+ { name: "wrench", component: MdiWrench },
+ { name: "book", component: MdiBook },
+ { name: "file-cabinet", component: MdiFileCabinet },
+ { name: "dumbbell", component: MdiDumbbell },
+ { name: "basketball", component: MdiBasketball },
+ { name: "gamepad", component: MdiGamepad },
+ { name: "toolbox", component: MdiToolbox },
+ { name: "lightbulb", component: MdiLightbulb },
+ { name: "plug", component: MdiPlug },
+ { name: "closet", component: MdiCloset },
+ { name: "microwave", component: MdiMicrowave },
+ { name: "coffee", component: MdiCoffee },
+] as const;
+
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+export function getIconComponent(iconName: string | undefined): any {
+ if (!iconName) {
+ return defaultIcon;
+ }
+ const icon = availableIcons.find(i => i.name === iconName);
+ return icon ? icon.component : defaultIcon;
+}
+
+export const defaultIcon = MdiPackageVariant;
diff --git a/frontend/locales/en.json b/frontend/locales/en.json
index 12bdf712..267a25a3 100644
--- a/frontend/locales/en.json
+++ b/frontend/locales/en.json
@@ -312,6 +312,7 @@
"create_modal": {
"tag_color": "Tag Color",
"tag_description": "Tag Description",
+ "tag_icon": "Tag Icon",
"tag_name": "Tag Name",
"tag_parent": "Parent Tag",
"title": "Create Tag",
diff --git a/frontend/pages/tag/[id].vue b/frontend/pages/tag/[id].vue
index 9f7614ce..5043dcf6 100644
--- a/frontend/pages/tag/[id].vue
+++ b/frontend/pages/tag/[id].vue
@@ -1,7 +1,6 @@
<script setup lang="ts">
import { useI18n } from "vue-i18n";
import { toast } from "@/components/ui/sonner";
- import MdiPackageVariant from "~icons/mdi/package-variant";
import MdiPencil from "~icons/mdi/pencil";
import MdiDelete from "~icons/mdi/delete";
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
@@ -11,7 +10,9 @@
import { Badge } from "@/components/ui/badge";
import { Separator } from "@/components/ui/separator";
import ColorSelector from "@/components/Form/ColorSelector.vue";
+ import IconSelector from "@/components/Form/IconSelector.vue";
import { getContrastTextColor } from "~/lib/utils";
+ import { getIconComponent } from "~/lib/icons";
import { DialogID } from "~/components/ui/dialog-provider/utils";
import FormTextField from "~/components/Form/TextField.vue";
import FormTextArea from "~/components/Form/TextArea.vue";
@@ -75,6 +76,7 @@
name: "",
description: "",
color: "",
+ icon: "",
parentTag: null as TagOut | null,
});
@@ -112,6 +114,10 @@
});
});
+ const tagIcon = computed(() => {
+ return getIconComponent(tag.value?.icon);
+ });
+
onMounted(async () => {
await tagStore.ensureAllTagsFetched();
});
@@ -144,6 +150,7 @@
updateData.name = tag.value?.name || "";
updateData.description = tag.value?.description || "";
updateData.color = "";
+ updateData.icon = tag.value?.icon || "";
if (tag.value?.parent) {
const parent = tagStore.tags.find(t => t.id === tag.value?.parentId);
updateData.parentTag = parent || null;
@@ -164,7 +171,7 @@
name: updateData.name,
description: updateData.description,
color: updateData.color,
- icon: "",
+ icon: updateData.icon,
parentId: updateData.parentTag?.id,
});
@@ -243,6 +250,7 @@
:show-hex="true"
:starting-color="tag.color"
/>
+ <IconSelector v-model="updateData.icon" :label="$t('components.tag.create_modal.tag_icon')" />
<DialogFooter>
<Button type="submit" :loading="updating"> {{ $t("global.update") }} </Button>
</DialogFooter>
@@ -265,7 +273,7 @@
: { backgroundColor: 'hsl(var(--secondary))', color: 'hsl(var(--secondary-foreground))' }
"
>
- <MdiPackageVariant class="size-7" />
+ <component :is="tagIcon" class="size-7" />
</div>
<div>
<div v-if="tag?.parentId" class="flex flex-wrap items-center gap-2">