@appdirect/design-system 0.0.11 → 0.0.12

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 (119) hide show
  1. package/README.md +84 -6
  2. package/dist/Buttons/ActionIcon.js +14 -0
  3. package/dist/Buttons/Button.js +66 -0
  4. package/dist/Buttons/CloseButton.js +48 -0
  5. package/dist/Buttons/index.js +13 -0
  6. package/dist/Combobox/AutocompleteClearable.js +36 -0
  7. package/dist/Combobox/Combobox.js +28 -0
  8. package/dist/Combobox/Multiselect.js +31 -0
  9. package/dist/Combobox/SearchableSelect.js +43 -0
  10. package/dist/Combobox/Select.js +72 -0
  11. package/dist/Combobox/index.js +10 -0
  12. package/dist/ComplexComponents/DashboardWidget/DashboardWidget.js +96 -0
  13. package/dist/ComplexComponents/DashboardWidget/index.js +1 -0
  14. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.js +82 -0
  15. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.js +23 -0
  16. package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.js +23 -0
  17. package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.js +230 -0
  18. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.js +30 -0
  19. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/DateRangeFilter.js +12 -0
  20. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/FilterRenderer.js +32 -0
  21. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/FilterSystem.js +90 -0
  22. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/MultiSelectFilter.js +43 -0
  23. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/SingleSelectFilter.js +30 -0
  24. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/index.js +39 -0
  25. package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/types.js +9 -0
  26. package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.js +31 -0
  27. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.js +42 -0
  28. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.js +21 -0
  29. package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.js +410 -0
  30. package/dist/ComplexComponents/DataTable/DataTable.js +405 -0
  31. package/dist/ComplexComponents/DataTable/ErrorOverlay/index.js +9 -0
  32. package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.js +27 -0
  33. package/dist/ComplexComponents/DataTable/index.js +1 -0
  34. package/dist/ComplexComponents/DataTable/translations/en.js +99 -0
  35. package/dist/ComplexComponents/DataTable/translations/index.js +17 -0
  36. package/dist/ComplexComponents/KeyInsight/KeyInsights.js +176 -0
  37. package/dist/ComplexComponents/KeyInsight/index.js +1 -0
  38. package/dist/ComplexComponents/NameValue/NameValue.js +94 -0
  39. package/dist/ComplexComponents/NameValue/NameValueItem.js +59 -0
  40. package/dist/ComplexComponents/NameValue/index.js +2 -0
  41. package/dist/ComplexComponents/PageContentHeader/PageContentHeader.js +92 -0
  42. package/dist/ComplexComponents/PageContentHeader/index.js +1 -0
  43. package/dist/ComplexComponents/Placeholder/Placeholder.js +51 -0
  44. package/dist/ComplexComponents/Placeholder/index.js +1 -0
  45. package/dist/ComplexComponents/Slat/Slat.js +53 -0
  46. package/dist/ComplexComponents/Slat/index.js +1 -0
  47. package/dist/ComplexComponents/Utilities/CopyButton.js +45 -0
  48. package/dist/ComplexComponents/Utilities/index.js +1 -0
  49. package/dist/DataDisplay/Alert.js +77 -0
  50. package/dist/DataDisplay/Avatar.js +157 -0
  51. package/dist/DataDisplay/Badge.js +78 -0
  52. package/dist/DataDisplay/Card.js +100 -0
  53. package/dist/DataDisplay/Chip.js +36 -0
  54. package/dist/DataDisplay/Indicator.js +59 -0
  55. package/dist/DataDisplay/List.js +60 -0
  56. package/dist/DataDisplay/Pill.js +81 -0
  57. package/dist/DataDisplay/Progress.js +42 -0
  58. package/dist/DataDisplay/Table.js +38 -0
  59. package/dist/DataDisplay/ThemeIcon.js +31 -0
  60. package/dist/DataDisplay/index.js +18 -0
  61. package/dist/Inputs/Checkbox.js +62 -0
  62. package/dist/Inputs/ColorInput.js +48 -0
  63. package/dist/Inputs/DropZone.js +12 -0
  64. package/dist/Inputs/FileInput.js +77 -0
  65. package/dist/Inputs/NumberInput.js +49 -0
  66. package/dist/Inputs/Radio.js +55 -0
  67. package/dist/Inputs/RadioGroup.js +59 -0
  68. package/dist/Inputs/SegmentedControl.js +50 -0
  69. package/dist/Inputs/Slider.js +50 -0
  70. package/dist/Inputs/SliderWithLabel.js +32 -0
  71. package/dist/Inputs/Switch.js +47 -0
  72. package/dist/Inputs/TextArea.js +50 -0
  73. package/dist/Inputs/TextInput.js +87 -0
  74. package/dist/Inputs/index.js +27 -0
  75. package/dist/Layout/Box.js +39 -0
  76. package/dist/Layout/Center.js +11 -0
  77. package/dist/Layout/Container.js +11 -0
  78. package/dist/Layout/Flex.js +12 -0
  79. package/dist/Layout/Grid.js +13 -0
  80. package/dist/Layout/Group.js +14 -0
  81. package/dist/Layout/Inline.js +46 -0
  82. package/dist/Layout/SimpleGrid.js +14 -0
  83. package/dist/Layout/Stack.js +45 -0
  84. package/dist/Layout/index.js +10 -0
  85. package/dist/Misc/Divider.js +8 -0
  86. package/dist/Misc/Paper.js +24 -0
  87. package/dist/Misc/index.js +10 -0
  88. package/dist/Navigation/Breadcrumb.js +60 -0
  89. package/dist/Navigation/NavLink.js +28 -0
  90. package/dist/Navigation/Stepper.js +8 -0
  91. package/dist/Navigation/Tabs.js +22 -0
  92. package/dist/Navigation/index.js +9 -0
  93. package/dist/Overlays/Drawer.js +63 -0
  94. package/dist/Overlays/Menu.js +85 -0
  95. package/dist/Overlays/Modal.js +61 -0
  96. package/dist/Overlays/Popover.js +118 -0
  97. package/dist/Overlays/Tooltip.js +71 -0
  98. package/dist/Overlays/index.js +12 -0
  99. package/dist/Shell/AppShellLayout.js +13 -0
  100. package/dist/Shell/HeaderBar.js +8 -0
  101. package/dist/Shell/SidebarNav.js +9 -0
  102. package/dist/Shell/SidebarNavLink.js +17 -0
  103. package/dist/Shell/SingleColumnLayout.js +11 -0
  104. package/dist/Shell/TertiaryColumnLayout.js +12 -0
  105. package/dist/Shell/index.js +6 -0
  106. package/dist/Typography/Code.js +8 -0
  107. package/dist/Typography/Kbd.js +58 -0
  108. package/dist/Typography/Text.js +8 -0
  109. package/dist/Typography/Title.js +11 -0
  110. package/dist/Typography/index.js +12 -0
  111. package/dist/config.js +202 -0
  112. package/dist/contracts/index.json +1 -1
  113. package/dist/hooks/useTableHandlers.js +136 -0
  114. package/dist/hooks/useTableRenderFunctions.js +164 -0
  115. package/dist/hooks/useTableState.js +70 -0
  116. package/dist/index.js +162 -0
  117. package/dist/stories/index.json +1 -1
  118. package/dist/types.js +127 -0
  119. package/package.json +9 -6
