@ackplus/react-tanstack-data-table 1.1.19 → 1.1.21
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/dist/lib/hooks/use-data-table-engine.d.ts.map +1 -1
- package/dist/lib/hooks/use-data-table-engine.js +54 -15
- package/dist/lib/types/data-table.types.d.ts +2 -1
- package/dist/lib/types/data-table.types.d.ts.map +1 -1
- package/package.json +3 -4
- package/src/index.ts +0 -75
- package/src/lib/components/data-table-view.tsx +0 -386
- package/src/lib/components/droupdown/menu-dropdown.tsx +0 -103
- package/src/lib/components/filters/filter-value-input.tsx +0 -225
- package/src/lib/components/filters/index.ts +0 -126
- package/src/lib/components/headers/draggable-header.tsx +0 -326
- package/src/lib/components/headers/index.ts +0 -6
- package/src/lib/components/headers/table-header.tsx +0 -175
- package/src/lib/components/index.ts +0 -21
- package/src/lib/components/pagination/data-table-pagination.tsx +0 -111
- package/src/lib/components/pagination/index.ts +0 -5
- package/src/lib/components/rows/data-table-row.tsx +0 -218
- package/src/lib/components/rows/empty-data-row.tsx +0 -69
- package/src/lib/components/rows/index.ts +0 -7
- package/src/lib/components/rows/loading-rows.tsx +0 -164
- package/src/lib/components/toolbar/bulk-actions-toolbar.tsx +0 -125
- package/src/lib/components/toolbar/column-filter-control.tsx +0 -432
- package/src/lib/components/toolbar/column-pinning-control.tsx +0 -275
- package/src/lib/components/toolbar/column-reset-control.tsx +0 -74
- package/src/lib/components/toolbar/column-visibility-control.tsx +0 -105
- package/src/lib/components/toolbar/data-table-toolbar.tsx +0 -257
- package/src/lib/components/toolbar/index.ts +0 -17
- package/src/lib/components/toolbar/table-export-control.tsx +0 -233
- package/src/lib/components/toolbar/table-refresh-control.tsx +0 -62
- package/src/lib/components/toolbar/table-search-control.tsx +0 -155
- package/src/lib/components/toolbar/table-size-control.tsx +0 -102
- package/src/lib/contexts/data-table-context.tsx +0 -126
- package/src/lib/data-table.tsx +0 -29
- package/src/lib/features/README.md +0 -161
- package/src/lib/features/column-filter.feature.ts +0 -493
- package/src/lib/features/index.ts +0 -23
- package/src/lib/features/selection.feature.ts +0 -322
- package/src/lib/hooks/index.ts +0 -2
- package/src/lib/hooks/use-data-table-engine.ts +0 -1516
- package/src/lib/icons/add-icon.tsx +0 -23
- package/src/lib/icons/csv-icon.tsx +0 -15
- package/src/lib/icons/delete-icon.tsx +0 -30
- package/src/lib/icons/excel-icon.tsx +0 -15
- package/src/lib/icons/index.ts +0 -7
- package/src/lib/icons/unpin-icon.tsx +0 -18
- package/src/lib/icons/view-comfortable-icon.tsx +0 -45
- package/src/lib/icons/view-compact-icon.tsx +0 -55
- package/src/lib/types/column.types.ts +0 -63
- package/src/lib/types/data-table-api.ts +0 -191
- package/src/lib/types/data-table.types.ts +0 -192
- package/src/lib/types/export.types.ts +0 -223
- package/src/lib/types/index.ts +0 -24
- package/src/lib/types/slots.types.ts +0 -342
- package/src/lib/types/table.types.ts +0 -88
- package/src/lib/utils/column-helpers.ts +0 -72
- package/src/lib/utils/debounced-fetch.utils.ts +0 -131
- package/src/lib/utils/export-utils.ts +0 -712
- package/src/lib/utils/index.ts +0 -27
- package/src/lib/utils/logger.ts +0 -203
- package/src/lib/utils/slot-helpers.tsx +0 -194
- package/src/lib/utils/special-columns.utils.ts +0 -101
- package/src/lib/utils/styling-helpers.ts +0 -126
- package/src/lib/utils/table-helpers.ts +0 -106
|
@@ -1,386 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DataTableView – presentational layer for DataTable.
|
|
3
|
-
* Renders based on engine result; no fetch, export, or API logic.
|
|
4
|
-
*/
|
|
5
|
-
import { Table, TableContainer, TableBody, Box, Paper } from '@mui/material';
|
|
6
|
-
import React, { useCallback } from 'react';
|
|
7
|
-
|
|
8
|
-
import { getSlotComponentWithProps, mergeSlotProps } from '../utils/slot-helpers';
|
|
9
|
-
import { TableHeader } from './headers';
|
|
10
|
-
import { DataTablePagination } from './pagination';
|
|
11
|
-
import { DataTableRow, LoadingRows, EmptyDataRow } from './rows';
|
|
12
|
-
import { DataTableToolbar, BulkActionsToolbar } from './toolbar';
|
|
13
|
-
import type { DataTableProps } from '../types/data-table.types';
|
|
14
|
-
import type { EngineResult } from '../hooks/use-data-table-engine';
|
|
15
|
-
|
|
16
|
-
export interface DataTableViewProps<T = any> extends DataTableProps<T> {
|
|
17
|
-
engine: EngineResult<T>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function DataTableView<T extends Record<string, any>>({
|
|
21
|
-
engine,
|
|
22
|
-
extraFilter = null,
|
|
23
|
-
footerFilter = null,
|
|
24
|
-
enableGlobalFilter = true,
|
|
25
|
-
enableColumnVisibility = true,
|
|
26
|
-
enableColumnFilter = false,
|
|
27
|
-
enableExport = false,
|
|
28
|
-
enableReset = true,
|
|
29
|
-
enableTableSizeControl = true,
|
|
30
|
-
enableColumnPinning = false,
|
|
31
|
-
enableRefresh = false,
|
|
32
|
-
enableBulkActions = false,
|
|
33
|
-
bulkActions,
|
|
34
|
-
enableRowSelection = false,
|
|
35
|
-
enableColumnDragging = false,
|
|
36
|
-
enableColumnResizing = false,
|
|
37
|
-
enableStickyHeaderOrFooter = false,
|
|
38
|
-
maxHeight = '400px',
|
|
39
|
-
enableVirtualization = false,
|
|
40
|
-
enablePagination = false,
|
|
41
|
-
tableProps = {},
|
|
42
|
-
enableHover = true,
|
|
43
|
-
enableStripes = false,
|
|
44
|
-
emptyMessage = 'No data available',
|
|
45
|
-
skeletonRows = 5,
|
|
46
|
-
onRowClick,
|
|
47
|
-
selectOnRowClick = false,
|
|
48
|
-
renderSubComponent,
|
|
49
|
-
slots = {},
|
|
50
|
-
slotProps = {},
|
|
51
|
-
}: DataTableViewProps<T>) {
|
|
52
|
-
const {
|
|
53
|
-
table,
|
|
54
|
-
refs,
|
|
55
|
-
derived,
|
|
56
|
-
state,
|
|
57
|
-
actions,
|
|
58
|
-
} = engine;
|
|
59
|
-
|
|
60
|
-
const {
|
|
61
|
-
tableContainerRef,
|
|
62
|
-
apiRef,
|
|
63
|
-
} = refs;
|
|
64
|
-
|
|
65
|
-
const {
|
|
66
|
-
tableLoading,
|
|
67
|
-
rows,
|
|
68
|
-
visibleLeafColumns,
|
|
69
|
-
useFixedLayout,
|
|
70
|
-
tableStyle,
|
|
71
|
-
isSomeRowsSelected,
|
|
72
|
-
selectedRowCount,
|
|
73
|
-
tableTotalRow,
|
|
74
|
-
} = derived;
|
|
75
|
-
|
|
76
|
-
const {
|
|
77
|
-
pagination,
|
|
78
|
-
selectionState,
|
|
79
|
-
tableSize,
|
|
80
|
-
} = state;
|
|
81
|
-
|
|
82
|
-
const {
|
|
83
|
-
handleColumnReorder,
|
|
84
|
-
renderRowModel,
|
|
85
|
-
} = actions;
|
|
86
|
-
|
|
87
|
-
const rowVirtualizer = renderRowModel.rowVirtualizer;
|
|
88
|
-
|
|
89
|
-
const renderTableRows = useCallback(() => {
|
|
90
|
-
if (tableLoading) {
|
|
91
|
-
const { component: LoadingRowComponent, props: loadingRowProps } = getSlotComponentWithProps(
|
|
92
|
-
slots,
|
|
93
|
-
slotProps || {},
|
|
94
|
-
'loadingRow',
|
|
95
|
-
LoadingRows,
|
|
96
|
-
{}
|
|
97
|
-
);
|
|
98
|
-
return (
|
|
99
|
-
<LoadingRowComponent
|
|
100
|
-
rowCount={enablePagination ? Math.min(pagination.pageSize, skeletonRows) : skeletonRows}
|
|
101
|
-
colSpan={table.getAllColumns().length}
|
|
102
|
-
slots={slots}
|
|
103
|
-
slotProps={slotProps}
|
|
104
|
-
{...loadingRowProps}
|
|
105
|
-
/>
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
if (rows.length === 0) {
|
|
109
|
-
const { component: EmptyRowComponent, props: emptyRowProps } = getSlotComponentWithProps(
|
|
110
|
-
slots,
|
|
111
|
-
slotProps || {},
|
|
112
|
-
'emptyRow',
|
|
113
|
-
EmptyDataRow,
|
|
114
|
-
{}
|
|
115
|
-
);
|
|
116
|
-
return (
|
|
117
|
-
<EmptyRowComponent
|
|
118
|
-
colSpan={table.getAllColumns().length}
|
|
119
|
-
message={emptyMessage}
|
|
120
|
-
slots={slots}
|
|
121
|
-
slotProps={slotProps}
|
|
122
|
-
{...emptyRowProps}
|
|
123
|
-
/>
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
if (enableVirtualization && !enablePagination && rows.length > 0) {
|
|
127
|
-
const virtualItems = rowVirtualizer.getVirtualItems();
|
|
128
|
-
return (
|
|
129
|
-
<>
|
|
130
|
-
{virtualItems.length > 0 && (
|
|
131
|
-
<tr>
|
|
132
|
-
<td
|
|
133
|
-
colSpan={table.getAllColumns().length}
|
|
134
|
-
style={{
|
|
135
|
-
height: `${virtualItems[0]?.start ?? 0}px`,
|
|
136
|
-
padding: 0,
|
|
137
|
-
border: 0,
|
|
138
|
-
}}
|
|
139
|
-
/>
|
|
140
|
-
</tr>
|
|
141
|
-
)}
|
|
142
|
-
{virtualItems.map((virtualRow) => {
|
|
143
|
-
const row = rows[virtualRow.index];
|
|
144
|
-
if (!row) return null;
|
|
145
|
-
return (
|
|
146
|
-
<DataTableRow
|
|
147
|
-
key={row.id}
|
|
148
|
-
row={row}
|
|
149
|
-
enableHover={enableHover}
|
|
150
|
-
enableStripes={enableStripes}
|
|
151
|
-
isOdd={virtualRow.index % 2 === 1}
|
|
152
|
-
renderSubComponent={renderSubComponent}
|
|
153
|
-
disableStickyHeader={enableStickyHeaderOrFooter}
|
|
154
|
-
onRowClick={onRowClick}
|
|
155
|
-
selectOnRowClick={selectOnRowClick}
|
|
156
|
-
slots={slots}
|
|
157
|
-
slotProps={slotProps}
|
|
158
|
-
/>
|
|
159
|
-
);
|
|
160
|
-
})}
|
|
161
|
-
{virtualItems.length > 0 && (
|
|
162
|
-
<tr>
|
|
163
|
-
<td
|
|
164
|
-
colSpan={table.getAllColumns().length}
|
|
165
|
-
style={{
|
|
166
|
-
height: `${rowVirtualizer.getTotalSize() -
|
|
167
|
-
(virtualItems[virtualItems.length - 1]?.end ?? 0)}px`,
|
|
168
|
-
padding: 0,
|
|
169
|
-
border: 0,
|
|
170
|
-
}}
|
|
171
|
-
/>
|
|
172
|
-
</tr>
|
|
173
|
-
)}
|
|
174
|
-
</>
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
return rows.map((row, index) => (
|
|
178
|
-
<DataTableRow
|
|
179
|
-
key={row.id}
|
|
180
|
-
row={row}
|
|
181
|
-
enableHover={enableHover}
|
|
182
|
-
enableStripes={enableStripes}
|
|
183
|
-
isOdd={index % 2 === 1}
|
|
184
|
-
renderSubComponent={renderSubComponent}
|
|
185
|
-
disableStickyHeader={enableStickyHeaderOrFooter}
|
|
186
|
-
onRowClick={onRowClick}
|
|
187
|
-
selectOnRowClick={selectOnRowClick}
|
|
188
|
-
slots={slots}
|
|
189
|
-
slotProps={slotProps}
|
|
190
|
-
/>
|
|
191
|
-
));
|
|
192
|
-
}, [
|
|
193
|
-
tableLoading,
|
|
194
|
-
rows,
|
|
195
|
-
enableVirtualization,
|
|
196
|
-
enablePagination,
|
|
197
|
-
pagination.pageSize,
|
|
198
|
-
skeletonRows,
|
|
199
|
-
table,
|
|
200
|
-
slotProps,
|
|
201
|
-
emptyMessage,
|
|
202
|
-
rowVirtualizer,
|
|
203
|
-
enableHover,
|
|
204
|
-
enableStripes,
|
|
205
|
-
renderSubComponent,
|
|
206
|
-
enableStickyHeaderOrFooter,
|
|
207
|
-
onRowClick,
|
|
208
|
-
selectOnRowClick,
|
|
209
|
-
slots,
|
|
210
|
-
]);
|
|
211
|
-
|
|
212
|
-
const { component: RootComponent, props: rootSlotProps } = getSlotComponentWithProps(
|
|
213
|
-
slots,
|
|
214
|
-
slotProps || {},
|
|
215
|
-
'root',
|
|
216
|
-
Box,
|
|
217
|
-
{}
|
|
218
|
-
);
|
|
219
|
-
const { component: ToolbarComponent, props: toolbarSlotProps } = getSlotComponentWithProps(
|
|
220
|
-
slots,
|
|
221
|
-
slotProps || {},
|
|
222
|
-
'toolbar',
|
|
223
|
-
DataTableToolbar,
|
|
224
|
-
{}
|
|
225
|
-
);
|
|
226
|
-
const { component: BulkActionsComponent, props: bulkActionsSlotProps } = getSlotComponentWithProps(
|
|
227
|
-
slots,
|
|
228
|
-
slotProps || {},
|
|
229
|
-
'bulkActionsToolbar',
|
|
230
|
-
BulkActionsToolbar,
|
|
231
|
-
{}
|
|
232
|
-
);
|
|
233
|
-
const { component: TableContainerComponent, props: tableContainerSlotProps } = getSlotComponentWithProps(
|
|
234
|
-
slots,
|
|
235
|
-
slotProps || {},
|
|
236
|
-
'tableContainer',
|
|
237
|
-
TableContainer,
|
|
238
|
-
{}
|
|
239
|
-
);
|
|
240
|
-
const { component: TableComponent, props: tableComponentSlotProps } = getSlotComponentWithProps(
|
|
241
|
-
slots,
|
|
242
|
-
slotProps || {},
|
|
243
|
-
'table',
|
|
244
|
-
Table,
|
|
245
|
-
{}
|
|
246
|
-
);
|
|
247
|
-
const { component: BodyComponent, props: bodySlotProps } = getSlotComponentWithProps(
|
|
248
|
-
slots,
|
|
249
|
-
slotProps || {},
|
|
250
|
-
'body',
|
|
251
|
-
TableBody,
|
|
252
|
-
{}
|
|
253
|
-
);
|
|
254
|
-
const { component: FooterComponent, props: footerSlotProps } = getSlotComponentWithProps(
|
|
255
|
-
slots,
|
|
256
|
-
slotProps || {},
|
|
257
|
-
'footer',
|
|
258
|
-
Box,
|
|
259
|
-
{}
|
|
260
|
-
);
|
|
261
|
-
const { component: PaginationComponent, props: paginationSlotProps } = getSlotComponentWithProps(
|
|
262
|
-
slots,
|
|
263
|
-
slotProps || {},
|
|
264
|
-
'pagination',
|
|
265
|
-
DataTablePagination,
|
|
266
|
-
{}
|
|
267
|
-
);
|
|
268
|
-
|
|
269
|
-
return (
|
|
270
|
-
<RootComponent {...rootSlotProps}>
|
|
271
|
-
{(enableGlobalFilter || extraFilter) ? (
|
|
272
|
-
<ToolbarComponent
|
|
273
|
-
extraFilter={extraFilter}
|
|
274
|
-
enableGlobalFilter={enableGlobalFilter}
|
|
275
|
-
enableColumnVisibility={enableColumnVisibility}
|
|
276
|
-
enableColumnFilter={enableColumnFilter}
|
|
277
|
-
enableExport={enableExport}
|
|
278
|
-
enableReset={enableReset}
|
|
279
|
-
enableTableSizeControl={enableTableSizeControl}
|
|
280
|
-
enableColumnPinning={enableColumnPinning}
|
|
281
|
-
enableRefresh={enableRefresh}
|
|
282
|
-
{...toolbarSlotProps}
|
|
283
|
-
refreshButtonProps={{
|
|
284
|
-
loading: tableLoading,
|
|
285
|
-
showSpinnerWhileLoading: false,
|
|
286
|
-
onRefresh: () => apiRef.current?.data?.refresh?.(true),
|
|
287
|
-
...toolbarSlotProps.refreshButtonProps,
|
|
288
|
-
}}
|
|
289
|
-
/>
|
|
290
|
-
) : null}
|
|
291
|
-
|
|
292
|
-
{enableBulkActions && enableRowSelection && isSomeRowsSelected ? (
|
|
293
|
-
<BulkActionsComponent
|
|
294
|
-
selectionState={selectionState}
|
|
295
|
-
selectedRowCount={selectedRowCount}
|
|
296
|
-
bulkActions={bulkActions}
|
|
297
|
-
sx={{
|
|
298
|
-
position: 'relative',
|
|
299
|
-
zIndex: 2,
|
|
300
|
-
...bulkActionsSlotProps.sx,
|
|
301
|
-
}}
|
|
302
|
-
{...bulkActionsSlotProps}
|
|
303
|
-
/>
|
|
304
|
-
) : null}
|
|
305
|
-
|
|
306
|
-
<TableContainerComponent
|
|
307
|
-
component={Paper}
|
|
308
|
-
ref={tableContainerRef}
|
|
309
|
-
sx={{
|
|
310
|
-
width: '100%',
|
|
311
|
-
overflowX: 'auto',
|
|
312
|
-
...(enableStickyHeaderOrFooter && {
|
|
313
|
-
maxHeight,
|
|
314
|
-
overflowY: 'auto',
|
|
315
|
-
}),
|
|
316
|
-
...(enableVirtualization && {
|
|
317
|
-
maxHeight,
|
|
318
|
-
overflowY: 'auto',
|
|
319
|
-
}),
|
|
320
|
-
...tableContainerSlotProps?.sx,
|
|
321
|
-
}}
|
|
322
|
-
{...tableContainerSlotProps}
|
|
323
|
-
>
|
|
324
|
-
<TableComponent
|
|
325
|
-
size={tableSize}
|
|
326
|
-
stickyHeader={enableStickyHeaderOrFooter}
|
|
327
|
-
style={{
|
|
328
|
-
...tableStyle,
|
|
329
|
-
...tableProps?.style,
|
|
330
|
-
}}
|
|
331
|
-
{...mergeSlotProps(tableProps || {}, tableComponentSlotProps)}
|
|
332
|
-
>
|
|
333
|
-
{useFixedLayout ? (
|
|
334
|
-
<colgroup>
|
|
335
|
-
{visibleLeafColumns().map((column) => (
|
|
336
|
-
<col
|
|
337
|
-
key={column.id}
|
|
338
|
-
style={{
|
|
339
|
-
width: column.getSize(),
|
|
340
|
-
minWidth: column.columnDef.minSize,
|
|
341
|
-
maxWidth: column.columnDef.maxSize,
|
|
342
|
-
}}
|
|
343
|
-
/>
|
|
344
|
-
))}
|
|
345
|
-
</colgroup>
|
|
346
|
-
) : null}
|
|
347
|
-
<TableHeader
|
|
348
|
-
draggable={enableColumnDragging}
|
|
349
|
-
enableColumnResizing={enableColumnResizing}
|
|
350
|
-
enableStickyHeader={enableStickyHeaderOrFooter}
|
|
351
|
-
onColumnReorder={handleColumnReorder}
|
|
352
|
-
slots={slots}
|
|
353
|
-
slotProps={slotProps}
|
|
354
|
-
/>
|
|
355
|
-
<BodyComponent {...bodySlotProps}>
|
|
356
|
-
{renderTableRows()}
|
|
357
|
-
</BodyComponent>
|
|
358
|
-
</TableComponent>
|
|
359
|
-
</TableContainerComponent>
|
|
360
|
-
|
|
361
|
-
{enablePagination ? (
|
|
362
|
-
<FooterComponent
|
|
363
|
-
sx={{
|
|
364
|
-
...(enableStickyHeaderOrFooter && {
|
|
365
|
-
position: 'sticky',
|
|
366
|
-
bottom: 0,
|
|
367
|
-
backgroundColor: 'background.paper',
|
|
368
|
-
borderTop: '1px solid',
|
|
369
|
-
borderColor: 'divider',
|
|
370
|
-
zIndex: 1,
|
|
371
|
-
}),
|
|
372
|
-
...footerSlotProps.sx,
|
|
373
|
-
}}
|
|
374
|
-
{...footerSlotProps}
|
|
375
|
-
>
|
|
376
|
-
<PaginationComponent
|
|
377
|
-
footerFilter={footerFilter}
|
|
378
|
-
pagination={pagination}
|
|
379
|
-
totalRow={tableTotalRow}
|
|
380
|
-
{...paginationSlotProps}
|
|
381
|
-
/>
|
|
382
|
-
</FooterComponent>
|
|
383
|
-
) : null}
|
|
384
|
-
</RootComponent>
|
|
385
|
-
);
|
|
386
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { Button, Menu, MenuProps, Popover } from '@mui/material';
|
|
2
|
-
import React, {
|
|
3
|
-
cloneElement,
|
|
4
|
-
ReactElement,
|
|
5
|
-
ReactNode,
|
|
6
|
-
useCallback,
|
|
7
|
-
useMemo,
|
|
8
|
-
useState,
|
|
9
|
-
} from 'react';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
type ChildrenEvent = {
|
|
13
|
-
handleClose: () => void;
|
|
14
|
-
open: boolean;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
type AnchorEvent = {
|
|
18
|
-
isOpen: boolean;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export interface MenuDropdownProps
|
|
22
|
-
extends Omit<MenuProps, 'children' | 'open'> {
|
|
23
|
-
children?: ((event: ChildrenEvent) => ReactNode) | ReactNode | any;
|
|
24
|
-
anchor?: ((event: AnchorEvent) => ReactElement<any>) | ReactElement<any>;
|
|
25
|
-
label?: ReactNode;
|
|
26
|
-
component?: typeof Popover | typeof Menu;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function MenuDropdown({
|
|
30
|
-
children,
|
|
31
|
-
anchor,
|
|
32
|
-
label,
|
|
33
|
-
component,
|
|
34
|
-
...props
|
|
35
|
-
}: MenuDropdownProps): ReactElement {
|
|
36
|
-
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
37
|
-
const isOpen = useMemo(() => Boolean(anchorEl), [anchorEl]);
|
|
38
|
-
const handleClick = useCallback(
|
|
39
|
-
(event: React.MouseEvent<HTMLElement>) => {
|
|
40
|
-
event.preventDefault();
|
|
41
|
-
event.stopPropagation();
|
|
42
|
-
setAnchorEl(event.currentTarget as HTMLElement);
|
|
43
|
-
},
|
|
44
|
-
[],
|
|
45
|
-
);
|
|
46
|
-
const handleClose = useCallback((event:any) => {
|
|
47
|
-
event?.preventDefault();
|
|
48
|
-
event?.stopPropagation();
|
|
49
|
-
setAnchorEl(null);
|
|
50
|
-
}, []);
|
|
51
|
-
const anchorNode = useMemo(() => {
|
|
52
|
-
if (anchor) {
|
|
53
|
-
let node = anchor;
|
|
54
|
-
if (typeof anchor === 'function') {
|
|
55
|
-
node = anchor({ isOpen: isOpen });
|
|
56
|
-
}
|
|
57
|
-
const existingOnClick = (node as ReactElement<any>).props?.onClick;
|
|
58
|
-
return cloneElement(node as ReactElement<any>, {
|
|
59
|
-
onClick: (event: React.MouseEvent<HTMLElement>) => {
|
|
60
|
-
existingOnClick?.(event);
|
|
61
|
-
if (!event.defaultPrevented) {
|
|
62
|
-
handleClick(event);
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
return <Button onClick={handleClick}>{label as any}</Button>;
|
|
68
|
-
}, [
|
|
69
|
-
anchor,
|
|
70
|
-
handleClick,
|
|
71
|
-
isOpen,
|
|
72
|
-
label,
|
|
73
|
-
]);
|
|
74
|
-
|
|
75
|
-
const DropDownComponent = (component || Popover) as React.ComponentType<any>;
|
|
76
|
-
|
|
77
|
-
return (
|
|
78
|
-
<>
|
|
79
|
-
{anchorNode}
|
|
80
|
-
<DropDownComponent
|
|
81
|
-
anchorEl={anchorEl}
|
|
82
|
-
open={isOpen}
|
|
83
|
-
onClose={handleClose}
|
|
84
|
-
anchorOrigin={{
|
|
85
|
-
vertical: 'bottom',
|
|
86
|
-
horizontal: 'left',
|
|
87
|
-
}}
|
|
88
|
-
transformOrigin={{
|
|
89
|
-
vertical: 'top',
|
|
90
|
-
horizontal: 'left',
|
|
91
|
-
}}
|
|
92
|
-
{...props}
|
|
93
|
-
>
|
|
94
|
-
{typeof children === 'function' ?
|
|
95
|
-
children({
|
|
96
|
-
handleClose,
|
|
97
|
-
open: isOpen,
|
|
98
|
-
}) :
|
|
99
|
-
children}
|
|
100
|
-
</DropDownComponent>
|
|
101
|
-
</>
|
|
102
|
-
);
|
|
103
|
-
}
|