@ackplus/react-tanstack-data-table 1.0.19-beta-0.15 → 1.0.20

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 (46) hide show
  1. package/README.md +868 -38
  2. package/package.json +1 -1
  3. package/src/index.d.ts +1 -4
  4. package/src/index.js +2 -9
  5. package/src/lib/components/filters/filter-value-input.d.ts +8 -1
  6. package/src/lib/components/filters/filter-value-input.js +14 -31
  7. package/src/lib/components/headers/draggable-header.d.ts +6 -2
  8. package/src/lib/components/headers/draggable-header.js +42 -50
  9. package/src/lib/components/headers/table-header.d.ts +8 -2
  10. package/src/lib/components/headers/table-header.js +24 -18
  11. package/src/lib/components/pagination/data-table-pagination.d.ts +8 -2
  12. package/src/lib/components/pagination/data-table-pagination.js +27 -15
  13. package/src/lib/components/rows/data-table-row.d.ts +9 -2
  14. package/src/lib/components/rows/data-table-row.js +21 -7
  15. package/src/lib/components/rows/empty-data-row.d.ts +11 -4
  16. package/src/lib/components/rows/empty-data-row.js +14 -2
  17. package/src/lib/components/rows/loading-rows.d.ts +9 -2
  18. package/src/lib/components/rows/loading-rows.js +29 -19
  19. package/src/lib/components/table/data-table.js +27 -32
  20. package/src/lib/components/table/data-table.types.d.ts +0 -18
  21. package/src/lib/components/toolbar/bulk-actions-toolbar.d.ts +9 -3
  22. package/src/lib/components/toolbar/bulk-actions-toolbar.js +15 -10
  23. package/src/lib/components/toolbar/column-filter-control.d.ts +14 -1
  24. package/src/lib/components/toolbar/column-filter-control.js +14 -12
  25. package/src/lib/components/toolbar/column-pinning-control.d.ts +12 -1
  26. package/src/lib/components/toolbar/column-pinning-control.js +24 -42
  27. package/src/lib/components/toolbar/column-reset-control.d.ts +8 -1
  28. package/src/lib/components/toolbar/column-reset-control.js +34 -6
  29. package/src/lib/components/toolbar/column-visibility-control.d.ts +10 -1
  30. package/src/lib/components/toolbar/column-visibility-control.js +7 -7
  31. package/src/lib/components/toolbar/data-table-toolbar.d.ts +9 -2
  32. package/src/lib/components/toolbar/data-table-toolbar.js +15 -2
  33. package/src/lib/components/toolbar/table-export-control.d.ts +7 -1
  34. package/src/lib/components/toolbar/table-export-control.js +24 -68
  35. package/src/lib/components/toolbar/table-search-control.d.ts +12 -1
  36. package/src/lib/components/toolbar/table-search-control.js +24 -11
  37. package/src/lib/components/toolbar/table-size-control.d.ts +9 -1
  38. package/src/lib/components/toolbar/table-size-control.js +17 -9
  39. package/src/lib/examples/index.d.ts +2 -0
  40. package/src/lib/examples/index.js +5 -1
  41. package/src/lib/examples/simple-slots-example.d.ts +1 -0
  42. package/src/lib/examples/simple-slots-example.js +115 -0
  43. package/src/lib/types/data-table-api.d.ts +4 -1
  44. package/src/lib/types/slots.types.d.ts +142 -137
  45. package/src/lib/utils/slot-helpers.d.ts +12 -6
  46. package/src/lib/utils/slot-helpers.js +86 -12
@@ -1,83 +1,35 @@
1
- import { TableProps, TableContainerProps, BoxProps } from '@mui/material';
1
+ import { TableProps, TableContainerProps, BoxProps, ToolbarProps, TableRowProps, TableCellProps, TableHeadProps, TableBodyProps } from '@mui/material';
2
2
  import { Table, Row, Column } from '@tanstack/react-table';
3
- import { ComponentType, ReactNode } from 'react';
3
+ import { ComponentType, ReactNode, HTMLAttributes, ComponentProps } from 'react';
4
4
  import { DataTableColumn, TableFilters, ExportProgress, ExportResult, ExportError, ServerExportColumn } from './index';
