@kareemelbalshe/any-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/LICENSE +21 -0
- package/README.md +998 -0
- package/dist/adapters/apiAdapter.d.ts +2 -0
- package/dist/adapters/index.d.ts +5 -0
- package/dist/adapters/objectUtils.d.ts +18 -0
- package/dist/adapters/paginationAdapter.d.ts +2 -0
- package/dist/adapters/searchAdapter.d.ts +4 -0
- package/dist/adapters/sortAdapter.d.ts +7 -0
- package/dist/columns/autoColumns.d.ts +5 -0
- package/dist/columns/columnResolver.d.ts +13 -0
- package/dist/columns/index.d.ts +3 -0
- package/dist/columns/typeDetector.d.ts +7 -0
- package/dist/components/AnyTable.d.ts +8 -0
- package/dist/components/TableBody.d.ts +17 -0
- package/dist/components/TableConfirmDialog.d.ts +13 -0
- package/dist/components/TableEmptyState.d.ts +8 -0
- package/dist/components/TableErrorState.d.ts +6 -0
- package/dist/components/TableHeader.d.ts +16 -0
- package/dist/components/TablePagination.d.ts +14 -0
- package/dist/components/TableSearch.d.ts +9 -0
- package/dist/components/TableSkeleton.d.ts +7 -0
- package/dist/components/index.d.ts +9 -0
- package/dist/favicon.svg +65 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/useAnyTableController.d.ts +18 -0
- package/dist/hooks/useAnyTableData.d.ts +22 -0
- package/dist/hooks/useAnyTablePagination.d.ts +24 -0
- package/dist/hooks/useAnyTableSearch.d.ts +14 -0
- package/dist/hooks/useAnyTableSorting.d.ts +15 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +1930 -0
- package/dist/index.js.map +1 -0
- package/dist/logo.svg +65 -0
- package/dist/renderers/ActionRenderer.d.ts +8 -0
- package/dist/renderers/CellRenderer.d.ts +8 -0
- package/dist/renderers/DefaultRenderers.d.ts +52 -0
- package/dist/renderers/index.d.ts +3 -0
- package/dist/style.css +1 -0
- package/dist/theme/defaultTheme.d.ts +3 -0
- package/dist/theme/index.d.ts +2 -0
- package/dist/theme/themeContext.d.ts +8 -0
- package/dist/types/action.types.d.ts +117 -0
- package/dist/types/api.types.d.ts +99 -0
- package/dist/types/column.types.d.ts +101 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/table.types.d.ts +252 -0
- package/dist/types/theme.types.d.ts +51 -0
- package/package.json +80 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { ColumnDef, SortDirection } from './column.types';
|
|
3
|
+
import { TableAction, SwitchAction } from './action.types';
|
|
4
|
+
import { ApiConfig } from './api.types';
|
|
5
|
+
import { AnyTableTheme } from './theme.types';
|
|
6
|
+
export type RowKeyResolver<TData = any> = (keyof TData & string) | string | ((row: TData, index: number) => string | number);
|
|
7
|
+
export interface SearchConfig<TData = any> {
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
mode?: "server" | "client" | "auto";
|
|
10
|
+
param?: string;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
debounce?: number;
|
|
13
|
+
filter?: (row: TData, searchValue: string) => boolean;
|
|
14
|
+
searchableColumns?: (keyof TData | string)[];
|
|
15
|
+
}
|
|
16
|
+
export interface SortingConfig<TData = any> {
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
mode?: "server" | "client" | "auto";
|
|
19
|
+
defaultSortBy?: keyof TData | string;
|
|
20
|
+
defaultSortOrder?: "asc" | "desc";
|
|
21
|
+
sortByParam?: string;
|
|
22
|
+
sortOrderParam?: string;
|
|
23
|
+
allowUnsort?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface PaginationConfig {
|
|
26
|
+
enabled?: boolean;
|
|
27
|
+
mode?: "server" | "client" | "auto";
|
|
28
|
+
pageParam?: string;
|
|
29
|
+
pageSizeParam?: string;
|
|
30
|
+
defaultPage?: number;
|
|
31
|
+
defaultPageSize?: number;
|
|
32
|
+
pageSizeOptions?: number[];
|
|
33
|
+
showPageSizeSelector?: boolean;
|
|
34
|
+
showTotalCount?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface TableState<TData = any> {
|
|
37
|
+
data: TData[];
|
|
38
|
+
loading: boolean;
|
|
39
|
+
error: any;
|
|
40
|
+
page: number;
|
|
41
|
+
pageSize: number;
|
|
42
|
+
total: number;
|
|
43
|
+
totalPages: number;
|
|
44
|
+
search: string;
|
|
45
|
+
sortBy: string | null;
|
|
46
|
+
sortOrder: SortDirection;
|
|
47
|
+
selectedRowKeys: (string | number)[];
|
|
48
|
+
selectedRows: TData[];
|
|
49
|
+
isServerMode: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface TableInstance<TData = any> {
|
|
52
|
+
/**
|
|
53
|
+
* Refetches the data from the API adapter or resets data stream.
|
|
54
|
+
*/
|
|
55
|
+
refresh: () => Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Resets all search, sorting, pagination, and selection state to default.
|
|
58
|
+
*/
|
|
59
|
+
reset: () => void;
|
|
60
|
+
/**
|
|
61
|
+
* Clears active search input and resets page to 1.
|
|
62
|
+
*/
|
|
63
|
+
resetSearch: () => void;
|
|
64
|
+
/**
|
|
65
|
+
* Clears active sorting column.
|
|
66
|
+
*/
|
|
67
|
+
resetSorting: () => void;
|
|
68
|
+
/**
|
|
69
|
+
* Resets pagination page to 1.
|
|
70
|
+
*/
|
|
71
|
+
resetPagination: () => void;
|
|
72
|
+
/**
|
|
73
|
+
* Programmatically navigates to a specific page number.
|
|
74
|
+
*/
|
|
75
|
+
setPage: (page: number) => void;
|
|
76
|
+
/**
|
|
77
|
+
* Programmatically sets the page size limit.
|
|
78
|
+
*/
|
|
79
|
+
setPageSize: (pageSize: number) => void;
|
|
80
|
+
/**
|
|
81
|
+
* Programmatically sets the search query value.
|
|
82
|
+
*/
|
|
83
|
+
setSearch: (search: string) => void;
|
|
84
|
+
/**
|
|
85
|
+
* Programmatically sorts by column and direction.
|
|
86
|
+
*/
|
|
87
|
+
setSorting: (sortBy: string | null, sortOrder: SortDirection) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Returns an array of currently selected row objects.
|
|
90
|
+
*/
|
|
91
|
+
getSelectedRows: () => TData[];
|
|
92
|
+
/**
|
|
93
|
+
* Clears all row selections.
|
|
94
|
+
*/
|
|
95
|
+
clearSelection: () => void;
|
|
96
|
+
/**
|
|
97
|
+
* Returns current internal state snapshot.
|
|
98
|
+
*/
|
|
99
|
+
getState: () => TableState<TData>;
|
|
100
|
+
}
|
|
101
|
+
export interface AnyTableProps<TData = any> {
|
|
102
|
+
/**
|
|
103
|
+
* Direct local data array. Used when not passing `api`.
|
|
104
|
+
*/
|
|
105
|
+
data?: TData[];
|
|
106
|
+
/**
|
|
107
|
+
* Smart API configuration for fetching remote REST API data.
|
|
108
|
+
*/
|
|
109
|
+
api?: ApiConfig<TData>;
|
|
110
|
+
/**
|
|
111
|
+
* Column definitions. If omitted or autoColumns=true, columns are generated dynamically.
|
|
112
|
+
*/
|
|
113
|
+
columns?: (ColumnDef<TData> | (keyof TData & string))[];
|
|
114
|
+
/**
|
|
115
|
+
* Whether to automatically detect columns from data rows if columns prop is omitted or partial. Defaults to true.
|
|
116
|
+
*/
|
|
117
|
+
autoColumns?: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Unique row identifier accessor or key name (e.g. 'id', '_id', row => row.userId). Defaults to 'id' or '_id'.
|
|
120
|
+
*/
|
|
121
|
+
rowKey?: RowKeyResolver<TData>;
|
|
122
|
+
/**
|
|
123
|
+
* Table section title.
|
|
124
|
+
*/
|
|
125
|
+
title?: React.ReactNode;
|
|
126
|
+
/**
|
|
127
|
+
* Table section subtitle / description.
|
|
128
|
+
*/
|
|
129
|
+
subtitle?: React.ReactNode;
|
|
130
|
+
/**
|
|
131
|
+
* Action buttons, switch toggles, and operations for each row.
|
|
132
|
+
*/
|
|
133
|
+
actions?: (TableAction<TData> | SwitchAction<TData>)[];
|
|
134
|
+
/**
|
|
135
|
+
* Header title for the Actions column. Defaults to 'Actions'.
|
|
136
|
+
*/
|
|
137
|
+
actionsTitle?: string;
|
|
138
|
+
/**
|
|
139
|
+
* Column width for the Actions column. Defaults to 'auto'.
|
|
140
|
+
*/
|
|
141
|
+
actionsWidth?: string | number;
|
|
142
|
+
/**
|
|
143
|
+
* Search feature configuration or boolean to enable default search.
|
|
144
|
+
*/
|
|
145
|
+
search?: boolean | SearchConfig<TData>;
|
|
146
|
+
/**
|
|
147
|
+
* Sorting feature configuration or boolean to enable default sorting.
|
|
148
|
+
*/
|
|
149
|
+
sorting?: boolean | SortingConfig<TData>;
|
|
150
|
+
/**
|
|
151
|
+
* Pagination feature configuration or boolean to enable default pagination.
|
|
152
|
+
*/
|
|
153
|
+
pagination?: boolean | PaginationConfig;
|
|
154
|
+
/**
|
|
155
|
+
* Enables row selection checkboxes.
|
|
156
|
+
*/
|
|
157
|
+
selectable?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Callback fired whenever row selection changes.
|
|
160
|
+
*/
|
|
161
|
+
onSelectionChange?: (selectedRows: TData[], selectedKeys: (string | number)[]) => void;
|
|
162
|
+
/**
|
|
163
|
+
* Callback fired when a table row is clicked.
|
|
164
|
+
*/
|
|
165
|
+
onRowClick?: (row: TData, index: number, event: React.MouseEvent<HTMLTableRowElement>) => void;
|
|
166
|
+
/**
|
|
167
|
+
* Manual loading state override.
|
|
168
|
+
*/
|
|
169
|
+
loading?: boolean;
|
|
170
|
+
/**
|
|
171
|
+
* Custom skeleton/spinner loader component.
|
|
172
|
+
*/
|
|
173
|
+
loadingComponent?: React.ReactNode;
|
|
174
|
+
/**
|
|
175
|
+
* Custom empty state component when no records exist.
|
|
176
|
+
*/
|
|
177
|
+
emptyComponent?: React.ReactNode;
|
|
178
|
+
/**
|
|
179
|
+
* Custom empty state title text.
|
|
180
|
+
*/
|
|
181
|
+
emptyTitle?: string;
|
|
182
|
+
/**
|
|
183
|
+
* Custom empty state description text.
|
|
184
|
+
*/
|
|
185
|
+
emptyDescription?: string;
|
|
186
|
+
/**
|
|
187
|
+
* Custom error state component or function with retry callback.
|
|
188
|
+
*/
|
|
189
|
+
errorComponent?: React.ReactNode | ((error: any, retry: () => void) => React.ReactNode);
|
|
190
|
+
/**
|
|
191
|
+
* Custom theme tokens and class overrides.
|
|
192
|
+
*/
|
|
193
|
+
theme?: Partial<AnyTableTheme>;
|
|
194
|
+
/**
|
|
195
|
+
* Custom CSS classes for the outer wrapper.
|
|
196
|
+
*/
|
|
197
|
+
className?: string;
|
|
198
|
+
/**
|
|
199
|
+
* Custom CSS classes for the `<table>` element.
|
|
200
|
+
*/
|
|
201
|
+
tableClassName?: string;
|
|
202
|
+
/**
|
|
203
|
+
* Custom action buttons to place in the table top header (e.g. "Add User", "Export CSV").
|
|
204
|
+
*/
|
|
205
|
+
headerActions?: React.ReactNode;
|
|
206
|
+
/**
|
|
207
|
+
* Whether to show table header (`<thead>`). Defaults to true.
|
|
208
|
+
*/
|
|
209
|
+
showHeader?: boolean;
|
|
210
|
+
/**
|
|
211
|
+
* Shows borders around table and cells. Defaults to true.
|
|
212
|
+
*/
|
|
213
|
+
bordered?: boolean;
|
|
214
|
+
/**
|
|
215
|
+
* Alternates row background colors (zebra striping). Defaults to false.
|
|
216
|
+
*/
|
|
217
|
+
striped?: boolean;
|
|
218
|
+
/**
|
|
219
|
+
* Highlights row on hover. Defaults to true.
|
|
220
|
+
*/
|
|
221
|
+
hoverable?: boolean;
|
|
222
|
+
/**
|
|
223
|
+
* Compact table density. Defaults to false.
|
|
224
|
+
*/
|
|
225
|
+
compact?: boolean;
|
|
226
|
+
/**
|
|
227
|
+
* Makes the table header sticky when scrolling vertically. Defaults to false.
|
|
228
|
+
*/
|
|
229
|
+
stickyHeader?: boolean;
|
|
230
|
+
/**
|
|
231
|
+
* Ref object to expose imperative controller API.
|
|
232
|
+
*/
|
|
233
|
+
tableRef?: React.Ref<TableInstance<TData>>;
|
|
234
|
+
thead?: string[];
|
|
235
|
+
headerData?: string[];
|
|
236
|
+
tbodys?: TData[];
|
|
237
|
+
titleHeader?: string;
|
|
238
|
+
add?: boolean;
|
|
239
|
+
linkAdd?: string;
|
|
240
|
+
addHandler?: () => void;
|
|
241
|
+
view?: boolean;
|
|
242
|
+
linkView?: string;
|
|
243
|
+
viewHandler?: (id: string) => void;
|
|
244
|
+
edit?: boolean;
|
|
245
|
+
linkEdit?: string;
|
|
246
|
+
editHandler?: (id: string) => void;
|
|
247
|
+
del?: boolean;
|
|
248
|
+
handleDelete?: (id: string) => void;
|
|
249
|
+
block?: boolean;
|
|
250
|
+
handleBlock?: (id: string) => void;
|
|
251
|
+
buttons?: any[];
|
|
252
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type ThemeMode = "light" | "dark" | "system" | "auto";
|
|
2
|
+
export interface ThemeColors {
|
|
3
|
+
primary: string;
|
|
4
|
+
primaryHover: string;
|
|
5
|
+
primaryLight: string;
|
|
6
|
+
secondary: string;
|
|
7
|
+
success: string;
|
|
8
|
+
warning: string;
|
|
9
|
+
danger: string;
|
|
10
|
+
info: string;
|
|
11
|
+
scaffold: string;
|
|
12
|
+
card: string;
|
|
13
|
+
cardSecondary: string;
|
|
14
|
+
border: string;
|
|
15
|
+
textPrimary: string;
|
|
16
|
+
textSecondary: string;
|
|
17
|
+
textMuted: string;
|
|
18
|
+
inputBg: string;
|
|
19
|
+
rowHover: string;
|
|
20
|
+
rowSelected: string;
|
|
21
|
+
}
|
|
22
|
+
export interface AnyTableThemeClasses {
|
|
23
|
+
container?: string;
|
|
24
|
+
tableWrapper?: string;
|
|
25
|
+
table?: string;
|
|
26
|
+
thead?: string;
|
|
27
|
+
th?: string;
|
|
28
|
+
tbody?: string;
|
|
29
|
+
tr?: string;
|
|
30
|
+
td?: string;
|
|
31
|
+
searchContainer?: string;
|
|
32
|
+
searchInput?: string;
|
|
33
|
+
paginationContainer?: string;
|
|
34
|
+
paginationButton?: string;
|
|
35
|
+
paginationButtonActive?: string;
|
|
36
|
+
paginationSelect?: string;
|
|
37
|
+
actionButton?: string;
|
|
38
|
+
switchTrack?: string;
|
|
39
|
+
switchThumb?: string;
|
|
40
|
+
skeleton?: string;
|
|
41
|
+
emptyState?: string;
|
|
42
|
+
errorState?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface AnyTableTheme {
|
|
45
|
+
mode?: ThemeMode;
|
|
46
|
+
colors?: Partial<ThemeColors>;
|
|
47
|
+
classes?: AnyTableThemeClasses;
|
|
48
|
+
borderRadius?: string;
|
|
49
|
+
fontFamily?: string;
|
|
50
|
+
density?: "compact" | "normal" | "spacious";
|
|
51
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kareemelbalshe/any-table",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A developer-facing, smart data table library with 3-tier API detection, auto columns, server/client search, sort & pagination, extensible action callbacks, and customizable themes.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react",
|
|
7
|
+
"table",
|
|
8
|
+
"data-table",
|
|
9
|
+
"smart-table",
|
|
10
|
+
"any-table",
|
|
11
|
+
"pagination",
|
|
12
|
+
"sorting",
|
|
13
|
+
"search",
|
|
14
|
+
"auto-columns",
|
|
15
|
+
"typescript",
|
|
16
|
+
"react-table"
|
|
17
|
+
],
|
|
18
|
+
"author": "Kareem Elbalshe",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"main": "./dist/index.cjs",
|
|
22
|
+
"module": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"import": "./dist/index.js",
|
|
28
|
+
"require": "./dist/index.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./style.css": "./dist/style.css"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE"
|
|
36
|
+
],
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/kareemelbalshe/anyTable.git"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/kareemelbalshe/anyTable/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://kareemelbalshe.github.io/anyTable/",
|
|
48
|
+
"scripts": {
|
|
49
|
+
"dev": "vite",
|
|
50
|
+
"build": "vite build",
|
|
51
|
+
"build:demo": "vite build --mode demo",
|
|
52
|
+
"preview": "vite preview",
|
|
53
|
+
"test": "vitest run",
|
|
54
|
+
"test:watch": "vitest",
|
|
55
|
+
"typecheck": "tsc --noEmit",
|
|
56
|
+
"prepublishOnly": "npm run test && npm run build"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"react": ">=18.0.0",
|
|
60
|
+
"react-dom": ">=18.0.0"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"react-icons": "^5.5.0"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@tailwindcss/vite": "^4.3.3",
|
|
67
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
68
|
+
"@testing-library/react": "^16.2.0",
|
|
69
|
+
"@types/node": "^24.10.1",
|
|
70
|
+
"@types/react": "^19.2.5",
|
|
71
|
+
"@types/react-dom": "^19.2.3",
|
|
72
|
+
"@vitejs/plugin-react": "^5.1.1",
|
|
73
|
+
"jsdom": "^26.0.0",
|
|
74
|
+
"tailwindcss": "^4.3.3",
|
|
75
|
+
"typescript": "~5.9.3",
|
|
76
|
+
"vite": "^7.2.4",
|
|
77
|
+
"vite-plugin-dts": "^4.5.3",
|
|
78
|
+
"vitest": "^3.0.7"
|
|
79
|
+
}
|
|
80
|
+
}
|