@varialkit/table 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs.md +617 -0
- package/examples/index.tsx +1 -0
- package/examples.tsx +1177 -0
- package/package.json +32 -0
- package/src/Table.scss +531 -0
- package/src/Table.tsx +1380 -0
- package/src/Table.types.ts +158 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Cell,
|
|
3
|
+
ColumnDef,
|
|
4
|
+
Header,
|
|
5
|
+
Row,
|
|
6
|
+
Table as TanStackTable,
|
|
7
|
+
TableOptions
|
|
8
|
+
} from '@tanstack/react-table';
|
|
9
|
+
import type { HTMLAttributes, MouseEvent, ReactNode } from 'react';
|
|
10
|
+
|
|
11
|
+
export type TableDensity = 'compact' | 'standard' | 'spacious';
|
|
12
|
+
export type TableLayoutMode = 'list' | 'grid';
|
|
13
|
+
export type TableGridType = 'grid' | 'masonry';
|
|
14
|
+
export type TableActionMenuSurfaceStyle = 'solid' | 'translucent' | 'glass';
|
|
15
|
+
|
|
16
|
+
export type TableGridSpacing = {
|
|
17
|
+
// Base gap fallback when row/column gaps are not specified.
|
|
18
|
+
gap?: number | string;
|
|
19
|
+
// Card-to-card spacing between columns.
|
|
20
|
+
columnGap?: number | string;
|
|
21
|
+
// Card-to-card spacing between rows/items.
|
|
22
|
+
rowGap?: number | string;
|
|
23
|
+
// Gap between detail fields inside each card.
|
|
24
|
+
detailsGap?: number | string;
|
|
25
|
+
// Inner padding around the details section inside each card.
|
|
26
|
+
detailsPadding?: number | string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type TablePaginationLabels = {
|
|
30
|
+
pageLabel?: string;
|
|
31
|
+
rowsLabel?: string;
|
|
32
|
+
prevLabel?: string;
|
|
33
|
+
nextLabel?: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type TableRenderBody<TData> = (
|
|
37
|
+
table: TanStackTable<TData>,
|
|
38
|
+
rows: Array<Row<TData>>
|
|
39
|
+
) => ReactNode;
|
|
40
|
+
|
|
41
|
+
export type TableRenderGridCell<TData> = (
|
|
42
|
+
cell: Cell<TData, unknown>,
|
|
43
|
+
row: Row<TData>,
|
|
44
|
+
table: TanStackTable<TData>
|
|
45
|
+
) => ReactNode;
|
|
46
|
+
|
|
47
|
+
export type TableGridCellRenderers<TData> = Record<
|
|
48
|
+
string,
|
|
49
|
+
TableRenderGridCell<TData>
|
|
50
|
+
>;
|
|
51
|
+
|
|
52
|
+
export type TableGridCellVariant = 'detail' | 'media';
|
|
53
|
+
|
|
54
|
+
export type TableGridColumnConfig = {
|
|
55
|
+
// Media cells render in the card media area (typically images/video).
|
|
56
|
+
variant?: TableGridCellVariant;
|
|
57
|
+
// Grid-only default visibility (does not affect list/TanStack column visibility).
|
|
58
|
+
hiddenByDefault?: boolean;
|
|
59
|
+
// Controls whether the cell label is shown in grid.
|
|
60
|
+
showLabel?: boolean;
|
|
61
|
+
// Removes internal grid cell padding (useful for full-bleed media).
|
|
62
|
+
unpadded?: boolean;
|
|
63
|
+
// Optional className for this grid column's cell wrapper.
|
|
64
|
+
className?: string;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type TableGridColumnConfigMap = Record<string, TableGridColumnConfig>;
|
|
68
|
+
|
|
69
|
+
export type TableProps<TData> = {
|
|
70
|
+
data: Array<TData>;
|
|
71
|
+
columns: Array<ColumnDef<TData, unknown>>;
|
|
72
|
+
// Passthrough for TanStack options (sorting, pinning, column visibility, etc.).
|
|
73
|
+
tableOptions?: Omit<TableOptions<TData>, 'data' | 'columns'>;
|
|
74
|
+
// Optional custom row id resolver used by TanStack.
|
|
75
|
+
getRowId?: TableOptions<TData>['getRowId'];
|
|
76
|
+
className?: string;
|
|
77
|
+
tableClassName?: string;
|
|
78
|
+
headerClassName?: string;
|
|
79
|
+
bodyClassName?: string;
|
|
80
|
+
// Custom content to render inside the header actions cell.
|
|
81
|
+
headerActions?: ReactNode;
|
|
82
|
+
// Toggle the built-in column controls menu (visibility + ordering).
|
|
83
|
+
enableColumnControls?: boolean;
|
|
84
|
+
// Accessible label for the built-in column controls trigger button.
|
|
85
|
+
columnControlsLabel?: string;
|
|
86
|
+
// Optional surface treatment override for the built-in gear action menu.
|
|
87
|
+
// When omitted, the menu resolves from root surface attributes.
|
|
88
|
+
actionMenuSurfaceStyle?: TableActionMenuSurfaceStyle;
|
|
89
|
+
// Optional density options for the built-in controls menu.
|
|
90
|
+
densityOptions?: TableDensity[];
|
|
91
|
+
// Optional list/grid options for the built-in controls menu.
|
|
92
|
+
layoutModeOptions?: TableLayoutMode[];
|
|
93
|
+
// Optional grid type options for the built-in controls menu (shown in grid layout).
|
|
94
|
+
gridTypeOptions?: TableGridType[];
|
|
95
|
+
// Callback invoked when a user picks a density from the controls menu.
|
|
96
|
+
// If omitted, the menu will manage density locally.
|
|
97
|
+
onDensityChange?: (density: TableDensity) => void;
|
|
98
|
+
// Enables the built-in layout switcher (list/grid) in the action menu.
|
|
99
|
+
enableLayoutToggle?: boolean;
|
|
100
|
+
// Callback invoked when a user picks a layout mode from the controls menu.
|
|
101
|
+
// If omitted, the menu will manage layout locally.
|
|
102
|
+
onLayoutModeChange?: (mode: TableLayoutMode) => void;
|
|
103
|
+
// Preferred layout mode. Defaults to list.
|
|
104
|
+
layoutMode?: TableLayoutMode;
|
|
105
|
+
rowClassName?: (row: Row<TData>) => string;
|
|
106
|
+
cellClassName?: (cell: Cell<TData, unknown>) => string;
|
|
107
|
+
headerCellClassName?: (header: Header<TData, unknown>) => string;
|
|
108
|
+
renderHeaderCell?: (header: Header<TData, unknown>) => ReactNode;
|
|
109
|
+
renderCell?: (cell: Cell<TData, unknown>) => ReactNode;
|
|
110
|
+
// Optional default renderer for grid cell values.
|
|
111
|
+
renderGridCell?: TableRenderGridCell<TData>;
|
|
112
|
+
// Optional per-column renderers for grid cell values (keyed by column id).
|
|
113
|
+
gridCellRenderers?: TableGridCellRenderers<TData>;
|
|
114
|
+
// Grid-only column presentation config keyed by column id.
|
|
115
|
+
gridColumnConfig?: TableGridColumnConfigMap;
|
|
116
|
+
// Controlled set of grid-visible column ids (grid-only, does not affect list mode).
|
|
117
|
+
gridVisibleColumnIds?: string[];
|
|
118
|
+
// Callback for grid-only visible column ids.
|
|
119
|
+
onGridVisibleColumnIdsChange?: (columnIds: string[]) => void;
|
|
120
|
+
// Optional custom grid row renderer.
|
|
121
|
+
renderGridRow?: (
|
|
122
|
+
row: Row<TData>,
|
|
123
|
+
cells: Array<ReactNode>,
|
|
124
|
+
table: TanStackTable<TData>
|
|
125
|
+
) => ReactNode;
|
|
126
|
+
// Grid presentation type used when layoutMode resolves to "grid".
|
|
127
|
+
gridType?: TableGridType;
|
|
128
|
+
// Callback invoked when a user picks a grid type from the controls menu.
|
|
129
|
+
// If omitted, the menu will manage grid type locally.
|
|
130
|
+
onGridTypeChange?: (gridType: TableGridType) => void;
|
|
131
|
+
// Optional granular spacing overrides for grid mode.
|
|
132
|
+
gridSpacing?: TableGridSpacing;
|
|
133
|
+
renderRow?: (row: Row<TData>, cells: Array<ReactNode>) => ReactNode;
|
|
134
|
+
renderBody?: TableRenderBody<TData>;
|
|
135
|
+
emptyState?: ReactNode;
|
|
136
|
+
onRowClick?: (row: Row<TData>, event: MouseEvent<HTMLElement>) => void;
|
|
137
|
+
stickyHeader?: boolean;
|
|
138
|
+
// Forces sticky header + pinned column backgrounds to be transparent.
|
|
139
|
+
transparentSticky?: boolean;
|
|
140
|
+
// Forces table/thead/tbody backgrounds to be transparent.
|
|
141
|
+
transparentBackground?: boolean;
|
|
142
|
+
showHeader?: boolean;
|
|
143
|
+
density?: TableDensity;
|
|
144
|
+
wrapperProps?: HTMLAttributes<HTMLDivElement>;
|
|
145
|
+
tableProps?: HTMLAttributes<HTMLTableElement>;
|
|
146
|
+
getRowProps?: (row: Row<TData>) => HTMLAttributes<HTMLTableRowElement>;
|
|
147
|
+
getCellProps?: (cell: Cell<TData, unknown>) => HTMLAttributes<HTMLTableCellElement>;
|
|
148
|
+
getHeaderProps?: (header: Header<TData, unknown>) => HTMLAttributes<HTMLTableCellElement>;
|
|
149
|
+
enableSorting?: boolean;
|
|
150
|
+
// Renders the built-in pagination footer (TanStack state + Solara UI).
|
|
151
|
+
showPagination?: boolean;
|
|
152
|
+
// Overrides for pagination footer labels.
|
|
153
|
+
paginationLabels?: TablePaginationLabels;
|
|
154
|
+
// Page size options for the pagination footer dropdown.
|
|
155
|
+
paginationPageSizes?: number[];
|
|
156
|
+
// CSS grid min width used by the default grid layout.
|
|
157
|
+
gridMinColumnWidth?: number | string;
|
|
158
|
+
};
|
package/src/index.ts
ADDED