@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
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React from "react";
3
+ import { Text } from "@mantine/core";
4
+ import { translate } from '../../translations/index.js';
5
+ const ResultCount = ({ resultCount, totalCount, isLoading, hasActiveFilters }) => {
6
+ if (isLoading) {
7
+ return (_jsx(Text, { size: "xs", span: true, children: translate("table.filters.result.count.loading") }));
8
+ }
9
+ // When filters are active, show filtered results
10
+ if (hasActiveFilters) {
11
+ const filteredCount = resultCount || 0;
12
+ const total = totalCount || 0;
13
+ if (filteredCount === 0) {
14
+ return (_jsx(Text, { size: "xs", span: true, children: translate("table.filters.result.count.filtered.none", { total }) }));
15
+ }
16
+ if (filteredCount === 1) {
17
+ return (_jsx(Text, { size: "xs", span: true, children: translate("table.filters.result.count.filtered.one", { total }) }));
18
+ }
19
+ return (_jsx(Text, { size: "xs", span: true, children: translate("table.filters.result.count.filtered.many", {
20
+ count: filteredCount,
21
+ total
22
+ }) }));
23
+ }
24
+ // When no filters, show total records
25
+ const count = totalCount || resultCount || 0;
26
+ if (count === 1) {
27
+ return (_jsx(Text, { size: "xs", span: true, children: translate("table.filters.result.count.total.one") }));
28
+ }
29
+ return (_jsx(Text, { size: "xs", span: true, children: translate("table.filters.result.count.total.many", { count }) }));
30
+ };
31
+ export default ResultCount;
@@ -0,0 +1,42 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React, { useCallback, useState } from "react";
3
+ import { rem, TextInput } from "@mantine/core";
4
+ import { IconSearch, IconX } from '@tabler/icons-react';
5
+ // Local translation function
6
+ const translate = (key, params) => {
7
+ if (!params)
8
+ return key;
9
+ return Object.entries(params).reduce((str, [key, value]) => {
10
+ return str.replace(`{${key}}`, String(value));
11
+ }, key);
12
+ };
13
+ const debounce = (fn, timeout = 1000) => {
14
+ let timer;
15
+ return (value) => {
16
+ if (timer) {
17
+ clearTimeout(timer);
18
+ }
19
+ timer = setTimeout(() => {
20
+ fn(value);
21
+ }, timeout);
22
+ };
23
+ };
24
+ const SearchFilter = ({ searchTerm, onChange }) => {
25
+ const [value, setValue] = useState(searchTerm);
26
+ const debouncedOnChange = useCallback(debounce(onChange), [onChange]);
27
+ const handleChange = (event) => {
28
+ const newValue = event.currentTarget.value;
29
+ setValue(newValue);
30
+ debouncedOnChange(newValue);
31
+ };
32
+ const handleClear = () => {
33
+ setValue("");
34
+ onChange("");
35
+ };
36
+ return (_jsx(TextInput, { size: "xs", placeholder: translate("table.search.placeholder"), style: { flexGrow: "1" }, onChange: handleChange, rightSection: value ? (_jsx(IconX, { "data-testid": "search-clear", onClick: handleClear, style: { width: rem(14), height: rem(14), cursor: "pointer" } })) : (_jsx(IconSearch, { style: { width: rem(14), height: rem(14) } })), value: value, styles: {
37
+ wrapper: {
38
+ fontSize: "var(--mantine-font-size-xs)",
39
+ },
40
+ } }));
41
+ };
42
+ export default SearchFilter;
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React from "react";
3
+ import { MultiSelect } from "@mantine/core";
4
+ // Local translation function
5
+ const translate = (key, params) => {
6
+ if (!params)
7
+ return key;
8
+ return Object.entries(params).reduce((str, [key, value]) => {
9
+ return str.replace(`{${key}}`, String(value));
10
+ }, key);
11
+ };
12
+ const SelectFilter = ({ label, data, selectedValue, onChange, placeholderEmpty = "All", placeholderWithSelection = "Select more" }) => {
13
+ const hasSelection = selectedValue && selectedValue.length > 0;
14
+ const placeholder = hasSelection ? placeholderWithSelection : placeholderEmpty;
15
+ return (_jsx(MultiSelect, { size: "xs", label: label, placeholder: placeholder, data: data, value: selectedValue || [], onChange: (value) => onChange(value.length > 0 ? value : null), clearable: true, styles: {
16
+ label: {
17
+ fontWeight: 600,
18
+ },
19
+ } }));
20
+ };
21
+ export default SelectFilter;
@@ -0,0 +1,410 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React, { useEffect, useState } from "react";
3
+ import { ActionIcon, Indicator, Stack, Text, rem } from '@mantine/core';
4
+ import { Button } from '../../../Buttons/Button.js';
5
+ import { Grid } from '../../../Layout/Grid.js';
6
+ import { SimpleGrid } from '../../../Layout/SimpleGrid.js';
7
+ import { Inline } from '../../../Layout/Inline.js';
8
+ import { IconFilter, IconMaximize, IconMinimize, IconBaselineDensityMedium, IconBaselineDensitySmall, IconBaselineDensityLarge } from '@tabler/icons-react';
9
+ import { MRT_ToolbarAlertBanner as BaseMRTToolbarAlertBanner, } from "mantine-react-table-open";
10
+ import { translate } from '../translations/index.js';
11
+ import SelectFilter from "./SelectFilter.js";
12
+ import SearchFilter from "./SearchFilter.js";
13
+ import DateRangeSelector from "./DateRangeSelectorFilter/index.js";
14
+ import FilterChip from "./FilterChip.js";
15
+ import ResultCount from "./ResultCount/index.js";
16
+ // =============================================================================
17
+ // TYPES & INTERFACES
18
+ // =============================================================================
19
+ /**
20
+ * Enum defining all available cities for filtering
21
+ * @TODO: Consider moving this to a separate constants file for better maintainability
22
+ */
23
+ export var City;
24
+ (function (City) {
25
+ City["NEW_YORK"] = "New York";
26
+ City["LOS_ANGELES"] = "Los Angeles";
27
+ City["CHICAGO"] = "Chicago";
28
+ City["SAN_FRANCISCO"] = "San Francisco";
29
+ City["BOSTON"] = "Boston";
30
+ City["SEATTLE"] = "Seattle";
31
+ City["DENVER"] = "Denver";
32
+ City["PORTLAND"] = "Portland";
33
+ City["AUSTIN"] = "Austin";
34
+ City["MIAMI"] = "Miami";
35
+ City["PHOENIX"] = "Phoenix";
36
+ City["LAS_VEGAS"] = "Las Vegas";
37
+ City["DETROIT"] = "Detroit";
38
+ City["NASHVILLE"] = "Nashville";
39
+ City["ATLANTA"] = "Atlanta";
40
+ City["ORLANDO"] = "Orlando";
41
+ City["TAMPA"] = "Tampa";
42
+ City["CHARLOTTE"] = "Charlotte";
43
+ City["INDIANAPOLIS"] = "Indianapolis";
44
+ City["COLUMBUS"] = "Columbus";
45
+ })(City || (City = {}));
46
+ // =============================================================================
47
+ // CONSTANTS & UTILITIES
48
+ // =============================================================================
49
+ /**
50
+ * Typed wrapper for the MRT Toolbar Alert Banner
51
+ */
52
+ const MRTToolbarAlertBanner = BaseMRTToolbarAlertBanner;
53
+ /**
54
+ * Date formatting options for display purposes
55
+ */
56
+ const DATE_FORMAT_OPTIONS = {
57
+ year: "numeric",
58
+ month: "long",
59
+ day: "numeric",
60
+ };
61
+ /**
62
+ * Shared styling for action buttons (30x30 square buttons)
63
+ */
64
+ const ACTION_BUTTON_STYLES = {
65
+ width: rem(30),
66
+ height: rem(30),
67
+ minWidth: rem(30),
68
+ minHeight: rem(30),
69
+ padding: 0,
70
+ display: 'flex',
71
+ alignItems: 'center',
72
+ justifyContent: 'center',
73
+ borderRadius: 'var(--mantine-radius-sm)',
74
+ border: '1px solid var(--ad-color-border-default)',
75
+ background: 'var(--ad-white)',
76
+ };
77
+ const ACTION_ICON_STYLES = {
78
+ width: rem(30),
79
+ height: rem(30),
80
+ borderRadius: 'var(--mantine-radius-sm)',
81
+ border: '1px solid var(--ad-color-border-default)',
82
+ };
83
+ /**
84
+ * Icon styling for consistent appearance
85
+ */
86
+ const ICON_STYLES = {
87
+ color: 'var(--ad-color-text-default)',
88
+ };
89
+ /**
90
+ * City options data for the select filter
91
+ * @TODO: Consider moving this to a separate data file or fetching from an API
92
+ */
93
+ const CITY_OPTIONS = [
94
+ { value: City.ATLANTA, label: "table.filters.city.atlanta" },
95
+ { value: City.AUSTIN, label: "table.filters.city.austin" },
96
+ { value: City.BOSTON, label: "table.filters.city.boston" },
97
+ { value: City.CHARLOTTE, label: "table.filters.city.charlotte" },
98
+ { value: City.CHICAGO, label: "table.filters.city.chicago" },
99
+ { value: City.COLUMBUS, label: "table.filters.city.columbus" },
100
+ { value: City.DENVER, label: "table.filters.city.denver" },
101
+ { value: City.DETROIT, label: "table.filters.city.detroit" },
102
+ { value: City.INDIANAPOLIS, label: "table.filters.city.indianapolis" },
103
+ { value: City.LAS_VEGAS, label: "table.filters.city.las.vegas" },
104
+ { value: City.LOS_ANGELES, label: "table.filters.city.los.angeles" },
105
+ { value: City.MIAMI, label: "table.filters.city.miami" },
106
+ { value: City.NASHVILLE, label: "table.filters.city.nashville" },
107
+ { value: City.NEW_YORK, label: "table.filters.city.new.york" },
108
+ { value: City.ORLANDO, label: "table.filters.city.orlando" },
109
+ { value: City.PHOENIX, label: "table.filters.city.phoenix" },
110
+ { value: City.PORTLAND, label: "table.filters.city.portland" },
111
+ { value: City.SAN_FRANCISCO, label: "table.filters.city.san.francisco" },
112
+ { value: City.SEATTLE, label: "table.filters.city.seattle" },
113
+ { value: City.TAMPA, label: "table.filters.city.tampa" },
114
+ ].map(option => ({
115
+ ...option,
116
+ label: translate(option.label),
117
+ }));
118
+ // =============================================================================
119
+ // UTILITY FUNCTIONS
120
+ // =============================================================================
121
+ /**
122
+ * Utility function to determine if filters are currently active
123
+ * @param filters - The current filter state
124
+ * @returns boolean indicating if any filters are applied
125
+ */
126
+ const hasActiveFilters = (filters) => {
127
+ const { cities, dateRange } = filters;
128
+ return Boolean((cities && cities.length > 0) ||
129
+ (dateRange && dateRange.start && dateRange.end));
130
+ };
131
+ /**
132
+ * Utility function to process date range selection
133
+ * Handles the logic for ensuring both dates are selected and sets end time to end of day
134
+ * @param value - The selected date range value
135
+ * @returns Processed DateRange or null
136
+ */
137
+ const toBoundaryDate = (v) => {
138
+ if (v == null)
139
+ return null;
140
+ return v instanceof Date ? v : new Date(`${v}T12:00:00`);
141
+ };
142
+ const processDateRangeSelection = (value) => {
143
+ // Helper functions for date validation
144
+ const isOnlyOneDateSelected = () => {
145
+ return !!(value && (value[0] === null || value[1] === null));
146
+ };
147
+ const areBothDatesSelected = () => {
148
+ return !!(value && value[0] !== null && value[1] !== null);
149
+ };
150
+ // Return early if only one date is selected (incomplete selection)
151
+ if (isOnlyOneDateSelected()) {
152
+ return null;
153
+ }
154
+ let range = null;
155
+ if (value !== null && areBothDatesSelected()) {
156
+ const start = toBoundaryDate(value[0]);
157
+ let endDate = toBoundaryDate(value[1]);
158
+ if (endDate) {
159
+ const endOfDay = new Date(endDate);
160
+ endOfDay.setHours(23, 59, 59, 999);
161
+ endDate = endOfDay;
162
+ }
163
+ range = {
164
+ start,
165
+ end: endDate,
166
+ };
167
+ }
168
+ return range;
169
+ };
170
+ /**
171
+ * Utility function to get the appropriate density icon based on current state
172
+ * @param density - Current table density setting
173
+ * @returns React element for the density icon
174
+ */
175
+ const getDensityIcon = (density) => {
176
+ const iconProps = { size: 18, style: ICON_STYLES };
177
+ switch (density) {
178
+ case 'md':
179
+ return _jsx(IconBaselineDensityMedium, { ...iconProps });
180
+ case 'xs':
181
+ return _jsx(IconBaselineDensitySmall, { ...iconProps });
182
+ case 'xl':
183
+ return _jsx(IconBaselineDensityLarge, { ...iconProps });
184
+ default:
185
+ return _jsx(IconBaselineDensityMedium, { ...iconProps });
186
+ }
187
+ };
188
+ /**
189
+ * Utility function to cycle through density options
190
+ * @param currentDensity - Current density setting
191
+ * @returns Next density setting in the cycle
192
+ */
193
+ const getNextDensity = (currentDensity) => {
194
+ const densityMap = {
195
+ 'xs': 'md',
196
+ 'md': 'xl',
197
+ 'xl': 'xs'
198
+ };
199
+ return densityMap[currentDensity] || 'md';
200
+ };
201
+ // =============================================================================
202
+ // SUB-COMPONENTS
203
+ // =============================================================================
204
+ /**
205
+ * Reusable action icon component with consistent styling
206
+ * Used for fullscreen and density toggle buttons
207
+ */
208
+ const ActionIconButton = ({ onClick, ariaLabel, icon, testId }) => (_jsx(ActionIcon, { variant: "subtle", onClick: onClick, "aria-label": ariaLabel, style: ACTION_ICON_STYLES, "data-testid": testId, children: icon }));
209
+ /**
210
+ * Filter toggle button with indicator support
211
+ * Shows an indicator dot when filters are active
212
+ * Conditionally renders ActionIcon (icon-only) or Button (icon+text) based on text prop
213
+ */
214
+ const FilterIconButton = ({ onClick, areFiltersShown, text }) => {
215
+ const icon = _jsx(IconFilter, { size: 18, style: ICON_STYLES });
216
+ // If no text provided or empty string, use ActionIcon for icon-only display with perfect centering
217
+ if (!text || text.trim() === '') {
218
+ return (_jsx(ActionIcon, { "data-testid": "additional-filter-toggle", onClick: onClick, "aria-label": translate("table.filters.toggle.aria"), style: {
219
+ width: rem(30),
220
+ height: rem(30),
221
+ borderRadius: 'var(--mantine-radius-sm)',
222
+ border: areFiltersShown
223
+ ? '1px solid var(--ad-color-brand-primary)'
224
+ : '1px solid var(--ad-color-border-default)',
225
+ background: 'var(--ad-white)',
226
+ color: 'var(--ad-color-text-default)',
227
+ }, children: icon }));
228
+ }
229
+ // If text is provided, use Button with leftSection for icon + text display
230
+ return (_jsx(Button, { "data-testid": "additional-filter-toggle", variant: areFiltersShown ? "outline" : "default", onClick: onClick, "aria-label": translate("table.filters.toggle.aria"), size: "xs", leftSection: icon, style: {
231
+ height: rem(30),
232
+ borderRadius: 'var(--mantine-radius-sm)',
233
+ border: areFiltersShown
234
+ ? '1px solid var(--ad-color-brand-primary)'
235
+ : '1px solid var(--ad-color-border-default)',
236
+ background: 'var(--ad-white)',
237
+ }, children: text }));
238
+ };
239
+ const ActiveFilters = ({ filters, onClearFilters, onRemoveCity, onRemoveDateRange, }) => {
240
+ const { cities, dateRange } = filters;
241
+ return (_jsxs(_Fragment, { children: [_jsx(Text, { size: "xs", span: true, role: "button", fw: 600, style: { cursor: "pointer" }, onClick: onClearFilters, c: "blue", "data-testid": "clear-filters", children: translate("table.filters.clear.filters") }), cities && cities.map((city) => (_jsx(FilterChip, { label: city, onClick: () => onRemoveCity(city) }, city))), dateRange && (_jsx(FilterChip, { label: translate("table.filters.chip.date.range.label", {
242
+ startDate: dateRange.start?.toLocaleDateString(undefined, DATE_FORMAT_OPTIONS) || '',
243
+ endDate: dateRange.end?.toLocaleDateString(undefined, DATE_FORMAT_OPTIONS) || '',
244
+ }), onClick: onRemoveDateRange }))] }));
245
+ };
246
+ const ToolbarActions = ({ table }) => {
247
+ const isFullScreen = table.getState().isFullScreen ?? false;
248
+ const currentDensity = table.getState().density;
249
+ const handleFullscreenToggle = () => {
250
+ table.setIsFullScreen(!isFullScreen);
251
+ };
252
+ const handleDensityToggle = () => {
253
+ const nextDensity = getNextDensity(currentDensity);
254
+ table.setDensity(nextDensity);
255
+ };
256
+ return (_jsxs(Inline, { justify: "flex-end", gap: "xs", children: [_jsx(ActionIconButton, { onClick: handleFullscreenToggle, ariaLabel: isFullScreen ? "Exit fullscreen" : "Enter fullscreen", icon: isFullScreen ?
257
+ _jsx(IconMinimize, { size: 18, style: ICON_STYLES }) :
258
+ _jsx(IconMaximize, { size: 18, style: ICON_STYLES }) }), _jsx(ActionIconButton, { onClick: handleDensityToggle, ariaLabel: "Toggle density", icon: getDensityIcon(currentDensity), testId: "toggle-dense-padding" })] }));
259
+ };
260
+ const ExpandableFilters = ({ visible, locale, cities, onDateChange, onCityChange, dateRangeSelectorKey, }) => {
261
+ if (!visible)
262
+ return null;
263
+ return (_jsxs(SimpleGrid, { "data-testid": "additional-filters", cols: 3, spacing: "xs", role: "menu", children: [_jsx(DateRangeSelector, { label: translate("table.filters.applied.on"), locale: locale, onChange: onDateChange }, dateRangeSelectorKey), _jsx(SelectFilter, { label: translate("table.filters.city"), onChange: onCityChange, selectedValue: cities || null, placeholderEmpty: translate("table.filters.placeholder.all"), placeholderWithSelection: translate("table.filters.placeholder.select.more"), data: CITY_OPTIONS })] }));
264
+ };
265
+ // =============================================================================
266
+ // MAIN COMPONENT
267
+ // =============================================================================
268
+ /**
269
+ * CustomTopToolbar - Main toolbar component for data tables
270
+ *
271
+ * Features:
272
+ * - Search functionality
273
+ * - Filter toggle with indicator
274
+ * - Active filter chips with remove functionality
275
+ * - Fullscreen and density controls
276
+ * - Expandable filter section (date range, city selection)
277
+ * - Result count display
278
+ * - Selection alert banner integration
279
+ *
280
+ * @param props - CustomTopToolbarProps containing all necessary data and handlers
281
+ */
282
+ const CustomTopToolbar = ({ filtersState, locale, resultCount, totalCount, onChange, table, numberOfSelectedRows, isLoading, showFilters, onFilterToggleChange, }) => {
283
+ // =============================================================================
284
+ // STATE MANAGEMENT
285
+ // =============================================================================
286
+ const { searchTerm, cities, dateRange } = filtersState;
287
+ const [dateRangeSelectorRefreshKey, setDateRangeSelectorRefreshKey] = useState(0);
288
+ const [showFiltersState, setShowFiltersState] = useState(showFilters);
289
+ // =============================================================================
290
+ // EFFECTS
291
+ // =============================================================================
292
+ /**
293
+ * Reset date range selector when date range is cleared
294
+ * This forces the component to re-render and clear its internal state
295
+ */
296
+ useEffect(() => {
297
+ if (dateRange === null) {
298
+ setDateRangeSelectorRefreshKey(prev => prev + 1);
299
+ }
300
+ }, [dateRange]);
301
+ // =============================================================================
302
+ // EVENT HANDLERS
303
+ // =============================================================================
304
+ /**
305
+ * Handles date range selection changes
306
+ * Processes the raw date selection and converts it to our DateRange format
307
+ */
308
+ const handleDateChange = (value) => {
309
+ const processedRange = processDateRangeSelection(value);
310
+ // Only update if we have a complete range or null (clear)
311
+ if (processedRange !== null || value === null) {
312
+ onChange({ dateRange: processedRange });
313
+ }
314
+ };
315
+ /**
316
+ * Toggles the visibility of the expandable filters section
317
+ */
318
+ const handleFilterToggle = () => {
319
+ const newShowFilters = !showFiltersState;
320
+ setShowFiltersState(newShowFilters);
321
+ onFilterToggleChange?.();
322
+ };
323
+ /**
324
+ * Clears all applied filters except search term
325
+ */
326
+ const handleClearAllFilters = () => {
327
+ onChange({
328
+ searchTerm,
329
+ cities: null,
330
+ dateRange: null,
331
+ });
332
+ setDateRangeSelectorRefreshKey(prev => prev + 1);
333
+ };
334
+ /**
335
+ * Removes a specific city from the cities filter
336
+ */
337
+ const handleRemoveCity = (cityToRemove) => {
338
+ const updatedCities = cities?.filter((city) => city !== cityToRemove) || [];
339
+ onChange({
340
+ cities: updatedCities.length > 0 ? updatedCities : null,
341
+ });
342
+ };
343
+ /**
344
+ * Removes the date range filter
345
+ */
346
+ const handleRemoveDateRange = () => {
347
+ onChange({ dateRange: null });
348
+ };
349
+ /**
350
+ * Handles search term changes
351
+ */
352
+ const handleSearchChange = (value) => {
353
+ onChange({ searchTerm: value });
354
+ };
355
+ /**
356
+ * Handles city selection changes
357
+ */
358
+ const handleCityChange = (value) => {
359
+ onChange({ cities: value });
360
+ };
361
+ // =============================================================================
362
+ // COMPUTED VALUES
363
+ // =============================================================================
364
+ const filtersAreActive = hasActiveFilters(filtersState);
365
+ // Get correct result counts from table state
366
+ const currentFilteredTotal = table.getFilteredRowModel().rows.length; // Total filtered results across all pages
367
+ const totalRecords = table.getCoreRowModel().rows.length; // Total unfiltered records
368
+ const currentPageSize = table.getState().pagination.pageSize;
369
+ const currentPageData = table.getRowModel().rows.length; // Current page only
370
+ // Determine the correct counts to display based on filter state and server-side vs client-side
371
+ let displayResultCount;
372
+ let displayTotalCount;
373
+ if (totalCount !== undefined) {
374
+ // Server-side/manual pagination: use provided props
375
+ displayTotalCount = totalCount;
376
+ if (filtersAreActive) {
377
+ // When filters are active, show filtered count vs total
378
+ displayResultCount = resultCount;
379
+ }
380
+ else {
381
+ // When no filters are active, show total count only
382
+ displayResultCount = totalCount;
383
+ }
384
+ }
385
+ else {
386
+ // Client-side pagination with full dataset: use table instance methods
387
+ if (filtersAreActive) {
388
+ // When filters are active, show filtered count
389
+ displayResultCount = currentFilteredTotal;
390
+ displayTotalCount = totalRecords;
391
+ }
392
+ else {
393
+ // When no filters are active, show total count only
394
+ displayResultCount = totalRecords;
395
+ displayTotalCount = totalRecords;
396
+ }
397
+ }
398
+ // =============================================================================
399
+ // RENDER
400
+ // =============================================================================
401
+ return (_jsxs(_Fragment, { children: [_jsxs(Stack, { p: "md", gap: "xshalf", style: {
402
+ borderBottom: "1px solid var(--ad-color-border-subtle)",
403
+ }, children: [_jsxs(Grid, { gap: "md", children: [_jsx(Grid.Col, { span: { base: 12, md: 6 }, children: _jsxs(Inline, { gap: "xs", align: "center", children: [filtersAreActive ? (_jsx(Indicator, { size: "8", children: _jsx(FilterIconButton, { areFiltersShown: showFiltersState, onClick: handleFilterToggle, text: "" }) })) : (_jsx(FilterIconButton, { areFiltersShown: showFiltersState, onClick: handleFilterToggle, text: "" })), _jsx(SearchFilter, { searchTerm: searchTerm, onChange: handleSearchChange })] }) }), _jsx(Grid.Col, { span: { base: 12, md: 6 }, children: _jsx(ToolbarActions, { table: table }) })] }), _jsx(Inline, { justify: "space-between", children: _jsxs(Inline, { gap: "xs", children: [filtersAreActive && (_jsx(ActiveFilters, { filters: filtersState, onClearFilters: handleClearAllFilters, onRemoveCity: handleRemoveCity, onRemoveDateRange: handleRemoveDateRange })), _jsx(ResultCount, { resultCount: displayResultCount, totalCount: displayTotalCount, isLoading: isLoading ?? false, hasActiveFilters: filtersAreActive })] }) }), _jsx(ExpandableFilters, { visible: showFiltersState, locale: locale, cities: cities, onDateChange: handleDateChange, onCityChange: handleCityChange, dateRangeSelectorKey: dateRangeSelectorRefreshKey })] }), _jsx(MRTToolbarAlertBanner, { stackAlertBanner: true, table: table, bg: "blue", numberofselectedrows: numberOfSelectedRows, style: {
404
+ borderRadius: 0,
405
+ color: 'var(--ad-white)',
406
+ borderTop: '1px solid var(--ad-color-brand-primary)',
407
+ padding: 'var(--mantine-spacing-xs)',
408
+ } })] }));
409
+ };
410
+ export default CustomTopToolbar;