diff --git a/vault/components/tag-input.tsx b/vault/components/tag-input.tsx new file mode 100644 index 0000000..c9e2ff7 --- /dev/null +++ b/vault/components/tag-input.tsx @@ -0,0 +1,54 @@ +"use client"; + +import { X } from "lucide-react"; +import { Input } from "@/components/ui/input"; + +interface TagInputProps { + tags: string[]; + onChange: (tags: string[]) => void; +} + +export function TagInput({ tags, onChange }: TagInputProps) { + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === "Enter" || e.key === ",") { + e.preventDefault(); + const val = (e.target as HTMLInputElement).value.trim(); + if (val && !tags.includes(val)) { + onChange([...tags, val]); + } + (e.target as HTMLInputElement).value = ""; + } + if (e.key === "Backspace" && (e.target as HTMLInputElement).value === "" && tags.length > 0) { + onChange(tags.slice(0, -1)); + } + }; + + const removeTag = (tag: string) => { + onChange(tags.filter((t) => t !== tag)); + }; + + return ( +
+ {tags.map((tag) => ( + + {tag} + + + ))} + +
+ ); +}