@appdirect/design-system 0.0.0-stage → 0.0.1
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/README.md +12 -2
- package/dist/Buttons/ActionIcon.tsx +37 -0
- package/dist/Buttons/Button.module.css +5 -0
- package/dist/Buttons/Button.tsx +124 -0
- package/dist/Buttons/CloseButton.tsx +83 -0
- package/dist/Buttons/index.ts +20 -0
- package/dist/Combobox/AutocompleteClearable.tsx +128 -0
- package/dist/Combobox/Combobox.tsx +37 -0
- package/dist/Combobox/Multiselect.tsx +158 -0
- package/dist/Combobox/SearchableSelect.tsx +131 -0
- package/dist/Combobox/Select.tsx +154 -0
- package/dist/Combobox/index.ts +20 -0
- package/dist/ComplexComponents/DashboardWidget/DashboardWidget.tsx +280 -0
- package/dist/ComplexComponents/DashboardWidget/index.ts +2 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.tsx +177 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.ts +35 -0
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.tsx +74 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.tsx +358 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.tsx +48 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/DateRangeFilter.tsx +26 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/FilterRenderer.tsx +71 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/FilterSystem.tsx +158 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/MultiSelectFilter.tsx +79 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/SingleSelectFilter.tsx +65 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/index.ts +70 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/types.ts +140 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.tsx +76 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.tsx +73 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.tsx +50 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.tsx +788 -0
- package/dist/ComplexComponents/DataTable/DataTable.tsx +582 -0
- package/dist/ComplexComponents/DataTable/ErrorOverlay/index.tsx +29 -0
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.tsx +57 -0
- package/dist/ComplexComponents/DataTable/index.ts +2 -0
- package/dist/ComplexComponents/DataTable/translations/en.ts +115 -0
- package/dist/ComplexComponents/DataTable/translations/index.ts +23 -0
- package/dist/ComplexComponents/KeyInsight/KeyInsights.tsx +221 -0
- package/dist/ComplexComponents/KeyInsight/index.ts +2 -0
- package/dist/ComplexComponents/NameValue/NameValue.tsx +175 -0
- package/dist/ComplexComponents/NameValue/NameValueItem.tsx +100 -0
- package/dist/ComplexComponents/NameValue/index.ts +4 -0
- package/dist/ComplexComponents/PageContentHeader/DescriptionBlock.tsx +65 -0
- package/dist/ComplexComponents/PageContentHeader/PageContentHeader.tsx +383 -0
- package/dist/ComplexComponents/PageContentHeader/index.ts +4 -0
- package/dist/ComplexComponents/Utilities/CopyButton.tsx +82 -0
- package/dist/ComplexComponents/Utilities/index.ts +2 -0
- package/dist/DataDisplay/Alert.tsx +130 -0
- package/dist/DataDisplay/Avatar.tsx +216 -0
- package/dist/DataDisplay/Badge.tsx +119 -0
- package/dist/DataDisplay/Card.module.css +26 -0
- package/dist/DataDisplay/Card.tsx +163 -0
- package/dist/DataDisplay/Chip.tsx +66 -0
- package/dist/DataDisplay/Indicator.tsx +122 -0
- package/dist/DataDisplay/List.tsx +90 -0
- package/dist/DataDisplay/Pill.tsx +125 -0
- package/dist/DataDisplay/Progress.tsx +77 -0
- package/dist/DataDisplay/Table.tsx +57 -0
- package/dist/DataDisplay/ThemeIcon.tsx +67 -0
- package/dist/DataDisplay/index.ts +41 -0
- package/dist/Inputs/Checkbox.tsx +94 -0
- package/dist/Inputs/ColorInput.tsx +124 -0
- package/dist/Inputs/DropZone.tsx +78 -0
- package/dist/Inputs/FileInput.tsx +120 -0
- package/dist/Inputs/NumberInput.tsx +125 -0
- package/dist/Inputs/Radio.tsx +86 -0
- package/dist/Inputs/RadioGroup.tsx +90 -0
- package/dist/Inputs/SegmentedControl.tsx +64 -0
- package/dist/Inputs/Slider.tsx +69 -0
- package/dist/Inputs/Switch.tsx +67 -0
- package/dist/Inputs/TextArea.tsx +126 -0
- package/dist/Inputs/TextInput.tsx +167 -0
- package/dist/Inputs/index.ts +51 -0
- package/dist/Layout/Box.tsx +82 -0
- package/dist/Layout/Center.tsx +17 -0
- package/dist/Layout/Container.tsx +17 -0
- package/dist/Layout/Flex.tsx +18 -0
- package/dist/Layout/Grid.tsx +31 -0
- package/dist/Layout/Group.tsx +54 -0
- package/dist/Layout/Inline.tsx +86 -0
- package/dist/Layout/SimpleGrid.tsx +50 -0
- package/dist/Layout/Stack.tsx +86 -0
- package/dist/Layout/index.ts +29 -0
- package/dist/Misc/Divider.tsx +27 -0
- package/dist/Misc/Paper.tsx +47 -0
- package/dist/Misc/index.ts +15 -0
- package/dist/Navigation/Breadcrumb.tsx +138 -0
- package/dist/Navigation/NavLink.tsx +37 -0
- package/dist/Navigation/Stepper.tsx +17 -0
- package/dist/Navigation/Tabs.tsx +29 -0
- package/dist/Navigation/index.ts +17 -0
- package/dist/Overlays/Drawer.tsx +123 -0
- package/dist/Overlays/Menu.tsx +192 -0
- package/dist/Overlays/Modal.tsx +159 -0
- package/dist/Overlays/Popover.tsx +319 -0
- package/dist/Overlays/Tooltip.tsx +131 -0
- package/dist/Overlays/index.ts +19 -0
- package/dist/Shell/AppShellLayout.tsx +56 -0
- package/dist/Shell/HeaderBar.tsx +26 -0
- package/dist/Shell/SidebarNav.tsx +47 -0
- package/dist/Shell/SidebarNavLink.tsx +50 -0
- package/dist/Shell/SingleColumnLayout.tsx +22 -0
- package/dist/Shell/TertiaryColumnLayout.tsx +32 -0
- package/dist/Shell/index.ts +17 -0
- package/dist/Typography/Code.tsx +27 -0
- package/dist/Typography/Kbd.tsx +87 -0
- package/dist/Typography/Text.tsx +27 -0
- package/dist/Typography/Title.tsx +34 -0
- package/dist/Typography/index.ts +21 -0
- package/dist/bin/ds-audit.js +521 -0
- package/dist/config.ts +226 -0
- package/dist/contracts/Alert.json +80 -0
- package/dist/contracts/Badge.json +78 -0
- package/dist/contracts/Box.json +52 -0
- package/dist/contracts/Button.json +111 -0
- package/dist/contracts/DataTable.json +68 -0
- package/dist/contracts/Grid.json +35 -0
- package/dist/contracts/Group.json +44 -0
- package/dist/contracts/Inline.json +73 -0
- package/dist/contracts/PageContentHeader.json +107 -0
- package/dist/contracts/Stack.json +62 -0
- package/dist/contracts/ds-component-contract.v1.json +23 -0
- package/dist/contracts/index.json +55 -0
- package/dist/css/foundations.css +703 -0
- package/dist/css/mantine.css +1797 -0
- package/dist/hooks/useTableHandlers.ts +179 -0
- package/dist/hooks/useTableRenderFunctions.tsx +283 -0
- package/dist/hooks/useTableState.ts +81 -0
- package/dist/index.ts +210 -0
- package/dist/types.ts +202 -0
- package/package.json +56 -4
|
@@ -0,0 +1,788 @@
|
|
|
1
|
+
import React, { ReactElement, useEffect, useState } from "react";
|
|
2
|
+
import { ActionIcon, Indicator, Stack, Text, rem } from '@mantine/core';
|
|
3
|
+
import { Button } from '../../../Buttons/Button';
|
|
4
|
+
import { Grid } from '../../../Layout/Grid';
|
|
5
|
+
import { SimpleGrid } from '../../../Layout/SimpleGrid';
|
|
6
|
+
import { Inline } from '../../../Layout/Inline';
|
|
7
|
+
import { IconFilter, IconMaximize, IconMinimize, IconBaselineDensityMedium, IconBaselineDensitySmall, IconBaselineDensityLarge } from '@tabler/icons-react';
|
|
8
|
+
import { DatesRangeValue, type DateValue } from "@mantine/dates";
|
|
9
|
+
import {
|
|
10
|
+
MRT_TableInstance as MRTTableInstance,
|
|
11
|
+
MRT_ToggleFullScreenButton as MRTToggleFullScreenButton,
|
|
12
|
+
MRT_ToggleDensePaddingButton as MRTToggleDensePaddingButton,
|
|
13
|
+
MRT_ToolbarAlertBanner as BaseMRTToolbarAlertBanner,
|
|
14
|
+
MRT_RowData,
|
|
15
|
+
} from "mantine-react-table-open";
|
|
16
|
+
import { translate } from '../translations';
|
|
17
|
+
import SelectFilter from "./SelectFilter";
|
|
18
|
+
import SearchFilter from "./SearchFilter";
|
|
19
|
+
import DateRangeSelector from "./DateRangeSelectorFilter";
|
|
20
|
+
import FilterChip from "./FilterChip";
|
|
21
|
+
import ResultCount from "./ResultCount/index";
|
|
22
|
+
|
|
23
|
+
// =============================================================================
|
|
24
|
+
// TYPES & INTERFACES
|
|
25
|
+
// =============================================================================
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Enum defining all available cities for filtering
|
|
29
|
+
* @TODO: Consider moving this to a separate constants file for better maintainability
|
|
30
|
+
*/
|
|
31
|
+
export enum City {
|
|
32
|
+
NEW_YORK = "New York",
|
|
33
|
+
LOS_ANGELES = "Los Angeles",
|
|
34
|
+
CHICAGO = "Chicago",
|
|
35
|
+
SAN_FRANCISCO = "San Francisco",
|
|
36
|
+
BOSTON = "Boston",
|
|
37
|
+
SEATTLE = "Seattle",
|
|
38
|
+
DENVER = "Denver",
|
|
39
|
+
PORTLAND = "Portland",
|
|
40
|
+
AUSTIN = "Austin",
|
|
41
|
+
MIAMI = "Miami",
|
|
42
|
+
PHOENIX = "Phoenix",
|
|
43
|
+
LAS_VEGAS = "Las Vegas",
|
|
44
|
+
DETROIT = "Detroit",
|
|
45
|
+
NASHVILLE = "Nashville",
|
|
46
|
+
ATLANTA = "Atlanta",
|
|
47
|
+
ORLANDO = "Orlando",
|
|
48
|
+
TAMPA = "Tampa",
|
|
49
|
+
CHARLOTTE = "Charlotte",
|
|
50
|
+
INDIANAPOLIS = "Indianapolis",
|
|
51
|
+
COLUMBUS = "Columbus",
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Interface for date range filter values
|
|
56
|
+
*/
|
|
57
|
+
export interface DateRange {
|
|
58
|
+
start: Date | null;
|
|
59
|
+
end: Date | null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Central interface for all filter states
|
|
64
|
+
*/
|
|
65
|
+
export interface Filters {
|
|
66
|
+
cities?: City[] | null;
|
|
67
|
+
dateRange?: DateRange | null;
|
|
68
|
+
searchTerm?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Props for the main CustomTopToolbar component
|
|
73
|
+
*/
|
|
74
|
+
export interface CustomTopToolbarProps<T extends MRT_RowData> {
|
|
75
|
+
filtersState: Filters;
|
|
76
|
+
locale: string;
|
|
77
|
+
onChange: (filters: Filters) => void;
|
|
78
|
+
resultCount: number;
|
|
79
|
+
totalCount?: number; // Total records across all pages (unfiltered)
|
|
80
|
+
numberOfSelectedRows: number;
|
|
81
|
+
table: MRTTableInstance<T>;
|
|
82
|
+
isLoading?: boolean;
|
|
83
|
+
onFilterToggleChange: () => void;
|
|
84
|
+
showFilters: boolean;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Extended props for the MRT Toolbar Alert Banner
|
|
89
|
+
*/
|
|
90
|
+
interface ExtendedAlertBannerProps<T extends MRT_RowData> {
|
|
91
|
+
stackAlertBanner?: boolean;
|
|
92
|
+
table: MRTTableInstance<T>;
|
|
93
|
+
bg?: string;
|
|
94
|
+
numberofselectedrows: number;
|
|
95
|
+
style?: React.CSSProperties;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Props for the filter icon button component
|
|
100
|
+
*/
|
|
101
|
+
interface FilterIconButtonProps {
|
|
102
|
+
onClick: () => void;
|
|
103
|
+
areFiltersShown: boolean;
|
|
104
|
+
text?: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Props for action icon components (fullscreen, density)
|
|
109
|
+
*/
|
|
110
|
+
interface ActionIconButtonProps {
|
|
111
|
+
onClick: () => void;
|
|
112
|
+
ariaLabel: string;
|
|
113
|
+
icon: ReactElement;
|
|
114
|
+
testId?: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// =============================================================================
|
|
118
|
+
// CONSTANTS & UTILITIES
|
|
119
|
+
// =============================================================================
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Typed wrapper for the MRT Toolbar Alert Banner
|
|
123
|
+
*/
|
|
124
|
+
const MRTToolbarAlertBanner = BaseMRTToolbarAlertBanner as React.ComponentType<ExtendedAlertBannerProps<any>>;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Date formatting options for display purposes
|
|
128
|
+
*/
|
|
129
|
+
const DATE_FORMAT_OPTIONS: Intl.DateTimeFormatOptions = {
|
|
130
|
+
year: "numeric",
|
|
131
|
+
month: "long",
|
|
132
|
+
day: "numeric",
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Shared styling for action buttons (30x30 square buttons)
|
|
137
|
+
*/
|
|
138
|
+
const ACTION_BUTTON_STYLES = {
|
|
139
|
+
width: rem(30),
|
|
140
|
+
height: rem(30),
|
|
141
|
+
minWidth: rem(30),
|
|
142
|
+
minHeight: rem(30),
|
|
143
|
+
padding: 0,
|
|
144
|
+
display: 'flex',
|
|
145
|
+
alignItems: 'center',
|
|
146
|
+
justifyContent: 'center',
|
|
147
|
+
borderRadius: 'var(--mantine-radius-sm)',
|
|
148
|
+
border: '1px solid var(--ad-color-border-default)',
|
|
149
|
+
background: 'var(--ad-white)',
|
|
150
|
+
} as const;
|
|
151
|
+
|
|
152
|
+
const ACTION_ICON_STYLES = {
|
|
153
|
+
width: rem(30),
|
|
154
|
+
height: rem(30),
|
|
155
|
+
borderRadius: 'var(--mantine-radius-sm)',
|
|
156
|
+
border: '1px solid var(--ad-color-border-default)',
|
|
157
|
+
} as const;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Icon styling for consistent appearance
|
|
161
|
+
*/
|
|
162
|
+
const ICON_STYLES = {
|
|
163
|
+
color: 'var(--ad-color-text-default)',
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* City options data for the select filter
|
|
168
|
+
* @TODO: Consider moving this to a separate data file or fetching from an API
|
|
169
|
+
*/
|
|
170
|
+
const CITY_OPTIONS = [
|
|
171
|
+
{ value: City.ATLANTA, label: "table.filters.city.atlanta" as const },
|
|
172
|
+
{ value: City.AUSTIN, label: "table.filters.city.austin" as const },
|
|
173
|
+
{ value: City.BOSTON, label: "table.filters.city.boston" as const },
|
|
174
|
+
{ value: City.CHARLOTTE, label: "table.filters.city.charlotte" as const },
|
|
175
|
+
{ value: City.CHICAGO, label: "table.filters.city.chicago" as const },
|
|
176
|
+
{ value: City.COLUMBUS, label: "table.filters.city.columbus" as const },
|
|
177
|
+
{ value: City.DENVER, label: "table.filters.city.denver" as const },
|
|
178
|
+
{ value: City.DETROIT, label: "table.filters.city.detroit" as const },
|
|
179
|
+
{ value: City.INDIANAPOLIS, label: "table.filters.city.indianapolis" as const },
|
|
180
|
+
{ value: City.LAS_VEGAS, label: "table.filters.city.las.vegas" as const },
|
|
181
|
+
{ value: City.LOS_ANGELES, label: "table.filters.city.los.angeles" as const },
|
|
182
|
+
{ value: City.MIAMI, label: "table.filters.city.miami" as const },
|
|
183
|
+
{ value: City.NASHVILLE, label: "table.filters.city.nashville" as const },
|
|
184
|
+
{ value: City.NEW_YORK, label: "table.filters.city.new.york" as const },
|
|
185
|
+
{ value: City.ORLANDO, label: "table.filters.city.orlando" as const },
|
|
186
|
+
{ value: City.PHOENIX, label: "table.filters.city.phoenix" as const },
|
|
187
|
+
{ value: City.PORTLAND, label: "table.filters.city.portland" as const },
|
|
188
|
+
{ value: City.SAN_FRANCISCO, label: "table.filters.city.san.francisco" as const },
|
|
189
|
+
{ value: City.SEATTLE, label: "table.filters.city.seattle" as const },
|
|
190
|
+
{ value: City.TAMPA, label: "table.filters.city.tampa" as const },
|
|
191
|
+
].map(option => ({
|
|
192
|
+
...option,
|
|
193
|
+
label: translate(option.label),
|
|
194
|
+
}));
|
|
195
|
+
|
|
196
|
+
// =============================================================================
|
|
197
|
+
// UTILITY FUNCTIONS
|
|
198
|
+
// =============================================================================
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Utility function to determine if filters are currently active
|
|
202
|
+
* @param filters - The current filter state
|
|
203
|
+
* @returns boolean indicating if any filters are applied
|
|
204
|
+
*/
|
|
205
|
+
const hasActiveFilters = (filters: Filters): boolean => {
|
|
206
|
+
const { cities, dateRange } = filters;
|
|
207
|
+
return Boolean(
|
|
208
|
+
(cities && cities.length > 0) ||
|
|
209
|
+
(dateRange && dateRange.start && dateRange.end)
|
|
210
|
+
);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Utility function to process date range selection
|
|
215
|
+
* Handles the logic for ensuring both dates are selected and sets end time to end of day
|
|
216
|
+
* @param value - The selected date range value
|
|
217
|
+
* @returns Processed DateRange or null
|
|
218
|
+
*/
|
|
219
|
+
const toBoundaryDate = (v: DateValue | null): Date | null => {
|
|
220
|
+
if (v == null) return null;
|
|
221
|
+
return v instanceof Date ? v : new Date(`${v}T12:00:00`);
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const processDateRangeSelection = (value: DatesRangeValue | null): DateRange | null => {
|
|
225
|
+
// Helper functions for date validation
|
|
226
|
+
const isOnlyOneDateSelected = (): boolean => {
|
|
227
|
+
return !!(value && (value[0] === null || value[1] === null));
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const areBothDatesSelected = (): boolean => {
|
|
231
|
+
return !!(value && value[0] !== null && value[1] !== null);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// Return early if only one date is selected (incomplete selection)
|
|
235
|
+
if (isOnlyOneDateSelected()) {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
let range: DateRange | null = null;
|
|
240
|
+
|
|
241
|
+
if (value !== null && areBothDatesSelected()) {
|
|
242
|
+
const start = toBoundaryDate(value[0]);
|
|
243
|
+
let endDate = toBoundaryDate(value[1]);
|
|
244
|
+
|
|
245
|
+
if (endDate) {
|
|
246
|
+
const endOfDay = new Date(endDate);
|
|
247
|
+
endOfDay.setHours(23, 59, 59, 999);
|
|
248
|
+
endDate = endOfDay;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
range = {
|
|
252
|
+
start,
|
|
253
|
+
end: endDate,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return range;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Utility function to get the appropriate density icon based on current state
|
|
262
|
+
* @param density - Current table density setting
|
|
263
|
+
* @returns React element for the density icon
|
|
264
|
+
*/
|
|
265
|
+
const getDensityIcon = (density: string): ReactElement => {
|
|
266
|
+
const iconProps = { size: 18, style: ICON_STYLES };
|
|
267
|
+
|
|
268
|
+
switch (density) {
|
|
269
|
+
case 'md':
|
|
270
|
+
return <IconBaselineDensityMedium {...iconProps} />;
|
|
271
|
+
case 'xs':
|
|
272
|
+
return <IconBaselineDensitySmall {...iconProps} />;
|
|
273
|
+
case 'xl':
|
|
274
|
+
return <IconBaselineDensityLarge {...iconProps} />;
|
|
275
|
+
default:
|
|
276
|
+
return <IconBaselineDensityMedium {...iconProps} />;
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Utility function to cycle through density options
|
|
282
|
+
* @param currentDensity - Current density setting
|
|
283
|
+
* @returns Next density setting in the cycle
|
|
284
|
+
*/
|
|
285
|
+
const getNextDensity = (currentDensity: string): 'xs' | 'md' | 'xl' => {
|
|
286
|
+
const densityMap: Record<string, 'xs' | 'md' | 'xl'> = {
|
|
287
|
+
'xs': 'md',
|
|
288
|
+
'md': 'xl',
|
|
289
|
+
'xl': 'xs'
|
|
290
|
+
};
|
|
291
|
+
return densityMap[currentDensity] || 'md';
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// =============================================================================
|
|
295
|
+
// SUB-COMPONENTS
|
|
296
|
+
// =============================================================================
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Reusable action icon component with consistent styling
|
|
300
|
+
* Used for fullscreen and density toggle buttons
|
|
301
|
+
*/
|
|
302
|
+
const ActionIconButton: React.FC<ActionIconButtonProps> = ({
|
|
303
|
+
onClick,
|
|
304
|
+
ariaLabel,
|
|
305
|
+
icon,
|
|
306
|
+
testId
|
|
307
|
+
}) => (
|
|
308
|
+
<ActionIcon
|
|
309
|
+
variant="subtle"
|
|
310
|
+
onClick={onClick}
|
|
311
|
+
aria-label={ariaLabel}
|
|
312
|
+
style={ACTION_ICON_STYLES}
|
|
313
|
+
data-testid={testId}
|
|
314
|
+
>
|
|
315
|
+
{icon}
|
|
316
|
+
</ActionIcon>
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Filter toggle button with indicator support
|
|
321
|
+
* Shows an indicator dot when filters are active
|
|
322
|
+
* Conditionally renders ActionIcon (icon-only) or Button (icon+text) based on text prop
|
|
323
|
+
*/
|
|
324
|
+
const FilterIconButton: React.FC<FilterIconButtonProps> = ({
|
|
325
|
+
onClick,
|
|
326
|
+
areFiltersShown,
|
|
327
|
+
text
|
|
328
|
+
}) => {
|
|
329
|
+
const icon = <IconFilter size={18} style={ICON_STYLES} />;
|
|
330
|
+
|
|
331
|
+
// If no text provided or empty string, use ActionIcon for icon-only display with perfect centering
|
|
332
|
+
if (!text || text.trim() === '') {
|
|
333
|
+
return (
|
|
334
|
+
<ActionIcon
|
|
335
|
+
data-testid="additional-filter-toggle"
|
|
336
|
+
onClick={onClick}
|
|
337
|
+
aria-label={translate("table.filters.toggle.aria")}
|
|
338
|
+
style={{
|
|
339
|
+
width: rem(30),
|
|
340
|
+
height: rem(30),
|
|
341
|
+
borderRadius: 'var(--mantine-radius-sm)',
|
|
342
|
+
border: areFiltersShown
|
|
343
|
+
? '1px solid var(--ad-color-brand-primary)'
|
|
344
|
+
: '1px solid var(--ad-color-border-default)',
|
|
345
|
+
background: 'var(--ad-white)',
|
|
346
|
+
color: 'var(--ad-color-text-default)',
|
|
347
|
+
}}
|
|
348
|
+
>
|
|
349
|
+
{icon}
|
|
350
|
+
</ActionIcon>
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// If text is provided, use Button with leftSection for icon + text display
|
|
355
|
+
return (
|
|
356
|
+
<Button
|
|
357
|
+
data-testid="additional-filter-toggle"
|
|
358
|
+
variant={areFiltersShown ? "outline" : "default"}
|
|
359
|
+
onClick={onClick}
|
|
360
|
+
aria-label={translate("table.filters.toggle.aria")}
|
|
361
|
+
size="xs"
|
|
362
|
+
leftSection={icon}
|
|
363
|
+
style={{
|
|
364
|
+
height: rem(30),
|
|
365
|
+
borderRadius: 'var(--mantine-radius-sm)',
|
|
366
|
+
border: areFiltersShown
|
|
367
|
+
? '1px solid var(--ad-color-brand-primary)'
|
|
368
|
+
: '1px solid var(--ad-color-border-default)',
|
|
369
|
+
background: 'var(--ad-white)',
|
|
370
|
+
}}
|
|
371
|
+
>
|
|
372
|
+
{text}
|
|
373
|
+
</Button>
|
|
374
|
+
);
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Active filters display section
|
|
379
|
+
* Shows filter chips for currently applied filters and clear all button
|
|
380
|
+
*/
|
|
381
|
+
interface ActiveFiltersProps {
|
|
382
|
+
filters: Filters;
|
|
383
|
+
onClearFilters: () => void;
|
|
384
|
+
onRemoveCity: (cityToRemove: City) => void;
|
|
385
|
+
onRemoveDateRange: () => void;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const ActiveFilters: React.FC<ActiveFiltersProps> = ({
|
|
389
|
+
filters,
|
|
390
|
+
onClearFilters,
|
|
391
|
+
onRemoveCity,
|
|
392
|
+
onRemoveDateRange,
|
|
393
|
+
}) => {
|
|
394
|
+
const { cities, dateRange } = filters;
|
|
395
|
+
|
|
396
|
+
return (
|
|
397
|
+
<>
|
|
398
|
+
{/* Clear all filters button */}
|
|
399
|
+
<Text
|
|
400
|
+
size="xs"
|
|
401
|
+
span
|
|
402
|
+
role="button"
|
|
403
|
+
fw={600}
|
|
404
|
+
style={{ cursor: "pointer" }}
|
|
405
|
+
onClick={onClearFilters}
|
|
406
|
+
c="blue"
|
|
407
|
+
data-testid="clear-filters"
|
|
408
|
+
>
|
|
409
|
+
{translate("table.filters.clear.filters")}
|
|
410
|
+
</Text>
|
|
411
|
+
|
|
412
|
+
{/* City filter chips */}
|
|
413
|
+
{cities && cities.map((city) => (
|
|
414
|
+
<FilterChip
|
|
415
|
+
key={city}
|
|
416
|
+
label={city}
|
|
417
|
+
onClick={() => onRemoveCity(city)}
|
|
418
|
+
/>
|
|
419
|
+
))}
|
|
420
|
+
|
|
421
|
+
{/* Date range filter chip */}
|
|
422
|
+
{dateRange && (
|
|
423
|
+
<FilterChip
|
|
424
|
+
label={translate("table.filters.chip.date.range.label", {
|
|
425
|
+
startDate: dateRange.start?.toLocaleDateString(undefined, DATE_FORMAT_OPTIONS) || '',
|
|
426
|
+
endDate: dateRange.end?.toLocaleDateString(undefined, DATE_FORMAT_OPTIONS) || '',
|
|
427
|
+
})}
|
|
428
|
+
onClick={onRemoveDateRange}
|
|
429
|
+
/>
|
|
430
|
+
)}
|
|
431
|
+
</>
|
|
432
|
+
);
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Toolbar action buttons section
|
|
437
|
+
* Contains fullscreen toggle and density toggle buttons
|
|
438
|
+
*/
|
|
439
|
+
interface ToolbarActionsProps<T extends MRT_RowData> {
|
|
440
|
+
table: MRTTableInstance<T>;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const ToolbarActions = <T extends MRT_RowData>({ table }: ToolbarActionsProps<T>) => {
|
|
444
|
+
const isFullScreen = table.getState().isFullScreen ?? false;
|
|
445
|
+
const currentDensity = table.getState().density;
|
|
446
|
+
|
|
447
|
+
const handleFullscreenToggle = () => {
|
|
448
|
+
table.setIsFullScreen(!isFullScreen);
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
const handleDensityToggle = () => {
|
|
452
|
+
const nextDensity = getNextDensity(currentDensity);
|
|
453
|
+
table.setDensity(nextDensity);
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
return (
|
|
457
|
+
<Inline justify="flex-end" gap="xs">
|
|
458
|
+
{/* Fullscreen toggle button */}
|
|
459
|
+
<ActionIconButton
|
|
460
|
+
onClick={handleFullscreenToggle}
|
|
461
|
+
ariaLabel={isFullScreen ? "Exit fullscreen" : "Enter fullscreen"}
|
|
462
|
+
icon={isFullScreen ?
|
|
463
|
+
<IconMinimize size={18} style={ICON_STYLES} /> :
|
|
464
|
+
<IconMaximize size={18} style={ICON_STYLES} />
|
|
465
|
+
}
|
|
466
|
+
/>
|
|
467
|
+
|
|
468
|
+
{/* Density toggle button */}
|
|
469
|
+
<ActionIconButton
|
|
470
|
+
onClick={handleDensityToggle}
|
|
471
|
+
ariaLabel="Toggle density"
|
|
472
|
+
icon={getDensityIcon(currentDensity)}
|
|
473
|
+
testId="toggle-dense-padding"
|
|
474
|
+
/>
|
|
475
|
+
</Inline>
|
|
476
|
+
);
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Expandable filters section
|
|
481
|
+
* Contains date range and city selection filters
|
|
482
|
+
*/
|
|
483
|
+
interface ExpandableFiltersProps {
|
|
484
|
+
visible: boolean;
|
|
485
|
+
locale: string;
|
|
486
|
+
cities: City[] | null | undefined;
|
|
487
|
+
onDateChange: (value: DatesRangeValue | null) => void;
|
|
488
|
+
onCityChange: (value: string[] | null) => void;
|
|
489
|
+
dateRangeSelectorKey: number;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
const ExpandableFilters: React.FC<ExpandableFiltersProps> = ({
|
|
493
|
+
visible,
|
|
494
|
+
locale,
|
|
495
|
+
cities,
|
|
496
|
+
onDateChange,
|
|
497
|
+
onCityChange,
|
|
498
|
+
dateRangeSelectorKey,
|
|
499
|
+
}) => {
|
|
500
|
+
if (!visible) return null;
|
|
501
|
+
|
|
502
|
+
return (
|
|
503
|
+
<SimpleGrid data-testid="additional-filters" cols={3} spacing="xs" role="menu">
|
|
504
|
+
{/* Date range selector */}
|
|
505
|
+
<DateRangeSelector
|
|
506
|
+
key={dateRangeSelectorKey}
|
|
507
|
+
label={translate("table.filters.applied.on")}
|
|
508
|
+
locale={locale}
|
|
509
|
+
onChange={onDateChange}
|
|
510
|
+
/>
|
|
511
|
+
|
|
512
|
+
{/* City multi-select filter */}
|
|
513
|
+
<SelectFilter
|
|
514
|
+
label={translate("table.filters.city")}
|
|
515
|
+
onChange={onCityChange}
|
|
516
|
+
selectedValue={(cities as string[]) || null}
|
|
517
|
+
placeholderEmpty={translate("table.filters.placeholder.all")}
|
|
518
|
+
placeholderWithSelection={translate("table.filters.placeholder.select.more")}
|
|
519
|
+
data={CITY_OPTIONS}
|
|
520
|
+
/>
|
|
521
|
+
</SimpleGrid>
|
|
522
|
+
);
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
// =============================================================================
|
|
526
|
+
// MAIN COMPONENT
|
|
527
|
+
// =============================================================================
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* CustomTopToolbar - Main toolbar component for data tables
|
|
531
|
+
*
|
|
532
|
+
* Features:
|
|
533
|
+
* - Search functionality
|
|
534
|
+
* - Filter toggle with indicator
|
|
535
|
+
* - Active filter chips with remove functionality
|
|
536
|
+
* - Fullscreen and density controls
|
|
537
|
+
* - Expandable filter section (date range, city selection)
|
|
538
|
+
* - Result count display
|
|
539
|
+
* - Selection alert banner integration
|
|
540
|
+
*
|
|
541
|
+
* @param props - CustomTopToolbarProps containing all necessary data and handlers
|
|
542
|
+
*/
|
|
543
|
+
const CustomTopToolbar = <T extends MRT_RowData>({
|
|
544
|
+
filtersState,
|
|
545
|
+
locale,
|
|
546
|
+
resultCount,
|
|
547
|
+
totalCount,
|
|
548
|
+
onChange,
|
|
549
|
+
table,
|
|
550
|
+
numberOfSelectedRows,
|
|
551
|
+
isLoading,
|
|
552
|
+
showFilters,
|
|
553
|
+
onFilterToggleChange,
|
|
554
|
+
}: CustomTopToolbarProps<T>): ReactElement => {
|
|
555
|
+
|
|
556
|
+
// =============================================================================
|
|
557
|
+
// STATE MANAGEMENT
|
|
558
|
+
// =============================================================================
|
|
559
|
+
|
|
560
|
+
const { searchTerm, cities, dateRange } = filtersState;
|
|
561
|
+
const [dateRangeSelectorRefreshKey, setDateRangeSelectorRefreshKey] = useState<number>(0);
|
|
562
|
+
const [showFiltersState, setShowFiltersState] = useState(showFilters);
|
|
563
|
+
|
|
564
|
+
// =============================================================================
|
|
565
|
+
// EFFECTS
|
|
566
|
+
// =============================================================================
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Reset date range selector when date range is cleared
|
|
570
|
+
* This forces the component to re-render and clear its internal state
|
|
571
|
+
*/
|
|
572
|
+
useEffect(() => {
|
|
573
|
+
if (dateRange === null) {
|
|
574
|
+
setDateRangeSelectorRefreshKey(prev => prev + 1);
|
|
575
|
+
}
|
|
576
|
+
}, [dateRange]);
|
|
577
|
+
|
|
578
|
+
// =============================================================================
|
|
579
|
+
// EVENT HANDLERS
|
|
580
|
+
// =============================================================================
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Handles date range selection changes
|
|
584
|
+
* Processes the raw date selection and converts it to our DateRange format
|
|
585
|
+
*/
|
|
586
|
+
const handleDateChange = (value: DatesRangeValue | null): void => {
|
|
587
|
+
const processedRange = processDateRangeSelection(value);
|
|
588
|
+
|
|
589
|
+
// Only update if we have a complete range or null (clear)
|
|
590
|
+
if (processedRange !== null || value === null) {
|
|
591
|
+
onChange({ dateRange: processedRange });
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Toggles the visibility of the expandable filters section
|
|
597
|
+
*/
|
|
598
|
+
const handleFilterToggle = (): void => {
|
|
599
|
+
const newShowFilters = !showFiltersState;
|
|
600
|
+
setShowFiltersState(newShowFilters);
|
|
601
|
+
onFilterToggleChange?.();
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* Clears all applied filters except search term
|
|
606
|
+
*/
|
|
607
|
+
const handleClearAllFilters = (): void => {
|
|
608
|
+
onChange({
|
|
609
|
+
searchTerm,
|
|
610
|
+
cities: null,
|
|
611
|
+
dateRange: null,
|
|
612
|
+
});
|
|
613
|
+
setDateRangeSelectorRefreshKey(prev => prev + 1);
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Removes a specific city from the cities filter
|
|
618
|
+
*/
|
|
619
|
+
const handleRemoveCity = (cityToRemove: City): void => {
|
|
620
|
+
const updatedCities = cities?.filter((city) => city !== cityToRemove) || [];
|
|
621
|
+
onChange({
|
|
622
|
+
cities: updatedCities.length > 0 ? updatedCities : null,
|
|
623
|
+
});
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Removes the date range filter
|
|
628
|
+
*/
|
|
629
|
+
const handleRemoveDateRange = (): void => {
|
|
630
|
+
onChange({ dateRange: null });
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Handles search term changes
|
|
635
|
+
*/
|
|
636
|
+
const handleSearchChange = (value: string): void => {
|
|
637
|
+
onChange({ searchTerm: value });
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Handles city selection changes
|
|
642
|
+
*/
|
|
643
|
+
const handleCityChange = (value: string[] | null): void => {
|
|
644
|
+
onChange({ cities: value as City[] | null });
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
// =============================================================================
|
|
648
|
+
// COMPUTED VALUES
|
|
649
|
+
// =============================================================================
|
|
650
|
+
|
|
651
|
+
const filtersAreActive = hasActiveFilters(filtersState);
|
|
652
|
+
|
|
653
|
+
// Get correct result counts from table state
|
|
654
|
+
const currentFilteredTotal = table.getFilteredRowModel().rows.length; // Total filtered results across all pages
|
|
655
|
+
const totalRecords = table.getCoreRowModel().rows.length; // Total unfiltered records
|
|
656
|
+
const currentPageSize = table.getState().pagination.pageSize;
|
|
657
|
+
const currentPageData = table.getRowModel().rows.length; // Current page only
|
|
658
|
+
|
|
659
|
+
// Determine the correct counts to display based on filter state and server-side vs client-side
|
|
660
|
+
let displayResultCount: number;
|
|
661
|
+
let displayTotalCount: number;
|
|
662
|
+
|
|
663
|
+
if (totalCount !== undefined) {
|
|
664
|
+
// Server-side/manual pagination: use provided props
|
|
665
|
+
displayTotalCount = totalCount;
|
|
666
|
+
|
|
667
|
+
if (filtersAreActive) {
|
|
668
|
+
// When filters are active, show filtered count vs total
|
|
669
|
+
displayResultCount = resultCount;
|
|
670
|
+
} else {
|
|
671
|
+
// When no filters are active, show total count only
|
|
672
|
+
displayResultCount = totalCount;
|
|
673
|
+
}
|
|
674
|
+
} else {
|
|
675
|
+
// Client-side pagination with full dataset: use table instance methods
|
|
676
|
+
if (filtersAreActive) {
|
|
677
|
+
// When filters are active, show filtered count
|
|
678
|
+
displayResultCount = currentFilteredTotal;
|
|
679
|
+
displayTotalCount = totalRecords;
|
|
680
|
+
} else {
|
|
681
|
+
// When no filters are active, show total count only
|
|
682
|
+
displayResultCount = totalRecords;
|
|
683
|
+
displayTotalCount = totalRecords;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// =============================================================================
|
|
688
|
+
// RENDER
|
|
689
|
+
// =============================================================================
|
|
690
|
+
|
|
691
|
+
return (
|
|
692
|
+
<>
|
|
693
|
+
{/* Main toolbar content */}
|
|
694
|
+
<Stack
|
|
695
|
+
p="md"
|
|
696
|
+
gap="xshalf"
|
|
697
|
+
style={{
|
|
698
|
+
borderBottom: "1px solid var(--ad-color-border-subtle)",
|
|
699
|
+
}}
|
|
700
|
+
>
|
|
701
|
+
{/* Top row: Search and action buttons */}
|
|
702
|
+
<Grid gap="md">
|
|
703
|
+
<Grid.Col span={{ base: 12, md: 6 }}>
|
|
704
|
+
{/* Left side: Filter toggle and search */}
|
|
705
|
+
<Inline gap="xs" align="center">
|
|
706
|
+
{/* Filter toggle button with optional indicator */}
|
|
707
|
+
{filtersAreActive ? (
|
|
708
|
+
<Indicator size="8">
|
|
709
|
+
<FilterIconButton
|
|
710
|
+
areFiltersShown={showFiltersState}
|
|
711
|
+
onClick={handleFilterToggle}
|
|
712
|
+
text=""
|
|
713
|
+
/>
|
|
714
|
+
</Indicator>
|
|
715
|
+
) : (
|
|
716
|
+
<FilterIconButton
|
|
717
|
+
areFiltersShown={showFiltersState}
|
|
718
|
+
onClick={handleFilterToggle}
|
|
719
|
+
text=""
|
|
720
|
+
/>
|
|
721
|
+
)}
|
|
722
|
+
|
|
723
|
+
{/* Search input */}
|
|
724
|
+
<SearchFilter
|
|
725
|
+
searchTerm={searchTerm as string}
|
|
726
|
+
onChange={handleSearchChange}
|
|
727
|
+
/>
|
|
728
|
+
</Inline>
|
|
729
|
+
</Grid.Col>
|
|
730
|
+
|
|
731
|
+
{/* Right side: Action buttons */}
|
|
732
|
+
<Grid.Col span={{ base: 12, md: 6 }}>
|
|
733
|
+
<ToolbarActions table={table} />
|
|
734
|
+
</Grid.Col>
|
|
735
|
+
</Grid>
|
|
736
|
+
|
|
737
|
+
{/* Second row: Active filters and result count */}
|
|
738
|
+
<Inline justify="space-between">
|
|
739
|
+
<Inline gap="xs">
|
|
740
|
+
{/* Show active filters if any exist */}
|
|
741
|
+
{filtersAreActive && (
|
|
742
|
+
<ActiveFilters
|
|
743
|
+
filters={filtersState}
|
|
744
|
+
onClearFilters={handleClearAllFilters}
|
|
745
|
+
onRemoveCity={handleRemoveCity}
|
|
746
|
+
onRemoveDateRange={handleRemoveDateRange}
|
|
747
|
+
/>
|
|
748
|
+
)}
|
|
749
|
+
|
|
750
|
+
{/* Result count display */}
|
|
751
|
+
<ResultCount
|
|
752
|
+
resultCount={displayResultCount}
|
|
753
|
+
totalCount={displayTotalCount}
|
|
754
|
+
isLoading={isLoading ?? false}
|
|
755
|
+
hasActiveFilters={filtersAreActive}
|
|
756
|
+
/>
|
|
757
|
+
</Inline>
|
|
758
|
+
</Inline>
|
|
759
|
+
|
|
760
|
+
{/* Expandable filters section */}
|
|
761
|
+
<ExpandableFilters
|
|
762
|
+
visible={showFiltersState}
|
|
763
|
+
locale={locale}
|
|
764
|
+
cities={cities}
|
|
765
|
+
onDateChange={handleDateChange}
|
|
766
|
+
onCityChange={handleCityChange}
|
|
767
|
+
dateRangeSelectorKey={dateRangeSelectorRefreshKey}
|
|
768
|
+
/>
|
|
769
|
+
</Stack>
|
|
770
|
+
|
|
771
|
+
{/* Selection alert banner */}
|
|
772
|
+
<MRTToolbarAlertBanner
|
|
773
|
+
stackAlertBanner
|
|
774
|
+
table={table as any}
|
|
775
|
+
bg="blue"
|
|
776
|
+
numberofselectedrows={numberOfSelectedRows}
|
|
777
|
+
style={{
|
|
778
|
+
borderRadius: 0,
|
|
779
|
+
color: 'var(--ad-white)',
|
|
780
|
+
borderTop: '1px solid var(--ad-color-brand-primary)',
|
|
781
|
+
padding: 'var(--mantine-spacing-xs)',
|
|
782
|
+
}}
|
|
783
|
+
/>
|
|
784
|
+
</>
|
|
785
|
+
);
|
|
786
|
+
};
|
|
787
|
+
|
|
788
|
+
export default CustomTopToolbar;
|