diff --git a/compass/components/Table/Index.tsx b/compass/components/Table/Index.tsx index 756c743..53a0e13 100644 --- a/compass/components/Table/Index.tsx +++ b/compass/components/Table/Index.tsx @@ -9,9 +9,9 @@ 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 TagsInput from "../TagsInput/Index"; const usersExample = usersImport as unknown as User[]; @@ -31,17 +31,23 @@ 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", { - cell: (info) => , + cell: (info) => info.renderValue(), }), columnHelper.accessor("email", { + header: () => <> Email, cell: (info) => info.renderValue(), }), columnHelper.accessor("program", { - cell: (info) => , + cell: (info) => info.renderValue(), }), ]; @@ -53,40 +59,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/RowAction.tsx b/compass/components/Table/RowOpenAction.tsx similarity index 91% rename from compass/components/Table/RowAction.tsx rename to compass/components/Table/RowOpenAction.tsx index 37b0215..30d1cd3 100644 --- a/compass/components/Table/RowAction.tsx +++ b/compass/components/Table/RowOpenAction.tsx @@ -1,14 +1,14 @@ import Drawer from "@/components/page/Drawer"; import {ChangeEvent, useState} from "react"; -export const RowAction = ({ title }) => { +export const RowOpenAction = ({ title }) => { const [pageContent, setPageContent] = useState("") const handleDrawerContentChange = (newContent) => { setPageContent(newContent); }; - + return (
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
+
+ + ); +} diff --git a/compass/components/Table/TableAction.tsx b/compass/components/Table/TableAction.tsx index be4a309..f2a72a0 100644 --- a/compass/components/Table/TableAction.tsx +++ b/compass/components/Table/TableAction.tsx @@ -1,12 +1,36 @@ import { MagnifyingGlassIcon } from "@heroicons/react/24/solid"; +import { useRef, useState } from "react"; export const TableAction = () => { - return ( -
- Filter - Sort - -
- ); - }; - \ No newline at end of file + const searchInput = useRef(null); + const [searchActive, setSearchActive] = useState(false); + const activateSearch = () => { + setSearchActive(true); + if (searchInput.current === null) { return; } + searchInput.current.focus(); + searchInput.current.addEventListener("focusout", () => { + if (searchInput.current?.value.trim() === "") { + searchInput.current.value = ""; + deactivateSearch(); + } + }) + } + + const deactivateSearch = () => setSearchActive(false); + + return ( +
+ Filter + Sort + activateSearch()}> + + + +
+ ); +}; diff --git a/compass/components/page/Drawer.tsx b/compass/components/page/Drawer.tsx index d80cd9f..91118f3 100644 --- a/compass/components/page/Drawer.tsx +++ b/compass/components/page/Drawer.tsx @@ -26,10 +26,10 @@ const Drawer: FunctionComponent = ({ title, children, onSave, edita setEditContent(event.target.value); }; - const drawerClassName = `fixed top-0 right-0 w-1/2 h-full bg-white shadow-xl transform ease-in-out duration-300 ${ - isOpen ? "translate-x-0" : "translate-x-full" + const drawerClassName = `fixed top-0 right-0 w-1/2 h-full bg-white transform ease-in-out duration-300 ${ + isOpen ? "translate-x-0 shadow-xl" : "translate-x-full" }`; - + const saveChanges = () => { console.log(editContent); if (onSave) { @@ -39,7 +39,7 @@ const Drawer: FunctionComponent = ({ title, children, onSave, edita }; const addRow = () => { - + } return ( @@ -73,4 +73,4 @@ const Drawer: FunctionComponent = ({ title, children, onSave, edita ); }; -export default Drawer; \ No newline at end of file +export default Drawer;