mirror of
https://github.com/cssgunc/compass.git
synced 2025-04-10 06:10:17 -04:00
cleanup and checkpoint
This commit is contained in:
parent
b1b3313de0
commit
8667ef6431
|
@ -33,10 +33,16 @@ type User = {
|
||||||
export const Table = () => {
|
export const Table = () => {
|
||||||
const columnHelper = createColumnHelper<User>();
|
const columnHelper = createColumnHelper<User>();
|
||||||
const [presetOptions, setPresetOptions] = useState(["administrator", "volunteer", "employee"]);
|
const [presetOptions, setPresetOptions] = useState(["administrator", "volunteer", "employee"]);
|
||||||
|
const [tagColors, setTagColors] = useState(new Map());
|
||||||
|
|
||||||
const handleAddTag = (newTag) => {
|
const getTagColor = (tag: string) => {
|
||||||
setPresetOptions((prevOptions) => [...prevOptions, newTag]);
|
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 = [
|
const columns = [
|
||||||
columnHelper.display({
|
columnHelper.display({
|
||||||
|
@ -50,7 +56,9 @@ export const Table = () => {
|
||||||
columnHelper.accessor("role", {
|
columnHelper.accessor("role", {
|
||||||
cell: (info) => <TagsInput presetValue={info.getValue() }
|
cell: (info) => <TagsInput presetValue={info.getValue() }
|
||||||
presetOptions={presetOptions}
|
presetOptions={presetOptions}
|
||||||
addOption={handleAddTag}
|
setPresetOptions={setPresetOptions}
|
||||||
|
getTagColor={getTagColor}
|
||||||
|
setTagColors={setTagColors}
|
||||||
/>,
|
/>,
|
||||||
}),
|
}),
|
||||||
columnHelper.accessor("email", {
|
columnHelper.accessor("email", {
|
||||||
|
|
|
@ -11,7 +11,8 @@ interface TagsInputProps {
|
||||||
const TagsInput: React.FC<TagsInputProps> = ({
|
const TagsInput: React.FC<TagsInputProps> = ({
|
||||||
presetValue,
|
presetValue,
|
||||||
presetOptions,
|
presetOptions,
|
||||||
addOption,
|
setPresetOptions,
|
||||||
|
getTagColor
|
||||||
}) => {
|
}) => {
|
||||||
const [inputValue, setInputValue] = useState("");
|
const [inputValue, setInputValue] = useState("");
|
||||||
const [cellSelected, setCellSelected] = useState(false);
|
const [cellSelected, setCellSelected] = useState(false);
|
||||||
|
@ -49,7 +50,11 @@ const TagsInput: React.FC<TagsInputProps> = ({
|
||||||
|
|
||||||
const handleAddTag = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
const handleAddTag = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
if (e.key === "Enter" && inputValue.trim()) {
|
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));
|
setTags((prevTags) => new Set(prevTags).add(inputValue));
|
||||||
setOptions((prevOptions) => new Set(prevOptions).add(inputValue));
|
setOptions((prevOptions) => new Set(prevOptions).add(inputValue));
|
||||||
setInputValue("");
|
setInputValue("");
|
||||||
|
@ -72,6 +77,7 @@ const TagsInput: React.FC<TagsInputProps> = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteTagOption = (tagToDelete: string) => {
|
const handleDeleteTagOption = (tagToDelete: string) => {
|
||||||
|
// setPresetOptions(presetOptions.filter(tag => tag !== tagToDelete));
|
||||||
setOptions((prevOptions) => {
|
setOptions((prevOptions) => {
|
||||||
const updatedOptions = new Set(prevOptions);
|
const updatedOptions = new Set(prevOptions);
|
||||||
updatedOptions.delete(tagToDelete);
|
updatedOptions.delete(tagToDelete);
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import { XMarkIcon } from "@heroicons/react/24/solid";
|
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 }) => {
|
export const Tag = ({ children, handleDelete, active = false }) => {
|
||||||
|
|
||||||
|
const [tagColor, setTagColor] = useState('');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={`font-normal bg-cyan-100 text-gray-800 flex flex-row p-1 px-2 rounded-lg`}>
|
<span className={`font-normal bg-cyan-100 text-gray-800 flex flex-row p-1 px-2 rounded-lg`}>
|
||||||
{children}
|
{children}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user