diff --git a/compass/components/Table/Index.tsx b/compass/components/Table/Index.tsx index 77b597f..444e2f6 100644 --- a/compass/components/Table/Index.tsx +++ b/compass/components/Table/Index.tsx @@ -8,8 +8,7 @@ import { getCoreRowModel, useReactTable, } from "@tanstack/react-table"; - -import { useState } from "react"; +import { useState, useEffect } from "react"; import { RowOptionMenu } from "./RowOptionMenu"; import { RowOpenAction } from "./RowOpenAction"; import { TableAction } from "./TableAction"; @@ -33,6 +32,18 @@ type User = { export const Table = () => { const columnHelper = createColumnHelper(); + const [presetOptions, setPresetOptions] = useState(["administrator", "volunteer", "employee"]); + const [tagColors, setTagColors] = useState(new Map()); + + 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({ id: "options", @@ -43,7 +54,12 @@ export const Table = () => { cell: (info) => , }), columnHelper.accessor("role", { - cell: (info) => , + cell: (info) => , }), columnHelper.accessor("email", { header: () => <> Email, diff --git a/compass/components/TagsInput/Index.tsx b/compass/components/TagsInput/Index.tsx index ca0c947..60f695c 100644 --- a/compass/components/TagsInput/Index.tsx +++ b/compass/components/TagsInput/Index.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useState, useRef } from "react"; import "tailwindcss/tailwind.css"; import { TagsArray } from "./TagsArray"; import { TagDropdown } from "./TagDropdown"; @@ -11,6 +11,8 @@ interface TagsInputProps { const TagsInput: React.FC = ({ presetValue, presetOptions, + setPresetOptions, + getTagColor }) => { const [inputValue, setInputValue] = useState(""); const [cellSelected, setCellSelected] = useState(false); @@ -18,13 +20,41 @@ const TagsInput: React.FC = ({ new Set(presetValue ? [presetValue] : []) ); const [options, setOptions] = useState>(new Set(presetOptions)); + const dropdown = useRef(null); + + const handleClick = () => { + if (!cellSelected) { + setCellSelected(true); + // Add event listener only after setting cellSelected to true + setTimeout(() => { + window.addEventListener("click", handleOutsideClick); + }, 100); + } + } + + const handleOutsideClick = (event) => { + if (dropdown.current && !dropdown.current.contains(event.target)) { + setCellSelected(false); + // Remove event listener after handling outside click + window.removeEventListener("click", handleOutsideClick); + } + }; const handleInputChange = (e: React.ChangeEvent) => { - setInputValue(e.target.value); + setOptions(() => { + const newOptions = presetOptions.filter(item => item.includes(e.target.value.toLowerCase())); + return new Set(newOptions); + }) + setInputValue(e.target.value); // Update input value state }; const handleAddTag = (e: React.KeyboardEvent) => { if (e.key === "Enter" && inputValue.trim()) { + // 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(""); @@ -47,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); @@ -78,14 +109,13 @@ const TagsInput: React.FC = ({ }); } }; - - return ( -
setCellSelected(true)}> +
{!cellSelected ? ( ) : ( +
@@ -114,6 +144,7 @@ const TagsInput: React.FC = ({
+
)}
); diff --git a/compass/components/TagsInput/Tag.tsx b/compass/components/TagsInput/Tag.tsx index 1d5999c..c31950f 100644 --- a/compass/components/TagsInput/Tag.tsx +++ b/compass/components/TagsInput/Tag.tsx @@ -1,7 +1,10 @@ import { XMarkIcon } from "@heroicons/react/24/solid"; +import React, { useState, useEffect } from "react"; export const Tag = ({ children, handleDelete, active = false }) => { + const [tagColor, setTagColor] = useState(''); + return ( {children} @@ -12,4 +15,4 @@ export const Tag = ({ children, handleDelete, active = false }) => { )} ); -}; +}; \ No newline at end of file