@appdirect/design-system 0.0.0-stage → 0.0.2

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 (130) hide show
  1. package/README.md +12 -2
  2. package/dist/Buttons/ActionIcon.tsx +37 -0
  3. package/dist/Buttons/Button.module.css +5 -0
  4. package/dist/Buttons/Button.tsx +124 -0
  5. package/dist/Buttons/CloseButton.tsx +83 -0
  6. package/dist/Buttons/index.ts +20 -0
  7. package/dist/Combobox/AutocompleteClearable.tsx +128 -0
  8. package/dist/Combobox/Combobox.tsx +37 -0
  9. package/dist/Combobox/Multiselect.tsx +158 -0
  10. package/dist/Combobox/SearchableSelect.tsx +131 -0
  11. package/dist/Combobox/Select.tsx +154 -0
  12. package/dist/Combobox/index.ts +20 -0
  13. package/dist/ComplexComponents/DashboardWidget/DashboardWidget.tsx +313 -0
  14. package/dist/ComplexComponents/DashboardWidget/index.ts +2 -0
  15. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.tsx +177 -0
  16. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.ts +35 -0
  17. package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.tsx +74 -0
  18. package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.tsx +358 -0
  19. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.tsx +48 -0
  20. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/DateRangeFilter.tsx +26 -0
  21. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/FilterRenderer.tsx +71 -0
  22. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/FilterSystem.tsx +158 -0
  23. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/MultiSelectFilter.tsx +79 -0
  24. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/SingleSelectFilter.tsx +65 -0
  25. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/index.ts +70 -0
  26. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/types.ts +140 -0
  27. package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.tsx +76 -0
  28. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.tsx +73 -0
  29. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.tsx +50 -0
  30. package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.tsx +788 -0
  31. package/dist/ComplexComponents/DataTable/DataTable.tsx +582 -0
  32. package/dist/ComplexComponents/DataTable/ErrorOverlay/index.tsx +29 -0
  33. package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.tsx +57 -0
  34. package/dist/ComplexComponents/DataTable/index.ts +2 -0
  35. package/dist/ComplexComponents/DataTable/translations/en.ts +115 -0
  36. package/dist/ComplexComponents/DataTable/translations/index.ts +23 -0
  37. package/dist/ComplexComponents/KeyInsight/KeyInsights.tsx +221 -0
  38. package/dist/ComplexComponents/KeyInsight/index.ts +2 -0
  39. package/dist/ComplexComponents/NameValue/NameValue.tsx +175 -0
  40. package/dist/ComplexComponents/NameValue/NameValueItem.tsx +100 -0
  41. package/dist/ComplexComponents/NameValue/index.ts +4 -0
  42. package/dist/ComplexComponents/PageContentHeader/DescriptionBlock.tsx +65 -0
  43. package/dist/ComplexComponents/PageContentHeader/PageContentHeader.tsx +383 -0
  44. package/dist/ComplexComponents/PageContentHeader/index.ts +4 -0
  45. package/dist/ComplexComponents/Utilities/CopyButton.tsx +82 -0
  46. package/dist/ComplexComponents/Utilities/index.ts +2 -0
  47. package/dist/DataDisplay/Alert.tsx +130 -0
  48. package/dist/DataDisplay/Avatar.tsx +216 -0
  49. package/dist/DataDisplay/Badge.tsx +119 -0
  50. package/dist/DataDisplay/Card.module.css +26 -0
  51. package/dist/DataDisplay/Card.tsx +163 -0
  52. package/dist/DataDisplay/Chip.tsx +66 -0
  53. package/dist/DataDisplay/Indicator.tsx +122 -0
  54. package/dist/DataDisplay/List.tsx +90 -0
  55. package/dist/DataDisplay/Pill.tsx +125 -0
  56. package/dist/DataDisplay/Progress.tsx +77 -0
  57. package/dist/DataDisplay/Table.tsx +57 -0
  58. package/dist/DataDisplay/ThemeIcon.tsx +67 -0
  59. package/dist/DataDisplay/index.ts +41 -0
  60. package/dist/Inputs/Checkbox.tsx +94 -0
  61. package/dist/Inputs/ColorInput.tsx +124 -0
  62. package/dist/Inputs/DropZone.tsx +78 -0
  63. package/dist/Inputs/FileInput.tsx +120 -0
  64. package/dist/Inputs/NumberInput.tsx +125 -0
  65. package/dist/Inputs/Radio.tsx +86 -0
  66. package/dist/Inputs/RadioGroup.tsx +90 -0
  67. package/dist/Inputs/SegmentedControl.tsx +64 -0
  68. package/dist/Inputs/Slider.tsx +69 -0
  69. package/dist/Inputs/Switch.tsx +67 -0
  70. package/dist/Inputs/TextArea.tsx +126 -0
  71. package/dist/Inputs/TextInput.tsx +167 -0
  72. package/dist/Inputs/index.ts +51 -0
  73. package/dist/Layout/Box.tsx +82 -0
  74. package/dist/Layout/Center.tsx +17 -0
  75. package/dist/Layout/Container.tsx +17 -0
  76. package/dist/Layout/Flex.tsx +18 -0
  77. package/dist/Layout/Grid.tsx +31 -0
  78. package/dist/Layout/Group.tsx +54 -0
  79. package/dist/Layout/Inline.tsx +86 -0
  80. package/dist/Layout/SimpleGrid.tsx +50 -0
  81. package/dist/Layout/Stack.tsx +86 -0
  82. package/dist/Layout/index.ts +29 -0
  83. package/dist/Misc/Divider.tsx +27 -0
  84. package/dist/Misc/Paper.tsx +47 -0
  85. package/dist/Misc/index.ts +15 -0
  86. package/dist/Navigation/Breadcrumb.tsx +138 -0
  87. package/dist/Navigation/NavLink.tsx +37 -0
  88. package/dist/Navigation/Stepper.tsx +17 -0
  89. package/dist/Navigation/Tabs.tsx +29 -0
  90. package/dist/Navigation/index.ts +17 -0
  91. package/dist/Overlays/Drawer.tsx +123 -0
  92. package/dist/Overlays/Menu.tsx +192 -0
  93. package/dist/Overlays/Modal.tsx +159 -0
  94. package/dist/Overlays/Popover.tsx +319 -0
  95. package/dist/Overlays/Tooltip.tsx +131 -0
  96. package/dist/Overlays/index.ts +19 -0
  97. package/dist/Shell/AppShellLayout.tsx +56 -0
  98. package/dist/Shell/HeaderBar.tsx +26 -0
  99. package/dist/Shell/SidebarNav.tsx +47 -0
  100. package/dist/Shell/SidebarNavLink.tsx +50 -0
  101. package/dist/Shell/SingleColumnLayout.tsx +22 -0
  102. package/dist/Shell/TertiaryColumnLayout.tsx +32 -0
  103. package/dist/Shell/index.ts +17 -0
  104. package/dist/Typography/Code.tsx +27 -0
  105. package/dist/Typography/Kbd.tsx +87 -0
  106. package/dist/Typography/Text.tsx +27 -0
  107. package/dist/Typography/Title.tsx +34 -0
  108. package/dist/Typography/index.ts +21 -0
  109. package/dist/bin/ds-audit.js +521 -0
  110. package/dist/config.ts +226 -0
  111. package/dist/contracts/Alert.json +80 -0
  112. package/dist/contracts/Badge.json +78 -0
  113. package/dist/contracts/Box.json +52 -0
  114. package/dist/contracts/Button.json +111 -0
  115. package/dist/contracts/DataTable.json +68 -0
  116. package/dist/contracts/Grid.json +35 -0
  117. package/dist/contracts/Group.json +44 -0
  118. package/dist/contracts/Inline.json +73 -0
  119. package/dist/contracts/PageContentHeader.json +107 -0
  120. package/dist/contracts/Stack.json +62 -0
  121. package/dist/contracts/ds-component-contract.v1.json +23 -0
  122. package/dist/contracts/index.json +55 -0
  123. package/dist/css/foundations.css +703 -0
  124. package/dist/css/mantine.css +1777 -0
  125. package/dist/hooks/useTableHandlers.ts +179 -0
  126. package/dist/hooks/useTableRenderFunctions.tsx +283 -0
  127. package/dist/hooks/useTableState.ts +81 -0
  128. package/dist/index.ts +210 -0
  129. package/dist/types.ts +202 -0
  130. package/package.json +56 -4
