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.
Files changed (85) hide show
  1. package/README.md +219 -0
  2. package/dist/components/ui/button-group.d.ts +11 -0
  3. package/dist/components/ui/button.d.ts +10 -0
  4. package/dist/components/ui/checkbox.d.ts +4 -0
  5. package/dist/components/ui/collapsible.d.ts +5 -0
  6. package/dist/components/ui/debounced-input.d.ts +6 -0
  7. package/dist/components/ui/dropdown-menu.d.ts +29 -0
  8. package/dist/components/ui/empty.d.ts +11 -0
  9. package/dist/components/ui/input-group.d.ts +16 -0
  10. package/dist/components/ui/input.d.ts +3 -0
  11. package/dist/components/ui/item.d.ts +23 -0
  12. package/dist/components/ui/label.d.ts +4 -0
  13. package/dist/components/ui/native-select.d.ts +8 -0
  14. package/dist/components/ui/select.d.ts +15 -0
  15. package/dist/components/ui/separator.d.ts +4 -0
  16. package/dist/components/ui/skeleton.d.ts +2 -0
  17. package/dist/components/ui/spinner.d.ts +2 -0
  18. package/dist/components/ui/table.d.ts +10 -0
  19. package/dist/components/ui/textarea.d.ts +3 -0
  20. package/dist/index.cjs +37 -0
  21. package/dist/index.d.ts +1 -0
  22. package/dist/index.js +5173 -0
  23. package/dist/lib/utils.d.ts +2 -0
  24. package/dist/package/contexts/grid/GridContext.d.ts +4 -0
  25. package/dist/package/contexts/grid/types/index.d.ts +58 -0
  26. package/dist/package/core/index.d.ts +4 -0
  27. package/dist/package/core/types/index.d.ts +342 -0
  28. package/dist/package/features/index.d.ts +41 -0
  29. package/dist/package/hooks/useGrid.d.ts +3 -0
  30. package/dist/package/hooks/useGridState.d.ts +57 -0
  31. package/dist/package/hooks/useQueryArgs.d.ts +12 -0
  32. package/dist/package/hooks/useSyncScroll.d.ts +7 -0
  33. package/dist/package/index.d.ts +11 -0
  34. package/dist/package/state/rowDensity.d.ts +28 -0
  35. package/dist/package/state/useColumnOrderState.d.ts +4 -0
  36. package/dist/package/state/useColumnPinningState.d.ts +5 -0
  37. package/dist/package/state/useColumnSizingState.d.ts +5 -0
  38. package/dist/package/state/useColumnVisibilityState.d.ts +5 -0
  39. package/dist/package/state/useDensityState.d.ts +5 -0
  40. package/dist/package/state/useRowPinningState.d.ts +5 -0
  41. package/dist/package/state/useSplitViewState.d.ts +4 -0
  42. package/dist/package/ui/grid/sections/center/GridCenter.d.ts +3 -0
  43. package/dist/package/ui/grid/sections/center/GridCenterBody.d.ts +3 -0
  44. package/dist/package/ui/grid/sections/center/GridCenterHeader.d.ts +2 -0
  45. package/dist/package/ui/grid/sections/center/GridCenterRowPin.d.ts +3 -0
  46. package/dist/package/ui/grid/sections/center/feedback/GridCenterEmpty.d.ts +2 -0
  47. package/dist/package/ui/grid/sections/center/feedback/GridCenterEmptyMessage.d.ts +2 -0
  48. package/dist/package/ui/grid/sections/center/feedback/GridCenterError.d.ts +2 -0
  49. package/dist/package/ui/grid/sections/center/feedback/GridCenterErrorMessage.d.ts +2 -0
  50. package/dist/package/ui/grid/sections/center/feedback/GridCenterSkeleton.d.ts +2 -0
  51. package/dist/package/ui/grid/sections/end/GridEnd.d.ts +2 -0
  52. package/dist/package/ui/grid/sections/end/GridEndBody.d.ts +3 -0
  53. package/dist/package/ui/grid/sections/end/GridEndHeader.d.ts +2 -0
  54. package/dist/package/ui/grid/sections/end/GridEndRowPin.d.ts +5 -0
  55. package/dist/package/ui/grid/sections/end/feedback/GridEndEmpty.d.ts +2 -0
  56. package/dist/package/ui/grid/sections/end/feedback/GridEndSkeleton.d.ts +2 -0
  57. package/dist/package/ui/grid/sections/start/GridStart.d.ts +2 -0
  58. package/dist/package/ui/grid/sections/start/GridStartBody.d.ts +3 -0
  59. package/dist/package/ui/grid/sections/start/GridStartHeader.d.ts +2 -0
  60. package/dist/package/ui/grid/sections/start/GridStartRowPin.d.ts +5 -0
  61. package/dist/package/ui/grid/sections/start/feedback/GridStartEmpty.d.ts +2 -0
  62. package/dist/package/ui/grid/sections/start/feedback/GridStartSkeleton.d.ts +2 -0
  63. package/dist/package/ui/grid/shared/GridCell.d.ts +6 -0
  64. package/dist/package/ui/grid/shared/GridHead.d.ts +6 -0
  65. package/dist/package/ui/grid/shared/feedback/GridRowSkeleton.d.ts +8 -0
  66. package/dist/package/ui/header/HeaderFilter.d.ts +6 -0
  67. package/dist/package/ui/header/HeaderMenu.d.ts +6 -0
  68. package/dist/package/ui/header/HeaderResizing.d.ts +6 -0
  69. package/dist/package/ui/header/HeaderSort.d.ts +6 -0
  70. package/dist/package/ui/pagination/index.d.ts +2 -0
  71. package/dist/package/ui/toolbar/right/ToolbarRightColumns.d.ts +3 -0
  72. package/dist/package/ui/toolbar/right/ToolbarRightDnd.d.ts +2 -0
  73. package/dist/package/ui/toolbar/right/ToolbarRightFilter.d.ts +3 -0
  74. package/dist/package/ui/toolbar/right/ToolbarRightRows.d.ts +2 -0
  75. package/dist/package/ui/toolbar/right/ToolbarRightSettings.d.ts +2 -0
  76. package/dist/package/ui/toolbar/right/index.d.ts +4 -0
  77. package/dist/package/ui/toolbar/top/index.d.ts +2 -0
  78. package/dist/package/utils/URLSearch.d.ts +57 -0
  79. package/dist/package/utils/buildQueryString.d.ts +2 -0
  80. package/dist/package/utils/buildSortString.d.ts +4 -0
  81. package/dist/package/utils/getPinStyles.d.ts +4 -0
  82. package/dist/package/utils/pluckSelected.d.ts +40 -0
  83. package/dist/package/utils/printTable.d.ts +1 -0
  84. package/dist/package/utils/toTsv.d.ts +2 -0
  85. package/package.json +94 -0
