diff --git a/frontend/app/element/directorytable.less b/frontend/app/element/directorytable.less index fd498fb72..1a6ba514d 100644 --- a/frontend/app/element/directorytable.less +++ b/frontend/app/element/directorytable.less @@ -1,17 +1,48 @@ .dir-table { + overflow: auto; + width: 100%; + border: 2px solid var(--border-color); + border-radius: 3px; .dir-table-head { .dir-table-head-row { + display: flex; + border-bottom: 2px solid var(--border-color); + padding: 4px 0; .dir-table-head-cell { + position: relative; + padding: 2px 4px; + .dir-table-head-resize { + position: absolute; + top: 0; + right: 0; + height: 100%; + cursor: col-resize; + user-select: none; + touch-action: none; + width: 2px; + background: linear-gradient(var(--border-color), var(--border-color)) no-repeat center/2px 100%; + } + + &:last-child { + .dir-table-head-resize { + width: 0; + } + } } } } .dir-table-body { .dir-table-body-row { + display: flex; + border-radius: 3px; &:focus { - background-color: var(--highlight-bg-color); + background-color: var(--accent-color); } + .dir-table-body-cell { + overflow: hidden; + padding: 0.25rem; } } } diff --git a/frontend/app/element/directorytable.tsx b/frontend/app/element/directorytable.tsx index 18867f2c6..606aa6c13 100644 --- a/frontend/app/element/directorytable.tsx +++ b/frontend/app/element/directorytable.tsx @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import React from "react"; -import { createColumnHelper, flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table"; +import { createColumnHelper, flexRender, getCoreRowModel, useReactTable, Table } from "@tanstack/react-table"; import "./directorytable.less"; @@ -36,34 +36,73 @@ function DirectoryTable({ data }: DirectoryTableProps) { getCoreRowModel: getCoreRowModel(), }); + const columnSizeVars = React.useMemo(() => { + const headers = table.getFlatHeaders(); + const colSizes: { [key: string]: number } = {}; + for (let i = 0; i < headers.length; i++) { + const header = headers[i]!; + colSizes[`--header-${header.id}-size`] = header.getSize(); + colSizes[`--col-${header.column.id}-size`] = header.column.getSize(); + } + return colSizes; + }, [table.getState().columnSizingInfo]); + return ( - - +
+
{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())} -
+ + {table.getState().columnSizingInfo.isResizingColumn ? ( + + ) : ( + + )} + ); } +function TableBody({ table }: { table: Table }) { + return ( +
+ {table.getRowModel().rows.map((row) => ( +
+ {row.getVisibleCells().map((cell) => ( +
+ {cell.renderValue()} +
+ ))} +
+ ))} +
+ ); +} + +const MemoizedTableBody = React.memo( + TableBody, + (prev, next) => prev.table.options.data == next.table.options.data +) as typeof TableBody; + export { DirectoryTable };