1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Column resize initial draft

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2022-08-16 12:55:26 +03:00
parent d1069c9ddd
commit f4c55e590a
4 changed files with 39 additions and 2 deletions

View File

@ -72,6 +72,8 @@ export function TableList<Data>({
},
onSortingChange: setSorting,
getSortedRowModel: getSortedRowModel(),
enableColumnResizing: true,
columnResizeMode: 'onChange',
});
return (

View File

@ -1,4 +1,31 @@
.sortableColumn {
cursor: pointer;
user-select: none;
}
.resizer {
position: absolute;
right: 0;
top: 0;
height: 100%;
width: 5px;
background: rgba(0, 0, 0, 0.5);
cursor: col-resize;
user-select: none;
touch-action: none;
}
.resizer.isResizing {
background: blue;
opacity: 1;
}
@media (hover: hover) {
.resizer {
opacity: 0;
}
*:hover > .resizer {
opacity: 1;
}
}

View File

@ -2,6 +2,7 @@ import styles from "./table-header.module.scss";
import React from "react";
import type { Table } from "@tanstack/react-table";
import { flexRender } from '@tanstack/react-table';
import { cssNames } from "../../utils";
interface TableHeaderProps<Data> {
table: Table<Data>;
@ -13,7 +14,7 @@ export function TableHeader<Data>({ table }: TableHeaderProps<Data>) {
{table.getHeaderGroups().map(headerGroup => (
<tr key={headerGroup.id}>
{headerGroup.headers.map(header => (
<th key={header.id}>
<th key={header.id} style={{ position: 'relative', width: header.getSize() }}>
{header.isPlaceholder ? null : (
<div
{...{
@ -31,6 +32,13 @@ export function TableHeader<Data>({ table }: TableHeaderProps<Data>) {
asc: ' 🔼',
desc: ' 🔽',
}[header.column.getIsSorted() as string] ?? null}
{header.column.getCanResize() && (
<div
onMouseDown={header.getResizeHandler()}
onTouchStart={header.getResizeHandler()}
className={cssNames(styles.resizer, { [styles.isResizing]: header.column.getIsResizing() })}
></div>
)}
</div>
)}
</th>

View File

@ -36,7 +36,7 @@
<tr key={row.id}>
{row.getVisibleCells().map(cell => {
return (
<td key={cell.id}>
<td key={cell.id} style={{ width: cell.column.getSize() }}>
{flexRender(
cell.column.columnDef.cell,
cell.getContext()