diff --git a/compass/components/Table/Index.tsx b/compass/components/Table/Index.tsx index fdc11bd..0cc773b 100644 --- a/compass/components/Table/Index.tsx +++ b/compass/components/Table/Index.tsx @@ -33,10 +33,16 @@ type User = { export const Table = () => { const columnHelper = createColumnHelper(); const [presetOptions, setPresetOptions] = useState(["administrator", "volunteer", "employee"]); + const [tagColors, setTagColors] = useState(new Map()); - const handleAddTag = (newTag) => { - setPresetOptions((prevOptions) => [...prevOptions, newTag]); - } + const getTagColor = (tag: string) => { + if (!tagColors.has(tag)) { + const colors = ["bg-cyan-100", "bg-blue-100", "bg-green-100", "bg-yellow-100", "bg-purple-100"]; + const randomColor = colors[Math.floor(Math.random() * colors.length)]; + setTagColors(new Map(tagColors).set(tag, randomColor)); + } + return tagColors.get(tag); + }; const columns = [ columnHelper.display({ @@ -50,7 +56,9 @@ export const Table = () => { columnHelper.accessor("role", { cell: (info) => , }), columnHelper.accessor("email", { diff --git a/compass/components/TagsInput/Index.tsx b/compass/components/TagsInput/Index.tsx index ab9a98f..60f695c 100644 --- a/compass/components/TagsInput/Index.tsx +++ b/compass/components/TagsInput/Index.tsx @@ -11,7 +11,8 @@ interface TagsInputProps { const TagsInput: React.FC = ({ presetValue, presetOptions, - addOption, + setPresetOptions, + getTagColor }) => { const [inputValue, setInputValue] = useState(""); const [cellSelected, setCellSelected] = useState(false); @@ -49,7 +50,11 @@ const TagsInput: React.FC = ({ const handleAddTag = (e: React.KeyboardEvent) => { if (e.key === "Enter" && inputValue.trim()) { - addOption(inputValue); + // setPresetOptions((prevPreset) => { + // const uniqueSet = new Set(presetOptions); + // uniqueSet.add(inputValue); + // return Array.from(uniqueSet); + // }); setTags((prevTags) => new Set(prevTags).add(inputValue)); setOptions((prevOptions) => new Set(prevOptions).add(inputValue)); setInputValue(""); @@ -72,6 +77,7 @@ const TagsInput: React.FC = ({ }; const handleDeleteTagOption = (tagToDelete: string) => { + // setPresetOptions(presetOptions.filter(tag => tag !== tagToDelete)); setOptions((prevOptions) => { const updatedOptions = new Set(prevOptions); updatedOptions.delete(tagToDelete); diff --git a/compass/components/TagsInput/Tag.tsx b/compass/components/TagsInput/Tag.tsx index f44ba9c..c31950f 100644 --- a/compass/components/TagsInput/Tag.tsx +++ b/compass/components/TagsInput/Tag.tsx @@ -1,8 +1,10 @@ import { XMarkIcon } from "@heroicons/react/24/solid"; -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; export const Tag = ({ children, handleDelete, active = false }) => { + const [tagColor, setTagColor] = useState(''); + return ( {children}