@@ -0,0 +1,582 @@
1
+ 'use client';
2
+
3
+ import React, { useMemo } from 'react';
4
+ import {
5
+ useMantineReactTable,
6
+ MantineReactTable,
7
+ MRT_PaginationState as PaginationState,
8
+ MRT_RowSelectionState as RowSelectionState,
9
+ MRT_DensityState as DensityState,
10
+ MRT_RowData,
11
+ MRT_ColumnDef as ColumnDef,
12
+ } from 'mantine-react-table-open';
13
+ import { useTableState } from '../../hooks/useTableState';
14
+ import { useTableHandlers } from '../../hooks/useTableHandlers';
15
+ import { useTableRenderFunctions } from '../../hooks/useTableRenderFunctions';
16
+ import { type Filters, type DateRange, type City } from './CustomTopToolbar';
17
+
18
+ // ========================== EXPORTS ==========================
19
+ /**
20
+ * Re-export commonly used types from sub-components for convenience
21
+ * This allows consumers to import these types directly from the Table component
22
+ */
23
+ export type { Filters, DateRange, City };
24
+
25
+ // TODO: Review integration with PageContentHeader Description feature
26
+ // - Consider adding table description/subtitle support
27
+ // - Evaluate if table metadata should be displayed in header area
28
+ // - Review accessibility implications of description placement
29
+
30
+ // ========================== TYPES ==========================
31
+ /**
32
+ * Union type for sort directions used throughout the table
33
+ * null represents no sorting applied to a column
34
+ */
35
+ type SortDirection = 'asc' | 'desc' | null;
36
+
37
+ /**
38
+ * Enhanced TableColumn interface with better typing and additional options
39
+ * Extends the basic column definition with custom properties
40
+ */
41
+ export interface DataTableColumn<T extends MRT_RowData> {
42
+ /** The key from the data object to access the column value */
43
+ accessorKey: keyof T;
44
+ /** Column header - can be static text or a React component function */
45
+ header: string | (() => React.ReactNode);
46
+ /** Optional fixed width for the column in pixels */
47
+ size?: number;
48
+ /** Whether this column can be sorted by the user */
49
+ enableSorting?: boolean;
50
+ /** Whether filtering is enabled for this column */
51
+ enableColumnFilter?: boolean;
52
+ }
53
+
54
+ /**
55
+ * Page information interface for cursor-based pagination
56
+ * Used to determine navigation availability and cursor positions
57
+ */
58
+ export interface PageInfo {
59
+ /** Whether there are more pages after the current one */
60
+ hasNextPage: boolean;
61
+ /** Whether there are pages before the current one */
62
+ hasPreviousPage: boolean;
63
+ /** Cursor pointing to the start of the current page (for cursor-based pagination) */
64
+ startCursor?: string;
65
+ /** Cursor pointing to the end of the current page (for cursor-based pagination) */
66
+ endCursor?: string;
67
+ }
68
+
69
+ /**
70
+ * Comprehensive props interface for the Table component
71
+ * Organized by functionality for better maintainability
72
+ */
73
+ export interface DataTableProps<T extends MRT_RowData> {
74
+ // ==================== DATA PROPS ====================
75
+ /** Array of data objects to display in the table */
76
+ data: T[];
77
+ /** Column definitions specifying how to render each column */
78
+ columns: ColumnDef<T>[];
79
+ /** Total number of items across all pages (for pagination display) */
80
+ totalCount?: number;
81
+
82
+ // ==================== LOADING AND ERROR STATES ====================
83
+ /** Whether the table is currently loading data */
84
+ isLoading?: boolean;
85
+ /** Whether an error has occurred while loading data */
86
+ isError?: boolean;
87
+ /** Error message to display when isError is true */
88
+ error?: string;
89
+ /** Callback function to retry loading data after an error */
90
+ onRetry?: () => void;
91
+
92
+ // ==================== PAGINATION PROPS ====================
93
+ /** Page information for cursor-based pagination */
94
+ pageInfo?: PageInfo;
95
+ /** Callback fired when pagination state changes (page or page size) */
96
+ onPaginationChange?: (pagination: PaginationState) => void;
97
+ /** Default number of rows to show per page */
98
+ defaultPageSize?: number;
99
+
100
+ // ==================== SELECTION PROPS ====================
101
+ /** Callback fired when row selection changes */
102
+ onRowSelectionChange?: (rowSelection: RowSelectionState) => void;
103
+
104
+ // ==================== UI STATE PROPS ====================
105
+ /** Callback fired when table density (row height) changes */
106
+ onDensityChange?: (density: DensityState) => void;
107
+ /** Default density setting for the table */
108
+ defaultDensity?: DensityState;
109
+
110
+ // ==================== SORTING PROPS ====================
111
+ /** Callback fired when column sorting changes */
112
+ onSortChange?: (field: string, direction: SortDirection) => void;
113
+
114
+ // ==================== FILTER PROPS ====================
115
+ /** Current state of all applied filters */
116
+ filtersState?: Filters;
117
+ /** Callback fired when filters are modified */
118
+ onFiltersChange?: (filters: Filters) => void;
119
+ /** Locale string for internationalization */
120
+ locale?: string;
121
+
122
+ // ==================== FEATURE TOGGLES ====================
123
+ /** Whether to show the filters panel */
124
+ showFilters?: boolean;
125
+ /** Whether to show the global search input */
126
+ showSearch?: boolean;
127
+ /** Whether to show the density toggle button */
128
+ showDensityToggle?: boolean;
129
+ /** Whether to show the fullscreen toggle button */
130
+ showFullScreenToggle?: boolean;
131
+
132
+ // ==================== STYLE CUSTOMIZATION ====================
133
+ /** Additional props to pass to the table container element */
134
+ mantineTableContainerProps?: Record<string, any>;
135
+ /** Additional props to pass to the paper wrapper element */
136
+ mantinePaperProps?: Record<string, any>;
137
+
138
+ // ==================== DEPRECATED/UNUSED PROPS ====================
139
+ /** @deprecated Use totalCount instead - kept for backward compatibility */
140
+ resultCount?: number;
141
+ }
142
+
143
+ // ========================== CONSTANTS ==========================
144
+ /**
145
+ * Default values for various table configuration options
146
+ * Centralized to ensure consistency and easy modification
147
+ */
148
+ const DEFAULT_VALUES = {
149
+ /** Default number of rows per page */
150
+ PAGE_SIZE: 10,
151
+ /** Default table density (row height) - 'xs' is most compact */
152
+ DENSITY: 'xs' as DensityState,
153
+ /** Default locale for internationalization */
154
+ LOCALE: 'en',
155
+ /** Default total count when not provided */
156
+ TOTAL_COUNT: 0,
157
+ /** Default result count (deprecated) */
158
+ RESULT_COUNT: 0,
159
+ } as const;
160
+
161
+ /**
162
+ * Feature flags that control which table features are enabled by default
163
+ * Can be overridden by props but provide sensible defaults
164
+ */
165
+ const FEATURE_FLAGS = {
166
+ /** Enable filters panel by default */
167
+ SHOW_FILTERS: true,
168
+ /** Enable global search by default */
169
+ SHOW_SEARCH: true,
170
+ /** Enable density toggle by default */
171
+ SHOW_DENSITY_TOGGLE: true,
172
+ /** Enable fullscreen toggle by default */
173
+ SHOW_FULL_SCREEN_TOGGLE: true,
174
+ } as const;
175
+
176
+ // ========================== CUSTOM HOOKS ==========================
177
+
178
+ /**
179
+ * DataTable Component
180
+ *
181
+ * A powerful, feature-rich data table component built on top of Mantine React Table.
182
+ * Supports pagination, sorting, filtering, row selection, density controls, and more.
183
+ * Perfect for displaying large datasets with complex interaction requirements.
184
+ *
185
+ * @example
186
+ * // Basic usage with minimal configuration
187
+ * const userData = [
188
+ * { id: '1', name: 'John Doe', email: 'john@example.com', status: 'Active' },
189
+ * { id: '2', name: 'Jane Smith', email: 'jane@example.com', status: 'Inactive' },
190
+ * ];
191
+ *
192
+ * const columns = [
193
+ * { accessorKey: 'name', header: 'Name' },
194
+ * { accessorKey: 'email', header: 'Email' },
195
+ * { accessorKey: 'status', header: 'Status' },
196
+ * ];
197
+ *
198
+ * <DataTable
199
+ * data={userData}
200
+ * columns={columns}
201
+ * />
202
+ *
203
+ * @example
204
+ * // Advanced usage with pagination and filtering
205
+ * const [tableData, setTableData] = useState([]);
206
+ * const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 10 });
207
+ * const [filters, setFilters] = useState({});
208
+ * const [isLoading, setIsLoading] = useState(false);
209
+ *
210
+ * // Fetch data when pagination or filters change
211
+ * useEffect(() => {
212
+ * fetchData(pagination, filters);
213
+ * }, [pagination, filters]);
214
+ *
215
+ * <DataTable
216
+ * data={tableData}
217
+ * columns={columns}
218
+ * isLoading={isLoading}
219
+ * totalCount={1000}
220
+ * defaultPageSize={20}
221
+ * filtersState={filters}
222
+ * onPaginationChange={setPagination}
223
+ * onFiltersChange={setFilters}
224
+ * pageInfo={{
225
+ * hasNextPage: true,
226
+ * hasPreviousPage: false,
227
+ * startCursor: 'cursor-start',
228
+ * endCursor: 'cursor-end'
229
+ * }}
230
+ * />
231
+ *
232
+ * @example
233
+ * // With row selection and custom actions
234
+ * const [selectedRows, setSelectedRows] = useState({});
235
+ *
236
+ * const handleRowSelection = (rowSelection) => {
237
+ * setSelectedRows(rowSelection);
238
+ * console.log('Selected rows:', Object.keys(rowSelection));
239
+ * };
240
+ *
241
+ * const handleBulkAction = () => {
242
+ * const selectedIds = Object.keys(selectedRows);
243
+ * // Perform bulk action on selected rows
244
+ * };
245
+ *
246
+ * <DataTable
247
+ * data={tableData}
248
+ * columns={columns}
249
+ * onRowSelectionChange={handleRowSelection}
250
+ * // Custom toolbar actions will appear when rows are selected
251
+ * />
252
+ *
253
+ * @example
254
+ * // Error handling and retry functionality
255
+ * const [error, setError] = useState(null);
256
+ * const [isError, setIsError] = useState(false);
257
+ *
258
+ * const handleRetry = () => {
259
+ * setError(null);
260
+ * setIsError(false);
261
+ * // Retry data fetching logic
262
+ * fetchData();
263
+ * };
264
+ *
265
+ * <DataTable
266
+ * data={tableData}
267
+ * columns={columns}
268
+ * isError={isError}
269
+ * error={error}
270
+ * onRetry={handleRetry}
271
+ * />
272
+ *
273
+ * @example
274
+ * // Customized table features and styling
275
+ * <DataTable
276
+ * data={tableData}
277
+ * columns={columns}
278
+ * defaultDensity="md"
279
+ * showFilters={true}
280
+ * showSearch={true}
281
+ * showDensityToggle={true}
282
+ * showFullScreenToggle={false}
283
+ * locale="en-US"
284
+ * mantineTableContainerProps={{
285
+ * style: { maxHeight: '600px' }
286
+ * }}
287
+ * mantinePaperProps={{
288
+ * shadow: 'md',
289
+ * radius: 'md'
290
+ * }}
291
+ * />
292
+ *
293
+ * @example
294
+ * // Dynamic columns with conditional rendering
295
+ * const columns = useMemo(() => [
296
+ * { accessorKey: 'name', header: 'Name', enableSorting: true },
297
+ * { accessorKey: 'email', header: 'Email', enableColumnFilter: true },
298
+ * {
299
+ * accessorKey: 'status',
300
+ * header: () => <Text fw="bold">Status</Text>,
301
+ * size: 120,
302
+ * enableSorting: false
303
+ * },
304
+ * {
305
+ * accessorKey: 'actions',
306
+ * header: 'Actions',
307
+ * enableSorting: false,
308
+ * enableColumnFilter: false,
309
+ * Cell: ({ row }) => (
310
+ * <Inline>
311
+ * <Button size="xs" onClick={() => handleEdit(row.original)}>
312
+ * Edit
313
+ * </Button>
314
+ * <Button size="xs" color="red" onClick={() => handleDelete(row.original)}>
315
+ * Delete
316
+ * </Button>
317
+ * </Inline>
318
+ * )
319
+ * }
320
+ * ], []);
321
+ *
322
+ * <DataTable
323
+ * data={tableData}
324
+ * columns={columns}
325
+ * onSortChange={(field, direction) => {
326
+ * console.log(`Sorting ${field} in ${direction} order`);
327
+ * }}
328
+ * />
329
+ */
330
+ export function DataTable<T extends MRT_RowData>({
331
+ // ==================== DATA PROPS ====================
332
+ data,
333
+ columns,
334
+ totalCount = DEFAULT_VALUES.TOTAL_COUNT,
335
+
336
+ // ==================== LOADING AND ERROR STATES ====================
337
+ isLoading = false,
338
+ isError = false,
339
+ error,
340
+ onRetry,
341
+
342
+ // ==================== PAGINATION PROPS ====================
343
+ pageInfo,
344
+ onPaginationChange,
345
+ defaultPageSize = DEFAULT_VALUES.PAGE_SIZE,
346
+
347
+ // ==================== SELECTION PROPS ====================
348
+ onRowSelectionChange,
349
+
350
+ // ==================== UI STATE PROPS ====================
351
+ onDensityChange,
352
+ defaultDensity = DEFAULT_VALUES.DENSITY,
353
+
354
+ // ==================== SORTING PROPS ====================
355
+ onSortChange,
356
+
357
+ // ==================== FILTER PROPS ====================
358
+ filtersState = {},
359
+ onFiltersChange = () => {},
360
+ locale = DEFAULT_VALUES.LOCALE,
361
+
362
+ // ==================== FEATURE TOGGLES ====================
363
+ showFilters = FEATURE_FLAGS.SHOW_FILTERS,
364
+ showSearch = FEATURE_FLAGS.SHOW_SEARCH,
365
+ showDensityToggle = FEATURE_FLAGS.SHOW_DENSITY_TOGGLE,
366
+ showFullScreenToggle = FEATURE_FLAGS.SHOW_FULL_SCREEN_TOGGLE,
367
+
368
+ // ==================== STYLE CUSTOMIZATION ====================
369
+ mantineTableContainerProps = {},
370
+ mantinePaperProps = {},
371
+
372
+ // ==================== DEPRECATED/UNUSED PROPS ====================
373
+ resultCount = DEFAULT_VALUES.RESULT_COUNT,
374
+ }: DataTableProps<T>) {
375
+ // ==================== HOOK INITIALIZATION ====================
376
+ /** Initialize table state management */
377
+ const tableState = useTableState(defaultPageSize, defaultDensity);
378
+
379
+ /** Initialize event handlers with proper memoization */
380
+ const handlers = useTableHandlers(tableState, {
381
+ onPaginationChange,
382
+ onRowSelectionChange,
383
+ onDensityChange,
384
+ onSortChange,
385
+ });
386
+
387
+ /** Initialize render functions with all required dependencies */
388
+ const renderFunctions = useTableRenderFunctions(
389
+ {
390
+ filtersState,
391
+ locale,
392
+ onFiltersChange,
393
+ data,
394
+ showFilters,
395
+ isLoading,
396
+ totalCount,
397
+ pageInfo,
398
+ error,
399
+ onRetry,
400
+ },
401
+ { numberOfSelectedRows: tableState.numberOfSelectedRows },
402
+ { handleClearSelection: handlers.handleClearSelection }
403
+ );
404
+
405
+ // ==================== TABLE CONFIGURATION ====================
406
+ /**
407
+ * Memoized table configuration object
408
+ * Contains all options, state, and handlers for Mantine React Table
409
+ */
410
+ const tableConfig = useMemo(() => ({
411
+ // ==================== CORE DATA AND COLUMNS ====================
412
+ columns,
413
+ data,
414
+ /** Use the 'id' field from each row for unique identification (enables proper selection tracking) */
415
+ getRowId: (row: T) => row.id as string,
416
+
417
+ // ==================== FEATURE ENABLEMENT ====================
418
+ /** Enable row selection with checkboxes */
419
+ enableRowSelection: true,
420
+ /** Allow multiple rows to be selected simultaneously */
421
+ enableMultiRowSelection: true,
422
+ /** Show select all checkbox in header */
423
+ enableSelectAll: true,
424
+ /** Enable column-specific filtering */
425
+ enableColumnFilters: true,
426
+ /** Enable column sorting */
427
+ enableSorting: true,
428
+ /** Allow users to resize columns */
429
+ enableColumnResizing: true,
430
+ /** Keep header visible when scrolling */
431
+ enableStickyHeader: true,
432
+ /** Show density toggle button */
433
+ enableDensityToggle: showDensityToggle,
434
+ /** Show fullscreen toggle button */
435
+ enableFullScreenToggle: showFullScreenToggle,
436
+ /** Enable pagination controls */
437
+ enablePagination: true,
438
+ /** Disable built-in row actions (we handle them manually) */
439
+ enableRowActions: false,
440
+ /** Disable individual column actions - we'll use a custom column visibility button */
441
+ enableColumnActions: false,
442
+ /** Enable column hiding feature */
443
+ enableHiding: true,
444
+ /** Use manual pagination (parent handles data slicing) */
445
+ manualPagination: true,
446
+
447
+ // ==================== DATA AND STATE ====================
448
+ /** Total number of rows across all pages */
449
+ rowCount: totalCount,
450
+ /** Initial state with pinned actions column */
451
+ initialState: {
452
+ columnPinning: {
453
+ right: ['actions'],
454
+ },
455
+ },
456
+ /** Current state object passed to Mantine React Table */
457
+ state: {
458
+ pagination: tableState.pagination,
459
+ rowSelection: tableState.rowSelection,
460
+ density: tableState.density,
461
+ isLoading,
462
+ showAlertBanner: tableState.showAlertBanner,
463
+ },
464
+
465
+ // ==================== LAYOUT CONFIGURATION ====================
466
+ /** Use grid layout for better column control */
467
+ layoutMode: 'grid' as const,
468
+ /** Configure display columns (selection, etc.) */
469
+ displayColumnDefOptions: {
470
+ 'mrt-row-select': {
471
+ size: 40, // Minimal width for checkbox
472
+ grow: false, // Don't grow this column
473
+ },
474
+ },
475
+ /** Enable column pinning to keep actions column fixed */
476
+ enablePinning: true,
477
+
478
+ // ==================== EVENT HANDLERS ====================
479
+ /** Handle pagination changes (page navigation, page size changes) */
480
+ onPaginationChange: handlers.handlePaginationChange,
481
+ /** Handle row selection changes */
482
+ onRowSelectionChange: handlers.handleRowSelectionChange,
483
+ /** Handle density changes */
484
+ onDensityChange: handlers.handleDensityChange,
485
+ /** Handle sorting changes */
486
+ onSortingChange: handlers.handleSortingChange,
487
+
488
+ // ==================== RENDER FUNCTIONS ====================
489
+ /** Custom top toolbar with filters and actions */
490
+ renderTopToolbar: renderFunctions.renderTopToolbar,
491
+ /** Custom bottom toolbar with pagination */
492
+ renderBottomToolbar: renderFunctions.renderBottomToolbar,
493
+ /** Custom alert banner for selection state */
494
+ renderToolbarAlertBannerContent: renderFunctions.renderToolbarAlertBannerContent,
495
+ /** Custom empty state with error handling */
496
+ renderEmptyRowsFallback: renderFunctions.renderEmptyRowsFallback,
497
+ /** Custom header cell renderer */
498
+ mantineTableHeadCellProps: renderFunctions.renderTableHeadCell,
499
+
500
+ // ==================== ACCESSIBILITY AND STYLING ====================
501
+ /** Accessibility props for select all checkbox */
502
+ mantineSelectAllCheckboxProps: {
503
+ 'aria-label': 'Select all rows on this page',
504
+ },
505
+ /** Accessibility props for individual row checkboxes */
506
+ mantineSelectCheckboxProps: {
507
+ 'aria-label': 'Select row',
508
+ },
509
+ /** Table styling options */
510
+ mantineTableProps: {
511
+ striped: true, // Alternating row colors
512
+ highlightOnHover: true, // Highlight rows on hover
513
+ withColumnBorders: false, // No vertical borders between columns
514
+ },
515
+ /** Header row styling */
516
+ mantineTableHeadRowProps: {
517
+ style: {
518
+ borderBottom: '2px solid var(--ad-color-border-subtle)',
519
+ },
520
+ },
521
+ /** Body cell styling */
522
+ mantineTableBodyCellProps: {
523
+ style: {
524
+ padding: 'var(--mantine-spacing-xs)',
525
+ },
526
+ },
527
+ /** Alert banner styling */
528
+ mantineToolbarAlertBannerProps: {
529
+ color: 'blue',
530
+ },
531
+ /** Table container styling */
532
+ mantineTableContainerProps: {
533
+ style: {
534
+ backgroundColor: 'var(--ad-color-bg-default)',
535
+ },
536
+ ...mantineTableContainerProps, // Allow prop overrides
537
+ },
538
+ /** Paper wrapper styling */
539
+ mantinePaperProps: {
540
+ style: {
541
+ backgroundColor: 'var(--ad-color-bg-default)',
542
+ },
543
+ ...mantinePaperProps, // Allow prop overrides
544
+ },
545
+ }), [
546
+ // ==================== MEMOIZATION DEPENDENCIES ====================
547
+ // Core data dependencies
548
+ columns,
549
+ data,
550
+ showDensityToggle,
551
+ showFullScreenToggle,
552
+ totalCount,
553
+ isLoading,
554
+ // State dependencies
555
+ tableState.pagination,
556
+ tableState.rowSelection,
557
+ tableState.density,
558
+ tableState.showAlertBanner,
559
+ // Handler dependencies
560
+ handlers.handlePaginationChange,
561
+ handlers.handleRowSelectionChange,
562
+ handlers.handleDensityChange,
563
+ handlers.handleSortingChange,
564
+ // Render function dependencies
565
+ renderFunctions.renderTopToolbar,
566
+ renderFunctions.renderBottomToolbar,
567
+ renderFunctions.renderToolbarAlertBannerContent,
568
+ renderFunctions.renderEmptyRowsFallback,
569
+ renderFunctions.renderTableHeadCell,
570
+ // Style customization dependencies
571
+ mantineTableContainerProps,
572
+ mantinePaperProps,
573
+ ]);
574
+
575
+ // ==================== COMPONENT INITIALIZATION ====================
576
+ /** Initialize the Mantine React Table instance with our configuration */
577
+ const table = useMantineReactTable(tableConfig);
578
+
579
+ // ==================== RENDER ====================
580
+ /** Render the table component */
581
+ return <MantineReactTable table={table} />;
582
+ }
@@ -0,0 +1,29 @@
1
+ import React, { ReactElement } from "react";
2
+ import { Stack, Text } from "@mantine/core";
3
+ import { Button } from '../../../Buttons/Button';
4
+ import { translate } from '../translations';
5
+
6
+ interface ErrorOverlayProps {
7
+ error?: string;
8
+ onRetry?: () => void;
9
+ }
10
+
11
+ const ErrorOverlay = ({ error, onRetry }: ErrorOverlayProps): ReactElement => {
12
+ return (
13
+ <Stack align="center" justify="center" h={200}>
14
+ <Text size="lg" fw={500}>
15
+ {translate("table.error.title")}
16
+ </Text>
17
+ <Text size="sm" c="dimmed">
18
+ {error || translate("table.error.default")}
19
+ </Text>
20
+ {onRetry && (
21
+ <Button variant="default" onClick={onRetry}>
22
+ {translate("table.error.retry")}
23
+ </Button>
24
+ )}
25
+ </Stack>
26
+ );
27
+ };
28
+
29
+ export default ErrorOverlay;
@@ -0,0 +1,57 @@
1
+ import React, { ReactElement } from "react";
2
+ import { UnstyledButton,Text, Center, rem } from '@mantine/core';
3
+ import { Inline } from '../../..';
4
+ import { IconArrowUp, IconArrowDown, IconArrowsSort } from '@tabler/icons-react';
5
+ import { translate } from '../translations';
6
+
7
+ interface SortableHeaderCellProps {
8
+ label: string;
9
+ sortDirection?: 'asc' | 'desc' | null;
10
+ onSort?: () => void;
11
+ isSortable?: boolean;
12
+ }
13
+
14
+ const SortableHeaderCell = ({
15
+ label,
16
+ sortDirection = null,
17
+ onSort,
18
+ isSortable = true,
19
+ }: SortableHeaderCellProps): ReactElement => {
20
+ const renderSortIcon = () => {
21
+ if (!isSortable) return null;
22
+
23
+ switch (sortDirection) {
24
+ case 'asc':
25
+ return <IconArrowUp style={{ width: rem(16), height: rem(16) }} stroke={1.5} />;
26
+ case 'desc':
27
+ return <IconArrowDown style={{ width: rem(16), height: rem(16) }} stroke={1.5} />;
28
+ default:
29
+ return <IconArrowsSort style={{ width: rem(16), height: rem(16) }} stroke={1.5} />;
30
+ }
31
+ };
32
+
33
+ const directionText = sortDirection ? translate(`table.sort.${sortDirection}`) : translate("table.sort.none");
34
+ const ariaLabel = translate("table.sort.aria", {
35
+ column: label,
36
+ direction: directionText
37
+ });
38
+
39
+ return (
40
+ <UnstyledButton
41
+ onClick={isSortable ? onSort : undefined}
42
+ disabled={!isSortable}
43
+ aria-label={ariaLabel}
44
+ >
45
+ <Inline justify="space-between">
46
+ <Text fw={500} fz="sm">
47
+ {label}
48
+ </Text>
49
+ <Center>
50
+ {renderSortIcon()}
51
+ </Center>
52
+ </Inline>
53
+ </UnstyledButton>
54
+ );
55
+ };
56
+
57
+ export default SortableHeaderCell;
@@ -0,0 +1,2 @@
1
+ export { DataTable } from './DataTable';
2
+ export type { DataTableProps, DataTableColumn, PageInfo, Filters, DateRange, City } from './DataTable';