From 8b81f6cb4ff2a1e9d6103a507d97adcd9b8b95d3 Mon Sep 17 00:00:00 2001 From: Advik Arora Date: Tue, 2 Apr 2024 18:42:02 -0400 Subject: [PATCH] added delete and RowOption component --- compass/components/Table/Index.tsx | 10 +++++++--- compass/components/Table/RowOption.tsx | 10 ++++++++++ compass/components/Table/RowOptionMenu.tsx | 19 ++++++++++--------- compass/package-lock.json | 1 - 4 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 compass/components/Table/RowOption.tsx diff --git a/compass/components/Table/Index.tsx b/compass/components/Table/Index.tsx index d7db0d2..ce36256 100644 --- a/compass/components/Table/Index.tsx +++ b/compass/components/Table/Index.tsx @@ -31,13 +31,17 @@ type User = { export const Table = () => { const columnHelper = createColumnHelper(); + const deleteUser = (userId) => { + setData(currentData => currentData.filter(user => user.id !== userId)); + }; + const columns = [ columnHelper.display({ id: "options", - cell: props => + cell: props => deleteUser(props.row.original.id)} /> }), columnHelper.accessor("username", { - header: () => <> Username, + header: () => <> Username, cell: (info) => , }), columnHelper.accessor("role", { @@ -99,7 +103,7 @@ export const Table = () => { className={ "p-2 " + ((1 < i && i < columns.length - 1) ? "border-x" : "") - + ((i === 0) ? "text-center px-0" : "") + + ((i === 0) ? "text-left px-0" : "") } key={cell.id}> {flexRender(cell.column.columnDef.cell, cell.getContext())} diff --git a/compass/components/Table/RowOption.tsx b/compass/components/Table/RowOption.tsx new file mode 100644 index 0000000..0514c64 --- /dev/null +++ b/compass/components/Table/RowOption.tsx @@ -0,0 +1,10 @@ +import React from 'react'; +import { TrashIcon, DocumentDuplicateIcon, ArrowUpRightIcon, EyeSlashIcon } from "@heroicons/react/24/solid"; + +export const RowOption = ({ icon: Icon, label, onClick }) => { + return ( + + ); +}; \ No newline at end of file diff --git a/compass/components/Table/RowOptionMenu.tsx b/compass/components/Table/RowOptionMenu.tsx index f7a5c92..5830fb5 100644 --- a/compass/components/Table/RowOptionMenu.tsx +++ b/compass/components/Table/RowOptionMenu.tsx @@ -1,9 +1,10 @@ //delete, duplicate, open -import { TrashIcon, DocumentDuplicateIcon, ArrowUpRightIcon, EllipsisVerticalIcon } from "@heroicons/react/24/solid"; +import { TrashIcon, DocumentDuplicateIcon, ArrowUpRightIcon, EllipsisVerticalIcon, EyeSlashIcon } from "@heroicons/react/24/solid"; +import Button from "../Button"; import { useState, useEffect, useRef } from "react"; +import { RowOption } from "./RowOption"; - -export const RowOptionMenu = () => { +export const RowOptionMenu = ( { onDelete } ) => { const [menuOpen, setMenuOpen] = useState(false); const openMenu = () => setMenuOpen(true); const closeMenu = () => setMenuOpen(false); @@ -15,12 +16,12 @@ export const RowOptionMenu = () => { <>
*]:p-1 [&>*]:px-5 [&>*]:rounded" + (!menuOpen ? " invisible" : "")} + className={"justify-start border border-gray-200 shadow-lg flex flex-col absolute bg-white w-auto p-2 rounded [&>*]:rounded" + (!menuOpen ? " invisible" : "")} > -
Delete
-
Duplicate
-
Open
-
- + + { /* handle open */ }} /> + { /* handle hide */ }} /> + + ); } diff --git a/compass/package-lock.json b/compass/package-lock.json index 1c26973..fd7ab14 100644 --- a/compass/package-lock.json +++ b/compass/package-lock.json @@ -4395,4 +4395,3 @@ } } } -