@@ -0,0 +1,2 @@
1
+ declare const GridCenterSkeleton: () => import("react").JSX.Element;
2
+ export default GridCenterSkeleton;
@@ -0,0 +1,2 @@
1
+ declare const GridEnd: () => import("react").JSX.Element;
2
+ export default GridEnd;
@@ -0,0 +1,3 @@
1
+ import { default as React } from 'react';
2
+ declare const GridEndBody: () => React.JSX.Element;
3
+ export default GridEndBody;
@@ -0,0 +1,2 @@
1
+ declare const GridEndHeader: () => import("react").JSX.Element;
2
+ export default GridEndHeader;
@@ -0,0 +1,5 @@
1
+ import { GridFeatures } from '../../../../features';
2
+ import { Row, RowData } from '@tanstack/react-table';
3
+ export declare function GridEndRowPin({ row }: {
4
+ row: Row<GridFeatures, RowData>;
5
+ }): import("react").JSX.Element;
@@ -0,0 +1,2 @@
1
+ declare const GridEndEmpty: () => import("react").JSX.Element;
2
+ export default GridEndEmpty;
@@ -0,0 +1,2 @@
1
+ declare const GridEndSkeleton: () => import("react").JSX.Element;
2
+ export default GridEndSkeleton;
@@ -0,0 +1,2 @@
1
+ declare const GridStart: () => import("react").JSX.Element;
2
+ export default GridStart;
@@ -0,0 +1,3 @@
1
+ import { default as React } from 'react';
2
+ declare const GridStartBody: () => React.JSX.Element;
3
+ export default GridStartBody;
@@ -0,0 +1,2 @@
1
+ declare const GridStartHeader: () => import("react").JSX.Element;
2
+ export default GridStartHeader;
@@ -0,0 +1,5 @@
1
+ import { GridFeatures } from '../../../../features';
2
+ import { Row, RowData } from '@tanstack/react-table';
3
+ export declare function GridStartRowPin({ row }: {
4
+ row: Row<GridFeatures, RowData>;
5
+ }): import("react").JSX.Element;
@@ -0,0 +1,2 @@
1
+ declare const GridStartEmpty: () => import("react").JSX.Element;
2
+ export default GridStartEmpty;
@@ -0,0 +1,2 @@
1
+ declare const GridStartSkeleton: () => import("react").JSX.Element;
2
+ export default GridStartSkeleton;
@@ -0,0 +1,6 @@
1
+ import { GridFeatures } from '../../../features';
2
+ import { Cell, RowData } from '@tanstack/react-table';
3
+ declare const GridCell: ({ cell }: {
4
+ cell: Cell<GridFeatures, RowData, unknown>;
5
+ }) => import("react").JSX.Element | null;
6
+ export default GridCell;
@@ -0,0 +1,6 @@
1
+ import { GridFeatures } from '../../../features';
2
+ import { Header, RowData } from '@tanstack/react-table';
3
+ declare const GridHead: ({ header, }: {
4
+ header: Header<GridFeatures, RowData, unknown>;
5
+ }) => import("react").JSX.Element;
6
+ export default GridHead;
@@ -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,6 @@
1
+ import { GridFeatures } from '../../features';
2
+ import { Header, RowData } from '@tanstack/react-table';
3
+ declare const HeaderSort: ({ header, }: {
4
+ header: Header<GridFeatures, RowData, unknown>;
5
+ }) => import("react").JSX.Element;
6
+ export default HeaderSort;
@@ -0,0 +1,2 @@
1
+ declare const Pagination: () => import("react").JSX.Element;
2
+ export default Pagination;
@@ -0,0 +1,3 @@
1
+ import { default as React } from 'react';
2
+ declare const ToolbarRightColumns: () => React.JSX.Element;
3
+ export default ToolbarRightColumns;
@@ -0,0 +1,2 @@
1
+ declare const ToolbarDnd: () => import("react").JSX.Element;
2
+ export default ToolbarDnd;
@@ -0,0 +1,3 @@
1
+ import { default as React } from 'react';
2
+ declare const ToolbarFilters: () => React.JSX.Element;
3
+ export default ToolbarFilters;
@@ -0,0 +1,2 @@
1
+ declare const ToolbarRightRows: () => import("react").JSX.Element;
2
+ export default ToolbarRightRows;
@@ -0,0 +1,2 @@
1
+ declare const ToolbarRightSettings: () => import("react").JSX.Element;
2
+ export default ToolbarRightSettings;
@@ -0,0 +1,4 @@
1
+ declare const ToolbarRight: ({ height }: {
2
+ height: number;
3
+ }) => import("react").JSX.Element;
4
+ export default ToolbarRight;
@@ -0,0 +1,2 @@
1
+ declare const TopToolbar: () => import("react").JSX.Element;
2
+ export default TopToolbar;
@@ -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,2 @@
1
+ import { ColumnFiltersState } from '@tanstack/react-table';
2
+ export declare const buildQueryParams: (filters: ColumnFiltersState) => string;
@@ -0,0 +1,4 @@
1
+ export declare function buildSortString(sortOptions: {
2
+ id: string;
3
+ desc: boolean;
4
+ }[] | null | undefined): string;
@@ -0,0 +1,4 @@
1
+ import { Column, RowData } from '@tanstack/react-table';
2
+ import { CSSProperties } from 'react';
3
+ import { GridFeatures } from '../features';
4
+ export declare const getPinStyles: (column: Column<GridFeatures, RowData>, isSplit: boolean) => CSSProperties;
@@ -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;
@@ -0,0 +1,2 @@
1
+ export declare function escapeTsvValue(value: unknown): string;
2
+ export declare function toTsv(ranges: Array<Array<Array<unknown>>>): string;
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
+ }