5
5
  import { DataTableSize } from '../utils/table-helpers';
6
6
  import { DataTablePaginationProps } from "../components/pagination";
7
- export interface DataTableSlots<T = any> {
8
- root?: ComponentType<DataTableSlotProps<T>['root']>;
9
- tableContainer?: ComponentType<DataTableSlotProps<T>['tableContainer']>;
10
- table?: ComponentType<DataTableSlotProps<T>['table']>;
11
- toolbar?: ComponentType<DataTableSlotProps<T>['toolbar']>;
12
- header?: ComponentType<DataTableSlotProps<T>['header']>;
13
- headerRow?: ComponentType<DataTableSlotProps<T>['headerRow']>;
14
- headerCell?: ComponentType<DataTableSlotProps<T>['headerCell']>;
15
- sortIconAsc?: ComponentType<DataTableSlotProps<T>['sortIconAsc']>;
16
- sortIconDesc?: ComponentType<DataTableSlotProps<T>['sortIconDesc']>;
17
- body?: ComponentType<DataTableSlotProps<T>['body']>;
18
- row?: ComponentType<DataTableSlotProps<T>['row']>;
19
- cell?: ComponentType<DataTableSlotProps<T>['cell']>;
20
- loadingRow?: ComponentType<DataTableSlotProps<T>['loadingRow']>;
21
- emptyRow?: ComponentType<DataTableSlotProps<T>['emptyRow']>;
22
- expandedRow?: ComponentType<DataTableSlotProps<T>['expandedRow']>;
23
- footer?: ComponentType<DataTableSlotProps<T>['footer']>;
24
- pagination?: ComponentType<DataTableSlotProps<T>['pagination']>;
25
- searchInput?: ComponentType<DataTableSlotProps<T>['searchInput']>;
26
- columnVisibilityControl?: ComponentType<DataTableSlotProps<T>['columnVisibilityControl']>;
27
- columnCustomFilterControl?: ComponentType<DataTableSlotProps<T>['columnCustomFilterControl']>;
28
- columnPinningControl?: ComponentType<DataTableSlotProps<T>['columnPinningControl']>;
29
- exportButton?: ComponentType<DataTableSlotProps<T>['exportButton']>;
30
- resetButton?: ComponentType<DataTableSlotProps<T>['resetButton']>;
31
- tableSizeControl?: ComponentType<DataTableSlotProps<T>['tableSizeControl']>;
32
- bulkActionsToolbar?: ComponentType<DataTableSlotProps<T>['bulkActionsToolbar']>;
33
- searchIcon?: ComponentType<DataTableSlotProps<T>['searchIcon']>;
34
- clearIcon?: ComponentType<DataTableSlotProps<T>['clearIcon']>;
35
- exportIcon?: ComponentType<DataTableSlotProps<T>['exportIcon']>;
36
- columnIcon?: ComponentType<DataTableSlotProps<T>['columnIcon']>;
37
- resetIcon?: ComponentType<DataTableSlotProps<T>['resetIcon']>;
38
- moreIcon?: ComponentType<DataTableSlotProps<T>['moreIcon']>;
39
- filterIcon?: ComponentType<DataTableSlotProps<T>['filterIcon']>;
40
- pinIcon?: ComponentType<DataTableSlotProps<T>['pinIcon']>;
41
- unpinIcon?: ComponentType<DataTableSlotProps<T>['unpinIcon']>;
42
- leftIcon?: ComponentType<DataTableSlotProps<T>['leftIcon']>;
43
- rightIcon?: ComponentType<DataTableSlotProps<T>['rightIcon']>;
44
- csvIcon?: ComponentType<DataTableSlotProps<T>['csvIcon']>;
45
- excelIcon?: ComponentType<DataTableSlotProps<T>['excelIcon']>;
46
- selectAllIcon?: ComponentType<DataTableSlotProps<T>['selectAllIcon']>;
47
- deselectIcon?: ComponentType<DataTableSlotProps<T>['deselectIcon']>;
48
- tableSizeIcon?: ComponentType<DataTableSlotProps<T>['tableSizeIcon']>;
49
- tableSizeSmallIcon?: ComponentType<DataTableSlotProps<T>['tableSizeSmallIcon']>;
50
- tableSizeMediumIcon?: ComponentType<DataTableSlotProps<T>['tableSizeMediumIcon']>;
51
- checkboxSelection?: ComponentType<DataTableSlotProps<T>['checkboxSelection']>;
52
- expandIcon?: ComponentType<DataTableSlotProps<T>['expandIcon']>;
53
- collapseIcon?: ComponentType<DataTableSlotProps<T>['collapseIcon']>;
54
- loadingSkeleton?: ComponentType<DataTableSlotProps<T>['loadingSkeleton']>;
55
- noDataOverlay?: ComponentType<DataTableSlotProps<T>['noDataOverlay']>;
56
- exportProgressDialog?: ComponentType<DataTableSlotProps<T>['exportProgressDialog']>;
57
- }
7
+ import { DataTableToolbarProps } from '../components/toolbar/data-table-toolbar';
8
+ export type SlotComponent<TProps = any> = ComponentType<TProps>;
58
9
  export interface BaseSlotProps<T = any> {
59
10
  table: Table<T>;
60
- data: T[];
61
- columns: DataTableColumn<T>[];
62
11
  }
