diff --git a/src/components/common/TagInput.jsx b/src/components/common/TagInput.jsx new file mode 100644 index 00000000..58f3d16f --- /dev/null +++ b/src/components/common/TagInput.jsx @@ -0,0 +1,68 @@ +import React, { useState, useEffect } from "react"; +import { useFormContext } from "react-hook-form"; + +const TagInput = ({ + label = "Tags", + name = "tags", + placeholder = "Enter ... ", + color = "#e9ecef", +}) => { + const [tags, setTags] = useState([]); + const [input, setInput] = useState(""); + const { setValue } = useFormContext(); + + useEffect(() => { + setValue(name, tags); // sync to form when tags change + }, [tags, name, setValue]); + + const addTag = (e) => { + e.preventDefault(); + const trimmed = input.trim(); + if (trimmed !== "" && !tags.includes(trimmed)) { + setTags([...tags, trimmed]); + setInput(""); + } + }; + + const removeTag = (removeIndex) => { + const updated = tags.filter((_, i) => i !== removeIndex); + setTags(updated); + }; + + const backgroundColor = color || "#f8f9fa"; + const iconColor = `var(--bs-${color})`; + + return ( + <> + +