mirror of
https://github.com/cssgunc/compass.git
synced 2025-04-10 06:10:17 -04:00
Added dropdownAction
This commit is contained in:
parent
908cc07683
commit
f97783b9b5
|
@ -35,13 +35,13 @@ export const Table = () => {
|
||||||
cell: (info) => <RowAction title={info.getValue()} />,
|
cell: (info) => <RowAction title={info.getValue()} />,
|
||||||
}),
|
}),
|
||||||
columnHelper.accessor("role", {
|
columnHelper.accessor("role", {
|
||||||
cell: (info) => <TagsInput />,
|
cell: (info) => <TagsInput presetValue={info.getValue()} presetOptions={["Administrator","Employee","Volunteer"]} />,
|
||||||
}),
|
}),
|
||||||
columnHelper.accessor("email", {
|
columnHelper.accessor("email", {
|
||||||
cell: (info) => info.renderValue(),
|
cell: (info) => info.renderValue(),
|
||||||
}),
|
}),
|
||||||
columnHelper.accessor("program", {
|
columnHelper.accessor("program", {
|
||||||
cell: (info) => info.renderValue(),
|
cell: (info) => <TagsInput presetValue={info.getValue()} presetOptions={["Domestic","Economic","Community"]} />,
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
41
compass/components/TagsInput/DropdownAction.tsx
Normal file
41
compass/components/TagsInput/DropdownAction.tsx
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import { EllipsisHorizontalIcon } from "@heroicons/react/24/solid";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
export const DropdownAction = ({ tag }) => {
|
||||||
|
const [isVisible, setVisible] = useState(false);
|
||||||
|
const [inputValue, setInputValue] = useState(tag);
|
||||||
|
|
||||||
|
const handleBlur = () => {
|
||||||
|
setVisible(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
setInputValue(e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClick = (event: React.MouseEvent<SVGSVGElement, MouseEvent>) => {
|
||||||
|
event.stopPropagation(); // This stops the click event from propagating
|
||||||
|
setVisible(!isVisible); // Toggle visibility
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{isVisible ? (
|
||||||
|
<div className="absolute z-50 bg-white">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={inputValue}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
onBlur={handleBlur}
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<EllipsisHorizontalIcon
|
||||||
|
className="w-5 text-gray-500"
|
||||||
|
onClick={handleClick} // Attach the click event handler here
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
|
@ -1,29 +1,30 @@
|
||||||
// In a file TagsInput.tsx
|
import React, { useState } from 'react';
|
||||||
|
|
||||||
import { useState } from 'react';
|
|
||||||
import 'tailwindcss/tailwind.css';
|
import 'tailwindcss/tailwind.css';
|
||||||
import {TagsArray} from './TagsArray'; // Assuming this is the correct path
|
import { TagsArray } from './TagsArray'; // Corrected path assumption
|
||||||
import { TagDropdown } from './TagDropdown';
|
import { TagDropdown } from './TagDropdown';
|
||||||
|
|
||||||
const TagsInput = () => {
|
interface TagsInputProps {
|
||||||
|
presetOptions: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const TagsInput: React.FC<TagsInputProps> = ({ presetValue, presetOptions }) => {
|
||||||
const [inputValue, setInputValue] = useState('');
|
const [inputValue, setInputValue] = useState('');
|
||||||
const [cellSelected, setCellSelected] = useState(false);
|
const [cellSelected, setCellSelected] = useState(false);
|
||||||
const [tags, setTags] = useState<string[]>(['Administrator']);
|
const [tags, setTags] = useState<string[]>([presetValue]);
|
||||||
const [options, setOptions] = useState<string[]>(["Administrators", "Employees", "Volunteers"]);
|
const [options, setOptions] = useState<string[]>(presetOptions);
|
||||||
|
|
||||||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setInputValue(e.target.value);
|
setInputValue(e.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function to handle adding new tags when enter is pressed
|
|
||||||
const handleAddTag = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
const handleAddTag = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
if (e.key === 'Enter' && inputValue) {
|
if (e.key === 'Enter' && inputValue.trim()) {
|
||||||
setTags([...tags, inputValue]);
|
setTags(prevTags => [...prevTags, inputValue]);
|
||||||
|
setOptions(prevOptions => [...prevOptions, inputValue]);
|
||||||
setInputValue('');
|
setInputValue('');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function to handle deleting tags
|
|
||||||
const handleDeleteTag = (tagToDelete: string) => {
|
const handleDeleteTag = (tagToDelete: string) => {
|
||||||
setTags(tags.filter(tag => tag !== tagToDelete));
|
setTags(tags.filter(tag => tag !== tagToDelete));
|
||||||
};
|
};
|
||||||
|
@ -33,34 +34,30 @@ const TagsInput = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div className="w-50 cursor-pointer" onClick={() => setCellSelected(true)}>
|
||||||
className="w-full relative items-center cursor-pointer"
|
|
||||||
onClick={() => setCellSelected(true)}
|
|
||||||
>
|
|
||||||
{!cellSelected ? (
|
{!cellSelected ? (
|
||||||
<TagsArray tags={tags} />
|
<TagsArray tags={tags} />
|
||||||
) : (
|
) : (
|
||||||
<div className="absolute z-50 object-top">
|
<div className="absolute z-50 -mt-6">
|
||||||
<div className="rounded-md border border-gray-200 shadow">
|
<div className="rounded-md border border-gray-200 shadow">
|
||||||
<div className="flex flex-wrap rounded-t-md items-center gap-2 bg-gray-50 p-2">
|
<div className="flex flex-wrap rounded-t-md items-center gap-2 bg-gray-50 p-2">
|
||||||
<TagsArray active={true} tags={tags} />
|
<TagsArray active tags={tags} />
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
value={inputValue}
|
value={inputValue}
|
||||||
placeholder="Search for an option..."
|
placeholder="Search for an option..."
|
||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
onKeyDown={handleAddTag}
|
onKeyDown={handleAddTag}
|
||||||
onBlur={handleBlur}
|
onBlur={handleBlur}
|
||||||
className="focus:outline-none bg-transparent"
|
className="focus:outline-none bg-transparent"
|
||||||
autoFocus
|
autoFocus
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
<div className="flex rounded-b-md bg-white flex-col border-t border-gray-100 text-2xs font-medium text-gray-500 p-2">
|
|
||||||
Select an option or create one
|
|
||||||
<TagDropdown tags={options} />
|
|
||||||
</div>
|
</div>
|
||||||
|
<div className="flex rounded-b-md bg-white flex-col border-t border-gray-100 text-2xs font-medium text-gray-500 p-2">
|
||||||
</div>
|
Select an option or create one
|
||||||
|
<TagDropdown tags={options} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import { XMarkIcon } from "@heroicons/react/24/solid"
|
import { XMarkIcon } from "@heroicons/react/24/solid"
|
||||||
|
|
||||||
export const Tag = ({children, active = false}) => {
|
export const Tag = ({children, active = false}) => {
|
||||||
|
const handleClick = () => {
|
||||||
|
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<span className="font-normal text-gray-800 flex flex-row p-1 px-2 rounded-lg bg-blue-100">{children}
|
<span className="font-normal text-gray-800 flex flex-row p-1 px-2 rounded-lg bg-blue-100">{children}
|
||||||
{active && <XMarkIcon className="ml-1 w-3 text-blue-500" />}
|
{active && <XMarkIcon className="ml-1 w-3 text-blue-500" />}
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
import { EllipsisHorizontalIcon } from "@heroicons/react/24/solid"
|
|
||||||
import { Tag } from "./Tag"
|
|
||||||
|
|
||||||
export const TagDropdown = ({tags}) => {
|
import { Tag } from "./Tag";
|
||||||
return (
|
import { DropdownAction } from "./DropdownAction";
|
||||||
<div className="flex flex-col space-y-2 mt-2">
|
|
||||||
|
export const TagDropdown = ({ tags }) => {
|
||||||
{tags.map((tag) => {
|
return (
|
||||||
return <div className="rounded-md p-1 flex flex-row justify-between hover:bg-gray-100"><Tag>{tag}</Tag><EllipsisHorizontalIcon className="w-5 text-gray-500" /></div>
|
<div className="flex flex-col space-y-2 mt-2">
|
||||||
})}
|
{tags.map((tag, index) => (
|
||||||
|
<div key={index} className="items-center rounded-md p-1 flex flex-row justify-between hover:bg-gray-100">
|
||||||
|
<Tag>{tag}</Tag>
|
||||||
|
<DropdownAction tag={tag} />
|
||||||
</div>
|
</div>
|
||||||
)
|
))}
|
||||||
}
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user