63
- export interface DataTableSlotProps<T = any> {
64
- root: BaseSlotProps<T> & BoxProps & {
12
+ export type EnhancedSlotProps<TBase, TComponent = {}> = TBase & TComponent & {
13
+ [key: string]: any;
14
+ };
15
+ export interface DataTableSlots<T = any> {
16
+ root?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, BoxProps & {
65
17
  children: ReactNode;
66
- };
67
- tableContainer: BaseSlotProps<T> & TableContainerProps & {
18
+ }>>;
19
+ tableContainer?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, TableContainerProps & {
68
20
  children: ReactNode;
69
21
  enableStickyHeader?: boolean;
70
22
  maxHeight?: string | number;
71
23
  enableVirtualization?: boolean;
72
- };
73
- table: BaseSlotProps<T> & TableProps & {
24
+ }>>;
25
+ table?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, TableProps & {
74
26
  children: ReactNode;
75
27
  tableSize?: DataTableSize;
76
28
  enableStickyHeader?: boolean;
77
29
  fitToScreen?: boolean;
78
30
  tableStyle?: React.CSSProperties;
79
- };
80
- toolbar: BaseSlotProps<T> & {
31
+ }>>;
32
+ toolbar?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, ToolbarProps & DataTableToolbarProps & {
81
33
  title?: string;
82
34
  subtitle?: string;
83
35
  enableGlobalFilter?: boolean;
@@ -106,19 +58,19 @@ export interface DataTableSlotProps<T = any> {
106
58
  onExportComplete?: (result: ExportResult) => void;
107
59
  onExportError?: (error: ExportError) => void;
108
60
  onExportCancel?: () => void;
109
- };
110
- header: BaseSlotProps<T> & {
61
+ }>>;
62
+ header?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, TableHeadProps & {
111
63
  enableSorting?: boolean;
112
64
  draggable?: boolean;
113
65
  enableColumnResizing?: boolean;
114
66
  enableStickyHeader?: boolean;
115
67
  fitToScreen?: boolean;
116
68
  onColumnReorder?: (draggedColumnId: string, targetColumnId: string) => void;
117
- };
118
- headerRow: BaseSlotProps<T> & {
69
+ }>>;
70
+ headerRow?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, TableRowProps & {
119
71
  headerGroups: any[];
120
- };
121
- headerCell: BaseSlotProps<T> & {
72
+ }>>;
73
+ headerCell?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, TableCellProps & {
122
74
  header: any;
123
75
  column: Column<T>;
124
76
  enableSorting?: boolean;
@@ -128,18 +80,22 @@ export interface DataTableSlotProps<T = any> {
128
80
  isPinned?: boolean | 'left' | 'right';
129
81
  pinnedPosition?: number;
130
82
  pinnedRightPosition?: number;
131
- };
132
- sortIconAsc: Record<string, any>;
133
- sortIconDesc: Record<string, any>;
134
- body: BaseSlotProps<T> & {
83
+ }>>;
84
+ sortIconAsc?: SlotComponent<ComponentProps<'svg'> & {
85
+ [key: string]: any;
86
+ }>;
87
+ sortIconDesc?: SlotComponent<ComponentProps<'svg'> & {
88
+ [key: string]: any;
89
+ }>;
90
+ body?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, TableBodyProps & {
135
91
  children: ReactNode;
136
92
  rows: Row<T>[];
137
93
  loading?: boolean;
138
94
  emptyMessage?: string;
139
95
  enableVirtualization?: boolean;
140
96
  enablePagination?: boolean;
141
- };
142
- row: BaseSlotProps<T> & {
97
+ }>>;
98
+ row?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, TableRowProps & {
143
99
  row: Row<T>;
144
100
  index: number;
145
101
  enableHover?: boolean;
@@ -147,8 +103,8 @@ export interface DataTableSlotProps<T = any> {
147
103
  isOdd?: boolean;
148
104
  renderSubComponent?: (row: Row<T>) => ReactNode;
149
105
  disableStickyHeader?: boolean;
150
- };
151
- cell: BaseSlotProps<T> & {
106
+ }>>;
107
+ cell?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, TableCellProps & {
152
108
  row: Row<T>;
153
109
  cell: any;
154
110
  column: Column<T>;
@@ -157,41 +113,37 @@ export interface DataTableSlotProps<T = any> {
157
113
  pinnedPosition?: number;
158
114
  pinnedRightPosition?: number;
159
115
  alignment?: 'left' | 'center' | 'right';
160
- };
161
- loadingRow: BaseSlotProps<T> & {
116
+ }>>;
117
+ loadingRow?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, TableRowProps & {
162
118
  rowCount: number;
163
119
  colSpan: number;
164
- };
165
- emptyRow: BaseSlotProps<T> & {
120
+ }>>;
121
+ emptyRow?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, TableRowProps & {
166
122
  colSpan: number;
167
123
  message: string;
168
- };
169
- expandedRow: BaseSlotProps<T> & {
124
+ }>>;
125
+ expandedRow?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, TableRowProps & {
170
126
  row: Row<T>;
171
127
  colSpan: number;
172
128
  children: ReactNode;
173
- };
174
- footer: BaseSlotProps<T> & {
129
+ }>>;
130
+ footer?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, BoxProps & {
175
131
  children: ReactNode;
176
132
  enableStickyFooter?: boolean;
177
- };
178
- pagination: BaseSlotProps<T> & DataTablePaginationProps;
179
- searchInput: BaseSlotProps<T> & {
133
+ }>>;
134
+ pagination?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, DataTablePaginationProps>>;
135
+ searchInput?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, ComponentProps<'input'> & {
180
136
  value: string;
181
137
  onChange: (value: string) => void;
182
138
  placeholder?: string;
183
139
  autoFocus?: boolean;
184
- };
185
- columnsPanel: BaseSlotProps<T> & {
186
- getTogglableColumns: (columns: DataTableColumn<T>[]) => DataTableColumn<T>[];
187
- getPinnableColumns: (columns: DataTableColumn<T>[]) => DataTableColumn<T>[];
188
- };
189
- columnVisibilityControl: BaseSlotProps<T>;
190
- columnCustomFilterControl: BaseSlotProps<T>;
191
- columnPinningControl: BaseSlotProps<T>;
192
- resetButton: BaseSlotProps<T>;
193
- tableSizeControl: BaseSlotProps<T>;
194
- bulkActionsToolbar: BaseSlotProps<T> & {
140
+ }>>;
141
+ columnVisibilityControl?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, HTMLAttributes<HTMLDivElement>>>;
142
+ columnCustomFilterControl?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, HTMLAttributes<HTMLDivElement>>>;
143
+ columnPinningControl?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, HTMLAttributes<HTMLDivElement>>>;
144
+ resetButton?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, ComponentProps<'button'>>>;
145
+ tableSizeControl?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, HTMLAttributes<HTMLDivElement>>>;
146
+ bulkActionsToolbar?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, ToolbarProps & {
195
147
  selectionState: any;
196
148
  selectedRowCount: number;
197
149
  bulkActions?: (selectionState: any) => ReactNode;
@@ -199,8 +151,8 @@ export interface DataTableSlotProps<T = any> {
199
151
  enableSelectAll?: boolean;
200
152
  onSelectAll?: () => void;
201
153
  onDeselectAll?: () => void;
202
- };
203
- exportButton: BaseSlotProps<T> & {
154
+ }>>;
155
+ exportButton?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, ComponentProps<'button'> & {
204
156
  filename?: string;
205
157
  dataMode?: 'client' | 'server';
206
158
  serverExport?: {
@@ -221,52 +173,105 @@ export interface DataTableSlotProps<T = any> {
221
173
  onExportComplete?: (result: ExportResult) => void;
222
174
  onExportError?: (error: ExportError) => void;
223
175
  onExportCancel?: () => void;
224
- };
225
- searchIcon: Record<string, any>;
226
- clearIcon: Record<string, any>;
227
- exportIcon: Record<string, any>;
228
- columnIcon: Record<string, any>;
229
- resetIcon: Record<string, any>;
230
- moreIcon: Record<string, any>;
231
- filterIcon: Record<string, any>;
232
- pinIcon: Record<string, any>;
233
- unpinIcon: Record<string, any>;
234
- leftIcon: Record<string, any>;
235
- rightIcon: Record<string, any>;
236
- expandIcon: Record<string, any>;
237
- collapseIcon: Record<string, any>;
238
- csvIcon: Record<string, any>;
239
- excelIcon: Record<string, any>;
240
- selectAllIcon: Record<string, any>;
241
- deselectIcon: Record<string, any>;
242
- tableSizeIcon: Record<string, any>;
243
- tableSizeSmallIcon: Record<string, any>;
244
- tableSizeMediumIcon: Record<string, any>;
245
- checkboxSelection: BaseSlotProps<T> & {
176
+ }>>;
177
+ searchIcon?: SlotComponent<ComponentProps<'svg'> & {
178
+ [key: string]: any;
179
+ }>;
180
+ clearIcon?: SlotComponent<ComponentProps<'svg'> & {
181
+ [key: string]: any;
182
+ }>;
183
+ exportIcon?: SlotComponent<ComponentProps<'svg'> & {
184
+ [key: string]: any;
185
+ }>;
186
+ columnIcon?: SlotComponent<ComponentProps<'svg'> & {
187
+ [key: string]: any;
188
+ }>;
189
+ resetIcon?: SlotComponent<ComponentProps<'svg'> & {
190
+ [key: string]: any;
191
+ }>;
192
+ moreIcon?: SlotComponent<ComponentProps<'svg'> & {
193
+ [key: string]: any;
194
+ }>;
195
+ filterIcon?: SlotComponent<ComponentProps<'svg'> & {
196
+ [key: string]: any;
197
+ }>;
198
+ pinIcon?: SlotComponent<ComponentProps<'svg'> & {
199
+ [key: string]: any;
200
+ }>;
201
+ unpinIcon?: SlotComponent<ComponentProps<'svg'> & {
202
+ [key: string]: any;
203
+ }>;
204
+ leftIcon?: SlotComponent<ComponentProps<'svg'> & {
205
+ [key: string]: any;
206
+ }>;
207
+ rightIcon?: SlotComponent<ComponentProps<'svg'> & {
208
+ [key: string]: any;
209
+ }>;
210
+ csvIcon?: SlotComponent<ComponentProps<'svg'> & {
211
+ [key: string]: any;
212
+ }>;
213
+ excelIcon?: SlotComponent<ComponentProps<'svg'> & {
214
+ [key: string]: any;
215
+ }>;
216
+ selectAllIcon?: SlotComponent<ComponentProps<'svg'> & {
217
+ [key: string]: any;
218
+ }>;
219
+ deselectIcon?: SlotComponent<ComponentProps<'svg'> & {
220
+ [key: string]: any;
221
+ }>;
222
+ tableSizeIcon?: SlotComponent<ComponentProps<'svg'> & {
223
+ [key: string]: any;
224
+ }>;
225
+ tableSizeSmallIcon?: SlotComponent<ComponentProps<'svg'> & {
226
+ [key: string]: any;
227
+ }>;
228
+ tableSizeMediumIcon?: SlotComponent<ComponentProps<'svg'> & {
229
+ [key: string]: any;
230
+ }>;
231
+ checkboxSelection?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, ComponentProps<'input'> & {
246
232
  row?: Row<T>;
247
233
  checked: boolean;
248
234
  indeterminate?: boolean;
249
235
  onChange: (checked: boolean) => void;
250
236
  disabled?: boolean;
251
- };
252
- selectionColumn: DataTableColumn<T>;
253
- expandColumn: DataTableColumn<T>;
254
- loadingSkeleton: BaseSlotProps<T> & {
237
+ }>>;
238
+ expandIcon?: SlotComponent<ComponentProps<'svg'> & {
239
+ [key: string]: any;
240
+ }>;
241
+ collapseIcon?: SlotComponent<ComponentProps<'svg'> & {
242
+ [key: string]: any;
243
+ }>;
244
+ loadingSkeleton?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, HTMLAttributes<HTMLDivElement> & {
255
245
  rows: number;
256
246
  columns: number;
257
- };
258
- noDataOverlay: BaseSlotProps<T> & {
247
+ }>>;
248
+ noDataOverlay?: SlotComponent<EnhancedSlotProps<BaseSlotProps<T>, HTMLAttributes<HTMLDivElement> & {
259
249
  message: string;
260
- };
261
- exportProgressDialog: BaseSlotProps<T> & {
262
- open: boolean;
263
- progress: ExportProgress;
264
- onCancel: () => void;
265
- };
250
+ }>>;
251
+ selectionColumn?: DataTableColumn<T>;
252
+ expandColumn?: DataTableColumn<T>;
266
253
  }
267
- export interface DefaultSlots<T = any> extends DataTableSlots<T> {
254
+ export type DataTableSlotProps<T = any> = {
255
+ [K in keyof DataTableSlots<T>]?: Record<string, any>;
256
+ };
257
+ export interface ColumnsPanelSlotProps<T = any> {
258
+ getTogglableColumns?: (columns: DataTableColumn<T>[]) => DataTableColumn<T>[];
259
+ getPinnableColumns?: (columns: DataTableColumn<T>[]) => DataTableColumn<T>[];
268
260
  }
269
261
  export type PartialSlotProps<T = any> = {
270
262
  [K in keyof DataTableSlotProps<T>]?: Partial<DataTableSlotProps<T>[K]>;
263
+ } & {
264
+ columnsPanel?: ColumnsPanelSlotProps<T>;
271
265
  };
272
- export type SlotComponentProps<TSlot extends keyof DataTableSlots<T>, T = any> = DataTableSlotProps<T>[TSlot];
266
+ export type SlotComponentProps<TSlot extends keyof DataTableSlots<T>, T = any> = DataTableSlots<T>[TSlot] extends SlotComponent<infer TProps> ? TProps : never;
267
+ export type ExtractSlotProps<TSlot> = TSlot extends SlotComponent<infer TProps> ? TProps : never;
268
+ export interface DefaultSlots<T = any> extends DataTableSlots<T> {
269
+ }
270
+ export interface SlotConfiguration<T = any> {
271
+ slots?: Partial<DataTableSlots<T>>;
272
+ slotProps?: PartialSlotProps<T>;
273
+ }
274
+ export interface SlotOverrideConfig<T = any> {
275
+ overrideSlot?: <K extends keyof DataTableSlots<T>>(slotName: K, component: DataTableSlots<T>[K], props?: Partial<SlotComponentProps<K, T>>) => void;
276
+ mergeSlotProps?: <K extends keyof DataTableSlots<T>>(slotName: K, props: Partial<SlotComponentProps<K, T>>) => Partial<SlotComponentProps<K, T>>;
277
+ }
@@ -1,9 +1,15 @@
1
1
  import { ComponentType } from 'react';
2
2
  import { DataTableSlots } from '../types/slots.types';
3
3
  export declare function getSlotComponent<T, K extends keyof DataTableSlots<T>>(slots: Partial<DataTableSlots<T>> | undefined, slotName: K, fallback: ComponentType<any>): ComponentType<any>;
4
- export declare function renderSlot(slotComponent: ComponentType<any>, defaultProps: any, slotProps?: any): import("react/jsx-runtime").JSX.Element;
5
- export declare function createSlottableComponent<T, K extends keyof DataTableSlots<T>>(slotName: K, defaultComponent: ComponentType<any>): (props: {
6
- slots?: Partial<DataTableSlots<T>>;
7
- slotProps?: any;
8
- componentProps: any;
9
- }) => import("react/jsx-runtime").JSX.Element;
4
+ export declare function mergeSlotProps(defaultProps?: Record<string, any>, slotProps?: Record<string, any>, userProps?: Record<string, any>): Record<string, any>;
5
+ export declare function getSlotComponentWithProps<T, K extends keyof DataTableSlots<T>>(slots: Partial<DataTableSlots<T>> | undefined, slotProps: Record<string, any>, slotName: K, fallback: ComponentType<any>, defaultProps?: Record<string, any>): {
6
+ component: ComponentType<any>;
7
+ props: Record<string, any>;
8
+ };
9
+ export declare function isSlotOverridden<T, K extends keyof DataTableSlots<T>>(slots: Partial<DataTableSlots<T>> | undefined, slotName: K): boolean;
10
+ export declare function getOverriddenSlots<T>(slots: Partial<DataTableSlots<T>> | undefined): Array<keyof DataTableSlots<T>>;
11
+ export declare function extractSlotProps<T, K extends keyof DataTableSlots<T>>(slotProps: Record<string, any> | undefined, slotName: K): Record<string, any>;
12
+ export declare function createEnhancedSlotComponent<T, K extends keyof DataTableSlots<T>>(slots: Partial<DataTableSlots<T>> | undefined, slotName: K, fallback: ComponentType<any>, baseProps?: Record<string, any>): ComponentType<any>;
13
+ export declare function validateSlotProps<T, K extends keyof DataTableSlots<T>>(slotName: K, props: any, requiredProps?: string[]): boolean;
14
+ export declare function createSlotProps<T>(table: any, additionalProps?: Record<string, any>): Record<string, any>;
15
+ export declare function withSlotProps<T, K extends keyof DataTableSlots<T>>(slots: Partial<DataTableSlots<T>> | undefined, slotProps: Record<string, any>, slotName: K, fallback: ComponentType<any>): (props: any) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
@@ -1,21 +1,95 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSlotComponent = getSlotComponent;
4
- exports.renderSlot = renderSlot;
5
- exports.createSlottableComponent = createSlottableComponent;
6
- const jsx_runtime_1 = require("react/jsx-runtime");
4
+ exports.mergeSlotProps = mergeSlotProps;
5
+ exports.getSlotComponentWithProps = getSlotComponentWithProps;
6
+ exports.isSlotOverridden = isSlotOverridden;
7
+ exports.getOverriddenSlots = getOverriddenSlots;
8
+ exports.extractSlotProps = extractSlotProps;
9
+ exports.createEnhancedSlotComponent = createEnhancedSlotComponent;
10
+ exports.validateSlotProps = validateSlotProps;
11
+ exports.createSlotProps = createSlotProps;
12
+ exports.withSlotProps = withSlotProps;
13
+ const react_1 = require("react");
7
14
  function getSlotComponent(slots, slotName, fallback) {
8
15
  return (slots === null || slots === void 0 ? void 0 : slots[slotName]) || fallback;
9
16
  }
10
- function renderSlot(slotComponent, defaultProps, slotProps) {
11
- const mergedProps = Object.assign(Object.assign({}, defaultProps), slotProps);
12
- const Component = slotComponent;
13
- return (0, jsx_runtime_1.jsx)(Component, Object.assign({}, mergedProps));
17
+ function mergeSlotProps(defaultProps = {}, slotProps = {}, userProps = {}) {
18
+ const merged = Object.assign({}, defaultProps);
19
+ Object.keys(slotProps).forEach(key => {
20
+ const slotValue = slotProps[key];
21
+ const mergedValue = merged[key];
22
+ if (key === 'sx' && typeof slotValue === 'object' && typeof mergedValue === 'object') {
23
+ merged[key] = Object.assign(Object.assign({}, mergedValue), slotValue);
24
+ }
25
+ else if (key === 'style' && typeof slotValue === 'object' && typeof mergedValue === 'object') {
26
+ merged[key] = Object.assign(Object.assign({}, mergedValue), slotValue);
27
+ }
28
+ else if (key === 'className' && typeof slotValue === 'string' && typeof mergedValue === 'string') {
29
+ merged[key] = `${mergedValue} ${slotValue}`.trim();
30
+ }
31
+ else {
32
+ merged[key] = slotValue;
33
+ }
34
+ });
35
+ Object.keys(userProps).forEach(key => {
36
+ const userValue = userProps[key];
37
+ const mergedValue = merged[key];
38
+ if (key === 'sx' && typeof userValue === 'object' && typeof mergedValue === 'object') {
39
+ merged[key] = Object.assign(Object.assign({}, mergedValue), userValue);
40
+ }
41
+ else if (key === 'style' && typeof userValue === 'object' && typeof mergedValue === 'object') {
42
+ merged[key] = Object.assign(Object.assign({}, mergedValue), userValue);
43
+ }
44
+ else if (key === 'className' && typeof userValue === 'string' && typeof mergedValue === 'string') {
45
+ merged[key] = `${mergedValue} ${userValue}`.trim();
46
+ }
47
+ else {
48
+ merged[key] = userValue;
49
+ }
50
+ });
51
+ return merged;
14
52
  }
15
- function createSlottableComponent(slotName, defaultComponent) {
16
- return function SlottableComponent(props) {
17
- var _a;
18
- const SlotComponent = getSlotComponent(props.slots, slotName, defaultComponent);
19
- return renderSlot(SlotComponent, props.componentProps, (_a = props.slotProps) === null || _a === void 0 ? void 0 : _a[slotName]);
53
+ function getSlotComponentWithProps(slots, slotProps = {}, slotName, fallback, defaultProps = {}) {
54
+ const component = getSlotComponent(slots, slotName, fallback);
55
+ const props = mergeSlotProps(defaultProps, slotProps[slotName] || {}, {});
56
+ return { component, props };
57
+ }
58
+ function isSlotOverridden(slots, slotName) {
59
+ return Boolean(slots === null || slots === void 0 ? void 0 : slots[slotName]);
60
+ }
61
+ function getOverriddenSlots(slots) {
62
+ if (!slots)
63
+ return [];
64
+ return Object.keys(slots).filter(key => Boolean(slots[key]));
65
+ }
66
+ function extractSlotProps(slotProps, slotName) {
67
+ return ((slotProps === null || slotProps === void 0 ? void 0 : slotProps[slotName]) || {});
68
+ }
69
+ function createEnhancedSlotComponent(slots, slotName, fallback, baseProps = {}) {
70
+ const SlotComponent = getSlotComponent(slots, slotName, fallback);
71
+ return function EnhancedSlot(props) {
72
+ const mergedProps = mergeSlotProps(baseProps, {}, props);
73
+ return (0, react_1.createElement)(SlotComponent, mergedProps);
74
+ };
75
+ }
76
+ function validateSlotProps(slotName, props, requiredProps = []) {
77
+ if (process.env.NODE_ENV === 'development') {
78
+ const missingProps = requiredProps.filter(prop => !(prop in props));
79
+ if (missingProps.length > 0) {
80
+ console.warn(`Missing required props for slot "${String(slotName)}": ${missingProps.join(', ')}`);
81
+ return false;
82
+ }
83
+ }
84
+ return true;
85
+ }
86
+ function createSlotProps(table, additionalProps = {}) {
87
+ return Object.assign({ table }, additionalProps);
88
+ }
89
+ function withSlotProps(slots, slotProps = {}, slotName, fallback) {
90
+ return function SlotWrapper(props) {
91
+ const SlotComponent = getSlotComponent(slots, slotName, fallback);
92
+ const mergedProps = mergeSlotProps({}, slotProps[slotName] || {}, props);
93
+ return (0, react_1.createElement)(SlotComponent, mergedProps);
20
94
  };
21
95
  }