package/dist/config.js ADDED
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Design System Configuration
3
+ *
4
+ * This file contains the core configuration for the design system,
5
+ * including design tokens, component variants, and shared styling.
6
+ */
7
+ // ========================== DESIGN TOKENS ==========================
8
+ /**
9
+ * Design system color palette
10
+ * Extends Mantine's default colors with custom brand colors
11
+ */
12
+ export const designSystemColors = {
13
+ // Custom brand colors
14
+ primary: [
15
+ '#e8f4fd',
16
+ '#d0e7fb',
17
+ '#9fccf4',
18
+ '#6badee',
19
+ '#4394e9',
20
+ '#2d87e6',
21
+ '#2080e6',
22
+ '#1b6fd0',
23
+ '#1864bc',
24
+ '#1357a7'
25
+ ],
26
+ secondary: [
27
+ '#f0f9ff',
28
+ '#e0f2fe',
29
+ '#bae6fd',
30
+ '#7dd3fc',
31
+ '#38bdf8',
32
+ '#0ea5e9',
33
+ '#0284c7',
34
+ '#0369a1',
35
+ '#075985',
36
+ '#0c4a6e'
37
+ ],
38
+ };
39
+ /**
40
+ * Pixel lookup for the layout spacing scale (not a second runtime scale).
41
+ * Mantine Core `xs–xl` plus added `none` / `xxs` / `xxl`. Layout primitives
42
+ * pass `gap` through to Mantine; `styles/theme.ts` adds the extra keys.
43
+ */
44
+ export const spacing = {
45
+ none: '0px',
46
+ xxs: '4px',
47
+ xs: '10px',
48
+ sm: '12px',
49
+ md: '16px',
50
+ lg: '20px',
51
+ xl: '32px',
52
+ xxl: '48px',
53
+ };
54
+ /**
55
+ * Design system typography scale
56
+ * Font sizes, weights, and line heights
57
+ */
58
+ export const typography = {
59
+ fontSizes: {
60
+ xs: '12px',
61
+ sm: '14px',
62
+ md: '16px',
63
+ lg: '18px',
64
+ xl: '20px',
65
+ xxl: '24px',
66
+ },
67
+ fontWeights: {
68
+ normal: 400,
69
+ medium: 500,
70
+ semibold: 600,
71
+ bold: 700,
72
+ },
73
+ lineHeights: {
74
+ tight: 1.2,
75
+ normal: 1.5,
76
+ loose: 1.8,
77
+ },
78
+ };
79
+ /**
80
+ * Design system border radius values
81
+ * Consistent border radius for components
82
+ */
83
+ export const borderRadius = {
84
+ none: '0px',
85
+ sm: '4px',
86
+ md: '8px',
87
+ lg: '12px',
88
+ xl: '16px',
89
+ full: '9999px',
90
+ };
91
+ /**
92
+ * Design system shadows
93
+ * Box shadow definitions for elevation
94
+ */
95
+ export const shadows = {
96
+ none: 'none',
97
+ sm: '0 1px 2px 0 rgb(0 0 0 / 0.05)',
98
+ md: '0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)',
99
+ lg: '0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)',
100
+ xl: '0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1)',
101
+ };
102
+ // ========================== COMPONENT VARIANTS ==========================
103
+ /**
104
+ * Button component variants
105
+ * Consistent button styling across the design system
106
+ */
107
+ export const buttonVariants = {
108
+ primary: {
109
+ backgroundColor: '#326fde',
110
+ color: '#ffffff',
111
+ borderRadius: '4px',
112
+ fontFamily: 'Inter, sans-serif',
113
+ fontWeight: 600,
114
+ '&:hover': {
115
+ backgroundColor: '#2a5dc4',
116
+ },
117
+ },
118
+ secondary: {
119
+ backgroundColor: 'var(--mantine-color-gray-1)',
120
+ color: 'var(--mantine-color-gray-8)',
121
+ border: '1px solid var(--mantine-color-gray-3)',
122
+ '&:hover': {
123
+ backgroundColor: 'var(--mantine-color-gray-2)',
124
+ },
125
+ },
126
+ ghost: {
127
+ backgroundColor: 'transparent',
128
+ color: 'var(--mantine-color-gray-7)',
129
+ '&:hover': {
130
+ backgroundColor: 'var(--mantine-color-gray-1)',
131
+ },
132
+ },
133
+ };
134
+ /**
135
+ * Input component variants
136
+ * Consistent input styling across the design system
137
+ */
138
+ export const inputVariants = {
139
+ default: {
140
+ borderColor: 'var(--mantine-color-gray-3)',
141
+ '&:focus': {
142
+ borderColor: 'var(--mantine-color-primary-6)',
143
+ },
144
+ },
145
+ error: {
146
+ borderColor: 'var(--mantine-color-red-6)',
147
+ '&:focus': {
148
+ borderColor: 'var(--mantine-color-red-6)',
149
+ },
150
+ },
151
+ success: {
152
+ borderColor: 'var(--mantine-color-green-6)',
153
+ '&:focus': {
154
+ borderColor: 'var(--mantine-color-green-6)',
155
+ },
156
+ },
157
+ };
158
+ // ========================== COMMON PROPS ==========================
159
+ // Size tokens are canonically defined in types.ts (DS_SIZES / DSSize).
160
+ // Re-exported here for backward compatibility with existing component imports.
161
+ export { DS_SIZES as componentSizes } from './types.js';
162
+ /**
163
+ * Mantine color palette names accepted by components that pass through
164
+ * to Mantine's color prop. Distinct from semantic colors in types.ts.
165
+ */
166
+ export const componentColors = [
167
+ 'primary',
168
+ 'secondary',
169
+ 'gray',
170
+ 'red',
171
+ 'pink',
172
+ 'grape',
173
+ 'violet',
174
+ 'indigo',
175
+ 'blue',
176
+ 'cyan',
177
+ 'teal',
178
+ 'green',
179
+ 'lime',
180
+ 'yellow',
181
+ 'orange',
182
+ ];
183
+ // ========================== DESIGN SYSTEM UTILITIES ==========================
184
+ /**
185
+ * Get consistent spacing value
186
+ */
187
+ export const getSpacing = (size) => spacing[size];
188
+ /**
189
+ * Get consistent border radius value
190
+ */
191
+ export const getBorderRadius = (size) => borderRadius[size];
192
+ /**
193
+ * Get consistent shadow value
194
+ */
195
+ export const getShadow = (size) => shadows[size];
196
+ /**
197
+ * Generate component class names with AppDirect Design System prefix
198
+ */
199
+ export const addsClassName = (component, modifier) => {
200
+ const base = `adds-${component}`;
201
+ return modifier ? `${base}--${modifier}` : base;
202
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.11",
2
+ "version": "0.0.12",
3
3
  "contracts": [
4
4
  {
5
5
  "id": "Alert",
@@ -0,0 +1,136 @@
1
+ import { useCallback } from 'react';
2
+ /**
3
+ * Custom hook for table event handlers
4
+ *
5
+ * Manages all user interactions and state updates with proper memoization.
6
+ * Provides handlers for pagination, row selection, density changes, and sorting.
7
+ * All handlers are memoized to prevent unnecessary re-renders.
8
+ *
9
+ * @param tableState - Current table state from useTableState hook
10
+ * @param props - Callback props passed from parent component
11
+ * @returns Object containing all memoized event handlers
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const tableState = useTableState(10, 'xs');
16
+ * const handlers = useTableHandlers(tableState, {
17
+ * onPaginationChange: (pagination) => {
18
+ * console.log('Page changed:', pagination);
19
+ * },
20
+ * onRowSelectionChange: (selection) => {
21
+ * console.log('Selection changed:', selection);
22
+ * },
23
+ * });
24
+ *
25
+ * // Use handlers in table configuration
26
+ * const { handlePaginationChange, handleRowSelectionChange } = handlers;
27
+ * ```
28
+ *
29
+ * @example
30
+ * ```tsx
31
+ * // With sorting and density change handlers
32
+ * const handlers = useTableHandlers(tableState, {
33
+ * onSortChange: (field, direction) => {
34
+ * console.log(`Sorting ${field} in ${direction} order`);
35
+ * },
36
+ * onDensityChange: (density) => {
37
+ * console.log('Density changed:', density);
38
+ * },
39
+ * });
40
+ *
41
+ * // Clear all selections
42
+ * handlers.handleClearSelection();
43
+ * ```
44
+ *
45
+ * @example
46
+ * ```tsx
47
+ * // Complete table setup with all handlers
48
+ * const tableState = useTableState(20, 'md');
49
+ * const handlers = useTableHandlers(tableState, {
50
+ * onPaginationChange: async (pagination) => {
51
+ * await fetchData(pagination.pageIndex, pagination.pageSize);
52
+ * },
53
+ * onRowSelectionChange: (selection) => {
54
+ * setSelectedRows(selection);
55
+ * updateBulkActions(Object.keys(selection));
56
+ * },
57
+ * onSortChange: async (field, direction) => {
58
+ * await fetchSortedData(field, direction);
59
+ * },
60
+ * onDensityChange: (density) => {
61
+ * localStorage.setItem('tableDensity', density);
62
+ * },
63
+ * });
64
+ * ```
65
+ */
66
+ export function useTableHandlers(tableState, props) {
67
+ // Extract state and callbacks for cleaner code
68
+ const { pagination, setPagination, rowSelection, setRowSelection, density, setDensity } = tableState;
69
+ const { onPaginationChange, onRowSelectionChange, onDensityChange, onSortChange } = props;
70
+ /**
71
+ * Handles pagination state changes (page navigation, page size changes)
72
+ * Updates internal state and notifies parent component
73
+ */
74
+ const handlePaginationChange = useCallback((updater) => {
75
+ // Handle both direct values and updater functions
76
+ const newPagination = typeof updater === 'function' ? updater(pagination) : updater;
77
+ setPagination(newPagination);
78
+ // Notify parent component of pagination change
79
+ onPaginationChange?.(newPagination);
80
+ }, [pagination, onPaginationChange, setPagination]);
81
+ /**
82
+ * Handles row selection state changes
83
+ * Maintains selection state across pagination and notifies parent
84
+ */
85
+ const handleRowSelectionChange = useCallback((updater) => {
86
+ // Handle both direct values and updater functions
87
+ const newRowSelection = typeof updater === 'function' ? updater(rowSelection) : updater;
88
+ setRowSelection(newRowSelection);
89
+ // Notify parent component of selection change
90
+ onRowSelectionChange?.(newRowSelection);
91
+ }, [rowSelection, onRowSelectionChange, setRowSelection]);
92
+ /**
93
+ * Handles table density changes (affects row height and spacing)
94
+ * Updates UI density and notifies parent component
95
+ */
96
+ const handleDensityChange = useCallback((updater) => {
97
+ // Handle both direct values and updater functions
98
+ const newDensity = typeof updater === 'function' ? updater(density) : updater;
99
+ setDensity(newDensity);
100
+ // Notify parent component of density change
101
+ onDensityChange?.(newDensity);
102
+ }, [density, onDensityChange, setDensity]);
103
+ /**
104
+ * Clears all selected rows and notifies parent component
105
+ * Used by the "Clear Selection" button in the alert banner
106
+ */
107
+ const handleClearSelection = useCallback(() => {
108
+ setRowSelection({});
109
+ onRowSelectionChange?.({});
110
+ }, [onRowSelectionChange, setRowSelection]);
111
+ /**
112
+ * Handles column sorting changes
113
+ * Converts Mantine React Table sorting format to our simplified format
114
+ */
115
+ const handleSortingChange = useCallback((updater) => {
116
+ // Handle both direct values and updater functions
117
+ const sorting = typeof updater === 'function' ? updater([]) : updater;
118
+ if (sorting.length > 0) {
119
+ // Extract sorting information from first sort (single column sorting)
120
+ const { id, desc } = sorting[0];
121
+ onSortChange?.(id, desc ? 'desc' : 'asc');
122
+ }
123
+ else {
124
+ // No sorting applied
125
+ onSortChange?.('', null);
126
+ }
127
+ }, [onSortChange]);
128
+ // Return all memoized handlers
129
+ return {
130
+ handlePaginationChange,
131
+ handleRowSelectionChange,
132
+ handleDensityChange,
133
+ handleClearSelection,
134
+ handleSortingChange,
135
+ };
136
+ }
@@ -0,0 +1,164 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React, { useCallback } from 'react';
3
+ import CustomTopToolbar from '../ComplexComponents/DataTable/CustomTopToolbar/index.js';
4
+ import CustomBottomToolbar from '../ComplexComponents/DataTable/CustomBottomToolbar/index.js';
5
+ import CustomToolbarAlertBannerContent from '../ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.js';
6
+ import ErrorOverlay from '../ComplexComponents/DataTable/ErrorOverlay/index.js';
7
+ import SortableHeaderCell from '../ComplexComponents/DataTable/SortableHeaderCell/index.js';
8
+ /**
9
+ * ID used by Mantine React Table for the row selection column
10
+ * Stored as constant to avoid magic strings
11
+ */
12
+ const SELECTION_COLUMN_ID = 'mrt-row-select';
13
+ /**
14
+ * Styling constants using Mantine design tokens
15
+ * Ensures consistent theming and easy maintenance
16
+ */
17
+ const TABLE_STYLES = {
18
+ /** Styling for table header cells */
19
+ headerCell: {
20
+ fontWeight: 'bold',
21
+ },
22
+ };
23
+ /**
24
+ * Custom hook for table render functions
25
+ *
26
+ * Manages all custom rendering logic with proper memoization.
27
+ * Provides render functions for toolbars, alert banners, empty states, and header cells.
28
+ * All render functions are memoized to prevent unnecessary re-renders.
29
+ *
30
+ * @param props - Props needed for rendering (data, filters, etc.)
31
+ * @param tableState - Current table state (selection count, etc.)
32
+ * @param handlers - Event handlers for user interactions
33
+ * @returns Object containing all memoized render functions
34
+ *
35
+ * @example
36
+ * ```tsx
37
+ * const renderFunctions = useTableRenderFunctions(
38
+ * {
39
+ * filtersState: filters,
40
+ * locale: 'en',
41
+ * onFiltersChange: setFilters,
42
+ * data: tableData,
43
+ * showFilters: true,
44
+ * isLoading: false,
45
+ * totalCount: 100,
46
+ * pageInfo: { hasNextPage: true, hasPreviousPage: false },
47
+ * },
48
+ * { numberOfSelectedRows: 3 },
49
+ * { handleClearSelection: () => setSelection({}) }
50
+ * );
51
+ *
52
+ * // Use in table configuration
53
+ * const tableConfig = {
54
+ * renderTopToolbar: renderFunctions.renderTopToolbar,
55
+ * renderBottomToolbar: renderFunctions.renderBottomToolbar,
56
+ * // ... other render functions
57
+ * };
58
+ * ```
59
+ *
60
+ * @example
61
+ * ```tsx
62
+ * // Complete setup with error handling
63
+ * const renderFunctions = useTableRenderFunctions(
64
+ * {
65
+ * filtersState: {},
66
+ * locale: 'en',
67
+ * onFiltersChange: () => {},
68
+ * data: [],
69
+ * showFilters: false,
70
+ * isLoading: true,
71
+ * totalCount: 0,
72
+ * error: 'Failed to load data',
73
+ * onRetry: () => refetch(),
74
+ * },
75
+ * { numberOfSelectedRows: 0 },
76
+ * { handleClearSelection: () => {} }
77
+ * );
78
+ *
79
+ * // Error state will be handled by renderEmptyRowsFallback
80
+ * ```
81
+ *
82
+ * @example
83
+ * ```tsx
84
+ * // With custom header rendering
85
+ * const renderFunctions = useTableRenderFunctions(
86
+ * {
87
+ * filtersState: activeFilters,
88
+ * locale: userLocale,
89
+ * onFiltersChange: updateFilters,
90
+ * data: rows,
91
+ * showFilters: true,
92
+ * isLoading: false,
93
+ * totalCount: totalRows,
94
+ * pageInfo: paginationInfo,
95
+ * },
96
+ * { numberOfSelectedRows: selectedCount },
97
+ * { handleClearSelection: clearAll }
98
+ * );
99
+ *
100
+ * // Custom header cells with sorting support
101
+ * const headerProps = renderFunctions.renderTableHeadCell({ column });
102
+ * ```
103
+ */
104
+ export function useTableRenderFunctions(props, tableState, handlers) {
105
+ // Extract props for cleaner destructuring
106
+ const { filtersState, locale, onFiltersChange, data, showFilters, isLoading, totalCount, pageInfo, error, onRetry, } = props;
107
+ const { numberOfSelectedRows } = tableState;
108
+ const { handleClearSelection } = handlers;
109
+ /**
110
+ * Renders the top toolbar with filters, search, and action buttons
111
+ * Memoized to prevent unnecessary re-renders
112
+ */
113
+ const renderTopToolbar = useCallback((toolbarProps) => (_jsx(CustomTopToolbar, { ...toolbarProps, filtersState: filtersState, locale: locale, onChange: onFiltersChange, resultCount: data.length, totalCount: totalCount, showFilters: showFilters, numberOfSelectedRows: numberOfSelectedRows, onFilterToggleChange: () => { }, isLoading: isLoading })), [filtersState, locale, onFiltersChange, data.length, totalCount, showFilters, numberOfSelectedRows, isLoading]);
114
+ /**
115
+ * Renders the bottom toolbar with pagination controls and row count
116
+ * Includes custom cursor-based pagination with ActionIcon chevrons
117
+ */
118
+ const renderBottomToolbar = useCallback((toolbarProps) => (_jsx(CustomBottomToolbar, { ...toolbarProps, totalCount: totalCount, pageInfo: pageInfo, numberOfSelectedRows: numberOfSelectedRows })), [totalCount, pageInfo, numberOfSelectedRows]);
119
+ /**
120
+ * Renders the alert banner content shown when rows are selected
121
+ * Displays selection count and clear selection button
122
+ */
123
+ const renderToolbarAlertBannerContent = useCallback(() => (_jsx(CustomToolbarAlertBannerContent, { numberOfSelectedRows: numberOfSelectedRows, onClearSelection: handleClearSelection })), [numberOfSelectedRows, handleClearSelection]);
124
+ /**
125
+ * Renders the fallback content when the table is empty or has errors
126
+ * Shows error message with retry button when applicable
127
+ */
128
+ const renderEmptyRowsFallback = useCallback(() => (_jsx(ErrorOverlay, { error: error, onRetry: onRetry })), [error, onRetry]);
129
+ /**
130
+ * Custom renderer for table header cells
131
+ * Provides custom styling while preserving column actions functionality
132
+ * Excludes the row selection column to let Mantine React Table handle it
133
+ */
134
+ const renderTableHeadCell = useCallback(({ column }) => {
135
+ // Don't override the select column header - let Mantine React Table handle it
136
+ if (column.id === SELECTION_COLUMN_ID) {
137
+ return {};
138
+ }
139
+ // Don't override the actions column header - let Mantine React Table handle it for proper pinning
140
+ if (column.id === 'actions') {
141
+ return {};
142
+ }
143
+ const header = column.columnDef.header;
144
+ // If header is a function (custom Header component), let it render
145
+ if (typeof header === 'function' || column.columnDef.Header) {
146
+ return {
147
+ style: TABLE_STYLES.headerCell,
148
+ };
149
+ }
150
+ // For string headers, provide custom styling with SortableHeaderCell
151
+ return {
152
+ style: TABLE_STYLES.headerCell,
153
+ children: (_jsx(SortableHeaderCell, { label: header, sortDirection: column.getIsSorted(), onSort: () => column.toggleSorting(), isSortable: column.getCanSort() })),
154
+ };
155
+ }, []);
156
+ // Return all memoized render functions
157
+ return {
158
+ renderTopToolbar,
159
+ renderBottomToolbar,
160
+ renderToolbarAlertBannerContent,
161
+ renderEmptyRowsFallback,
162
+ renderTableHeadCell,
163
+ };
164
+ }
@@ -0,0 +1,70 @@
1
+ import { useState, useMemo } from 'react';
2
+ /**
3
+ * Custom hook for managing table state
4
+ *
5
+ * Manages core table state including pagination, row selection, and density settings.
6
+ * Provides computed values for selection count and alert banner visibility.
7
+ *
8
+ * @param defaultPageSize - Initial page size for pagination
9
+ * @param defaultDensity - Initial density setting for table rows
10
+ * @returns Object containing all state values and setters
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * const tableState = useTableState(10, 'xs');
15
+ *
16
+ * // Access state values
17
+ * const { pagination, rowSelection, density } = tableState;
18
+ *
19
+ * // Use state setters
20
+ * const { setPagination, setRowSelection, setDensity } = tableState;
21
+ *
22
+ * // Access computed values
23
+ * const { numberOfSelectedRows, showAlertBanner } = tableState;
24
+ * ```
25
+ *
26
+ * @example
27
+ * ```tsx
28
+ * // With custom defaults
29
+ * const tableState = useTableState(25, 'md');
30
+ *
31
+ * // Check if any rows are selected
32
+ * if (tableState.showAlertBanner) {
33
+ * console.log(`${tableState.numberOfSelectedRows} rows selected`);
34
+ * }
35
+ * ```
36
+ */
37
+ export function useTableState(defaultPageSize, defaultDensity) {
38
+ // ==================== STATE DECLARATIONS ====================
39
+ /** Pagination state containing current page index and page size */
40
+ const [pagination, setPagination] = useState({
41
+ pageIndex: 0, // Start at first page (0-based)
42
+ pageSize: defaultPageSize,
43
+ });
44
+ /** Row selection state - object mapping row IDs to selection status */
45
+ const [rowSelection, setRowSelection] = useState({});
46
+ /** Current table density setting affecting row height */
47
+ const [density, setDensity] = useState(defaultDensity);
48
+ // ==================== COMPUTED VALUES ====================
49
+ /**
50
+ * Number of currently selected rows across all pages
51
+ * Computed from the rowSelection object keys
52
+ */
53
+ const numberOfSelectedRows = useMemo(() => Object.keys(rowSelection).length, [rowSelection]);
54
+ /**
55
+ * Whether to show the alert banner indicating selected rows
56
+ * Only shown when there are selected rows
57
+ */
58
+ const showAlertBanner = useMemo(() => numberOfSelectedRows > 0, [numberOfSelectedRows]);
59
+ // Return all state and computed values for use in component
60
+ return {
61
+ pagination,
62
+ setPagination,
63
+ rowSelection,
64
+ setRowSelection,
65
+ density,
66
+ setDensity,
67
+ numberOfSelectedRows,
68
+ showAlertBanner,
69
+ };
70
+ }