react-shadcn-table 1.0.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/README.md +219 -0
- package/dist/components/ui/button-group.d.ts +11 -0
- package/dist/components/ui/button.d.ts +10 -0
- package/dist/components/ui/checkbox.d.ts +4 -0
- package/dist/components/ui/collapsible.d.ts +5 -0
- package/dist/components/ui/debounced-input.d.ts +6 -0
- package/dist/components/ui/dropdown-menu.d.ts +29 -0
- package/dist/components/ui/empty.d.ts +11 -0
- package/dist/components/ui/input-group.d.ts +16 -0
- package/dist/components/ui/input.d.ts +3 -0
- package/dist/components/ui/item.d.ts +23 -0
- package/dist/components/ui/label.d.ts +4 -0
- package/dist/components/ui/native-select.d.ts +8 -0
- package/dist/components/ui/select.d.ts +15 -0
- package/dist/components/ui/separator.d.ts +4 -0
- package/dist/components/ui/skeleton.d.ts +2 -0
- package/dist/components/ui/spinner.d.ts +2 -0
- package/dist/components/ui/table.d.ts +10 -0
- package/dist/components/ui/textarea.d.ts +3 -0
- package/dist/index.cjs +37 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5173 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/package/contexts/grid/GridContext.d.ts +4 -0
- package/dist/package/contexts/grid/types/index.d.ts +58 -0
- package/dist/package/core/index.d.ts +4 -0
- package/dist/package/core/types/index.d.ts +342 -0
- package/dist/package/features/index.d.ts +41 -0
- package/dist/package/hooks/useGrid.d.ts +3 -0
- package/dist/package/hooks/useGridState.d.ts +57 -0
- package/dist/package/hooks/useQueryArgs.d.ts +12 -0
- package/dist/package/hooks/useSyncScroll.d.ts +7 -0
- package/dist/package/index.d.ts +11 -0
- package/dist/package/state/rowDensity.d.ts +28 -0
- package/dist/package/state/useColumnOrderState.d.ts +4 -0
- package/dist/package/state/useColumnPinningState.d.ts +5 -0
- package/dist/package/state/useColumnSizingState.d.ts +5 -0
- package/dist/package/state/useColumnVisibilityState.d.ts +5 -0
- package/dist/package/state/useDensityState.d.ts +5 -0
- package/dist/package/state/useRowPinningState.d.ts +5 -0
- package/dist/package/state/useSplitViewState.d.ts +4 -0
- package/dist/package/ui/grid/sections/center/GridCenter.d.ts +3 -0
- package/dist/package/ui/grid/sections/center/GridCenterBody.d.ts +3 -0
- package/dist/package/ui/grid/sections/center/GridCenterHeader.d.ts +2 -0
- package/dist/package/ui/grid/sections/center/GridCenterRowPin.d.ts +3 -0
- package/dist/package/ui/grid/sections/center/feedback/GridCenterEmpty.d.ts +2 -0
- package/dist/package/ui/grid/sections/center/feedback/GridCenterEmptyMessage.d.ts +2 -0
- package/dist/package/ui/grid/sections/center/feedback/GridCenterError.d.ts +2 -0
- package/dist/package/ui/grid/sections/center/feedback/GridCenterErrorMessage.d.ts +2 -0
- package/dist/package/ui/grid/sections/center/feedback/GridCenterSkeleton.d.ts +2 -0
- package/dist/package/ui/grid/sections/end/GridEnd.d.ts +2 -0
- package/dist/package/ui/grid/sections/end/GridEndBody.d.ts +3 -0
- package/dist/package/ui/grid/sections/end/GridEndHeader.d.ts +2 -0
- package/dist/package/ui/grid/sections/end/GridEndRowPin.d.ts +5 -0
- package/dist/package/ui/grid/sections/end/feedback/GridEndEmpty.d.ts +2 -0
- package/dist/package/ui/grid/sections/end/feedback/GridEndSkeleton.d.ts +2 -0
- package/dist/package/ui/grid/sections/start/GridStart.d.ts +2 -0
- package/dist/package/ui/grid/sections/start/GridStartBody.d.ts +3 -0
- package/dist/package/ui/grid/sections/start/GridStartHeader.d.ts +2 -0
- package/dist/package/ui/grid/sections/start/GridStartRowPin.d.ts +5 -0
- package/dist/package/ui/grid/sections/start/feedback/GridStartEmpty.d.ts +2 -0
- package/dist/package/ui/grid/sections/start/feedback/GridStartSkeleton.d.ts +2 -0
- package/dist/package/ui/grid/shared/GridCell.d.ts +6 -0
- package/dist/package/ui/grid/shared/GridHead.d.ts +6 -0
- package/dist/package/ui/grid/shared/feedback/GridRowSkeleton.d.ts +8 -0
- package/dist/package/ui/header/HeaderFilter.d.ts +6 -0
- package/dist/package/ui/header/HeaderMenu.d.ts +6 -0
- package/dist/package/ui/header/HeaderResizing.d.ts +6 -0
- package/dist/package/ui/header/HeaderSort.d.ts +6 -0
- package/dist/package/ui/pagination/index.d.ts +2 -0
- package/dist/package/ui/toolbar/right/ToolbarRightColumns.d.ts +3 -0
- package/dist/package/ui/toolbar/right/ToolbarRightDnd.d.ts +2 -0
- package/dist/package/ui/toolbar/right/ToolbarRightFilter.d.ts +3 -0
- package/dist/package/ui/toolbar/right/ToolbarRightRows.d.ts +2 -0
- package/dist/package/ui/toolbar/right/ToolbarRightSettings.d.ts +2 -0
- package/dist/package/ui/toolbar/right/index.d.ts +4 -0
- package/dist/package/ui/toolbar/top/index.d.ts +2 -0
- package/dist/package/utils/URLSearch.d.ts +57 -0
- package/dist/package/utils/buildQueryString.d.ts +2 -0
- package/dist/package/utils/buildSortString.d.ts +4 -0
- package/dist/package/utils/getPinStyles.d.ts +4 -0
- package/dist/package/utils/pluckSelected.d.ts +40 -0
- package/dist/package/utils/printTable.d.ts +1 -0
- package/dist/package/utils/toTsv.d.ts +2 -0
- package/package.json +94 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GridFeatures } from '../../../../features';
|
|
2
|
+
import { Column, RowData } from '@tanstack/react-table';
|
|
3
|
+
declare const GridRowSkeleton: ({ column, i, j, }: {
|
|
4
|
+
column: Column<GridFeatures, RowData, unknown>;
|
|
5
|
+
i: number;
|
|
6
|
+
j: number;
|
|
7
|
+
}) => import("react").JSX.Element;
|
|
8
|
+
export default GridRowSkeleton;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { GridFeatures } from '../../features';
|
|
2
|
+
import { Column, RowData } from '@tanstack/react-table';
|
|
3
|
+
declare const HeaderFilter: ({ column, }: {
|
|
4
|
+
column: Column<GridFeatures, RowData, unknown>;
|
|
5
|
+
}) => import("react").JSX.Element | null;
|
|
6
|
+
export default HeaderFilter;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { GridFeatures } from '../../features';
|
|
2
|
+
import { Header, RowData } from '@tanstack/react-table';
|
|
3
|
+
declare const HeaderMenu: ({ header, }: {
|
|
4
|
+
header: Header<GridFeatures, RowData, unknown>;
|
|
5
|
+
}) => import("react").JSX.Element | null;
|
|
6
|
+
export default HeaderMenu;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { GridFeatures } from '../../features';
|
|
2
|
+
import { Header, RowData } from '@tanstack/react-table';
|
|
3
|
+
declare const HeaderResizing: ({ header, }: {
|
|
4
|
+
header: Header<GridFeatures, RowData, unknown>;
|
|
5
|
+
}) => import("react").JSX.Element;
|
|
6
|
+
export default HeaderResizing;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
interface ColumnFilter {
|
|
2
|
+
id: string;
|
|
3
|
+
value: unknown;
|
|
4
|
+
}
|
|
5
|
+
interface SortingItem {
|
|
6
|
+
id: string;
|
|
7
|
+
desc: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface Pagination {
|
|
10
|
+
pageIndex: number;
|
|
11
|
+
pageSize: number;
|
|
12
|
+
}
|
|
13
|
+
interface QueryArgs {
|
|
14
|
+
columnFilters: ColumnFilter[];
|
|
15
|
+
globalFilter?: string;
|
|
16
|
+
pagination: Pagination;
|
|
17
|
+
sorting: SortingItem[];
|
|
18
|
+
rowSelection?: Record<string, boolean>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Builds a MongoDB/Express-style URL query string from a TanStack Table
|
|
22
|
+
* state object (`QueryArgs`), suitable for sending to a REST API backend
|
|
23
|
+
* that expects `page`, `limit`, `sort`, `q`, and per-field filter params.
|
|
24
|
+
*
|
|
25
|
+
* Behavior:
|
|
26
|
+
* - `pagination.pageIndex` is converted from 0-based (TanStack) to 1-based
|
|
27
|
+
* (`page`) and `pagination.pageSize` is sent as `limit`.
|
|
28
|
+
* - Each entry in `columnFilters` is expanded via {@link appendColumnFilter}
|
|
29
|
+
* (supports plain values, range tuples, and Mongo operator objects).
|
|
30
|
+
* - `sorting` is joined into a single comma-separated `sort` param, prefixing
|
|
31
|
+
* descending fields with `-` (e.g. `sorting: [{ id: 'year', desc: true }]`
|
|
32
|
+
* → `sort=-year`). Omitted entirely if `sorting` is empty.
|
|
33
|
+
* - `globalFilter`, if provided and non-empty, is sent as `q`.
|
|
34
|
+
* - `rowSelection` is accepted in the input type but is **not** included in
|
|
35
|
+
* the resulting query string.
|
|
36
|
+
*
|
|
37
|
+
* @param queryArgs - The current TanStack Table state to serialize.
|
|
38
|
+
* @returns A URL query string (including the leading `?`), e.g.
|
|
39
|
+
* `"?page=1&limit=20&status=active&sort=-year"`.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const query = URLSearch({
|
|
44
|
+
* pagination: { pageIndex: 0, pageSize: 20 },
|
|
45
|
+
* columnFilters: [
|
|
46
|
+
* { id: 'status', value: 'active' },
|
|
47
|
+
* { id: 'year', value: [2020, 2023] },
|
|
48
|
+
* ],
|
|
49
|
+
* sorting: [{ id: 'year', desc: true }],
|
|
50
|
+
* globalFilter: 'toyota',
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* // query === "?page=1&limit=20&status=active&year[gte]=2020&year[lte]=2023&sort=-year&q=toyota"
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function URLSearch(queryArgs: QueryArgs): string;
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { RowSelectionState } from '@tanstack/react-table';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts the value of a specific field from all currently selected rows
|
|
4
|
+
* in a TanStack Table instance.
|
|
5
|
+
*
|
|
6
|
+
* Assumes `rowSelection` keys correspond directly to the index of the row
|
|
7
|
+
* in the `data` array (i.e. no custom `getRowId` is used). If a custom
|
|
8
|
+
* `getRowId` is configured on the table, this function will not work as
|
|
9
|
+
* expected since the keys will be custom IDs instead of indices.
|
|
10
|
+
*
|
|
11
|
+
* @template T - The type of a single row's data.
|
|
12
|
+
* @template K - The key of the field to extract from each selected row.
|
|
13
|
+
*
|
|
14
|
+
* @param data - The full array of row data (same array passed to the table).
|
|
15
|
+
* @param rowSelection - The current `rowSelection` state from TanStack Table,
|
|
16
|
+
* where keys are row indices (as strings) and values are `true`/`false`.
|
|
17
|
+
* @param field - The field name (key of `T`) whose value should be extracted
|
|
18
|
+
* from each selected row.
|
|
19
|
+
*
|
|
20
|
+
* @returns An array containing the value of `field` for every selected row.
|
|
21
|
+
* Rows that no longer exist in `data` (e.g. stale selection) are skipped.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const rowSelection = { "0": true, "2": true, "3": true };
|
|
26
|
+
* const data = [
|
|
27
|
+
* { id: "V001", driver: "John" },
|
|
28
|
+
* { id: "V002", driver: "Sam" },
|
|
29
|
+
* { id: "V003", driver: "Alex" },
|
|
30
|
+
* { id: "V004", driver: "Mia" },
|
|
31
|
+
* ];
|
|
32
|
+
*
|
|
33
|
+
* pluckSelected(data, rowSelection, 'id');
|
|
34
|
+
* // => ["V001", "V003", "V004"]
|
|
35
|
+
*
|
|
36
|
+
* pluckSelected(data, rowSelection, 'driver');
|
|
37
|
+
* // => ["John", "Alex", "Mia"]
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function pluckSelected<T, K extends keyof T>(data: T[], rowSelection: RowSelectionState, field: K): T[K][];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function printTable(title: string, headers: string[], rows: unknown[][]): void;
|
package/package.json
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-shadcn-table",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"dev": "vite",
|
|
20
|
+
"build": "tsc -b && vite build",
|
|
21
|
+
"lint": "eslint .",
|
|
22
|
+
"preview": "vite preview"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/jsdev-robin/react-shadcn-table.git"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/jsdev-robin/react-shadcn-table/issues"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react": "^18 || ^19",
|
|
33
|
+
"react-dom": "^18 || ^19"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@dnd-kit/core": "^6.3.1",
|
|
37
|
+
"@dnd-kit/modifiers": "^9.0.0",
|
|
38
|
+
"@dnd-kit/sortable": "^10.0.0",
|
|
39
|
+
"@dnd-kit/utilities": "^3.2.2",
|
|
40
|
+
"@tanstack/react-hotkeys": "^0.10.0",
|
|
41
|
+
"@tanstack/react-pacer": "^0.23.0",
|
|
42
|
+
"@tanstack/react-store": "^0.11.1",
|
|
43
|
+
"@tanstack/react-table": "^9.1.2",
|
|
44
|
+
"jspdf": "^4.2.1",
|
|
45
|
+
"jspdf-autotable": "^5.0.8",
|
|
46
|
+
"xlsx": "^0.18.5"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@babel/core": "^7.29.7",
|
|
50
|
+
"@eslint/js": "^10.0.1",
|
|
51
|
+
"@rolldown/plugin-babel": "^0.2.3",
|
|
52
|
+
"@tailwindcss/vite": "^4.3.3",
|
|
53
|
+
"@types/babel__core": "^7.20.5",
|
|
54
|
+
"@types/node": "^24.13.3",
|
|
55
|
+
"@types/react": "^19.2.17",
|
|
56
|
+
"@types/react-dom": "^19.2.3",
|
|
57
|
+
"@vitejs/plugin-react": "^6.0.4",
|
|
58
|
+
"babel-plugin-react-compiler": "^1.0.0",
|
|
59
|
+
"eslint": "^10.8.0",
|
|
60
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
61
|
+
"eslint-plugin-react-refresh": "^0.5.3",
|
|
62
|
+
"globals": "^17.7.0",
|
|
63
|
+
"tailwindcss": "^4.3.3",
|
|
64
|
+
"typescript": "~6.0.2",
|
|
65
|
+
"typescript-eslint": "^8.65.0",
|
|
66
|
+
"vite": "^8.2.0",
|
|
67
|
+
"clsx": "^2.1.1",
|
|
68
|
+
"vite-plugin-dts": "^5.0.3",
|
|
69
|
+
"shadcn": "^4.18.0",
|
|
70
|
+
"tailwind-merge": "^3.6.0",
|
|
71
|
+
"class-variance-authority": "^0.7.1",
|
|
72
|
+
"tw-animate-css": "^1.4.0",
|
|
73
|
+
"lucide-react": "^1.31.0",
|
|
74
|
+
"radix-ui": "^1.6.7"
|
|
75
|
+
},
|
|
76
|
+
"keywords": [
|
|
77
|
+
"react",
|
|
78
|
+
"table",
|
|
79
|
+
"data-table",
|
|
80
|
+
"shadcn",
|
|
81
|
+
"shadcn-ui",
|
|
82
|
+
"tanstack-table",
|
|
83
|
+
"radix-ui",
|
|
84
|
+
"tailwindcss",
|
|
85
|
+
"typescript",
|
|
86
|
+
"vite",
|
|
87
|
+
"dnd-kit",
|
|
88
|
+
"drag-and-drop",
|
|
89
|
+
"xlsx",
|
|
90
|
+
"excel-export",
|
|
91
|
+
"pdf-export",
|
|
92
|
+
"ui-components"
|
|
93
|
+
]
|
|
94
|
+
}
|