@appdirect/design-system 0.0.16 → 0.0.18
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/bin/ad-sync-design-md.mjs +0 -0
- package/dist/ComplexComponents/DataTable/CellHoverReveal/CellHoverReveal.module.css +25 -0
- package/dist/ComplexComponents/DataTable/CellHoverReveal/index.js +24 -0
- package/dist/ComplexComponents/DataTable/CellHoverReveal/index.tsx +44 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/CustomBottomToolbar.module.css +7 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.js +25 -77
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.tsx +101 -157
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.js +14 -7
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.ts +13 -7
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/CustomToolbarAlertBannerContent.module.css +4 -0
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.js +8 -20
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.tsx +40 -58
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/CustomTopToolbar.module.css +7 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/DateRangeSelectorFilter.module.css +3 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.js +50 -154
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.tsx +59 -205
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/utils.js +48 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/utils.ts +51 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.js +5 -25
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.tsx +7 -28
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount.js +16 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount.tsx +26 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.js +26 -28
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.tsx +38 -38
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.js +8 -18
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.module.css +3 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.tsx +25 -37
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.js +67 -378
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.tsx +170 -711
- package/dist/ComplexComponents/DataTable/DataTable.js +74 -393
- package/dist/ComplexComponents/DataTable/DataTable.tsx +229 -546
- package/dist/ComplexComponents/DataTable/DataTableGrid/DataTableGrid.module.css +85 -0
- package/dist/ComplexComponents/DataTable/DataTableGrid/index.js +46 -0
- package/dist/ComplexComponents/DataTable/DataTableGrid/index.tsx +143 -0
- package/dist/ComplexComponents/DataTable/DataTableShell/DataTableShell.module.css +38 -0
- package/dist/ComplexComponents/DataTable/DataTableShell/index.js +9 -0
- package/dist/ComplexComponents/DataTable/DataTableShell/index.tsx +47 -0
- package/dist/ComplexComponents/DataTable/ErrorOverlay/index.js +6 -6
- package/dist/ComplexComponents/DataTable/ErrorOverlay/index.tsx +53 -24
- package/dist/ComplexComponents/DataTable/SelectCheckbox/index.js +33 -0
- package/dist/ComplexComponents/DataTable/SelectCheckbox/index.tsx +63 -0
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/SortableHeaderCell.module.css +3 -0
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.js +43 -21
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.tsx +62 -38
- package/dist/ComplexComponents/DataTable/ToggleDensityButton/index.js +18 -0
- package/dist/ComplexComponents/DataTable/ToggleDensityButton/index.tsx +47 -0
- package/dist/ComplexComponents/DataTable/ToggleFullScreenButton/index.js +19 -0
- package/dist/ComplexComponents/DataTable/ToggleFullScreenButton/index.tsx +59 -0
- package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/ToolbarAlertBanner.module.css +15 -0
- package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/index.js +8 -0
- package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/index.tsx +20 -0
- package/dist/ComplexComponents/DataTable/hooks/useClickOutside.js +27 -0
- package/dist/ComplexComponents/DataTable/hooks/useClickOutside.ts +39 -0
- package/dist/ComplexComponents/DataTable/index.js +5 -1
- package/dist/ComplexComponents/DataTable/index.ts +13 -2
- package/dist/ComplexComponents/DataTable/table.module.css +9 -0
- package/dist/ComplexComponents/DataTable/tableFeatures.js +6 -0
- package/dist/ComplexComponents/DataTable/tableFeatures.ts +7 -0
- package/dist/ComplexComponents/DataTable/translations/en.js +16 -4
- package/dist/ComplexComponents/DataTable/translations/en.ts +16 -4
- package/dist/ComplexComponents/DataTable/translations/index.js +5 -0
- package/dist/ComplexComponents/DataTable/translations/index.ts +11 -1
- package/dist/ComplexComponents/DataTable/types.js +5 -0
- package/dist/ComplexComponents/DataTable/types.ts +17 -0
- package/dist/ComplexComponents/DataTable/utils/parseCSSVarId.js +3 -0
- package/dist/ComplexComponents/DataTable/utils/parseCSSVarId.ts +4 -0
- package/dist/DESIGN.md +9 -10
- package/dist/contracts/DataTable.json +83 -6
- package/dist/contracts/index.json +1 -1
- package/dist/css/foundations.css +4 -0
- package/dist/css/mantine.css +1 -1
- package/dist/css/tokens.css +3145 -0
- package/dist/index.js +3 -0
- package/dist/index.ts +14 -1
- package/dist/stories/ComplexComponents/DataTable/DataTable.stories.tsx +216 -458
- package/dist/stories/index.json +13 -15
- package/package.json +5 -3
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.js +0 -31
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.tsx +0 -76
- package/dist/hooks/useTableHandlers.js +0 -136
- package/dist/hooks/useTableHandlers.ts +0 -179
- package/dist/hooks/useTableRenderFunctions.js +0 -164
- package/dist/hooks/useTableRenderFunctions.tsx +0 -283
- package/dist/hooks/useTableState.js +0 -70
- package/dist/hooks/useTableState.ts +0 -81
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
'use client'; // DS-ADAPT: Next.js App Router
|
|
2
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomTopToolbar/DateRangeSelectorFilter/index.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
3
|
+
import React, { useMemo, useState, MutableRefObject, ReactElement } from "react";
|
|
2
4
|
import {
|
|
3
5
|
CloseButton,
|
|
4
6
|
Combobox,
|
|
@@ -7,214 +9,88 @@ import {
|
|
|
7
9
|
Popover,
|
|
8
10
|
useCombobox,
|
|
9
11
|
} from "@mantine/core";
|
|
10
|
-
import { DatePicker, DatesRangeValue
|
|
11
|
-
import { translate } from
|
|
12
|
+
import { DatePicker, DatesRangeValue } from "@mantine/dates";
|
|
13
|
+
import { translate } from "../../translations"; // DS-ADAPT: translate lives in DataTable/translations
|
|
14
|
+
import { Preset, getPresetLabel, getPresets, getDateRangeFromPreset } from "./utils";
|
|
15
|
+
import useClickOutside from '../../../../hooks/useClickOutside';
|
|
16
|
+
import styles from "./DateRangeSelectorFilter.module.css";
|
|
12
17
|
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
const y = d.getFullYear();
|
|
16
|
-
const m = String(d.getMonth() + 1).padStart(2, "0");
|
|
17
|
-
const day = String(d.getDate()).padStart(2, "0");
|
|
18
|
-
return `${y}-${m}-${day}`;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function formatDateValueLocale(v: DateValue | null, locale: string): string {
|
|
22
|
-
if (v == null) return "";
|
|
23
|
-
const d = typeof v === "string" ? new Date(`${v}T12:00:00`) : v;
|
|
24
|
-
return d.toLocaleDateString(locale);
|
|
25
|
-
}
|
|
18
|
+
/** DS-ADAPT: Mantine 9 DatePicker works with local `YYYY-MM-DD` strings; presets emit Dates. */
|
|
19
|
+
export type DateRangeInput = [Date | string | null, Date | string | null];
|
|
26
20
|
|
|
27
|
-
function toPickerDate(v: DateValue | null | undefined): Date {
|
|
28
|
-
if (v == null) return new Date();
|
|
29
|
-
return typeof v === "string" ? new Date(`${v}T12:00:00`) : v;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Props interface for the DateRangeSelector component
|
|
34
|
-
*/
|
|
35
21
|
interface DateRangeSelectorProps {
|
|
36
|
-
/** Label text displayed above the selector */
|
|
37
22
|
label: string;
|
|
38
|
-
/** Locale string for date formatting (e.g., 'en-US', 'fr-FR') */
|
|
39
23
|
locale: string;
|
|
40
|
-
|
|
41
|
-
onChange: (value: DatesRangeValue | null) => void;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Enum defining available preset date range options
|
|
46
|
-
*/
|
|
47
|
-
enum Preset {
|
|
48
|
-
WEEK = "week",
|
|
49
|
-
MONTH = "month",
|
|
50
|
-
QUARTER = "quarter",
|
|
51
|
-
CUSTOM = "custom",
|
|
24
|
+
onChange: (value: DateRangeInput | null) => void;
|
|
52
25
|
}
|
|
53
26
|
|
|
54
|
-
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/** Currently selected preset option */
|
|
61
|
-
preset: string | null;
|
|
62
|
-
/** Selected custom date range (Mantine 9 uses date strings or Date) */
|
|
63
|
-
customDateRange: DatesRangeValue;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Preset option interface for dropdown display
|
|
68
|
-
*/
|
|
69
|
-
interface PresetOption {
|
|
70
|
-
/** Display label for the preset */
|
|
71
|
-
label: string;
|
|
72
|
-
/** Internal value for the preset */
|
|
73
|
-
value: Preset;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Returns available preset options with translated labels
|
|
78
|
-
* @returns Array of preset options for the dropdown
|
|
79
|
-
*/
|
|
80
|
-
const getPresets = (): PresetOption[] => [
|
|
81
|
-
{
|
|
82
|
-
label: translate("table.filters.date.range.week"),
|
|
83
|
-
value: Preset.WEEK,
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
label: translate("table.filters.date.range.month"),
|
|
87
|
-
value: Preset.MONTH,
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
label: translate("table.filters.date.range.quarter"),
|
|
91
|
-
value: Preset.QUARTER,
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
label: translate("table.filters.date.range.custom"),
|
|
95
|
-
value: Preset.CUSTOM,
|
|
96
|
-
},
|
|
97
|
-
];
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Finds and returns the display label for a given preset value
|
|
101
|
-
* @param value - The preset value to look up
|
|
102
|
-
* @returns The translated label or empty string if not found
|
|
103
|
-
*/
|
|
104
|
-
const getPresetLabel = (value: string): string => {
|
|
105
|
-
return getPresets().find(item => item.value === value)?.label || "";
|
|
27
|
+
/** Parse a local `YYYY-MM-DD` string (or Date) to a local-midnight Date. */
|
|
28
|
+
const toLocalDate = (value: Date | string | null): Date | null => {
|
|
29
|
+
if (!value) return null;
|
|
30
|
+
if (value instanceof Date) return value;
|
|
31
|
+
const [y, m, d] = value.slice(0, 10).split("-").map(Number);
|
|
32
|
+
return new Date(y, m - 1, d);
|
|
106
33
|
};
|
|
107
34
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const getDateRangeFromPreset = (preset: string): DatesRangeValue | null => {
|
|
114
|
-
const now = new Date();
|
|
115
|
-
const start = new Date();
|
|
116
|
-
|
|
117
|
-
switch (preset) {
|
|
118
|
-
case Preset.WEEK:
|
|
119
|
-
start.setDate(now.getDate() - 7);
|
|
120
|
-
break;
|
|
121
|
-
case Preset.MONTH:
|
|
122
|
-
start.setMonth(now.getMonth() - 1);
|
|
123
|
-
break;
|
|
124
|
-
case Preset.QUARTER:
|
|
125
|
-
start.setMonth(now.getMonth() - 3);
|
|
126
|
-
break;
|
|
127
|
-
default:
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return [toDateStringValue(start), toDateStringValue(now)];
|
|
35
|
+
const toDateString = (value: Date | string | null): string | null => {
|
|
36
|
+
if (!value) return null;
|
|
37
|
+
if (typeof value === "string") return value.slice(0, 10);
|
|
38
|
+
const pad = (n: number): string => String(n).padStart(2, "0");
|
|
39
|
+
return `${value.getFullYear()}-${pad(value.getMonth() + 1)}-${pad(value.getDate())}`;
|
|
132
40
|
};
|
|
133
41
|
|
|
134
|
-
/**
|
|
135
|
-
* DateRangeSelector - A sophisticated date range filter component with preset options
|
|
136
|
-
* and custom date selection via floating calendar dialog.
|
|
137
|
-
*
|
|
138
|
-
* Features:
|
|
139
|
-
* - Preset options: Last week, month, quarter
|
|
140
|
-
* - Custom date range selection with floating calendar
|
|
141
|
-
* - Proper state management with rollback capability
|
|
142
|
-
* - Localized date display and formatting
|
|
143
|
-
* - Clear functionality with visual feedback
|
|
144
|
-
*/
|
|
145
42
|
const DateRangeSelector = ({ label, locale, onChange }: DateRangeSelectorProps): ReactElement => {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
customDateRange: [null, null],
|
|
43
|
+
const [dateFilterState, setDateFilterState] = useState({
|
|
44
|
+
previousPreset: null as string | null,
|
|
45
|
+
preset: null as string | null,
|
|
46
|
+
customDateRange: [null, null] as [string | null, string | null], // DS-ADAPT: date strings
|
|
151
47
|
});
|
|
152
|
-
|
|
153
|
-
// Destructure state for easier access
|
|
154
48
|
const { preset, customDateRange } = dateFilterState;
|
|
155
49
|
|
|
156
|
-
// Controls visibility of the floating date picker
|
|
157
50
|
const [isDatePickerOpened, setIsDatePickerOpened] = useState(false);
|
|
158
51
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
52
|
+
const presetSelectRef = useClickOutside(() => {
|
|
53
|
+
if (isDatePickerOpened) {
|
|
54
|
+
setDateFilterState(prev => ({
|
|
55
|
+
...prev,
|
|
56
|
+
preset: prev.previousPreset,
|
|
57
|
+
}));
|
|
58
|
+
setIsDatePickerOpened(false);
|
|
59
|
+
}
|
|
60
|
+
}, ["date-picker"]) as MutableRefObject<HTMLDivElement>;
|
|
61
|
+
|
|
164
62
|
const isDateRangeSelected = (value: string | null): boolean => {
|
|
165
63
|
return value === Preset.CUSTOM && customDateRange[0] !== null && customDateRange[1] !== null;
|
|
166
64
|
};
|
|
167
65
|
|
|
168
|
-
/**
|
|
169
|
-
* Determines what value to display in the input field
|
|
170
|
-
* Handles different states: empty, preset selected, custom dates, partial custom selection
|
|
171
|
-
*/
|
|
172
66
|
const getValueDisplayed = useMemo(() => {
|
|
173
|
-
// Show formatted date range for completed custom selection
|
|
174
67
|
if (isDateRangeSelected(preset)) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
)
|
|
68
|
+
const start = toLocalDate(customDateRange[0]);
|
|
69
|
+
const end = toLocalDate(customDateRange[1]);
|
|
70
|
+
|
|
71
|
+
if (start && end) {
|
|
72
|
+
return `${start.toLocaleDateString(locale)} - ${end.toLocaleDateString(locale)}`;
|
|
73
|
+
}
|
|
179
74
|
}
|
|
180
|
-
|
|
181
|
-
// Show helper text for partial custom selection
|
|
182
75
|
if (preset === Preset.CUSTOM) {
|
|
183
76
|
return translate("table.filters.date.range.select");
|
|
184
77
|
}
|
|
185
|
-
|
|
186
|
-
// Show preset label for selected presets
|
|
187
78
|
if (preset) {
|
|
188
79
|
return getPresetLabel(preset);
|
|
189
80
|
}
|
|
190
|
-
|
|
191
|
-
// Show placeholder for empty state
|
|
192
81
|
return <InputPlaceholder>{translate("table.filters.show.all")}</InputPlaceholder>;
|
|
193
82
|
}, [preset, customDateRange, locale]);
|
|
194
83
|
|
|
195
|
-
/**
|
|
196
|
-
* Combobox configuration for dropdown behavior
|
|
197
|
-
* Handles dropdown close events and option selection
|
|
198
|
-
*/
|
|
199
84
|
const combobox = useCombobox({
|
|
200
|
-
onDropdownClose: () =>
|
|
201
|
-
// Reset selected option when dropdown closes
|
|
202
|
-
},
|
|
85
|
+
onDropdownClose: () => combobox.resetSelectedOption(),
|
|
203
86
|
});
|
|
204
87
|
|
|
205
|
-
/**
|
|
206
|
-
* Renders preset options for the dropdown menu
|
|
207
|
-
*/
|
|
208
88
|
const options = getPresets().map(item => (
|
|
209
89
|
<Combobox.Option value={item.value} key={item.value}>
|
|
210
90
|
{item.label}
|
|
211
91
|
</Combobox.Option>
|
|
212
92
|
));
|
|
213
93
|
|
|
214
|
-
/**
|
|
215
|
-
* Handles clearing the current selection
|
|
216
|
-
* Resets all state and notifies parent component
|
|
217
|
-
*/
|
|
218
94
|
const handleClearClick = (): void => {
|
|
219
95
|
setDateFilterState(prev => ({
|
|
220
96
|
previousPreset: prev.preset,
|
|
@@ -225,14 +101,15 @@ const DateRangeSelector = ({ label, locale, onChange }: DateRangeSelectorProps):
|
|
|
225
101
|
onChange(null);
|
|
226
102
|
};
|
|
227
103
|
|
|
228
|
-
/**
|
|
229
|
-
* Handles selection of preset options from dropdown
|
|
230
|
-
* @param value - The selected preset value
|
|
231
|
-
*/
|
|
232
104
|
const handlePresetChange = (value: string): void => {
|
|
233
105
|
combobox.closeDropdown();
|
|
234
|
-
|
|
235
|
-
|
|
106
|
+
if (preset === Preset.CUSTOM && value !== Preset.CUSTOM) {
|
|
107
|
+
setDateFilterState(prev => ({
|
|
108
|
+
previousPreset: prev.preset,
|
|
109
|
+
preset: prev.preset,
|
|
110
|
+
customDateRange: [null, null],
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
236
113
|
setDateFilterState(prev => ({
|
|
237
114
|
...prev,
|
|
238
115
|
previousPreset: prev.preset,
|
|
@@ -240,28 +117,18 @@ const DateRangeSelector = ({ label, locale, onChange }: DateRangeSelectorProps):
|
|
|
240
117
|
}));
|
|
241
118
|
|
|
242
119
|
if (value === Preset.CUSTOM) {
|
|
243
|
-
// Open floating date picker for custom selection
|
|
244
120
|
setIsDatePickerOpened(true);
|
|
245
121
|
} else {
|
|
246
|
-
// Apply preset date range immediately and close any open picker
|
|
247
122
|
setIsDatePickerOpened(false);
|
|
248
123
|
onChange(getDateRangeFromPreset(value));
|
|
249
124
|
}
|
|
250
125
|
};
|
|
251
126
|
|
|
252
|
-
/**
|
|
253
|
-
* Handles clicks on the main input button
|
|
254
|
-
* Toggles dropdown or date picker based on current state
|
|
255
|
-
*/
|
|
256
127
|
const handleInputBaseClick = (): void => {
|
|
257
128
|
if (!isDatePickerOpened) {
|
|
258
|
-
// Open dropdown for preset selection
|
|
259
129
|
combobox.toggleDropdown();
|
|
260
130
|
} else {
|
|
261
|
-
// Close date picker
|
|
262
131
|
setIsDatePickerOpened(false);
|
|
263
|
-
|
|
264
|
-
// Revert to previous preset if no complete date range was selected
|
|
265
132
|
if (customDateRange[0] === null && customDateRange[1] === null) {
|
|
266
133
|
setDateFilterState(prev => ({
|
|
267
134
|
...prev,
|
|
@@ -272,26 +139,21 @@ const DateRangeSelector = ({ label, locale, onChange }: DateRangeSelectorProps):
|
|
|
272
139
|
}
|
|
273
140
|
};
|
|
274
141
|
|
|
275
|
-
/**
|
|
276
|
-
* Handles date range changes from the floating date picker
|
|
277
|
-
* @param value - The selected date range [startDate, endDate]
|
|
278
|
-
*/
|
|
279
142
|
const handleDatePickerChange = (value: DatesRangeValue): void => {
|
|
280
|
-
// Update state and notify parent immediately for real-time filtering
|
|
281
|
-
setDateFilterState(prev => ({ ...prev, customDateRange: value }));
|
|
282
|
-
onChange(value);
|
|
283
|
-
|
|
284
|
-
// Auto-close the picker when both dates are selected (complete range)
|
|
285
143
|
if (value[0] !== null && value[1] !== null) {
|
|
286
144
|
setIsDatePickerOpened(false);
|
|
287
145
|
}
|
|
146
|
+
setDateFilterState(prev => ({
|
|
147
|
+
...prev,
|
|
148
|
+
customDateRange: [toDateString(value[0]), toDateString(value[1])],
|
|
149
|
+
}));
|
|
150
|
+
onChange(value);
|
|
288
151
|
};
|
|
289
152
|
|
|
290
153
|
return (
|
|
291
154
|
<Popover opened={isDatePickerOpened} position="bottom-start">
|
|
292
155
|
<Popover.Target>
|
|
293
|
-
{
|
|
294
|
-
<div role="menuitem">
|
|
156
|
+
<div ref={presetSelectRef} role="menuitem">
|
|
295
157
|
<Combobox
|
|
296
158
|
size="xs"
|
|
297
159
|
store={combobox}
|
|
@@ -300,13 +162,13 @@ const DateRangeSelector = ({ label, locale, onChange }: DateRangeSelectorProps):
|
|
|
300
162
|
>
|
|
301
163
|
<Combobox.Target>
|
|
302
164
|
<InputBase
|
|
165
|
+
className={styles.field}
|
|
303
166
|
component="button"
|
|
304
167
|
type="button"
|
|
305
168
|
size="xs"
|
|
306
169
|
pointer
|
|
307
170
|
rightSection={
|
|
308
171
|
preset ? (
|
|
309
|
-
/* Clear button - shown when something is selected */
|
|
310
172
|
<CloseButton
|
|
311
173
|
size="xs"
|
|
312
174
|
variant="transparent"
|
|
@@ -315,32 +177,23 @@ const DateRangeSelector = ({ label, locale, onChange }: DateRangeSelectorProps):
|
|
|
315
177
|
aria-label="Clear date range"
|
|
316
178
|
/>
|
|
317
179
|
) : (
|
|
318
|
-
/* Dropdown chevron - shown when nothing is selected */
|
|
319
180
|
<Combobox.Chevron size="xs" />
|
|
320
181
|
)
|
|
321
182
|
}
|
|
322
183
|
onClick={handleInputBaseClick}
|
|
323
184
|
rightSectionPointerEvents={preset === null ? "none" : "all"}
|
|
324
185
|
label={label}
|
|
325
|
-
styles={{
|
|
326
|
-
label: {
|
|
327
|
-
fontWeight: 600,
|
|
328
|
-
},
|
|
329
|
-
}}
|
|
330
186
|
>
|
|
331
187
|
{getValueDisplayed}
|
|
332
188
|
</InputBase>
|
|
333
189
|
</Combobox.Target>
|
|
334
190
|
|
|
335
|
-
{/* Dropdown with preset options */}
|
|
336
191
|
<Combobox.Dropdown>
|
|
337
192
|
<Combobox.Options>{options}</Combobox.Options>
|
|
338
193
|
</Combobox.Dropdown>
|
|
339
194
|
</Combobox>
|
|
340
195
|
</div>
|
|
341
196
|
</Popover.Target>
|
|
342
|
-
|
|
343
|
-
{/* Floating date picker for custom date selection */}
|
|
344
197
|
<Popover.Dropdown>
|
|
345
198
|
<DatePicker
|
|
346
199
|
id="date-picker"
|
|
@@ -348,7 +201,8 @@ const DateRangeSelector = ({ label, locale, onChange }: DateRangeSelectorProps):
|
|
|
348
201
|
type="range"
|
|
349
202
|
value={customDateRange}
|
|
350
203
|
onChange={handleDatePickerChange}
|
|
351
|
-
defaultDate={
|
|
204
|
+
defaultDate={customDateRange[0] || customDateRange[1] || toDateString(new Date()) || undefined}
|
|
205
|
+
allowSingleDateInRange
|
|
352
206
|
/>
|
|
353
207
|
</Popover.Dropdown>
|
|
354
208
|
</Popover>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomTopToolbar/DateRangeSelectorFilter/utils.ts. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
2
|
+
import { translate } from "../../translations/index.js"; // DS-ADAPT: translate lives in DataTable/translations
|
|
3
|
+
export var Preset;
|
|
4
|
+
(function (Preset) {
|
|
5
|
+
Preset["WEEK"] = "week";
|
|
6
|
+
Preset["MONTH"] = "month";
|
|
7
|
+
Preset["QUARTER"] = "quarter";
|
|
8
|
+
Preset["CUSTOM"] = "custom";
|
|
9
|
+
})(Preset || (Preset = {}));
|
|
10
|
+
export const getPresets = () => [
|
|
11
|
+
{
|
|
12
|
+
label: translate("table.filters.date.range.week"),
|
|
13
|
+
value: Preset.WEEK,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
label: translate("table.filters.date.range.month"),
|
|
17
|
+
value: Preset.MONTH,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
label: translate("table.filters.date.range.quarter"),
|
|
21
|
+
value: Preset.QUARTER,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
label: translate("table.filters.date.range.custom"),
|
|
25
|
+
value: Preset.CUSTOM,
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
export const getPresetLabel = (value) => {
|
|
29
|
+
return getPresets().find(item => item.value === value)?.label || "";
|
|
30
|
+
};
|
|
31
|
+
export const getDateRangeFromPreset = (preset) => {
|
|
32
|
+
const now = new Date();
|
|
33
|
+
const start = new Date();
|
|
34
|
+
switch (preset) {
|
|
35
|
+
case Preset.WEEK:
|
|
36
|
+
start.setDate(now.getDate() - 7);
|
|
37
|
+
break;
|
|
38
|
+
case Preset.MONTH:
|
|
39
|
+
start.setMonth(now.getMonth() - 1);
|
|
40
|
+
break;
|
|
41
|
+
case Preset.QUARTER:
|
|
42
|
+
start.setMonth(now.getMonth() - 3);
|
|
43
|
+
break;
|
|
44
|
+
default:
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return [start, now];
|
|
48
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomTopToolbar/DateRangeSelectorFilter/utils.ts. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
2
|
+
import { translate } from "../../translations"; // DS-ADAPT: translate lives in DataTable/translations
|
|
3
|
+
|
|
4
|
+
export enum Preset {
|
|
5
|
+
WEEK = "week",
|
|
6
|
+
MONTH = "month",
|
|
7
|
+
QUARTER = "quarter",
|
|
8
|
+
CUSTOM = "custom",
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const getPresets = (): { label: string; value: Preset }[] => [
|
|
12
|
+
{
|
|
13
|
+
label: translate("table.filters.date.range.week"),
|
|
14
|
+
value: Preset.WEEK,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
label: translate("table.filters.date.range.month"),
|
|
18
|
+
value: Preset.MONTH,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
label: translate("table.filters.date.range.quarter"),
|
|
22
|
+
value: Preset.QUARTER,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
label: translate("table.filters.date.range.custom"),
|
|
26
|
+
value: Preset.CUSTOM,
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
export const getPresetLabel = (value: string): string => {
|
|
31
|
+
return getPresets().find(item => item.value === value)?.label || "";
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const getDateRangeFromPreset = (preset: string): [Date | null, Date | null] | null => {
|
|
35
|
+
const now = new Date();
|
|
36
|
+
const start = new Date();
|
|
37
|
+
switch (preset) {
|
|
38
|
+
case Preset.WEEK:
|
|
39
|
+
start.setDate(now.getDate() - 7);
|
|
40
|
+
break;
|
|
41
|
+
case Preset.MONTH:
|
|
42
|
+
start.setMonth(now.getMonth() - 1);
|
|
43
|
+
break;
|
|
44
|
+
case Preset.QUARTER:
|
|
45
|
+
start.setMonth(now.getMonth() - 3);
|
|
46
|
+
break;
|
|
47
|
+
default:
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return [start, now];
|
|
51
|
+
};
|
|
@@ -1,30 +1,10 @@
|
|
|
1
|
+
'use client'; // DS-ADAPT: Next.js App Router
|
|
1
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomTopToolbar/FilterChip.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
2
4
|
import React from "react";
|
|
3
|
-
import { Chip } from "@mantine/core";
|
|
4
|
-
import { RiCloseLine } from
|
|
5
|
-
/**
|
|
6
|
-
* FilterChip component for displaying active filters with remove functionality
|
|
7
|
-
* Shows as an outlined chip with a close icon for easy removal
|
|
8
|
-
*/
|
|
5
|
+
import { Chip, rem } from "@mantine/core";
|
|
6
|
+
import { RiCloseLine as CloseIcon } from "@remixicon/react"; // DS-ADAPT: @remixicon/react instead of remixicon svg import
|
|
9
7
|
const FilterChip = ({ label, onClick }) => {
|
|
10
|
-
return (_jsx(Chip, { color: "gray", size: "xs", variant: "outline", checked: true, onChange: onClick,
|
|
11
|
-
root: {
|
|
12
|
-
cursor: 'pointer',
|
|
13
|
-
'&[dataChecked="true"]': {
|
|
14
|
-
backgroundColor: 'transparent',
|
|
15
|
-
border: '1px solid var(--ad-color-border-default)',
|
|
16
|
-
color: 'var(--ad-color-text-dimmed)',
|
|
17
|
-
},
|
|
18
|
-
'&:hover': {
|
|
19
|
-
backgroundColor: 'var(--ad-color-bg-subtle)',
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
label: {
|
|
23
|
-
cursor: 'pointer',
|
|
24
|
-
},
|
|
25
|
-
iconWrapper: {
|
|
26
|
-
color: 'var(--ad-color-text-dimmed)',
|
|
27
|
-
},
|
|
28
|
-
}, children: label }));
|
|
8
|
+
return (_jsx(Chip, { color: "gray.3", size: "xs", icon: _jsx(CloseIcon, { style: { width: rem(10), height: rem(10) } }), variant: "outline", checked: true, onChange: onClick, children: label }));
|
|
29
9
|
};
|
|
30
10
|
export default FilterChip;
|
|
@@ -1,44 +1,23 @@
|
|
|
1
|
+
'use client'; // DS-ADAPT: Next.js App Router
|
|
2
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomTopToolbar/FilterChip.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
1
3
|
import React from "react";
|
|
2
|
-
import { Chip } from "@mantine/core";
|
|
3
|
-
import { RiCloseLine } from
|
|
4
|
+
import { Chip, rem } from "@mantine/core";
|
|
5
|
+
import { RiCloseLine as CloseIcon } from "@remixicon/react"; // DS-ADAPT: @remixicon/react instead of remixicon svg import
|
|
4
6
|
|
|
5
7
|
interface FilterChipProps {
|
|
6
8
|
label: string;
|
|
7
9
|
onClick: () => void;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
|
-
/**
|
|
11
|
-
* FilterChip component for displaying active filters with remove functionality
|
|
12
|
-
* Shows as an outlined chip with a close icon for easy removal
|
|
13
|
-
*/
|
|
14
12
|
const FilterChip = ({ label, onClick }: FilterChipProps): JSX.Element => {
|
|
15
13
|
return (
|
|
16
14
|
<Chip
|
|
17
|
-
color="gray"
|
|
15
|
+
color="gray.3"
|
|
18
16
|
size="xs"
|
|
17
|
+
icon={<CloseIcon style={{ width: rem(10), height: rem(10) }} />}
|
|
19
18
|
variant="outline"
|
|
20
|
-
checked
|
|
19
|
+
checked
|
|
21
20
|
onChange={onClick}
|
|
22
|
-
icon={<RiCloseLine size={12} />}
|
|
23
|
-
styles={{
|
|
24
|
-
root: {
|
|
25
|
-
cursor: 'pointer',
|
|
26
|
-
'&[dataChecked="true"]': {
|
|
27
|
-
backgroundColor: 'transparent',
|
|
28
|
-
border: '1px solid var(--ad-color-border-default)',
|
|
29
|
-
color: 'var(--ad-color-text-dimmed)',
|
|
30
|
-
},
|
|
31
|
-
'&:hover': {
|
|
32
|
-
backgroundColor: 'var(--ad-color-bg-subtle)',
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
label: {
|
|
36
|
-
cursor: 'pointer',
|
|
37
|
-
},
|
|
38
|
-
iconWrapper: {
|
|
39
|
-
color: 'var(--ad-color-text-dimmed)',
|
|
40
|
-
},
|
|
41
|
-
}}
|
|
42
21
|
>
|
|
43
22
|
{label}
|
|
44
23
|
</Chip>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client'; // DS-ADAPT: Next.js App Router
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomTopToolbar/ResultCount.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { Loader, Text } from "@mantine/core";
|
|
6
|
+
import { translate } from "../translations/index.js"; // DS-ADAPT: translate lives in DataTable/translations
|
|
7
|
+
const ResultCount = ({ resultCount, isLoading = false }) => {
|
|
8
|
+
const getResultCountText = () => {
|
|
9
|
+
if (resultCount === 1) {
|
|
10
|
+
return translate("table.filters.result.count.one");
|
|
11
|
+
}
|
|
12
|
+
return translate("table.filters.result.count.many", { count: resultCount });
|
|
13
|
+
};
|
|
14
|
+
return isLoading ? (_jsx(Loader, { color: "gray", size: "xs" })) : (_jsx(Text, { size: "sm", children: getResultCountText() }));
|
|
15
|
+
};
|
|
16
|
+
export default ResultCount;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use client'; // DS-ADAPT: Next.js App Router
|
|
2
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomTopToolbar/ResultCount.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
3
|
+
import React, { ReactElement } from "react";
|
|
4
|
+
import { Loader, Text } from "@mantine/core";
|
|
5
|
+
import { translate } from "../translations"; // DS-ADAPT: translate lives in DataTable/translations
|
|
6
|
+
|
|
7
|
+
interface ResultCountProps {
|
|
8
|
+
resultCount: number;
|
|
9
|
+
isLoading?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const ResultCount = ({ resultCount, isLoading = false }: ResultCountProps): ReactElement => {
|
|
13
|
+
const getResultCountText = (): string => {
|
|
14
|
+
if (resultCount === 1) {
|
|
15
|
+
return translate("table.filters.result.count.one");
|
|
16
|
+
}
|
|
17
|
+
return translate("table.filters.result.count.many", { count: resultCount });
|
|
18
|
+
};
|
|
19
|
+
return isLoading ? (
|
|
20
|
+
<Loader color="gray" size="xs" />
|
|
21
|
+
) : (
|
|
22
|
+
<Text size="sm">{getResultCountText()}</Text>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default ResultCount;
|