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:
parent
d1069c9ddd
commit
f4c55e590a
@ -72,6 +72,8 @@ export function TableList<Data>({
|
|||||||
},
|
},
|
||||||
onSortingChange: setSorting,
|
onSortingChange: setSorting,
|
||||||
getSortedRowModel: getSortedRowModel(),
|
getSortedRowModel: getSortedRowModel(),
|
||||||
|
enableColumnResizing: true,
|
||||||
|
columnResizeMode: 'onChange',
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -2,3 +2,30 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
user-select: none;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,6 +2,7 @@ import styles from "./table-header.module.scss";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import type { Table } from "@tanstack/react-table";
|
import type { Table } from "@tanstack/react-table";
|
||||||
import { flexRender } from '@tanstack/react-table';
|
import { flexRender } from '@tanstack/react-table';
|
||||||
|
import { cssNames } from "../../utils";
|
||||||
|
|
||||||
interface TableHeaderProps<Data> {
|
interface TableHeaderProps<Data> {
|
||||||
table: Table<Data>;
|
table: Table<Data>;
|
||||||
@ -13,7 +14,7 @@ export function TableHeader<Data>({ table }: TableHeaderProps<Data>) {
|
|||||||
{table.getHeaderGroups().map(headerGroup => (
|
{table.getHeaderGroups().map(headerGroup => (
|
||||||
<tr key={headerGroup.id}>
|
<tr key={headerGroup.id}>
|
||||||
{headerGroup.headers.map(header => (
|
{headerGroup.headers.map(header => (
|
||||||
<th key={header.id}>
|
<th key={header.id} style={{ position: 'relative', width: header.getSize() }}>
|
||||||
{header.isPlaceholder ? null : (
|
{header.isPlaceholder ? null : (
|
||||||
<div
|
<div
|
||||||
{...{
|
{...{
|
||||||
@ -31,6 +32,13 @@ export function TableHeader<Data>({ table }: TableHeaderProps<Data>) {
|
|||||||
asc: ' 🔼',
|
asc: ' 🔼',
|
||||||
desc: ' 🔽',
|
desc: ' 🔽',
|
||||||
}[header.column.getIsSorted() as string] ?? null}
|
}[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>
|
</div>
|
||||||
)}
|
)}
|
||||||
</th>
|
</th>
|
||||||
|
|||||||
@ -36,7 +36,7 @@
|
|||||||
<tr key={row.id}>
|
<tr key={row.id}>
|
||||||
{row.getVisibleCells().map(cell => {
|
{row.getVisibleCells().map(cell => {
|
||||||
return (
|
return (
|
||||||
<td key={cell.id}>
|
<td key={cell.id} style={{ width: cell.column.getSize() }}>
|
||||||
{flexRender(
|
{flexRender(
|
||||||
cell.column.columnDef.cell,
|
cell.column.columnDef.cell,
|
||||||
cell.getContext()
|
cell.getContext()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user