fix: make actions column sticky in members list (#17554)

* fix: make actions column sticky in members list

* clean up import

* change type definition

* remove old export

* include tanstack.d.ts

* fix declaration file

* move type def to packages/types/tanstack-table.d.ts

---------

Co-authored-by: Keith Williams <[email protected]>
This commit is contained in:
Eunjae LeeandKeith Williams authored and GitHub committed 2024-11-13 16:36:01 +00:00
1 parent 1ec1554cb5
commit 204e411585
4 files changed
+23 -34

No files matched your search

@@ -65,16 +65,17 @@ export function DataTable<TData, TValue>({
{table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id}>
{headerGroup.headers.map((header) => {
const meta = header.column.columnDef.meta as { sticky?: boolean; stickyLeft?: number };
const meta = header.column.columnDef.meta;
return (
<TableHead
key={header.id}
style={{
left: meta?.stickyLeft ? `${meta.stickyLeft}px` : undefined,
...(meta?.sticky?.position === "left" && { left: `${meta.sticky.gap || 0}px` }),
...(meta?.sticky?.position === "right" && { right: `${meta.sticky.gap || 0}px` }),
}}
className={classNames(
header.column.getCanSort() ? "cursor-pointer select-none" : "",
meta?.sticky && "bg-subtle sticky left-0 top-0 z-20"
meta?.sticky && "bg-subtle sticky top-0 z-20"
)}>
<div className="flex items-center" onClick={header.column.getToggleSortingHandler()}>
{header.isPlaceholder
@@ -119,16 +120,17 @@ export function DataTable<TData, TValue>({
)}>
{row.getVisibleCells().map((cell) => {
const column = table.getColumn(cell.column.id);
const meta = column?.columnDef.meta as { sticky?: boolean; stickyLeft?: number };
const meta = column?.columnDef.meta;
return (
<TableCell
key={cell.id}
style={{
left: meta?.stickyLeft ? `${meta.stickyLeft}px` : undefined,
...(meta?.sticky?.position === "left" && { left: `${meta.sticky.gap || 0}px` }),
...(meta?.sticky?.position === "right" && { right: `${meta.sticky.gap || 0}px` }),
}}
className={classNames(
variant === "compact" && "p-1.5",
meta?.sticky && "group-hover:bg-muted bg-default sticky left-0"
meta?.sticky && "group-hover:bg-muted bg-default sticky"
)}>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</TableCell>
-8
View File
@@ -1,8 +0,0 @@
import "@tanstack/react-table";
declare module "@tanstack/react-table" {
interface ColumnMeta<TData extends RowData, TValue> {
sticky?: boolean;
stickyLeft?: number;
}
}