From a59f9d784a1e242366c2f2a32b50132e0ffa0de3 Mon Sep 17 00:00:00 2001 From: "Andy Chan (12beesinatrenchcoat)" Date: Sun, 31 Mar 2024 00:32:25 -0400 Subject: [PATCH] Initial implementation of options menu --- compass/components/Table/Index.tsx | 93 +++++++++++++--------- compass/components/Table/RowOptionMenu.tsx | 26 ++++++ 2 files changed, 83 insertions(+), 36 deletions(-) create mode 100644 compass/components/Table/RowOptionMenu.tsx diff --git a/compass/components/Table/Index.tsx b/compass/components/Table/Index.tsx index d0c432a..d7db0d2 100644 --- a/compass/components/Table/Index.tsx +++ b/compass/components/Table/Index.tsx @@ -9,9 +9,10 @@ import { useReactTable, } from "@tanstack/react-table"; import { useState } from "react"; -import { RowAction } from "./RowAction"; +import { RowOptionMenu } from "./RowOptionMenu"; import { RowOpenAction } from "./RowOpenAction"; import { TableAction } from "./TableAction"; +import { Bars2Icon, AtSymbolIcon, HashtagIcon, ArrowDownCircleIcon } from "@heroicons/react/24/solid"; const usersExample = usersImport as unknown as User[]; @@ -31,17 +32,24 @@ export const Table = () => { const columnHelper = createColumnHelper(); const columns = [ + columnHelper.display({ + id: "options", + cell: props => + }), columnHelper.accessor("username", { - cell: (info) => , + header: () => <> Username, cell: (info) => , }), columnHelper.accessor("role", { + header: () => <> Role, cell: (info) => info.renderValue(), }), columnHelper.accessor("email", { + header: () => <> Email, cell: (info) => info.renderValue(), }), columnHelper.accessor("program", { + header: () => <> Program, cell: (info) => info.renderValue(), }), ]; @@ -54,40 +62,53 @@ export const Table = () => { getCoreRowModel: getCoreRowModel(), }); - return( + return (
-
- +
+ +
+ + + {table.getHeaderGroups().map((headerGroup) => ( + + {headerGroup.headers.map((header, i) => ( + + ))} + + ))} + + + {table.getRowModel().rows.map((row) => ( + + {row.getVisibleCells().map((cell, i) => ( + + ))} + + ))} + +
+ {header.isPlaceholder + ? null + : flexRender( + header.column.columnDef.header, + header.getContext() + )} +
+ {flexRender(cell.column.columnDef.cell, cell.getContext())} +
- - - {table.getHeaderGroups().map((headerGroup) => ( - - {headerGroup.headers.map((header) => ( - - ))} - - ))} - - - {table.getRowModel().rows.map((row) => ( - - {row.getVisibleCells().map((cell) => ( - - ))} - - ))} - -
- {header.isPlaceholder - ? null - : flexRender( - header.column.columnDef.header, - header.getContext() - )} -
- {flexRender(cell.column.columnDef.cell, cell.getContext())} -
-
) -} \ No newline at end of file +} diff --git a/compass/components/Table/RowOptionMenu.tsx b/compass/components/Table/RowOptionMenu.tsx new file mode 100644 index 0000000..f7a5c92 --- /dev/null +++ b/compass/components/Table/RowOptionMenu.tsx @@ -0,0 +1,26 @@ +//delete, duplicate, open +import { TrashIcon, DocumentDuplicateIcon, ArrowUpRightIcon, EllipsisVerticalIcon } from "@heroicons/react/24/solid"; +import { useState, useEffect, useRef } from "react"; + + +export const RowOptionMenu = () => { + const [menuOpen, setMenuOpen] = useState(false); + const openMenu = () => setMenuOpen(true); + const closeMenu = () => setMenuOpen(false); + + + // TODO: Hide menu if clicked elsewhere + + return ( + <> + +
*]:p-1 [&>*]:px-5 [&>*]:rounded" + (!menuOpen ? " invisible" : "")} + > +
Delete
+
Duplicate
+
Open
+
+ + ); +}