@mistersee/global-table 0.1.1
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/README.md +376 -0
- package/dist/ColumnToggle.d.ts +11 -0
- package/dist/LimitSelect.d.ts +6 -0
- package/dist/Pagination.d.ts +14 -0
- package/dist/SeeTable.d.ts +5 -0
- package/dist/SkeletonRows.d.ts +5 -0
- package/dist/global-table.js +2444 -0
- package/dist/icons/CheckIcon.d.ts +3 -0
- package/dist/icons/ColumnsIcon.d.ts +3 -0
- package/dist/icons/DragHandleIcon.d.ts +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/types.d.ts +111 -0
- package/dist/utils/cn.d.ts +1 -0
- package/dist/utils/columnOrder.d.ts +8 -0
- package/dist/utils/pagination.d.ts +14 -0
- package/dist/utils/stickyOffsets.d.ts +13 -0
- package/media/demo-table.png +0 -0
- package/media/demo.png +0 -0
- package/package.json +53 -0
package/dist/index.d.ts
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export type StickySide = 'left' | 'right';
|
|
3
|
+
export interface ColumnDef<T> {
|
|
4
|
+
key: string;
|
|
5
|
+
header: ReactNode;
|
|
6
|
+
/**
|
|
7
|
+
* Optional column width override in px, or `'auto'` to fit content
|
|
8
|
+
* (e.g. action buttons). When omitted, the table uses default
|
|
9
|
+
* min-width 120px and max-width 310px.
|
|
10
|
+
*/
|
|
11
|
+
width?: number | 'auto';
|
|
12
|
+
sticky?: StickySide;
|
|
13
|
+
/** Used when building initial visibility if defaultVisibleColumns is omitted */
|
|
14
|
+
defaultVisible?: boolean;
|
|
15
|
+
cell?: (row: T, rowIndex: number) => ReactNode;
|
|
16
|
+
className?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface SeeTableClassNames {
|
|
19
|
+
root?: string;
|
|
20
|
+
toolbar?: string;
|
|
21
|
+
tableWrapper?: string;
|
|
22
|
+
table?: string;
|
|
23
|
+
thead?: string;
|
|
24
|
+
th?: string;
|
|
25
|
+
tbody?: string;
|
|
26
|
+
tr?: string;
|
|
27
|
+
td?: string;
|
|
28
|
+
skeleton?: string;
|
|
29
|
+
columnToggle?: string;
|
|
30
|
+
pagination?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface SeeTableProps<T extends Record<string, unknown>> {
|
|
33
|
+
columns: ColumnDef<T>[];
|
|
34
|
+
data: T[];
|
|
35
|
+
getRowId?: (row: T, index: number) => string;
|
|
36
|
+
/** Uncontrolled initial visible column keys. Default: all columns where defaultVisible !== false */
|
|
37
|
+
defaultVisibleColumns?: string[];
|
|
38
|
+
/** Hybrid pagination: pass limit+skip+onPaginationChange for controlled mode */
|
|
39
|
+
limit?: number;
|
|
40
|
+
skip?: number;
|
|
41
|
+
total?: number;
|
|
42
|
+
onPaginationChange?: (next: {
|
|
43
|
+
limit: number;
|
|
44
|
+
skip: number;
|
|
45
|
+
}) => void;
|
|
46
|
+
limitOptions?: number[];
|
|
47
|
+
loading?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Column keys that stay sticky on the left while scrolling horizontally.
|
|
50
|
+
* When set, these keys override `column.sticky` for the left side.
|
|
51
|
+
*/
|
|
52
|
+
stickyLeft?: string[];
|
|
53
|
+
/**
|
|
54
|
+
* Column keys that stay sticky on the right while scrolling horizontally.
|
|
55
|
+
* When set, these keys override `column.sticky` for the right side.
|
|
56
|
+
*/
|
|
57
|
+
stickyRight?: string[];
|
|
58
|
+
/**
|
|
59
|
+
* Render custom action elements for each row (buttons, menus, etc.).
|
|
60
|
+
* Applied to the column matching `actionsKey` (default `"actions"`).
|
|
61
|
+
* If that column is missing, one is appended automatically.
|
|
62
|
+
*/
|
|
63
|
+
renderActions?: (row: T, rowIndex: number) => ReactNode;
|
|
64
|
+
/** Column key used by `renderActions`. Default: `"actions"` */
|
|
65
|
+
actionsKey?: string;
|
|
66
|
+
/** Header label when auto-creating the actions column. Default: `"Actions"` */
|
|
67
|
+
actionsHeader?: ReactNode;
|
|
68
|
+
/**
|
|
69
|
+
* Controlled column key order from the parent.
|
|
70
|
+
* Used with `onColumnOrderChange` and `enableColumnReorder`.
|
|
71
|
+
*/
|
|
72
|
+
columnOrder?: string[];
|
|
73
|
+
/**
|
|
74
|
+
* Called when the user drops a column into a new position.
|
|
75
|
+
* Required for reordering when `enableColumnReorder` is true.
|
|
76
|
+
*/
|
|
77
|
+
onColumnOrderChange?: (nextOrder: string[]) => void;
|
|
78
|
+
/**
|
|
79
|
+
* Enable header drag-and-drop reordering.
|
|
80
|
+
* Default: `true` only when `onColumnOrderChange` is provided; otherwise `false`.
|
|
81
|
+
* Pass `false` to force-disable even if `onColumnOrderChange` is set.
|
|
82
|
+
*/
|
|
83
|
+
enableColumnReorder?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Show the column visibility toggle button (next to limit select).
|
|
86
|
+
* Default: `true`. Pass `false` to hide it.
|
|
87
|
+
*/
|
|
88
|
+
showColumnToggle?: boolean;
|
|
89
|
+
/** Label for the column visibility toggle button. Default: `"Columns"` */
|
|
90
|
+
columnsLabel?: ReactNode;
|
|
91
|
+
/**
|
|
92
|
+
* When true, shows a leading index column (`#`) at the front of the table.
|
|
93
|
+
* Numbering follows pagination: `skip + rowIndex + 1`.
|
|
94
|
+
*/
|
|
95
|
+
showIndex?: boolean;
|
|
96
|
+
/** Header label for the index column. Default: `"#"` */
|
|
97
|
+
indexHeader?: ReactNode;
|
|
98
|
+
/** Width of the index column in px. Default: `56` */
|
|
99
|
+
indexWidth?: number;
|
|
100
|
+
/**
|
|
101
|
+
* Custom render for the index cell.
|
|
102
|
+
* `index` is the 1-based absolute row number (accounts for pagination skip).
|
|
103
|
+
*/
|
|
104
|
+
renderIndex?: (row: T, rowIndex: number, index: number) => ReactNode;
|
|
105
|
+
/**
|
|
106
|
+
* Per-field cell class names from outside (e.g. price → `text-green-500`).
|
|
107
|
+
* Value can be a static class string or a function of the row.
|
|
108
|
+
*/
|
|
109
|
+
fieldClassNames?: Partial<Record<string, string | ((row: T, rowIndex: number) => string | undefined)>>;
|
|
110
|
+
classNames?: SeeTableClassNames;
|
|
111
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cn(...inputs: Array<string | false | null | undefined>): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Merge an explicit order with the full column key list (append any missing keys). */
|
|
2
|
+
export declare function applyColumnOrder(keys: string[], order?: string[]): string[];
|
|
3
|
+
/**
|
|
4
|
+
* Move `fromKey` relative to `toKey`.
|
|
5
|
+
* Dragging right inserts after the drop target; dragging left inserts before it.
|
|
6
|
+
* (Fixes adjacent rightward moves that previously looked like no-ops.)
|
|
7
|
+
*/
|
|
8
|
+
export declare function moveColumnKey(order: string[], fromKey: string, toKey: string): string[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function clampSkip(skip: number, total: number, limit: number): number;
|
|
2
|
+
export declare function slicePage<T>(data: T[], skip: number, limit: number): T[];
|
|
3
|
+
export declare function resolvePaginationState(args: {
|
|
4
|
+
dataLength: number;
|
|
5
|
+
limit: number;
|
|
6
|
+
skip: number;
|
|
7
|
+
total?: number;
|
|
8
|
+
}): {
|
|
9
|
+
limit: number;
|
|
10
|
+
skip: number;
|
|
11
|
+
total: number;
|
|
12
|
+
pageIndex: number;
|
|
13
|
+
pageCount: number;
|
|
14
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { StickySide } from '../types';
|
|
2
|
+
export declare function resolveColumnWidthPx(col: {
|
|
3
|
+
key: string;
|
|
4
|
+
width?: number | 'auto';
|
|
5
|
+
}, measured?: Record<string, number>): number;
|
|
6
|
+
export declare function getStickyOffsets(columns: Array<{
|
|
7
|
+
key: string;
|
|
8
|
+
sticky?: StickySide;
|
|
9
|
+
width?: number | 'auto';
|
|
10
|
+
}>, measured?: Record<string, number>): Record<string, {
|
|
11
|
+
side: StickySide;
|
|
12
|
+
offset: number;
|
|
13
|
+
}>;
|
|
Binary file
|
package/media/demo.png
ADDED
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mistersee/global-table",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/global-table.js",
|
|
6
|
+
"module": "./dist/global-table.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/global-table.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": ["dist", "media"],
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"framer-motion": ">=11",
|
|
18
|
+
"react": ">=18",
|
|
19
|
+
"react-dom": ">=18",
|
|
20
|
+
"tailwindcss": ">=4"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"dev": "vite",
|
|
24
|
+
"build": "bunx tsc -b && vite build --mode lib && bunx tsc -p tsconfig.lib.json",
|
|
25
|
+
"build:demo": "bunx tsc -b && vite build",
|
|
26
|
+
"lint": "eslint .",
|
|
27
|
+
"preview": "vite preview"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"framer-motion": "^13.2.0",
|
|
31
|
+
"react": "^19.2.8",
|
|
32
|
+
"react-dom": "^19.2.8",
|
|
33
|
+
"tailwind-merge": "^3.7.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@eslint/js": "^10.0.1",
|
|
37
|
+
"@microsoft/api-extractor": "^7.59.1",
|
|
38
|
+
"@tailwindcss/vite": "^4.3.3",
|
|
39
|
+
"@types/node": "^24.13.3",
|
|
40
|
+
"@types/react": "^19.3.0",
|
|
41
|
+
"@types/react-dom": "^19.2.7",
|
|
42
|
+
"@vitejs/plugin-react": "^6.1.1",
|
|
43
|
+
"eslint": "^10.10.0",
|
|
44
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
45
|
+
"eslint-plugin-react-refresh": "^0.5.6",
|
|
46
|
+
"globals": "^17.12.0",
|
|
47
|
+
"tailwindcss": "^4.3.3",
|
|
48
|
+
"typescript": "~6.0.2",
|
|
49
|
+
"typescript-eslint": "^8.69.0",
|
|
50
|
+
"vite": "^8.3.0",
|
|
51
|
+
"vite-plugin-dts": "^5.1.0"
|
|
52
|
+
}
|
|
53
|
+
}
|