@razorpay/blade 12.47.0 → 12.48.0
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/build/lib/native/components/Input/TextInput/TextInput.js +1 -1
- package/build/lib/native/components/Input/TextInput/TextInput.js.map +1 -1
- package/build/lib/native/components/Input/TextInput/useFormattedInput.js +1 -1
- package/build/lib/native/components/Input/TextInput/useFormattedInput.js.map +1 -1
- package/build/lib/web/development/components/BottomSheet/BottomSheet.web.js +2 -1
- package/build/lib/web/development/components/BottomSheet/BottomSheet.web.js.map +1 -1
- package/build/lib/web/development/components/DatePicker/BaseDatePicker.web.js +162 -113
- package/build/lib/web/development/components/DatePicker/BaseDatePicker.web.js.map +1 -1
- package/build/lib/web/development/components/DatePicker/CalendarFooter.web.js +1 -1
- package/build/lib/web/development/components/DatePicker/CalendarFooter.web.js.map +1 -1
- package/build/lib/web/development/components/DatePicker/DateInput.web.js +202 -147
- package/build/lib/web/development/components/DatePicker/DateInput.web.js.map +1 -1
- package/build/lib/web/development/components/DatePicker/QuickSelection/PresetContext.js +122 -0
- package/build/lib/web/development/components/DatePicker/QuickSelection/PresetContext.js.map +1 -0
- package/build/lib/web/development/components/DatePicker/QuickSelection/PresetDropdown.web.js +46 -0
- package/build/lib/web/development/components/DatePicker/QuickSelection/PresetDropdown.web.js.map +1 -0
- package/build/lib/web/development/components/DatePicker/QuickSelection/PresetSideBar.web.js +19 -19
- package/build/lib/web/development/components/DatePicker/QuickSelection/PresetSideBar.web.js.map +1 -1
- package/build/lib/web/development/components/DatePicker/QuickSelection/utils.js +9 -0
- package/build/lib/web/development/components/DatePicker/QuickSelection/utils.js.map +1 -0
- package/build/lib/web/development/components/DatePicker/usePopup.js +10 -2
- package/build/lib/web/development/components/DatePicker/usePopup.js.map +1 -1
- package/build/lib/web/development/components/DatePicker/utils.js +419 -1
- package/build/lib/web/development/components/DatePicker/utils.js.map +1 -1
- package/build/lib/web/development/components/Input/TextInput/TextInput.js +3 -1
- package/build/lib/web/development/components/Input/TextInput/TextInput.js.map +1 -1
- package/build/lib/web/development/components/Input/TextInput/useFormattedInput.js +21 -0
- package/build/lib/web/development/components/Input/TextInput/useFormattedInput.js.map +1 -1
- package/build/lib/web/production/components/BottomSheet/BottomSheet.web.js +2 -1
- package/build/lib/web/production/components/BottomSheet/BottomSheet.web.js.map +1 -1
- package/build/lib/web/production/components/DatePicker/BaseDatePicker.web.js +162 -113
- package/build/lib/web/production/components/DatePicker/BaseDatePicker.web.js.map +1 -1
- package/build/lib/web/production/components/DatePicker/CalendarFooter.web.js +1 -1
- package/build/lib/web/production/components/DatePicker/CalendarFooter.web.js.map +1 -1
- package/build/lib/web/production/components/DatePicker/DateInput.web.js +202 -147
- package/build/lib/web/production/components/DatePicker/DateInput.web.js.map +1 -1
- package/build/lib/web/production/components/DatePicker/QuickSelection/PresetContext.js +122 -0
- package/build/lib/web/production/components/DatePicker/QuickSelection/PresetContext.js.map +1 -0
- package/build/lib/web/production/components/DatePicker/QuickSelection/PresetDropdown.web.js +46 -0
- package/build/lib/web/production/components/DatePicker/QuickSelection/PresetDropdown.web.js.map +1 -0
- package/build/lib/web/production/components/DatePicker/QuickSelection/PresetSideBar.web.js +19 -19
- package/build/lib/web/production/components/DatePicker/QuickSelection/PresetSideBar.web.js.map +1 -1
- package/build/lib/web/production/components/DatePicker/QuickSelection/utils.js +9 -0
- package/build/lib/web/production/components/DatePicker/QuickSelection/utils.js.map +1 -0
- package/build/lib/web/production/components/DatePicker/usePopup.js +10 -2
- package/build/lib/web/production/components/DatePicker/usePopup.js.map +1 -1
- package/build/lib/web/production/components/DatePicker/utils.js +419 -1
- package/build/lib/web/production/components/DatePicker/utils.js.map +1 -1
- package/build/lib/web/production/components/Input/TextInput/TextInput.js +3 -1
- package/build/lib/web/production/components/Input/TextInput/TextInput.js.map +1 -1
- package/build/lib/web/production/components/Input/TextInput/useFormattedInput.js +21 -0
- package/build/lib/web/production/components/Input/TextInput/useFormattedInput.js.map +1 -1
- package/build/types/components/index.d.ts +10 -5
- package/build/types/components/index.native.d.ts +10 -5
- package/package.json +1 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { createContext, useMemo, useContext } from 'react';
|
|
2
|
+
import { isSamePreset } from './utils.js';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
var PresetContext = /*#__PURE__*/createContext(null);
|
|
6
|
+
var PresetProvider = function PresetProvider(_ref) {
|
|
7
|
+
var children = _ref.children,
|
|
8
|
+
presets = _ref.presets,
|
|
9
|
+
selectedPreset = _ref.selectedPreset,
|
|
10
|
+
currentDate = _ref.currentDate;
|
|
11
|
+
var contextValue = useMemo(function () {
|
|
12
|
+
// No presets provided → return empty state
|
|
13
|
+
if (!presets) {
|
|
14
|
+
return {
|
|
15
|
+
presetStates: [],
|
|
16
|
+
selectedPresetIndex: null,
|
|
17
|
+
selectedPresetLabel: null,
|
|
18
|
+
isCustomSelected: false,
|
|
19
|
+
effectiveSelectionType: null // Default when no presets
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// STEP 1: Calculate each preset's value and type
|
|
24
|
+
// Example: "Last 7 days" → [2024-01-01, 2024-01-08], isCustomType: false
|
|
25
|
+
// Example: "Custom" → [null, null], isCustomType: true
|
|
26
|
+
var presetStates = presets.map(function (preset) {
|
|
27
|
+
var _presetValue, _presetValue2;
|
|
28
|
+
var presetValue = null;
|
|
29
|
+
var isCustomType = false;
|
|
30
|
+
presetValue = preset.value(currentDate); // Call function: "Last 7 days" → [startDate, endDate]
|
|
31
|
+
// Check if preset returns valid dates (defined) or null (custom)
|
|
32
|
+
isCustomType = !(((_presetValue = presetValue) === null || _presetValue === void 0 ? void 0 : _presetValue[0]) instanceof Date && ((_presetValue2 = presetValue) === null || _presetValue2 === void 0 ? void 0 : _presetValue2[1]) instanceof Date);
|
|
33
|
+
return {
|
|
34
|
+
preset: preset,
|
|
35
|
+
// Original preset object { label: "Last 7 days", value: fn }
|
|
36
|
+
value: presetValue,
|
|
37
|
+
// Calculated dates [2024-01-01, 2024-01-08] or [null, null]
|
|
38
|
+
isSelected: false,
|
|
39
|
+
// ⏳ Will calculate this next
|
|
40
|
+
isCustomType: isCustomType // true = Custom preset, false = Defined preset
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// STEP 2: Figure out which preset is currently selected
|
|
45
|
+
// Example: User selected [2024-01-01, 2024-01-08] → matches "Last 7 days" preset
|
|
46
|
+
var selectedPresetIndex = null;
|
|
47
|
+
var isCustomSelected = false;
|
|
48
|
+
if (!selectedPreset) {
|
|
49
|
+
// No dates selected → find and select "Custom" preset by default
|
|
50
|
+
selectedPresetIndex = presetStates.findIndex(function (state) {
|
|
51
|
+
return state.isCustomType;
|
|
52
|
+
});
|
|
53
|
+
isCustomSelected = selectedPresetIndex !== -1;
|
|
54
|
+
} else {
|
|
55
|
+
// User has selected dates → see if they match any defined preset
|
|
56
|
+
// Example: selectedPreset = [2024-01-01, 2024-01-08], check if matches "Last 7 days"
|
|
57
|
+
selectedPresetIndex = presetStates.findIndex(function (state) {
|
|
58
|
+
return !state.isCustomType && isSamePreset(selectedPreset, state.value);
|
|
59
|
+
});
|
|
60
|
+
if (selectedPresetIndex === -1) {
|
|
61
|
+
// No match found → user made custom selection → select "Custom" preset
|
|
62
|
+
selectedPresetIndex = presetStates.findIndex(function (state) {
|
|
63
|
+
return state.isCustomType;
|
|
64
|
+
});
|
|
65
|
+
isCustomSelected = true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// STEP 3: Mark the selected preset as selected
|
|
70
|
+
if (selectedPresetIndex !== -1) {
|
|
71
|
+
presetStates[selectedPresetIndex].isSelected = true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// STEP 4: Get the label for display
|
|
75
|
+
// Example: selectedPresetIndex = 0 → presetStates[0].preset.label = "Last 7 days"
|
|
76
|
+
var selectedPresetLabel = selectedPresetIndex !== -1 ? presetStates[selectedPresetIndex].preset.label : null;
|
|
77
|
+
|
|
78
|
+
// STEP 5: Calculate effective selection type based on selected preset
|
|
79
|
+
// If preset returns same-day range (like "Today"), display as single date
|
|
80
|
+
var effectiveSelectionType = 'range'; // Default to range
|
|
81
|
+
|
|
82
|
+
if (selectedPresetIndex !== -1) {
|
|
83
|
+
var _selectedPresetState$, _selectedPresetState$2;
|
|
84
|
+
var selectedPresetState = presetStates[selectedPresetIndex];
|
|
85
|
+
|
|
86
|
+
// Check if selected preset represents same day (like "Today" preset)
|
|
87
|
+
if ((_selectedPresetState$ = selectedPresetState.value) !== null && _selectedPresetState$ !== void 0 && _selectedPresetState$[0] && (_selectedPresetState$2 = selectedPresetState.value) !== null && _selectedPresetState$2 !== void 0 && _selectedPresetState$2[1] && selectedPresetState.value[0].toDateString() === selectedPresetState.value[1].toDateString()) {
|
|
88
|
+
effectiveSelectionType = 'single'; // Same day = display as single
|
|
89
|
+
} else {
|
|
90
|
+
effectiveSelectionType = 'range'; // Different days = display as range
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Return final calculated state - this gets shared with all components
|
|
95
|
+
return {
|
|
96
|
+
presetStates: presetStates,
|
|
97
|
+
// Array: [{ preset, value, isSelected, isCustomType }, ...]
|
|
98
|
+
selectedPresetIndex: selectedPresetIndex,
|
|
99
|
+
// Number: 0, 1, 2... or null
|
|
100
|
+
selectedPresetLabel: selectedPresetLabel,
|
|
101
|
+
// String: "Last 7 days" or "Custom" or null
|
|
102
|
+
isCustomSelected: isCustomSelected,
|
|
103
|
+
// Boolean: true if custom dates selected
|
|
104
|
+
effectiveSelectionType: effectiveSelectionType // 'single' | 'range' based on preset analysis
|
|
105
|
+
};
|
|
106
|
+
}, [presets, selectedPreset, currentDate]); // Recalculate when any of these change
|
|
107
|
+
|
|
108
|
+
return /*#__PURE__*/jsx(PresetContext.Provider, {
|
|
109
|
+
value: contextValue,
|
|
110
|
+
children: children
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
var usePresetContext = function usePresetContext() {
|
|
114
|
+
var context = useContext(PresetContext);
|
|
115
|
+
if (!context) {
|
|
116
|
+
throw new Error('usePresetContext must be used within PresetProvider');
|
|
117
|
+
}
|
|
118
|
+
return context;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export { PresetProvider, usePresetContext };
|
|
122
|
+
//# sourceMappingURL=PresetContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PresetContext.js","sources":["../../../../../../../src/components/DatePicker/QuickSelection/PresetContext.tsx"],"sourcesContent":["import React, { createContext, useContext, useMemo } from 'react';\nimport type { DatesRangeValue, CalendarProps } from '../types';\nimport { isSamePreset } from './utils';\n\ntype PresetState = {\n preset: NonNullable<CalendarProps<'range'>['presets']>[0];\n value: DatesRangeValue | null;\n isSelected: boolean;\n isCustomType: boolean;\n};\n\ntype PresetContextValue = {\n presetStates: PresetState[];\n selectedPresetIndex: number | null;\n selectedPresetLabel: string | null;\n isCustomSelected: boolean;\n effectiveSelectionType: 'single' | 'range' | null;\n};\n\nconst PresetContext = createContext<PresetContextValue | null>(null);\n\ntype PresetProviderProps = {\n children: React.ReactNode;\n presets: CalendarProps<'range'>['presets'];\n selectedPreset: DatesRangeValue | null;\n currentDate: Date;\n};\n\nexport const PresetProvider = ({\n children,\n presets,\n selectedPreset,\n currentDate,\n}: PresetProviderProps): React.ReactElement => {\n const contextValue = useMemo(() => {\n // No presets provided → return empty state\n if (!presets) {\n return {\n presetStates: [],\n selectedPresetIndex: null,\n selectedPresetLabel: null,\n isCustomSelected: false,\n effectiveSelectionType: null, // Default when no presets\n };\n }\n\n // STEP 1: Calculate each preset's value and type\n // Example: \"Last 7 days\" → [2024-01-01, 2024-01-08], isCustomType: false\n // Example: \"Custom\" → [null, null], isCustomType: true\n const presetStates: PresetState[] = presets.map((preset) => {\n let presetValue: DatesRangeValue | null = null;\n let isCustomType = false;\n\n presetValue = preset.value(currentDate); // Call function: \"Last 7 days\" → [startDate, endDate]\n // Check if preset returns valid dates (defined) or null (custom)\n isCustomType = !(presetValue?.[0] instanceof Date && presetValue?.[1] instanceof Date);\n\n return {\n preset, // Original preset object { label: \"Last 7 days\", value: fn }\n value: presetValue, // Calculated dates [2024-01-01, 2024-01-08] or [null, null]\n isSelected: false, // ⏳ Will calculate this next\n isCustomType, // true = Custom preset, false = Defined preset\n };\n });\n\n // STEP 2: Figure out which preset is currently selected\n // Example: User selected [2024-01-01, 2024-01-08] → matches \"Last 7 days\" preset\n let selectedPresetIndex: number | null = null;\n let isCustomSelected = false;\n\n if (!selectedPreset) {\n // No dates selected → find and select \"Custom\" preset by default\n selectedPresetIndex = presetStates.findIndex((state) => state.isCustomType);\n isCustomSelected = selectedPresetIndex !== -1;\n } else {\n // User has selected dates → see if they match any defined preset\n // Example: selectedPreset = [2024-01-01, 2024-01-08], check if matches \"Last 7 days\"\n selectedPresetIndex = presetStates.findIndex(\n (state) => !state.isCustomType && isSamePreset(selectedPreset, state.value),\n );\n\n if (selectedPresetIndex === -1) {\n // No match found → user made custom selection → select \"Custom\" preset\n selectedPresetIndex = presetStates.findIndex((state) => state.isCustomType);\n isCustomSelected = true;\n }\n }\n\n // STEP 3: Mark the selected preset as selected\n if (selectedPresetIndex !== -1) {\n presetStates[selectedPresetIndex].isSelected = true;\n }\n\n // STEP 4: Get the label for display\n // Example: selectedPresetIndex = 0 → presetStates[0].preset.label = \"Last 7 days\"\n const selectedPresetLabel =\n selectedPresetIndex !== -1 ? presetStates[selectedPresetIndex].preset.label : null;\n\n // STEP 5: Calculate effective selection type based on selected preset\n // If preset returns same-day range (like \"Today\"), display as single date\n let effectiveSelectionType: 'single' | 'range' = 'range'; // Default to range\n\n if (selectedPresetIndex !== -1) {\n const selectedPresetState = presetStates[selectedPresetIndex];\n\n // Check if selected preset represents same day (like \"Today\" preset)\n if (\n selectedPresetState.value?.[0] &&\n selectedPresetState.value?.[1] &&\n selectedPresetState.value[0].toDateString() === selectedPresetState.value[1].toDateString()\n ) {\n effectiveSelectionType = 'single'; // Same day = display as single\n } else {\n effectiveSelectionType = 'range'; // Different days = display as range\n }\n }\n\n // Return final calculated state - this gets shared with all components\n return {\n presetStates, // Array: [{ preset, value, isSelected, isCustomType }, ...]\n selectedPresetIndex, // Number: 0, 1, 2... or null\n selectedPresetLabel, // String: \"Last 7 days\" or \"Custom\" or null\n isCustomSelected, // Boolean: true if custom dates selected\n effectiveSelectionType, // 'single' | 'range' based on preset analysis\n };\n }, [presets, selectedPreset, currentDate]); // Recalculate when any of these change\n\n return <PresetContext.Provider value={contextValue}>{children}</PresetContext.Provider>;\n};\n\nexport const usePresetContext = (): PresetContextValue => {\n const context = useContext(PresetContext);\n if (!context) {\n throw new Error('usePresetContext must be used within PresetProvider');\n }\n return context;\n};\n"],"names":["PresetContext","createContext","PresetProvider","_ref","children","presets","selectedPreset","currentDate","contextValue","useMemo","presetStates","selectedPresetIndex","selectedPresetLabel","isCustomSelected","effectiveSelectionType","map","preset","_presetValue","_presetValue2","presetValue","isCustomType","value","Date","isSelected","findIndex","state","isSamePreset","label","_selectedPresetState$","_selectedPresetState$2","selectedPresetState","toDateString","_jsx","Provider","usePresetContext","context","useContext","Error"],"mappings":";;;;AAmBA,IAAMA,aAAa,gBAAGC,aAAa,CAA4B,IAAI,CAAC,CAAA;IASvDC,cAAc,GAAG,SAAjBA,cAAcA,CAAAC,IAAA,EAKoB;AAAA,EAAA,IAJ7CC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;IACRC,OAAO,GAAAF,IAAA,CAAPE,OAAO;IACPC,cAAc,GAAAH,IAAA,CAAdG,cAAc;IACdC,WAAW,GAAAJ,IAAA,CAAXI,WAAW,CAAA;AAEX,EAAA,IAAMC,YAAY,GAAGC,OAAO,CAAC,YAAM;AACjC;IACA,IAAI,CAACJ,OAAO,EAAE;MACZ,OAAO;AACLK,QAAAA,YAAY,EAAE,EAAE;AAChBC,QAAAA,mBAAmB,EA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,sBAAA,KAAA,KAAA,CAAA,IAAzBA,sBAAA,CAA4B,CAAC,CAAC,IAC9BC,mBAAmB,CAACT,KAAK,CAAC,CAAC,CAAC,CAACU,YAAY,EAAE,KAAKD,mBAAmB,CAACT,KAAK,CAAC,CAAC,CAAC,CAACU,YAAY,EAAE,EAC3F;QACAjB,sBAAsB,GAAG,QAAQ,CAAC;AACpC,OAAC,MAAM;QACLA,sBAAsB,GAAG,OAAO,CAAC;AACnC,OAAA;AACF,KAAA;;AAEA;IACA,OAAO;AACLJ,MAAAA,YAAY,EAAZA,YAAY;AAAE;AACdC,MAAAA,mBAAmB,EAAnBA,mBAAmB;AAAE;AACrBC,MAAAA,mBAAmB,EAAnBA,mBAAmB;AAAE;AACrBC,MAAAA,gBAAgB,EAAhBA,gBAAgB;AAAE;MAClBC,sBAAsB,EAAtBA,sBAAsB;KACvB,CAAA;GACF,EAAE,CAACT,OAAO,EAAEC,cAAc,EAAEC,WAAW,CAAC,CAAC,CAAC;;AAE3C,EAAA,oBAAOyB,GAAA,CAAChC,aAAa,CAACiC,QAAQ,EAAA;AAACZ,IAAAA,KAAK,EAAEb,YAAa;AAAAJ,IAAAA,QAAA,EAAEA,QAAAA;AAAQ,GAAyB,CAAC,CAAA;AACzF,EAAC;IAEY8B,gBAAgB,GAAG,SAAnBA,gBAAgBA,GAA6B;AACxD,EAAA,IAAMC,OAAO,GAAGC,UAAU,CAACpC,aAAa,CAAC,CAAA;EACzC,IAAI,CAACmC,OAAO,EAAE;AACZ,IAAA,MAAM,IAAIE,KAAK,CAAC,qDAAqD,CAAC,CAAA;AACxE,GAAA;AACA,EAAA,OAAOF,OAAO,CAAA;AAChB;;;;"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import 'react';
|
|
2
|
+
import { usePresetContext } from './PresetContext.js';
|
|
3
|
+
import '../../ActionList/index.js';
|
|
4
|
+
import '../../Dropdown/index.js';
|
|
5
|
+
import { InputDropdownButton } from '../../Dropdown/InputDropdownButton.web.js';
|
|
6
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
7
|
+
import { Dropdown } from '../../Dropdown/Dropdown.js';
|
|
8
|
+
import { DropdownOverlay } from '../../Dropdown/DropdownOverlay.web.js';
|
|
9
|
+
import { ActionList } from '../../ActionList/ActionList.js';
|
|
10
|
+
import { ActionListItem } from '../../ActionList/ActionListItem.js';
|
|
11
|
+
|
|
12
|
+
var PresetDropdown = function PresetDropdown(_ref) {
|
|
13
|
+
var onSelection = _ref.onSelection,
|
|
14
|
+
onOpenCalendar = _ref.onOpenCalendar;
|
|
15
|
+
var _usePresetContext = usePresetContext(),
|
|
16
|
+
presetStates = _usePresetContext.presetStates,
|
|
17
|
+
selectedPresetLabel = _usePresetContext.selectedPresetLabel;
|
|
18
|
+
return /*#__PURE__*/jsxs(Dropdown, {
|
|
19
|
+
children: [/*#__PURE__*/jsx(InputDropdownButton, {
|
|
20
|
+
value: selectedPresetLabel !== null && selectedPresetLabel !== void 0 ? selectedPresetLabel : 'Custom'
|
|
21
|
+
}), /*#__PURE__*/jsx(DropdownOverlay, {
|
|
22
|
+
children: /*#__PURE__*/jsx(ActionList, {
|
|
23
|
+
children: presetStates.map(function (_ref2) {
|
|
24
|
+
var preset = _ref2.preset,
|
|
25
|
+
isSelected = _ref2.isSelected,
|
|
26
|
+
isCustomType = _ref2.isCustomType;
|
|
27
|
+
return /*#__PURE__*/jsx(ActionListItem, {
|
|
28
|
+
title: preset.label,
|
|
29
|
+
value: preset.label,
|
|
30
|
+
isSelected: isSelected,
|
|
31
|
+
onClick: function onClick() {
|
|
32
|
+
onSelection(preset.value);
|
|
33
|
+
// If this is a custom preset selection, also trigger calendar opening
|
|
34
|
+
if (isCustomType && onOpenCalendar) {
|
|
35
|
+
onOpenCalendar();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}, preset.label);
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
})]
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { PresetDropdown };
|
|
46
|
+
//# sourceMappingURL=PresetDropdown.web.js.map
|
package/build/lib/web/development/components/DatePicker/QuickSelection/PresetDropdown.web.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PresetDropdown.web.js","sources":["../../../../../../../src/components/DatePicker/QuickSelection/PresetDropdown.web.tsx"],"sourcesContent":["import React from 'react';\nimport type { DatesRangeValue } from '../types';\nimport { usePresetContext } from './PresetContext';\nimport { ActionList, ActionListItem } from '~components/ActionList';\nimport { Dropdown, DropdownOverlay } from '~components/Dropdown';\nimport { InputDropdownButton } from '~components/Dropdown/InputDropdownButton';\n\ntype PresetDropdownProps = {\n onSelection: (preset: (date: Date) => DatesRangeValue) => void;\n onOpenCalendar?: () => void;\n};\n\nconst PresetDropdown = ({\n onSelection,\n onOpenCalendar,\n}: PresetDropdownProps): React.ReactElement => {\n const { presetStates, selectedPresetLabel } = usePresetContext();\n\n return (\n <Dropdown>\n <InputDropdownButton value={selectedPresetLabel ?? 'Custom'} />\n <DropdownOverlay>\n <ActionList>\n {presetStates.map(({ preset, isSelected, isCustomType }) => (\n <ActionListItem\n key={preset.label}\n title={preset.label}\n value={preset.label}\n isSelected={isSelected}\n onClick={() => {\n onSelection(preset.value);\n // If this is a custom preset selection, also trigger calendar opening\n if (isCustomType && onOpenCalendar) {\n onOpenCalendar();\n }\n }}\n />\n ))}\n </ActionList>\n </DropdownOverlay>\n </Dropdown>\n );\n};\n\nexport { PresetDropdown };\n"],"names":["PresetDropdown","_ref","onSelection","onOpenCalendar","_usePresetContext","usePresetContext","presetStates","selectedPresetLabel","_jsxs","Dropdown","children","_jsx","InputDropdownButton","value","DropdownOverlay","ActionList","map","_ref2","preset","isSelected","isCustomType","ActionListItem","title","label","onClick"],"mappings":";;;;;;;;;;;AAYA,IAAMA,cAAc,GAAG,SAAjBA,cAAcA,CAAAC,IAAA,EAG2B;AAAA,EAAA,IAF7CC,WAAW,GAAAD,IAAA,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babel/runtime/helpers/defineProperty';
|
|
2
|
+
import { usePresetContext } from './PresetContext.js';
|
|
2
3
|
import { QuickSelectionItem } from './QuickSelectionItem.web.js';
|
|
3
4
|
import '../../Box/index.js';
|
|
4
|
-
import '
|
|
5
|
+
import '../../Box/BaseBox/index.js';
|
|
5
6
|
import '../../Chip/index.js';
|
|
6
7
|
import '../../Divider/index.js';
|
|
7
|
-
import '../../Box/BaseBox/index.js';
|
|
8
|
-
import '../../../utils/makeAccessible/index.js';
|
|
9
8
|
import '../../../tokens/global/index.js';
|
|
9
|
+
import '../../../utils/index.js';
|
|
10
|
+
import '../../../utils/makeAccessible/index.js';
|
|
10
11
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
11
12
|
import { Box } from '../../Box/Box.js';
|
|
12
13
|
import { Divider } from '../../Divider/Divider.js';
|
|
@@ -19,18 +20,12 @@ import { makeAccessible } from '../../../utils/makeAccessible/makeAccessible.web
|
|
|
19
20
|
|
|
20
21
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
21
22
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
22
|
-
var isSamePreset = function isSamePreset(value1, value2) {
|
|
23
|
-
if (!(value1 !== null && value1 !== void 0 && value1[0]) || !(value1 !== null && value1 !== void 0 && value1[1])) return false;
|
|
24
|
-
if (!(value2 !== null && value2 !== void 0 && value2[0]) || !(value2 !== null && value2 !== void 0 && value2[1])) return false;
|
|
25
|
-
return value1[0].toDateString() === value2[0].toDateString() && value1[1].toDateString() === value2[1].toDateString();
|
|
26
|
-
};
|
|
27
23
|
var PresetSideBar = function PresetSideBar(_ref) {
|
|
28
|
-
var
|
|
29
|
-
presets = _ref.presets,
|
|
30
|
-
selectedPreset = _ref.selectedPreset,
|
|
31
|
-
onSelection = _ref.onSelection,
|
|
24
|
+
var onSelection = _ref.onSelection,
|
|
32
25
|
isMobile = _ref.isMobile;
|
|
33
|
-
|
|
26
|
+
var _usePresetContext = usePresetContext(),
|
|
27
|
+
presetStates = _usePresetContext.presetStates;
|
|
28
|
+
if (presetStates.length === 0) return /*#__PURE__*/jsx(Fragment, {});
|
|
34
29
|
if (isMobile) {
|
|
35
30
|
return /*#__PURE__*/jsxs(Box, {
|
|
36
31
|
children: [/*#__PURE__*/jsx(Divider, {
|
|
@@ -42,11 +37,15 @@ var PresetSideBar = function PresetSideBar(_ref) {
|
|
|
42
37
|
accessibilityLabel: "Select Presets",
|
|
43
38
|
onChange: function onChange(_ref2) {
|
|
44
39
|
var values = _ref2.values;
|
|
45
|
-
|
|
46
|
-
return preset.label === values[0];
|
|
47
|
-
})
|
|
40
|
+
var selectedPreset = presetStates.find(function (state) {
|
|
41
|
+
return state.preset.label === values[0];
|
|
42
|
+
});
|
|
43
|
+
if (selectedPreset) {
|
|
44
|
+
onSelection(selectedPreset.preset.value);
|
|
45
|
+
}
|
|
48
46
|
},
|
|
49
|
-
children:
|
|
47
|
+
children: presetStates.map(function (_ref3, index) {
|
|
48
|
+
var preset = _ref3.preset;
|
|
50
49
|
return /*#__PURE__*/jsx(Chip, {
|
|
51
50
|
value: preset.label,
|
|
52
51
|
"data-analytics-name": preset.label,
|
|
@@ -70,8 +69,9 @@ var PresetSideBar = function PresetSideBar(_ref) {
|
|
|
70
69
|
role: 'listbox',
|
|
71
70
|
label: 'Select Presets'
|
|
72
71
|
})), {}, {
|
|
73
|
-
children:
|
|
74
|
-
var
|
|
72
|
+
children: presetStates.map(function (_ref4, index) {
|
|
73
|
+
var preset = _ref4.preset,
|
|
74
|
+
isSelected = _ref4.isSelected;
|
|
75
75
|
return /*#__PURE__*/jsx(QuickSelectionItem, {
|
|
76
76
|
isSelected: isSelected,
|
|
77
77
|
onClick: function onClick() {
|
package/build/lib/web/development/components/DatePicker/QuickSelection/PresetSideBar.web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PresetSideBar.web.js","sources":["../../../../../../../src/components/DatePicker/QuickSelection/PresetSideBar.web.tsx"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"PresetSideBar.web.js","sources":["../../../../../../../src/components/DatePicker/QuickSelection/PresetSideBar.web.tsx"],"sourcesContent":["import type { DatesRangeValue } from '../types';\nimport { usePresetContext } from './PresetContext';\nimport { QuickSelectionItem } from './QuickSelectionItem.web';\nimport { Box } from '~components/Box';\nimport BaseBox from '~components/Box/BaseBox';\nimport { Chip, ChipGroup } from '~components/Chip';\nimport { Divider } from '~components/Divider';\nimport { size } from '~tokens/global';\nimport { makeSpace } from '~utils';\nimport { makeAccessible } from '~utils/makeAccessible';\n\ntype PresetSideBarProps = {\n isMobile?: boolean;\n onSelection: (value: (date: Date) => DatesRangeValue) => void;\n};\n\nconst PresetSideBar = ({ onSelection, isMobile }: PresetSideBarProps): React.ReactElement => {\n const { presetStates } = usePresetContext();\n\n if (presetStates.length === 0) return <></>;\n\n if (isMobile) {\n return (\n <Box>\n <Divider marginTop=\"spacing.4\" />\n <ChipGroup\n marginTop=\"spacing.7\"\n size=\"small\"\n selectionType=\"single\"\n accessibilityLabel=\"Select Presets\"\n onChange={({ values }) => {\n const selectedPreset = presetStates.find((state) => state.preset.label === values[0]);\n if (selectedPreset) {\n onSelection(selectedPreset.preset.value);\n }\n }}\n >\n {presetStates.map(({ preset }, index) => {\n return (\n <Chip value={preset.label} key={index} data-analytics-name={preset.label}>\n {preset.label}\n </Chip>\n );\n })}\n </ChipGroup>\n </Box>\n );\n }\n\n return (\n <BaseBox\n padding=\"spacing.5\"\n display=\"flex\"\n flexDirection=\"column\"\n gap=\"spacing.2\"\n backgroundColor=\"surface.background.gray.moderate\"\n minWidth={makeSpace(size[160])}\n borderRightColor=\"surface.border.gray.muted\"\n borderRightStyle=\"solid\"\n borderRightWidth=\"thin\"\n {...makeAccessible({ role: 'listbox', label: 'Select Presets' })}\n >\n {presetStates.map(({ preset, isSelected }, index) => {\n return (\n <QuickSelectionItem\n key={index}\n isSelected={isSelected}\n onClick={() => onSelection(preset.value)}\n >\n {preset.label}\n </QuickSelectionItem>\n );\n })}\n </BaseBox>\n );\n};\n\nexport { PresetSideBar };\n"],"names":["PresetSideBar","_ref","onSelection","isMobile","_usePresetContext","usePresetContext","presetStates","length","_jsx","_Fragment","_jsxs","Box","children","Divider","marginTop","ChipGroup","size","selectionType","accessibilityLabel","onChange","_ref2","values","selectedPreset","find","state","preset","label","value","map","_ref3","index","Chip","BaseBox","_objectSpread","padding","display","flexDirection","gap","backgroundColor","minWidth","makeSpace","borderRightColor","borderRightStyle","borderRightWidth","makeAccessible","role","_ref4","isSelected","QuickSelectionItem","onClick"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgBA,IAAMA,aAAa,GAAG,SAAhBA,aAAaA,CAAAC,IAAA,EAA0E;AAAA,EAAA,IAApEC,WAAW,GAAAD,IAAA,CAAXC,WAAW;IAAEC,QAAQ,GAAAF,IAAA,CAARE,QAAQ,CAAA;AAC5C,EAAA,IAAAC,iBAAA,GAAyBC,gBAAgB,EAAE;IAAnCC,YAAY,GAAAF,iBAAA,CAAZE,YAAY,CAAA;EAEpB,IAAIA,YAAY,CAACC,MAAM,KAAK,CAAC,EAAE,oBAAOC,GAAA,CAAAC,QAAA,EAAA,EAAI,CAAC,CAAA;AAE3C,EAAA,IAAIN,QAAQ,EAAE;IACZ,oBACEO,IAAA,CAACC,GAAG,EAAA;MAAAC,QAAA,EAAA,cACFJ,GAAA,CAACK,OAAO,EAAA;AAACC,QAAAA,SA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AAe,EAAC,kCAAkC;AAClDC,IAAAA,QAAQ,EAAEC,SAAS,CAACxB,IAAI,CAAC,GAAG,CAAC,CAAE;AAC/ByB,IAAAA,gBAAgB,EAAC,2BAA2B;AAC5CC,IAAAA,gBAAgB,EAAC,OAAO;AACxBC,IAAAA,gBAAgB,EAAC,MAAA;AAAM,GAAA,EACnBC,cAAc,CAAC;AAAEC,IAAAA,IAAI,EAAE,SAAS;AAAEnB,IAAAA,KAAK,EAAE,gBAAA;AAAiB,GAAC,CAAC,CAAA,EAAA,EAAA,EAAA;IAAAd,QAAA,EAE/DN,YAAY,CAACsB,GAAG,CAAC,UAAAkB,KAAA,EAAyBhB,KAAK,EAAK;AAAA,MAAA,IAAhCL,MAAM,GAAAqB,KAAA,CAANrB,MAAM;QAAEsB,UAAU,GAAAD,KAAA,CAAVC,UAAU,CAAA;MACrC,oBACEvC,GAAA,CAACwC,kBAAkB,EAAA;AAEjBD,QAAAA,UAAU,EAAEA,UAAW;QACvBE,OAAO,EAAE,SAAAA,OAAA,GAAA;AAAA,UAAA,OAAM/C,WAAW,CAACuB,MAAM,CAACE,KAAK,CAAC,CAAA;SAAC;QAAAf,QAAA,EAExCa,MAAM,CAACC,KAAAA;AAAK,OAAA,EAJRI,KAKa,CAAC,CAAA;KAExB,CAAA;AAAC,GAAA,CACK,CAAC,CAAA;AAEd;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Helper function to check if two preset values are the same
|
|
2
|
+
var isSamePreset = function isSamePreset(value1, value2) {
|
|
3
|
+
if (!(value1 !== null && value1 !== void 0 && value1[0]) || !(value1 !== null && value1 !== void 0 && value1[1])) return false;
|
|
4
|
+
if (!(value2 !== null && value2 !== void 0 && value2[0]) || !(value2 !== null && value2 !== void 0 && value2[1])) return false;
|
|
5
|
+
return value1[0].toDateString() === value2[0].toDateString() && value1[1].toDateString() === value2[1].toDateString();
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export { isSamePreset };
|
|
9
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../../../../src/components/DatePicker/QuickSelection/utils.ts"],"sourcesContent":["import type { DatesRangeValue } from '~components/DatePicker/types';\n\n// Helper function to check if two preset values are the same\nexport const isSamePreset = (\n value1: DatesRangeValue | null,\n value2: DatesRangeValue | null,\n): boolean => {\n if (!value1?.[0] || !value1?.[1]) return false;\n if (!value2?.[0] || !value2?.[1]) return false;\n\n return (\n value1[0].toDateString() === value2[0].toDateString() &&\n value1[1].toDateString() === value2[1].toDateString()\n );\n};\n"],"names":["isSamePreset","value1","value2","toDateString"],"mappings":"AAEA;AACO,IAAMA,YAAY,GAAG,SAAfA,YAAYA,CACvBC,MAA8B,EAC9BC,MAA8B,EAClB;EACZ,IAAI,EAACD,MAAM,KAANA,IAAAA,IAAAA,MAAM,eAANA,MAAM,CAAG,CAAC,CAAC,CAAA,IAAI,EAACA,MAAM,KAAA,IAAA,IAANA,MAAM,KAANA,KAAAA,CAAAA,IAAAA,MAAM,CAAG,CAAC,CAAC,CAAE,EAAA,OAAO,KAAK,CAAA;EAC9C,IAAI,EAACC,MAAM,KAANA,IAAAA,IAAAA,MAAM,eAANA,MAAM,CAAG,CAAC,CAAC,CAAA,IAAI,EAACA,MAAM,KAAA,IAAA,IAANA,MAAM,KAANA,KAAAA,CAAAA,IAAAA,MAAM,CAAG,CAAC,CAAC,CAAE,EAAA,OAAO,KAAK,CAAA;AAE9C,EAAA,OACED,MAAM,CAAC,CAAC,CAAC,CAACE,YAAY,EAAE,KAAKD,MAAM,CAAC,CAAC,CAAC,CAACC,YAAY,EAAE,IACrDF,MAAM,CAAC,CAAC,CAAC,CAACE,YAAY,EAAE,KAAKD,MAAM,CAAC,CAAC,CAAC,CAACC,YAAY,EAAE,CAAA;AAEzD;;;;"}
|
|
@@ -13,7 +13,9 @@ var usePopup = function usePopup(_ref) {
|
|
|
13
13
|
placement = _ref.placement,
|
|
14
14
|
open = _ref.open,
|
|
15
15
|
_onOpenChange = _ref.onOpenChange,
|
|
16
|
-
referenceRef = _ref.referenceRef
|
|
16
|
+
referenceRef = _ref.referenceRef,
|
|
17
|
+
_ref$crossAxisOffset = _ref.crossAxisOffset,
|
|
18
|
+
crossAxisOffset = _ref$crossAxisOffset === void 0 ? 0 : _ref$crossAxisOffset;
|
|
17
19
|
var GAP = spacing[4];
|
|
18
20
|
var _useTheme = useTheme(),
|
|
19
21
|
theme = _useTheme.theme;
|
|
@@ -41,7 +43,13 @@ var usePopup = function usePopup(_ref) {
|
|
|
41
43
|
}), flip({
|
|
42
44
|
padding: GAP,
|
|
43
45
|
fallbackAxisSideDirection: 'end'
|
|
44
|
-
}),
|
|
46
|
+
}),
|
|
47
|
+
// Combined offset: default GAP + custom crossAxis adjustment
|
|
48
|
+
// crossAxisOffset allows fine-tuning calendar position (e.g., align with input text vs input border)
|
|
49
|
+
offset({
|
|
50
|
+
mainAxis: GAP,
|
|
51
|
+
crossAxis: crossAxisOffset
|
|
52
|
+
})],
|
|
45
53
|
whileElementsMounted: function whileElementsMounted(reference, floating, update) {
|
|
46
54
|
return autoUpdate(reference, floating, update, {
|
|
47
55
|
elementResize: false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePopup.js","sources":["../../../../../../src/components/DatePicker/usePopup.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport type { UseFloatingOptions } from '@floating-ui/react';\nimport {\n autoUpdate,\n flip,\n offset,\n shift,\n useClick,\n useDismiss,\n useFloating,\n useInteractions,\n useRole,\n useTransitionStyles,\n} from '@floating-ui/react';\nimport { size, spacing } from '~tokens/global';\nimport { useTheme } from '~utils';\nimport { getFloatingPlacementParts } from '~utils/getFloatingPlacementParts';\n\ntype UsePopupProps = {\n enabled?: boolean;\n open?: boolean;\n placement: UseFloatingOptions['placement'];\n onOpenChange?: UseFloatingOptions['onOpenChange'];\n referenceRef: React.RefObject<HTMLButtonElement>;\n};\n\nconst usePopup = ({\n enabled = true,\n placement,\n open,\n onOpenChange,\n referenceRef,\n}: UsePopupProps) => {\n const GAP = spacing[4];\n const { theme } = useTheme();\n const [side] = getFloatingPlacementParts(placement!);\n const isOppositeAxis = side === 'right' || side === 'bottom';\n\n const { refs, floatingStyles, context, placement: computedPlacement } = useFloating({\n open,\n onOpenChange: (isOpen, event, reason) => {\n onOpenChange?.(isOpen, event, reason);\n if (reason === 'escape-key') {\n referenceRef.current?.focus();\n }\n },\n placement,\n strategy: 'fixed',\n elements: {\n reference: referenceRef.current,\n },\n middleware: [\n shift({ crossAxis: false, padding: GAP }),\n flip({ padding: GAP, fallbackAxisSideDirection: 'end' }),\n offset(GAP),\n ],\n whileElementsMounted: (reference, floating, update) =>\n autoUpdate(reference, floating, update, {\n elementResize: false,\n }),\n });\n\n // we need to animate from the offset of the computed placement\n // because placement can change dynamically based on available space\n const [computedSide] = getFloatingPlacementParts(computedPlacement);\n const computedIsHorizontal = computedSide === 'left' || computedSide === 'right';\n const animationOffset = isOppositeAxis ? -size[4] : size[4];\n const { isMounted, styles: animationStyles } = useTransitionStyles(context, {\n duration: theme.motion.duration.quick,\n initial: {\n opacity: 0,\n transform: `translate${computedIsHorizontal ? 'X' : 'Y'}(${animationOffset}px)`,\n },\n });\n\n // remove click handler if popover is controlled\n const click = useClick(context);\n const dismiss = useDismiss(context, { enabled });\n const role = useRole(context);\n const { getReferenceProps, getFloatingProps } = useInteractions([click, dismiss, role]);\n\n return {\n refs,\n context,\n isMounted,\n floatingStyles,\n animationStyles,\n getReferenceProps,\n getFloatingProps,\n } as const;\n};\n\nexport { usePopup };\n"],"names":["usePopup","_ref","_ref$enabled","enabled","placement","open","onOpenChange","referenceRef","GAP","spacing","_useTheme","useTheme","theme","_getFloatingPlacement","getFloatingPlacementParts","_getFloatingPlacement2","_slicedToArray","side","isOppositeAxis","_useFloating","useFloating","isOpen","event","reason","_referenceRef$current","current","focus","strategy","elements","reference","middleware","shift","crossAxis","padding","flip","fallbackAxisSideDirection","offset","whileElementsMounted","floating","update","autoUpdate","elementResize","refs","floatingStyles","context","computedPlacement","_getFloatingPlacement3","_getFloatingPlacement4","computedSide","computedIsHorizontal","animationOffset","size","_useTransitionStyles","useTransitionStyles","duration","motion","quick","initial","opacity","transform","concat","isMounted","animationStyles","styles","click","useClick","dismiss","useDismiss","role","useRole","_useInteractions","useInteractions","getReferenceProps","getFloatingProps"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"usePopup.js","sources":["../../../../../../src/components/DatePicker/usePopup.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport type { UseFloatingOptions } from '@floating-ui/react';\nimport {\n autoUpdate,\n flip,\n offset,\n shift,\n useClick,\n useDismiss,\n useFloating,\n useInteractions,\n useRole,\n useTransitionStyles,\n} from '@floating-ui/react';\nimport { size, spacing } from '~tokens/global';\nimport { useTheme } from '~utils';\nimport { getFloatingPlacementParts } from '~utils/getFloatingPlacementParts';\n\ntype UsePopupProps = {\n enabled?: boolean;\n open?: boolean;\n placement: UseFloatingOptions['placement'];\n onOpenChange?: UseFloatingOptions['onOpenChange'];\n referenceRef: React.RefObject<HTMLButtonElement>;\n crossAxisOffset?: number;\n};\n\nconst usePopup = ({\n enabled = true,\n placement,\n open,\n onOpenChange,\n referenceRef,\n crossAxisOffset = 0,\n}: UsePopupProps) => {\n const GAP = spacing[4];\n const { theme } = useTheme();\n const [side] = getFloatingPlacementParts(placement!);\n const isOppositeAxis = side === 'right' || side === 'bottom';\n\n const { refs, floatingStyles, context, placement: computedPlacement } = useFloating({\n open,\n onOpenChange: (isOpen, event, reason) => {\n onOpenChange?.(isOpen, event, reason);\n if (reason === 'escape-key') {\n referenceRef.current?.focus();\n }\n },\n placement,\n strategy: 'fixed',\n elements: {\n reference: referenceRef.current,\n },\n middleware: [\n shift({ crossAxis: false, padding: GAP }),\n flip({ padding: GAP, fallbackAxisSideDirection: 'end' }),\n // Combined offset: default GAP + custom crossAxis adjustment\n // crossAxisOffset allows fine-tuning calendar position (e.g., align with input text vs input border)\n offset({ mainAxis: GAP, crossAxis: crossAxisOffset }),\n ],\n whileElementsMounted: (reference, floating, update) =>\n autoUpdate(reference, floating, update, {\n elementResize: false,\n }),\n });\n\n // we need to animate from the offset of the computed placement\n // because placement can change dynamically based on available space\n const [computedSide] = getFloatingPlacementParts(computedPlacement);\n const computedIsHorizontal = computedSide === 'left' || computedSide === 'right';\n const animationOffset = isOppositeAxis ? -size[4] : size[4];\n const { isMounted, styles: animationStyles } = useTransitionStyles(context, {\n duration: theme.motion.duration.quick,\n initial: {\n opacity: 0,\n transform: `translate${computedIsHorizontal ? 'X' : 'Y'}(${animationOffset}px)`,\n },\n });\n\n // remove click handler if popover is controlled\n const click = useClick(context);\n const dismiss = useDismiss(context, { enabled });\n const role = useRole(context);\n const { getReferenceProps, getFloatingProps } = useInteractions([click, dismiss, role]);\n\n return {\n refs,\n context,\n isMounted,\n floatingStyles,\n animationStyles,\n getReferenceProps,\n getFloatingProps,\n } as const;\n};\n\nexport { usePopup };\n"],"names":["usePopup","_ref","_ref$enabled","enabled","placement","open","onOpenChange","referenceRef","_ref$crossAxisOffset","crossAxisOffset","GAP","spacing","_useTheme","useTheme","theme","_getFloatingPlacement","getFloatingPlacementParts","_getFloatingPlacement2","_slicedToArray","side","isOppositeAxis","_useFloating","useFloating","isOpen","event","reason","_referenceRef$current","current","focus","strategy","elements","reference","middleware","shift","crossAxis","padding","flip","fallbackAxisSideDirection","offset","mainAxis","whileElementsMounted","floating","update","autoUpdate","elementResize","refs","floatingStyles","context","computedPlacement","_getFloatingPlacement3","_getFloatingPlacement4","computedSide","computedIsHorizontal","animationOffset","size","_useTransitionStyles","useTransitionStyles","duration","motion","quick","initial","opacity","transform","concat","isMounted","animationStyles","styles","click","useClick","dismiss","useDismiss","role","useRole","_useInteractions","useInteractions","getReferenceProps","getFloatingProps"],"mappings":";;;;;;;;;AA2BA,IAAMA,QAAQ,GAAG,SAA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