@semcore/date-picker 16.2.4 → 17.0.0-prerelease.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/CHANGELOG.md +6 -0
- package/lib/cjs/DatePicker.js +116 -139
- package/lib/cjs/DatePicker.js.map +1 -1
- package/lib/cjs/DateRangeComparator.js +144 -149
- package/lib/cjs/DateRangeComparator.js.map +1 -1
- package/lib/cjs/DateRangePicker.js +86 -101
- package/lib/cjs/DateRangePicker.js.map +1 -1
- package/lib/cjs/MonthDateRangeComparator.js +173 -180
- package/lib/cjs/MonthDateRangeComparator.js.map +1 -1
- package/lib/cjs/MonthPicker.js +70 -87
- package/lib/cjs/MonthPicker.js.map +1 -1
- package/lib/cjs/MonthRangePicker.js +96 -111
- package/lib/cjs/MonthRangePicker.js.map +1 -1
- package/lib/cjs/components/ButtonTrigger.js +12 -11
- package/lib/cjs/components/ButtonTrigger.js.map +1 -1
- package/lib/cjs/components/Calendar.js +409 -466
- package/lib/cjs/components/Calendar.js.map +1 -1
- package/lib/cjs/components/DateRangeComparatorAbstract.js +574 -626
- package/lib/cjs/components/DateRangeComparatorAbstract.js.map +1 -1
- package/lib/cjs/components/InputTrigger.js +585 -677
- package/lib/cjs/components/InputTrigger.js.map +1 -1
- package/lib/cjs/components/PickerAbstract.js +254 -273
- package/lib/cjs/components/PickerAbstract.js.map +1 -1
- package/lib/cjs/components/RangePickerAbstract.js +407 -439
- package/lib/cjs/components/RangePickerAbstract.js.map +1 -1
- package/lib/cjs/components/index.js +92 -102
- package/lib/cjs/components/index.js.map +1 -1
- package/lib/cjs/index.d.js.map +1 -1
- package/lib/cjs/index.js +15 -15
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/translations/__intergalactic-dynamic-locales.js +17 -17
- package/lib/cjs/translations/__intergalactic-dynamic-locales.js.map +1 -1
- package/lib/cjs/utils/cronTabScheduler.js +13 -22
- package/lib/cjs/utils/cronTabScheduler.js.map +1 -1
- package/lib/cjs/utils/datesIntersects.js +12 -19
- package/lib/cjs/utils/datesIntersects.js.map +1 -1
- package/lib/cjs/utils/formatDate.js +11 -9
- package/lib/cjs/utils/formatDate.js.map +1 -1
- package/lib/cjs/utils/includesDate.js +11 -16
- package/lib/cjs/utils/includesDate.js.map +1 -1
- package/lib/cjs/utils/isBetweenPlugin.js +6 -6
- package/lib/cjs/utils/isBetweenPlugin.js.map +1 -1
- package/lib/cjs/utils/shortDateRangeFormat.js +29 -33
- package/lib/cjs/utils/shortDateRangeFormat.js.map +1 -1
- package/lib/es6/DatePicker.js +117 -141
- package/lib/es6/DatePicker.js.map +1 -1
- package/lib/es6/DateRangeComparator.js +130 -135
- package/lib/es6/DateRangeComparator.js.map +1 -1
- package/lib/es6/DateRangePicker.js +87 -102
- package/lib/es6/DateRangePicker.js.map +1 -1
- package/lib/es6/MonthDateRangeComparator.js +159 -166
- package/lib/es6/MonthDateRangeComparator.js.map +1 -1
- package/lib/es6/MonthPicker.js +72 -89
- package/lib/es6/MonthPicker.js.map +1 -1
- package/lib/es6/MonthRangePicker.js +97 -112
- package/lib/es6/MonthRangePicker.js.map +1 -1
- package/lib/es6/components/ButtonTrigger.js +4 -3
- package/lib/es6/components/ButtonTrigger.js.map +1 -1
- package/lib/es6/components/Calendar.js +400 -457
- package/lib/es6/components/Calendar.js.map +1 -1
- package/lib/es6/components/DateRangeComparatorAbstract.js +552 -604
- package/lib/es6/components/DateRangeComparatorAbstract.js.map +1 -1
- package/lib/es6/components/InputTrigger.js +568 -660
- package/lib/es6/components/InputTrigger.js.map +1 -1
- package/lib/es6/components/PickerAbstract.js +246 -265
- package/lib/es6/components/PickerAbstract.js.map +1 -1
- package/lib/es6/components/RangePickerAbstract.js +397 -429
- package/lib/es6/components/RangePickerAbstract.js.map +1 -1
- package/lib/es6/components/index.js +74 -85
- package/lib/es6/components/index.js.map +1 -1
- package/lib/es6/index.d.js.map +1 -1
- package/lib/es6/translations/__intergalactic-dynamic-locales.js +16 -16
- package/lib/es6/translations/__intergalactic-dynamic-locales.js.map +1 -1
- package/lib/es6/utils/cronTabScheduler.js +13 -21
- package/lib/es6/utils/cronTabScheduler.js.map +1 -1
- package/lib/es6/utils/datesIntersects.js +10 -18
- package/lib/es6/utils/datesIntersects.js.map +1 -1
- package/lib/es6/utils/formatDate.js +6 -6
- package/lib/es6/utils/formatDate.js.map +1 -1
- package/lib/es6/utils/includesDate.js +10 -15
- package/lib/es6/utils/includesDate.js.map +1 -1
- package/lib/es6/utils/isBetweenPlugin.js +4 -4
- package/lib/es6/utils/isBetweenPlugin.js.map +1 -1
- package/lib/es6/utils/shortDateRangeFormat.js +27 -31
- package/lib/es6/utils/shortDateRangeFormat.js.map +1 -1
- package/lib/esm/DatePicker.mjs +109 -114
- package/lib/esm/DateRangeComparator.mjs +112 -105
- package/lib/esm/DateRangePicker.mjs +76 -80
- package/lib/esm/MonthDateRangeComparator.mjs +141 -134
- package/lib/esm/MonthPicker.mjs +65 -70
- package/lib/esm/MonthRangePicker.mjs +86 -88
- package/lib/esm/components/ButtonTrigger.mjs +4 -3
- package/lib/esm/components/Calendar.mjs +397 -423
- package/lib/esm/components/DateRangeComparatorAbstract.mjs +559 -516
- package/lib/esm/components/InputTrigger.mjs +550 -557
- package/lib/esm/components/PickerAbstract.mjs +249 -244
- package/lib/esm/components/RangePickerAbstract.mjs +400 -384
- package/lib/esm/components/index.mjs +73 -69
- package/lib/esm/translations/__intergalactic-dynamic-locales.mjs +1 -1
- package/lib/esm/utils/cronTabScheduler.mjs +13 -18
- package/lib/esm/utils/datesIntersects.mjs +10 -14
- package/lib/esm/utils/formatDate.mjs +6 -6
- package/lib/esm/utils/includesDate.mjs +10 -13
- package/lib/esm/utils/isBetweenPlugin.mjs +4 -4
- package/lib/esm/utils/shortDateRangeFormat.mjs +27 -27
- package/lib/types/index.d.ts +2 -44
- package/package.json +16 -17
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
4
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
5
|
-
import _callSuper from "@babel/runtime/helpers/esm/callSuper";
|
|
6
|
-
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
7
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
8
2
|
import { sstyled, assignProps, Component } from "@semcore/core";
|
|
3
|
+
import { Flex } from "@semcore/base-components";
|
|
9
4
|
import { LinkTrigger } from "@semcore/base-trigger";
|
|
10
5
|
import Button from "@semcore/button";
|
|
11
6
|
import Checkbox from "@semcore/checkbox";
|
|
12
7
|
import i18nEnhance from "@semcore/core/lib/utils/enhances/i18nEnhance";
|
|
13
8
|
import Dropdown from "@semcore/dropdown";
|
|
14
|
-
import { Flex } from "@semcore/flex-box";
|
|
15
9
|
import dayjs from "dayjs";
|
|
16
10
|
import React from "react";
|
|
17
11
|
import { localizedMessages } from "../translations/__intergalactic-dynamic-locales.mjs";
|
|
@@ -19,564 +13,592 @@ import { formatMMYY, formatDDMMYY } from "../utils/formatDate.mjs";
|
|
|
19
13
|
import { includesDate } from "../utils/includesDate.mjs";
|
|
20
14
|
import shortDateRangeFormat from "../utils/shortDateRangeFormat.mjs";
|
|
21
15
|
/*!__reshadow-styles__:"../style/date-picker.shadow.css"*/
|
|
22
|
-
|
|
16
|
+
const style = (
|
|
23
17
|
/*__reshadow_css_start__*/
|
|
24
18
|
(sstyled.insert(
|
|
25
19
|
/*__inner_css_start__*/
|
|
26
|
-
".
|
|
20
|
+
".___SPopper_9ubmf_gg_{padding:var(--intergalactic-spacing-4x, 16px);outline:0}.___SPopper_9ubmf_gg_::-moz-focus-inner{border:0;padding:0}.___SPopper_9ubmf_gg_:active,.___SPopper_9ubmf_gg_:focus{-webkit-text-decoration:none;text-decoration:none}@media (hover:hover){.___SPopper_9ubmf_gg_:hover{-webkit-text-decoration:none;text-decoration:none}}.___SHeader_9ubmf_gg_,.___STitle_9ubmf_gg_{display:flex;align-items:center}.___STitle_9ubmf_gg_{font-size:var(--intergalactic-fs-200, 14px);color:var(--intergalactic-text-primary, #191b23);height:32px;width:100%;justify-content:center}.___SToday_9ubmf_gg_{display:flex;margin-top:var(--intergalactic-spacing-3x, 12px);justify-content:center}.___SPeriod_9ubmf_gg_{display:flex;flex-direction:column;margin-bottom:var(--intergalactic-spacing-2x, 8px)}.___SButton_9ubmf_gg_ .___SInner_9ubmf_gg_{justify-content:flex-start}.___SInputMask_9ubmf_gg_{color:var(--intergalactic-text-primary, #191b23);line-height:normal;padding-right:var(--intergalactic-spacing-2x, 8px);transition:width calc(var(--intergalactic-duration-medium, 300)*1ms) ease,min-width calc(var(--intergalactic-duration-medium, 300)*1ms) ease}.___SInputMask_9ubmf_gg_.__animationsDisabled_9ubmf_gg_{transition:none}.___SInputMask_9ubmf_gg_ .___SValue_9ubmf_gg_{letter-spacing:0}.___SInputMask_9ubmf_gg_ .___SValue_9ubmf_gg_:focus{outline:0}.___SIndicator_9ubmf_gg_{color:var(--intergalactic-text-secondary, #6c6e79)}.___SRangeIndicator_9ubmf_gg_{border-radius:50%;flex-shrink:0}.___SRangeIndicator_9ubmf_gg_._range_value_9ubmf_gg_{background-color:var(--intergalactic-date-picker-cell-active, #2bb3ff)}.___SRangeIndicator_9ubmf_gg_._range_compare_9ubmf_gg_{background-color:var(--intergalactic-date-picker-cell-comparison-active, #8649e1)}.___SRangeIndicator_9ubmf_gg_.__disabled_9ubmf_gg_{opacity:var(--intergalactic-disabled-opacity, 0.3)}.___SHumanizedDate_9ubmf_gg_{position:absolute;pointer-events:none;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;width:100%}.___SMask_9ubmf_gg_{letter-spacing:0;white-space:nowrap;overflow:hidden}.___SDateRange_9ubmf_gg_ .___SMask_9ubmf_gg_,.___SDateRange_9ubmf_gg_ .___SValue_9ubmf_gg_,.___SSingleDateInput_9ubmf_gg_ .___SMask_9ubmf_gg_,.___SSingleDateInput_9ubmf_gg_ .___SValue_9ubmf_gg_{opacity:0}.___SSingleDateInput_9ubmf_gg_:focus-within .___SHumanizedDate_9ubmf_gg_{opacity:0;z-index:var(--intergalactic-z-index-deep, -999)}.___SSingleDateInput_9ubmf_gg_:focus-within .___SMask_9ubmf_gg_,.___SSingleDateInput_9ubmf_gg_:focus-within .___SValue_9ubmf_gg_{opacity:1}.___SDateRange_9ubmf_gg_:focus-within .___SHumanizedDate_9ubmf_gg_{opacity:0;z-index:var(--intergalactic-z-index-deep, -999)}.___SDateRange_9ubmf_gg_:focus-within .___SMask_9ubmf_gg_,.___SDateRange_9ubmf_gg_:focus-within .___SValue_9ubmf_gg_{opacity:1}.___SInputMask_9ubmf_gg_.__noHumanizedDate_9ubmf_gg_ .___SMask_9ubmf_gg_,.___SInputMask_9ubmf_gg_.__noHumanizedDate_9ubmf_gg_ .___SValue_9ubmf_gg_{opacity:1}.___SDateRange_9ubmf_gg_ .___SInputMask_9ubmf_gg_:focus-within .___SMask_9ubmf_gg_{background-color:var(--intergalactic-bg-highlight-focus, rgba(0, 143, 248, 0.2))}.___SDateRange_9ubmf_gg_:focus-within .___SRangeSep_9ubmf_gg_,.___SRangeSep_9ubmf_gg_.__fulfilled_9ubmf_gg_{color:var(--intergalactic-text-primary, #191b23)}.___SRangeComparatorHeader_9ubmf_gg_{border-bottom:1px solid var(--intergalactic-border-primary, #c4c7cf)}.___SRangeCalendar_9ubmf_gg_,.___SRangeComparatorHeader_9ubmf_gg_{padding:var(--intergalactic-spacing-4x, 16px)}.___SFooter_9ubmf_gg_{border-top:1px solid var(--intergalactic-border-primary, #c4c7cf)}.___SFooter_9ubmf_gg_,.___SPeriodsList_9ubmf_gg_{padding:var(--intergalactic-spacing-4x, 16px)}.___STooltip_9ubmf_gg_{padding:var(--intergalactic-spacing-3x, 12px)}.___SCompareToggle_9ubmf_gg_{white-space:nowrap}@media (prefers-reduced-motion){.___SInputMask_9ubmf_gg_{transition:none}}",
|
|
27
21
|
/*__inner_css_end__*/
|
|
28
|
-
"
|
|
22
|
+
"9ubmf_gg_"
|
|
29
23
|
), /*__reshadow_css_end__*/
|
|
30
24
|
{
|
|
31
|
-
"__SHeader": "
|
|
32
|
-
"__STitle": "
|
|
33
|
-
"__SToday": "
|
|
34
|
-
"__SPeriod": "
|
|
35
|
-
"__SButton": "
|
|
36
|
-
"__SInner": "
|
|
37
|
-
"__SInputMask": "
|
|
38
|
-
"_animationsDisabled": "
|
|
39
|
-
"__SIndicator": "
|
|
40
|
-
"__SRangeIndicator": "
|
|
41
|
-
"_range_value": "
|
|
42
|
-
"_range_compare": "
|
|
43
|
-
"_disabled": "
|
|
44
|
-
"__SHumanizedDate": "
|
|
45
|
-
"__SMask": "
|
|
46
|
-
"__SSingleDateInput": "
|
|
47
|
-
"__SValue": "
|
|
48
|
-
"__SDateRange": "
|
|
49
|
-
"_noHumanizedDate": "
|
|
50
|
-
"__SRangeSep": "
|
|
51
|
-
"_fulfilled": "
|
|
52
|
-
"__SRangeComparatorHeader": "
|
|
53
|
-
"__SRangeCalendar": "
|
|
54
|
-
"__SFooter": "
|
|
55
|
-
"__SPeriodsList": "
|
|
56
|
-
"__STooltip": "
|
|
57
|
-
"__SCompareToggle": "
|
|
58
|
-
"__SPopper": "
|
|
25
|
+
"__SHeader": "___SHeader_9ubmf_gg_",
|
|
26
|
+
"__STitle": "___STitle_9ubmf_gg_",
|
|
27
|
+
"__SToday": "___SToday_9ubmf_gg_",
|
|
28
|
+
"__SPeriod": "___SPeriod_9ubmf_gg_",
|
|
29
|
+
"__SButton": "___SButton_9ubmf_gg_",
|
|
30
|
+
"__SInner": "___SInner_9ubmf_gg_",
|
|
31
|
+
"__SInputMask": "___SInputMask_9ubmf_gg_",
|
|
32
|
+
"_animationsDisabled": "__animationsDisabled_9ubmf_gg_",
|
|
33
|
+
"__SIndicator": "___SIndicator_9ubmf_gg_",
|
|
34
|
+
"__SRangeIndicator": "___SRangeIndicator_9ubmf_gg_",
|
|
35
|
+
"_range_value": "_range_value_9ubmf_gg_",
|
|
36
|
+
"_range_compare": "_range_compare_9ubmf_gg_",
|
|
37
|
+
"_disabled": "__disabled_9ubmf_gg_",
|
|
38
|
+
"__SHumanizedDate": "___SHumanizedDate_9ubmf_gg_",
|
|
39
|
+
"__SMask": "___SMask_9ubmf_gg_",
|
|
40
|
+
"__SSingleDateInput": "___SSingleDateInput_9ubmf_gg_",
|
|
41
|
+
"__SValue": "___SValue_9ubmf_gg_",
|
|
42
|
+
"__SDateRange": "___SDateRange_9ubmf_gg_",
|
|
43
|
+
"_noHumanizedDate": "__noHumanizedDate_9ubmf_gg_",
|
|
44
|
+
"__SRangeSep": "___SRangeSep_9ubmf_gg_",
|
|
45
|
+
"_fulfilled": "__fulfilled_9ubmf_gg_",
|
|
46
|
+
"__SRangeComparatorHeader": "___SRangeComparatorHeader_9ubmf_gg_",
|
|
47
|
+
"__SRangeCalendar": "___SRangeCalendar_9ubmf_gg_",
|
|
48
|
+
"__SFooter": "___SFooter_9ubmf_gg_",
|
|
49
|
+
"__SPeriodsList": "___SPeriodsList_9ubmf_gg_",
|
|
50
|
+
"__STooltip": "___STooltip_9ubmf_gg_",
|
|
51
|
+
"__SCompareToggle": "___SCompareToggle_9ubmf_gg_",
|
|
52
|
+
"__SPopper": "___SPopper_9ubmf_gg_"
|
|
59
53
|
})
|
|
60
54
|
);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
dateRanges[_key] = arguments[_key];
|
|
67
|
-
}
|
|
68
|
-
var allDates = dateRanges.flat().filter(Boolean).filter(function(date) {
|
|
69
|
-
return !Number.isNaN(new Date(date).getTime());
|
|
70
|
-
});
|
|
55
|
+
const INTERACTION_TAGS = ["INPUT"];
|
|
56
|
+
const INTERACTION_KEYS = ["ArrowDown", "Enter", " "];
|
|
57
|
+
const defaultDisplayedPeriod = new Date((/* @__PURE__ */ new Date()).setHours(0, 0, 0, 0));
|
|
58
|
+
const getLatestDate = (...dateRanges) => {
|
|
59
|
+
const allDates = dateRanges.flat().filter(Boolean).filter((date) => !Number.isNaN(new Date(date).getTime()));
|
|
71
60
|
if (!allDates.length) return null;
|
|
72
|
-
allDates.sort(
|
|
73
|
-
|
|
74
|
-
});
|
|
75
|
-
var latestDate = allDates[0];
|
|
61
|
+
allDates.sort((a, b) => new Date(b).getTime() - new Date(a).getTime());
|
|
62
|
+
const latestDate = allDates[0];
|
|
76
63
|
return latestDate;
|
|
77
64
|
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
_defineProperty(
|
|
87
|
-
_defineProperty(
|
|
88
|
-
_defineProperty(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
var action = direction >= 1 ? "add" : "subtract";
|
|
96
|
-
var date = dayjs(displayedPeriod)[action](1, _this.navigateStep).toDate();
|
|
97
|
-
_this.handlers.displayedPeriod(date);
|
|
98
|
-
});
|
|
99
|
-
_defineProperty(_this, "bindHandlerNavigateClick", function(direction) {
|
|
100
|
-
return function() {
|
|
101
|
-
return _this.navigateView(direction);
|
|
102
|
-
};
|
|
65
|
+
class DateRangeComparatorAbstract extends Component {
|
|
66
|
+
constructor(...args) {
|
|
67
|
+
super(...args);
|
|
68
|
+
_defineProperty(this, "prevButtonRef", /* @__PURE__ */ React.createRef());
|
|
69
|
+
_defineProperty(this, "nextButtonRef", /* @__PURE__ */ React.createRef());
|
|
70
|
+
_defineProperty(this, "popperRef", /* @__PURE__ */ React.createRef());
|
|
71
|
+
_defineProperty(this, "resetButtonRef", /* @__PURE__ */ React.createRef());
|
|
72
|
+
_defineProperty(this, "applyButtonRef", /* @__PURE__ */ React.createRef());
|
|
73
|
+
_defineProperty(this, "periodRefs", []);
|
|
74
|
+
_defineProperty(this, "unitRefs", {});
|
|
75
|
+
_defineProperty(this, "navigateView", (direction) => {
|
|
76
|
+
const {
|
|
77
|
+
displayedPeriod
|
|
78
|
+
} = this.asProps;
|
|
79
|
+
const action = direction >= 1 ? "add" : "subtract";
|
|
80
|
+
const date = dayjs(displayedPeriod)[action](1, this.navigateStep).toDate();
|
|
81
|
+
this.handlers.displayedPeriod(date);
|
|
103
82
|
});
|
|
104
|
-
_defineProperty(
|
|
105
|
-
|
|
106
|
-
|
|
83
|
+
_defineProperty(this, "bindHandlerNavigateClick", (direction) => () => this.navigateView(direction));
|
|
84
|
+
_defineProperty(this, "handleApplyClick", () => {
|
|
85
|
+
const {
|
|
86
|
+
value,
|
|
87
|
+
preselectedValue,
|
|
88
|
+
preselectedCompare
|
|
89
|
+
} = this.asProps;
|
|
90
|
+
return this.handleApply(preselectedValue ?? (value == null ? void 0 : value.value), preselectedCompare ?? (value == null ? void 0 : value.compare));
|
|
107
91
|
});
|
|
108
|
-
_defineProperty(
|
|
109
|
-
|
|
92
|
+
_defineProperty(this, "handleApply", (value, compare) => {
|
|
93
|
+
this.handlers.value({
|
|
110
94
|
value,
|
|
111
95
|
compare
|
|
112
96
|
});
|
|
113
|
-
|
|
97
|
+
this.handlers.visible(false);
|
|
114
98
|
});
|
|
115
|
-
_defineProperty(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
var highlightedPeriodNormalized = highlightedPeriod === null || highlightedPeriod === void 0 ? void 0 : highlightedPeriod.getDate();
|
|
138
|
-
if (_this.navigateStep === "month") {
|
|
139
|
-
displayedPeriodNormalized = displayedPeriod === null || displayedPeriod === void 0 ? void 0 : displayedPeriod.getMonth();
|
|
140
|
-
highlightedPeriodNormalized = highlightedPeriod === null || highlightedPeriod === void 0 ? void 0 : highlightedPeriod.getMonth();
|
|
141
|
-
}
|
|
142
|
-
if (_this.navigateStep === "year") {
|
|
143
|
-
displayedPeriodNormalized = displayedPeriod === null || displayedPeriod === void 0 ? void 0 : displayedPeriod.getYear();
|
|
144
|
-
highlightedPeriodNormalized = highlightedPeriod === null || highlightedPeriod === void 0 ? void 0 : highlightedPeriod.getYear();
|
|
145
|
-
}
|
|
146
|
-
var offset = highlightedPeriodNormalized - displayedPeriodNormalized;
|
|
147
|
-
if (offset < 0 || offset > 1) {
|
|
148
|
-
return highlightedPeriod;
|
|
149
|
-
}
|
|
150
|
-
return displayedPeriod;
|
|
151
|
-
};
|
|
152
|
-
var isPeriodTarget = _this.periodRefs.find(function(el) {
|
|
153
|
-
return el === target;
|
|
154
|
-
});
|
|
155
|
-
var isResetButtonTarget = target === _this.resetButtonRef.current;
|
|
156
|
-
var isApplyButtonTarget = target === _this.applyButtonRef.current;
|
|
157
|
-
var areTargetedControls = isPeriodTarget || isResetButtonTarget || isApplyButtonTarget;
|
|
158
|
-
if (place === "popper" && e.key === " " && highlighted.length && !areTargetedControls) {
|
|
159
|
-
var highlightedDate = highlighted[1] || highlighted[0];
|
|
160
|
-
if (!_this.isDisabled(highlightedDate)) {
|
|
161
|
-
_this.handleChange(highlightedDate);
|
|
99
|
+
_defineProperty(this, "handleKeydownDown", (place) => (e) => {
|
|
100
|
+
var _a;
|
|
101
|
+
const {
|
|
102
|
+
displayedPeriod,
|
|
103
|
+
preselectedValue,
|
|
104
|
+
visible,
|
|
105
|
+
focusedRange
|
|
106
|
+
} = this.asProps;
|
|
107
|
+
const {
|
|
108
|
+
key,
|
|
109
|
+
target
|
|
110
|
+
} = e;
|
|
111
|
+
const highlighted = focusedRange === "compare" ? this.asProps.compareHighlighted : this.asProps.highlighted;
|
|
112
|
+
if ([" ", "Enter"].includes(key) && [this.prevButtonRef.current, this.nextButtonRef.current].includes(target)) return;
|
|
113
|
+
if (place === "trigger" && INTERACTION_KEYS.includes(key)) {
|
|
114
|
+
e.preventDefault();
|
|
115
|
+
e.stopPropagation();
|
|
116
|
+
this.handlers.visible(!visible);
|
|
117
|
+
setTimeout(() => {
|
|
118
|
+
const popper = this.popperRef.current;
|
|
119
|
+
if (popper) {
|
|
120
|
+
popper.focus();
|
|
162
121
|
}
|
|
163
|
-
|
|
122
|
+
}, 0);
|
|
123
|
+
}
|
|
124
|
+
const day = this.keyDiff[key];
|
|
125
|
+
const setNextDisplayedPeriod = (next_highlighted) => {
|
|
126
|
+
const [startPeriod, endPeriod] = next_highlighted;
|
|
127
|
+
const highlightedPeriod = endPeriod || startPeriod;
|
|
128
|
+
let displayedPeriodNormalized = displayedPeriod == null ? void 0 : displayedPeriod.getDate();
|
|
129
|
+
let highlightedPeriodNormalized = highlightedPeriod == null ? void 0 : highlightedPeriod.getDate();
|
|
130
|
+
if (this.navigateStep === "month") {
|
|
131
|
+
displayedPeriodNormalized = displayedPeriod == null ? void 0 : displayedPeriod.getMonth();
|
|
132
|
+
highlightedPeriodNormalized = highlightedPeriod == null ? void 0 : highlightedPeriod.getMonth();
|
|
164
133
|
}
|
|
165
|
-
if (
|
|
166
|
-
|
|
134
|
+
if (this.navigateStep === "year") {
|
|
135
|
+
displayedPeriodNormalized = displayedPeriod == null ? void 0 : displayedPeriod.getYear();
|
|
136
|
+
highlightedPeriodNormalized = highlightedPeriod == null ? void 0 : highlightedPeriod.getYear();
|
|
167
137
|
}
|
|
168
|
-
|
|
169
|
-
if (
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
138
|
+
const offset = highlightedPeriodNormalized - displayedPeriodNormalized;
|
|
139
|
+
if (offset < 0 || offset > 1) {
|
|
140
|
+
return highlightedPeriod;
|
|
141
|
+
}
|
|
142
|
+
return displayedPeriod;
|
|
143
|
+
};
|
|
144
|
+
const isPeriodTarget = this.periodRefs.find((el) => el === target);
|
|
145
|
+
const isResetButtonTarget = target === this.resetButtonRef.current;
|
|
146
|
+
const isApplyButtonTarget = target === this.applyButtonRef.current;
|
|
147
|
+
const areTargetedControls = isPeriodTarget || isResetButtonTarget || isApplyButtonTarget;
|
|
148
|
+
if (place === "popper" && e.key === " " && highlighted.length && !areTargetedControls) {
|
|
149
|
+
const highlightedDate = highlighted[1] || highlighted[0];
|
|
150
|
+
if (!this.isDisabled(highlightedDate)) {
|
|
151
|
+
this.handleChange(highlightedDate);
|
|
152
|
+
}
|
|
153
|
+
e.preventDefault();
|
|
154
|
+
}
|
|
155
|
+
if (place === "popper" && e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
|
|
156
|
+
return this.handleApplyClick();
|
|
157
|
+
}
|
|
158
|
+
let changedDate = void 0;
|
|
159
|
+
if (day) {
|
|
160
|
+
if (INTERACTION_TAGS.includes(e.target.tagName)) return;
|
|
161
|
+
if (highlighted.length) {
|
|
162
|
+
let next_highlighted;
|
|
163
|
+
if ((preselectedValue == null ? void 0 : preselectedValue.length) === 1) {
|
|
164
|
+
next_highlighted = [preselectedValue[0], dayjs(highlighted[1] || highlighted[0]).add(day, this.keyStep).toDate()];
|
|
165
|
+
changedDate = next_highlighted[1];
|
|
166
|
+
} else {
|
|
167
|
+
next_highlighted = [dayjs(highlighted[0]).add(day, this.keyStep).toDate()];
|
|
168
|
+
changedDate = next_highlighted[0];
|
|
169
|
+
}
|
|
170
|
+
if (focusedRange === "compare") {
|
|
171
|
+
this.handlers.compareHighlighted(next_highlighted);
|
|
186
172
|
} else {
|
|
187
|
-
|
|
188
|
-
if (focusedRange === "compare") {
|
|
189
|
-
_this.handlers.compareHighlighted(_highlighted);
|
|
190
|
-
} else {
|
|
191
|
-
_this.handlers.highlighted(_highlighted);
|
|
192
|
-
}
|
|
193
|
-
changedDate = _highlighted[0];
|
|
173
|
+
this.handlers.highlighted(next_highlighted);
|
|
194
174
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
175
|
+
this.handlers.displayedPeriod(setNextDisplayedPeriod(next_highlighted));
|
|
176
|
+
} else {
|
|
177
|
+
const highlighted2 = [displayedPeriod ? displayedPeriod : dayjs().toDate()];
|
|
178
|
+
if (focusedRange === "compare") {
|
|
179
|
+
this.handlers.compareHighlighted(highlighted2);
|
|
180
|
+
} else {
|
|
181
|
+
this.handlers.highlighted(highlighted2);
|
|
201
182
|
}
|
|
183
|
+
changedDate = highlighted2[0];
|
|
202
184
|
}
|
|
203
|
-
|
|
185
|
+
e.preventDefault();
|
|
186
|
+
if (changedDate) {
|
|
187
|
+
const formatter = this.keyStep === "month" ? formatMMYY : formatDDMMYY;
|
|
188
|
+
const formattedDate = formatter(changedDate, this.asProps.locale);
|
|
189
|
+
(_a = this.unitRefs[formattedDate]) == null ? void 0 : _a.focus();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
204
192
|
});
|
|
205
|
-
_defineProperty(
|
|
193
|
+
_defineProperty(this, "triggerFormattingProps", {
|
|
206
194
|
day: "numeric",
|
|
207
195
|
month: "short",
|
|
208
196
|
year: "numeric"
|
|
209
197
|
});
|
|
210
|
-
_defineProperty(
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
198
|
+
_defineProperty(this, "handleChange", (date) => {
|
|
199
|
+
const {
|
|
200
|
+
focusedRange,
|
|
201
|
+
preselectedCompare,
|
|
202
|
+
preselectedValue
|
|
203
|
+
} = this.asProps;
|
|
204
|
+
let highlighted = [];
|
|
205
|
+
let value = focusedRange === "compare" ? preselectedCompare : preselectedValue;
|
|
215
206
|
if (Array.isArray(date)) {
|
|
216
207
|
value = date;
|
|
217
|
-
} else if (!(
|
|
208
|
+
} else if (!(value == null ? void 0 : value.length)) {
|
|
218
209
|
value = [date];
|
|
219
210
|
highlighted = [date];
|
|
220
|
-
} else if ((
|
|
211
|
+
} else if ((value == null ? void 0 : value.length) >= 2) {
|
|
221
212
|
value = [date];
|
|
222
213
|
highlighted = [date];
|
|
223
|
-
} else if ((
|
|
224
|
-
|
|
225
|
-
value = [date, (_value4 = value) === null || _value4 === void 0 ? void 0 : _value4[0]];
|
|
214
|
+
} else if ((value == null ? void 0 : value[0]) > date) {
|
|
215
|
+
value = [date, value == null ? void 0 : value[0]];
|
|
226
216
|
} else {
|
|
227
|
-
|
|
228
|
-
value = [(_value5 = value) === null || _value5 === void 0 ? void 0 : _value5[0], date];
|
|
217
|
+
value = [value == null ? void 0 : value[0], date];
|
|
229
218
|
}
|
|
230
219
|
if (focusedRange === "compare") {
|
|
231
|
-
|
|
232
|
-
|
|
220
|
+
this.handlers.preselectedCompare(value);
|
|
221
|
+
this.handlers.compareHighlighted(highlighted);
|
|
233
222
|
} else {
|
|
234
|
-
|
|
235
|
-
|
|
223
|
+
this.handlers.preselectedValue(value);
|
|
224
|
+
this.handlers.highlighted(highlighted);
|
|
236
225
|
}
|
|
237
226
|
});
|
|
238
|
-
return _this;
|
|
239
227
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
var navigateStep = this.navigateStep;
|
|
278
|
-
return {
|
|
279
|
-
getI18nText,
|
|
280
|
-
"ref": this.prevButtonRef,
|
|
281
|
-
"onClick": this.bindHandlerNavigateClick(-1),
|
|
282
|
-
"aria-label": navigateStep === "month" ? getI18nText("prevMonth") : getI18nText("prevYear")
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
}, {
|
|
286
|
-
key: "getNextProps",
|
|
287
|
-
value: function getNextProps() {
|
|
288
|
-
var getI18nText = this.asProps.getI18nText;
|
|
289
|
-
var navigateStep = this.navigateStep;
|
|
290
|
-
return {
|
|
291
|
-
getI18nText,
|
|
292
|
-
"ref": this.nextButtonRef,
|
|
293
|
-
"onClick": this.bindHandlerNavigateClick(1),
|
|
294
|
-
"aria-label": navigateStep === "month" ? getI18nText("nextMonth") : getI18nText("nextYear")
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
}, {
|
|
298
|
-
key: "uncontrolledProps",
|
|
299
|
-
value: function uncontrolledProps() {
|
|
300
|
-
var _this3 = this;
|
|
301
|
-
return {
|
|
302
|
-
displayedPeriod: null,
|
|
303
|
-
visible: [null, function(visible) {
|
|
304
|
-
if (!visible) {
|
|
305
|
-
_this3.handlers.highlighted([]);
|
|
306
|
-
_this3.handlers.compareHighlighted([]);
|
|
307
|
-
_this3.handlers.preselectedValue(void 0);
|
|
308
|
-
_this3.handlers.preselectedCompare(void 0);
|
|
309
|
-
_this3.handlers.compareToggle(void 0);
|
|
310
|
-
_this3.handlers.focusedRange("value");
|
|
311
|
-
} else {
|
|
312
|
-
var _this3$asProps$value;
|
|
313
|
-
_this3.handlers.compareToggle(!!((_this3$asProps$value = _this3.asProps.value) !== null && _this3$asProps$value !== void 0 && (_this3$asProps$value = _this3$asProps$value.compare) !== null && _this3$asProps$value !== void 0 && _this3$asProps$value.length));
|
|
314
|
-
}
|
|
315
|
-
var _this3$asProps = _this3.asProps, value = _this3$asProps.value, displayedPeriod = _this3$asProps.displayedPeriod;
|
|
316
|
-
var newDisplayedPeriod = value ? getLatestDate(value.value, value.compare) : void 0;
|
|
317
|
-
if (visible) {
|
|
318
|
-
if (newDisplayedPeriod && newDisplayedPeriod !== displayedPeriod) {
|
|
319
|
-
_this3.handlers.displayedPeriod(newDisplayedPeriod);
|
|
320
|
-
} else if (!newDisplayedPeriod) {
|
|
321
|
-
var _this3$props = _this3.props, _displayedPeriod = _this3$props.displayedPeriod, _defaultDisplayedPeriod = _this3$props.defaultDisplayedPeriod;
|
|
322
|
-
_this3.handlers.displayedPeriod(_displayedPeriod || _defaultDisplayedPeriod);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}],
|
|
326
|
-
highlighted: null,
|
|
327
|
-
compareHighlighted: null,
|
|
328
|
-
preselectedValue: null,
|
|
329
|
-
preselectedCompare: null,
|
|
330
|
-
compareToggle: null,
|
|
331
|
-
focusedRange: null,
|
|
332
|
-
value: [null, function(value) {
|
|
333
|
-
var dates = [value === null || value === void 0 ? void 0 : value.value, value === null || value === void 0 ? void 0 : value.compare].flat(2).filter(function(date) {
|
|
334
|
-
var _date$isValid;
|
|
335
|
-
return date === null || date === void 0 || (_date$isValid = date.isValid) === null || _date$isValid === void 0 ? void 0 : _date$isValid.call(date);
|
|
336
|
-
});
|
|
337
|
-
if (dates.length > 0) _this3.handlers.displayedPeriod(getLatestDate(value));
|
|
338
|
-
}]
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
}, {
|
|
342
|
-
key: "getApplyProps",
|
|
343
|
-
value: function getApplyProps() {
|
|
344
|
-
var getI18nText = this.asProps.getI18nText;
|
|
345
|
-
return {
|
|
346
|
-
getI18nText,
|
|
347
|
-
onClick: this.handleApplyClick,
|
|
348
|
-
ref: this.applyButtonRef
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
}, {
|
|
352
|
-
key: "getResetProps",
|
|
353
|
-
value: function getResetProps() {
|
|
354
|
-
var _this4 = this;
|
|
355
|
-
var getI18nText = this.asProps.getI18nText;
|
|
356
|
-
return {
|
|
357
|
-
getI18nText,
|
|
358
|
-
onClick: function onClick() {
|
|
359
|
-
return _this4.handleApply(null, null);
|
|
360
|
-
},
|
|
361
|
-
ref: this.resetButtonRef
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
}, {
|
|
365
|
-
key: "isDisabled",
|
|
366
|
-
value: function isDisabled(date) {
|
|
367
|
-
var disabled = this.asProps.disabled;
|
|
368
|
-
return disabled.some(includesDate(dayjs(date), "date"));
|
|
369
|
-
}
|
|
370
|
-
}, {
|
|
371
|
-
key: "getDefaultPeriods",
|
|
372
|
-
value: function getDefaultPeriods() {
|
|
373
|
-
var getI18nText = this.asProps.getI18nText;
|
|
374
|
-
var today = new Date((/* @__PURE__ */ new Date()).setHours(0, 0, 0, 0));
|
|
375
|
-
return [{
|
|
376
|
-
children: getI18nText("lastMonth"),
|
|
377
|
-
value: [dayjs(today).subtract(1, "month").startOf("month").toDate(), dayjs(today).startOf("month").toDate()]
|
|
378
|
-
}, {
|
|
379
|
-
children: getI18nText("last3Months"),
|
|
380
|
-
value: [dayjs(today).subtract(2, "month").startOf("month").toDate(), dayjs(today).startOf("month").toDate()]
|
|
381
|
-
}, {
|
|
382
|
-
children: getI18nText("last6Months"),
|
|
383
|
-
value: [dayjs(today).subtract(5, "month").startOf("month").toDate(), dayjs(today).startOf("month").toDate()]
|
|
384
|
-
}, {
|
|
385
|
-
children: getI18nText("last12Months"),
|
|
386
|
-
value: [dayjs(today).subtract(11, "month").startOf("month").toDate(), dayjs(today).startOf("month").toDate()]
|
|
387
|
-
}];
|
|
388
|
-
}
|
|
389
|
-
}, {
|
|
390
|
-
key: "getTitleProps",
|
|
391
|
-
value: function getTitleProps(_props, index) {
|
|
392
|
-
var _this$asProps5 = this.asProps, locale = _this$asProps5.locale, displayedPeriod = _this$asProps5.displayedPeriod;
|
|
393
|
-
return {
|
|
394
|
-
children: new Intl.DateTimeFormat(locale, {
|
|
395
|
-
month: "long",
|
|
396
|
-
year: "numeric"
|
|
397
|
-
}).format(dayjs(displayedPeriod).add(index, this.navigateStep).startOf(this.navigateStep).toDate())
|
|
398
|
-
};
|
|
228
|
+
static defaultProps({
|
|
229
|
+
primaryRange,
|
|
230
|
+
defaultPrimaryRange,
|
|
231
|
+
secondaryRange,
|
|
232
|
+
defaultSecondaryRange
|
|
233
|
+
}) {
|
|
234
|
+
return {
|
|
235
|
+
i18n: localizedMessages,
|
|
236
|
+
locale: "en",
|
|
237
|
+
defaultValue: null,
|
|
238
|
+
defaultHighlighted: [],
|
|
239
|
+
defaultCompareHighlighted: [],
|
|
240
|
+
defaultDisplayedPeriod: getLatestDate(primaryRange, defaultPrimaryRange, secondaryRange, defaultSecondaryRange) || defaultDisplayedPeriod,
|
|
241
|
+
defaultVisible: false,
|
|
242
|
+
defaultPreselectedValue: null,
|
|
243
|
+
defaultPreselectedCompare: null,
|
|
244
|
+
defaultCompareToggle: null,
|
|
245
|
+
defaultFocusedRange: "value",
|
|
246
|
+
disabled: [],
|
|
247
|
+
size: "m"
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
getPeriodProps() {
|
|
251
|
+
var _a, _b;
|
|
252
|
+
const {
|
|
253
|
+
periods = this.getDefaultPeriods(),
|
|
254
|
+
onHighlightedChange,
|
|
255
|
+
onCompareHighlightedChange,
|
|
256
|
+
onDisplayedPeriodChange,
|
|
257
|
+
preselectedValue,
|
|
258
|
+
preselectedCompare,
|
|
259
|
+
focusedRange,
|
|
260
|
+
getI18nText
|
|
261
|
+
} = this.asProps;
|
|
262
|
+
let value = preselectedValue ?? ((_a = this.asProps.value) == null ? void 0 : _a.value);
|
|
263
|
+
if (focusedRange === "compare") {
|
|
264
|
+
value = preselectedCompare ?? ((_b = this.asProps.value) == null ? void 0 : _b.compare);
|
|
399
265
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
266
|
+
return {
|
|
267
|
+
periods,
|
|
268
|
+
value,
|
|
269
|
+
"onChange": (value2) => {
|
|
270
|
+
if (focusedRange === "compare") {
|
|
271
|
+
this.handlers.preselectedCompare(value2);
|
|
272
|
+
} else {
|
|
273
|
+
this.handlers.preselectedValue(value2);
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
"onHighlightedChange": focusedRange === "compare" ? onCompareHighlightedChange : onHighlightedChange,
|
|
277
|
+
onDisplayedPeriodChange,
|
|
278
|
+
"role": "listbox",
|
|
279
|
+
"aria-label": getI18nText("periods"),
|
|
280
|
+
"periodRef": (index) => (element) => {
|
|
281
|
+
if (!element) return;
|
|
282
|
+
this.periodRefs[index] = element;
|
|
417
283
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
locale,
|
|
478
|
-
disabledDates: disabled,
|
|
479
|
-
children: this.getRangeInput(),
|
|
480
|
-
getI18nText,
|
|
481
|
-
disabledErrorText,
|
|
482
|
-
onFocus: function onFocus() {
|
|
483
|
-
_this7.handlers.focusedRange("compare");
|
|
484
|
-
},
|
|
485
|
-
animationsDisabled
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
}, {
|
|
489
|
-
key: "getCompareToggleProps",
|
|
490
|
-
value: function getCompareToggleProps() {
|
|
491
|
-
var _this8 = this;
|
|
492
|
-
var _this$asProps9 = this.asProps, getI18nText = _this$asProps9.getI18nText, compareToggle = _this$asProps9.compareToggle;
|
|
493
|
-
return {
|
|
494
|
-
getI18nText,
|
|
495
|
-
checked: compareToggle,
|
|
496
|
-
onChange: function onChange(checked) {
|
|
497
|
-
if (checked) {
|
|
498
|
-
_this8.handlers.compareToggle(true);
|
|
499
|
-
_this8.handlers.focusedRange("compare");
|
|
500
|
-
} else {
|
|
501
|
-
_this8.handlers.compareToggle(false);
|
|
502
|
-
_this8.handlers.focusedRange("value");
|
|
503
|
-
_this8.handlers.preselectedCompare([]);
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
getPrevProps() {
|
|
287
|
+
const {
|
|
288
|
+
getI18nText
|
|
289
|
+
} = this.asProps;
|
|
290
|
+
const {
|
|
291
|
+
navigateStep
|
|
292
|
+
} = this;
|
|
293
|
+
return {
|
|
294
|
+
getI18nText,
|
|
295
|
+
"ref": this.prevButtonRef,
|
|
296
|
+
"onClick": this.bindHandlerNavigateClick(-1),
|
|
297
|
+
"aria-label": navigateStep === "month" ? getI18nText("prevMonth") : getI18nText("prevYear")
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
getNextProps() {
|
|
301
|
+
const {
|
|
302
|
+
getI18nText
|
|
303
|
+
} = this.asProps;
|
|
304
|
+
const {
|
|
305
|
+
navigateStep
|
|
306
|
+
} = this;
|
|
307
|
+
return {
|
|
308
|
+
getI18nText,
|
|
309
|
+
"ref": this.nextButtonRef,
|
|
310
|
+
"onClick": this.bindHandlerNavigateClick(1),
|
|
311
|
+
"aria-label": navigateStep === "month" ? getI18nText("nextMonth") : getI18nText("nextYear")
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
uncontrolledProps() {
|
|
315
|
+
return {
|
|
316
|
+
displayedPeriod: null,
|
|
317
|
+
visible: [null, (visible) => {
|
|
318
|
+
var _a, _b;
|
|
319
|
+
if (!visible) {
|
|
320
|
+
this.handlers.highlighted([]);
|
|
321
|
+
this.handlers.compareHighlighted([]);
|
|
322
|
+
this.handlers.preselectedValue(void 0);
|
|
323
|
+
this.handlers.preselectedCompare(void 0);
|
|
324
|
+
this.handlers.compareToggle(void 0);
|
|
325
|
+
this.handlers.focusedRange("value");
|
|
326
|
+
} else {
|
|
327
|
+
this.handlers.compareToggle(!!((_b = (_a = this.asProps.value) == null ? void 0 : _a.compare) == null ? void 0 : _b.length));
|
|
328
|
+
}
|
|
329
|
+
const {
|
|
330
|
+
value,
|
|
331
|
+
displayedPeriod
|
|
332
|
+
} = this.asProps;
|
|
333
|
+
const newDisplayedPeriod = value ? getLatestDate(value.value, value.compare) : void 0;
|
|
334
|
+
if (visible) {
|
|
335
|
+
if (newDisplayedPeriod && newDisplayedPeriod !== displayedPeriod) {
|
|
336
|
+
this.handlers.displayedPeriod(newDisplayedPeriod);
|
|
337
|
+
} else if (!newDisplayedPeriod) {
|
|
338
|
+
const {
|
|
339
|
+
displayedPeriod: displayedPeriod2,
|
|
340
|
+
defaultDisplayedPeriod: defaultDisplayedPeriod2
|
|
341
|
+
} = this.props;
|
|
342
|
+
this.handlers.displayedPeriod(displayedPeriod2 || defaultDisplayedPeriod2);
|
|
504
343
|
}
|
|
505
344
|
}
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
345
|
+
}],
|
|
346
|
+
highlighted: null,
|
|
347
|
+
compareHighlighted: null,
|
|
348
|
+
preselectedValue: null,
|
|
349
|
+
preselectedCompare: null,
|
|
350
|
+
compareToggle: null,
|
|
351
|
+
focusedRange: null,
|
|
352
|
+
value: [null, (value) => {
|
|
353
|
+
const dates = [value == null ? void 0 : value.value, value == null ? void 0 : value.compare].flat(2).filter((date) => {
|
|
354
|
+
var _a;
|
|
355
|
+
return (_a = date == null ? void 0 : date.isValid) == null ? void 0 : _a.call(date);
|
|
356
|
+
});
|
|
357
|
+
if (dates.length > 0) this.handlers.displayedPeriod(getLatestDate(value));
|
|
358
|
+
}]
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
getApplyProps() {
|
|
362
|
+
const {
|
|
363
|
+
getI18nText
|
|
364
|
+
} = this.asProps;
|
|
365
|
+
return {
|
|
366
|
+
getI18nText,
|
|
367
|
+
onClick: this.handleApplyClick,
|
|
368
|
+
ref: this.applyButtonRef
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
getResetProps() {
|
|
372
|
+
const {
|
|
373
|
+
getI18nText
|
|
374
|
+
} = this.asProps;
|
|
375
|
+
return {
|
|
376
|
+
getI18nText,
|
|
377
|
+
onClick: () => this.handleApply(null, null),
|
|
378
|
+
ref: this.resetButtonRef
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
isDisabled(date) {
|
|
382
|
+
const {
|
|
383
|
+
disabled
|
|
384
|
+
} = this.asProps;
|
|
385
|
+
return disabled.some(includesDate(dayjs(date), "date"));
|
|
386
|
+
}
|
|
387
|
+
getDefaultPeriods() {
|
|
388
|
+
const {
|
|
389
|
+
getI18nText
|
|
390
|
+
} = this.asProps;
|
|
391
|
+
const today = new Date((/* @__PURE__ */ new Date()).setHours(0, 0, 0, 0));
|
|
392
|
+
return [{
|
|
393
|
+
children: getI18nText("lastMonth"),
|
|
394
|
+
value: [dayjs(today).subtract(1, "month").startOf("month").toDate(), dayjs(today).startOf("month").toDate()]
|
|
395
|
+
}, {
|
|
396
|
+
children: getI18nText("last3Months"),
|
|
397
|
+
value: [dayjs(today).subtract(2, "month").startOf("month").toDate(), dayjs(today).startOf("month").toDate()]
|
|
398
|
+
}, {
|
|
399
|
+
children: getI18nText("last6Months"),
|
|
400
|
+
value: [dayjs(today).subtract(5, "month").startOf("month").toDate(), dayjs(today).startOf("month").toDate()]
|
|
401
|
+
}, {
|
|
402
|
+
children: getI18nText("last12Months"),
|
|
403
|
+
value: [dayjs(today).subtract(11, "month").startOf("month").toDate(), dayjs(today).startOf("month").toDate()]
|
|
404
|
+
}];
|
|
405
|
+
}
|
|
406
|
+
getTitleProps(_props, index) {
|
|
407
|
+
const {
|
|
408
|
+
locale,
|
|
409
|
+
displayedPeriod
|
|
410
|
+
} = this.asProps;
|
|
411
|
+
return {
|
|
412
|
+
children: new Intl.DateTimeFormat(locale, {
|
|
413
|
+
month: "long",
|
|
414
|
+
year: "numeric"
|
|
415
|
+
}).format(dayjs(displayedPeriod).add(index, this.navigateStep).startOf(this.navigateStep).toDate())
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
getTriggerProps({
|
|
419
|
+
placeholder = "Select date ranges",
|
|
420
|
+
separator = "vs."
|
|
421
|
+
}) {
|
|
422
|
+
var _a, _b;
|
|
423
|
+
const {
|
|
424
|
+
locale,
|
|
425
|
+
visible
|
|
426
|
+
} = this.asProps;
|
|
427
|
+
const value = (_a = this.asProps.value) == null ? void 0 : _a.value;
|
|
428
|
+
const compare = (_b = this.asProps.value) == null ? void 0 : _b.compare;
|
|
429
|
+
const formattingProps = {
|
|
430
|
+
locale,
|
|
431
|
+
...this.triggerFormattingProps
|
|
432
|
+
};
|
|
433
|
+
let children = placeholder;
|
|
434
|
+
if ((value == null ? void 0 : value[0]) && (value == null ? void 0 : value[1])) {
|
|
435
|
+
children = shortDateRangeFormat(value, formattingProps);
|
|
548
436
|
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
value: function defaultProps(_ref1) {
|
|
552
|
-
var primaryRange = _ref1.primaryRange, defaultPrimaryRange = _ref1.defaultPrimaryRange, secondaryRange = _ref1.secondaryRange, defaultSecondaryRange = _ref1.defaultSecondaryRange;
|
|
553
|
-
return {
|
|
554
|
-
i18n: localizedMessages,
|
|
555
|
-
locale: "en",
|
|
556
|
-
defaultValue: null,
|
|
557
|
-
defaultHighlighted: [],
|
|
558
|
-
defaultCompareHighlighted: [],
|
|
559
|
-
defaultDisplayedPeriod: getLatestDate(primaryRange, defaultPrimaryRange, secondaryRange, defaultSecondaryRange) || defaultDisplayedPeriod,
|
|
560
|
-
defaultVisible: false,
|
|
561
|
-
defaultPreselectedValue: null,
|
|
562
|
-
defaultPreselectedCompare: null,
|
|
563
|
-
defaultCompareToggle: null,
|
|
564
|
-
defaultFocusedRange: "value",
|
|
565
|
-
disabled: [],
|
|
566
|
-
size: "m"
|
|
567
|
-
};
|
|
437
|
+
if ((compare == null ? void 0 : compare[0]) && (compare == null ? void 0 : compare[1])) {
|
|
438
|
+
children = `${children || ""} ${separator} ${shortDateRangeFormat(compare, formattingProps)}`;
|
|
568
439
|
}
|
|
569
|
-
|
|
570
|
-
|
|
440
|
+
return {
|
|
441
|
+
children,
|
|
442
|
+
visible,
|
|
443
|
+
onClick: () => this.handlers.visible(!visible),
|
|
444
|
+
onKeyDown: this.handleKeydownDown("trigger")
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
getRangeInput() {
|
|
448
|
+
throw new Error("not implemented");
|
|
449
|
+
}
|
|
450
|
+
getRangeInputProps() {
|
|
451
|
+
return {
|
|
452
|
+
inputRole: null
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
getValueDateRangeProps() {
|
|
456
|
+
const {
|
|
457
|
+
value,
|
|
458
|
+
onDisplayedPeriodChange,
|
|
459
|
+
locale,
|
|
460
|
+
disabled,
|
|
461
|
+
disabledErrorText,
|
|
462
|
+
getI18nText,
|
|
463
|
+
focusedRange,
|
|
464
|
+
preselectedValue,
|
|
465
|
+
animationsDisabled,
|
|
466
|
+
visible
|
|
467
|
+
} = this.asProps;
|
|
468
|
+
return {
|
|
469
|
+
popoverVisible: visible,
|
|
470
|
+
focused: focusedRange === "value" ? true : void 0,
|
|
471
|
+
value: preselectedValue ?? (value == null ? void 0 : value.value),
|
|
472
|
+
onChange: (value2) => this.handlers.preselectedValue(value2),
|
|
473
|
+
onDisplayedPeriodChange,
|
|
474
|
+
locale,
|
|
475
|
+
disabledDates: disabled,
|
|
476
|
+
disabledErrorText,
|
|
477
|
+
children: this.getRangeInput(),
|
|
478
|
+
getI18nText,
|
|
479
|
+
onFocus: () => {
|
|
480
|
+
this.handlers.focusedRange("value");
|
|
481
|
+
},
|
|
482
|
+
animationsDisabled
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
getCompareDateRangeProps() {
|
|
486
|
+
var _a;
|
|
487
|
+
const {
|
|
488
|
+
value,
|
|
489
|
+
onDisplayedPeriodChange,
|
|
490
|
+
locale,
|
|
491
|
+
disabled,
|
|
492
|
+
disabledErrorText,
|
|
493
|
+
getI18nText,
|
|
494
|
+
focusedRange,
|
|
495
|
+
preselectedCompare,
|
|
496
|
+
compareToggle,
|
|
497
|
+
animationsDisabled,
|
|
498
|
+
visible
|
|
499
|
+
} = this.asProps;
|
|
500
|
+
return {
|
|
501
|
+
popoverVisible: visible,
|
|
502
|
+
focused: focusedRange === "compare" ? true : void 0,
|
|
503
|
+
disabled: !(compareToggle ?? ((_a = value == null ? void 0 : value.compare) == null ? void 0 : _a.length)),
|
|
504
|
+
value: preselectedCompare ?? (value == null ? void 0 : value.compare),
|
|
505
|
+
onChange: (value2) => this.handlers.preselectedCompare(value2),
|
|
506
|
+
onDisplayedPeriodChange,
|
|
507
|
+
locale,
|
|
508
|
+
disabledDates: disabled,
|
|
509
|
+
children: this.getRangeInput(),
|
|
510
|
+
getI18nText,
|
|
511
|
+
disabledErrorText,
|
|
512
|
+
onFocus: () => {
|
|
513
|
+
this.handlers.focusedRange("compare");
|
|
514
|
+
},
|
|
515
|
+
animationsDisabled
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
getCompareToggleProps() {
|
|
519
|
+
const {
|
|
520
|
+
getI18nText,
|
|
521
|
+
compareToggle
|
|
522
|
+
} = this.asProps;
|
|
523
|
+
return {
|
|
524
|
+
getI18nText,
|
|
525
|
+
checked: compareToggle,
|
|
526
|
+
onChange: (checked) => {
|
|
527
|
+
if (checked) {
|
|
528
|
+
this.handlers.compareToggle(true);
|
|
529
|
+
this.handlers.focusedRange("compare");
|
|
530
|
+
} else {
|
|
531
|
+
this.handlers.compareToggle(false);
|
|
532
|
+
this.handlers.focusedRange("value");
|
|
533
|
+
this.handlers.preselectedCompare([]);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
getCalendarProps(_props, index) {
|
|
539
|
+
const {
|
|
540
|
+
locale,
|
|
541
|
+
displayedPeriod,
|
|
542
|
+
disabled,
|
|
543
|
+
value,
|
|
544
|
+
onCompareHighlightedChange,
|
|
545
|
+
highlighted,
|
|
546
|
+
compareHighlighted,
|
|
547
|
+
onHighlightedChange,
|
|
548
|
+
preselectedCompare,
|
|
549
|
+
preselectedValue,
|
|
550
|
+
focusedRange,
|
|
551
|
+
getI18nText
|
|
552
|
+
} = this.asProps;
|
|
553
|
+
return {
|
|
554
|
+
locale,
|
|
555
|
+
displayedPeriod: dayjs(displayedPeriod).add(index, this.navigateStep).startOf(this.navigateStep).toDate(),
|
|
556
|
+
disabled,
|
|
557
|
+
onChange: this.handleChange,
|
|
558
|
+
highlighted,
|
|
559
|
+
compareHighlighted,
|
|
560
|
+
onCompareHighlightedChange,
|
|
561
|
+
onHighlightedChange,
|
|
562
|
+
range: focusedRange,
|
|
563
|
+
value: preselectedValue ?? (value == null ? void 0 : value.value),
|
|
564
|
+
compare: preselectedCompare ?? (value == null ? void 0 : value.compare),
|
|
565
|
+
unitRefs: this.unitRefs,
|
|
566
|
+
getI18nText,
|
|
567
|
+
actionsDescribing: index === 0 ? "range-compare" : null,
|
|
568
|
+
tabIndex: index === 0 ? 0 : -1
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
getPopperProps() {
|
|
572
|
+
return {
|
|
573
|
+
p: 0,
|
|
574
|
+
ref: this.popperRef,
|
|
575
|
+
onKeyDown: this.handleKeydownDown("popper")
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
render() {
|
|
579
|
+
var _ref = this.asProps, _ref4;
|
|
580
|
+
const {
|
|
581
|
+
Children,
|
|
582
|
+
styles,
|
|
583
|
+
"aria-label": providedAriaLabel
|
|
584
|
+
} = this.asProps;
|
|
585
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, (_ref4 = sstyled(styles), /* @__PURE__ */ React.createElement(Dropdown, assignProps({
|
|
586
|
+
"use:aria-label": providedAriaLabel,
|
|
587
|
+
"__excludeProps": ["onChange", "value"]
|
|
588
|
+
}, _ref), /* @__PURE__ */ React.createElement(Children, _ref4.cn("Children", {})))));
|
|
589
|
+
}
|
|
590
|
+
}
|
|
571
591
|
_defineProperty(DateRangeComparatorAbstract, "displayName", "DateRangeComparator");
|
|
572
592
|
_defineProperty(DateRangeComparatorAbstract, "style", style);
|
|
573
593
|
_defineProperty(DateRangeComparatorAbstract, "enhance", [i18nEnhance(localizedMessages)]);
|
|
574
|
-
_defineProperty(DateRangeComparatorAbstract, "subtract",
|
|
594
|
+
_defineProperty(DateRangeComparatorAbstract, "subtract", (date, amount, unit) => {
|
|
575
595
|
return dayjs(date).subtract(amount, unit).toDate();
|
|
576
596
|
});
|
|
577
597
|
function Apply(props) {
|
|
578
598
|
var _ref2 = arguments[0];
|
|
579
|
-
|
|
599
|
+
const {
|
|
600
|
+
getI18nText
|
|
601
|
+
} = props;
|
|
580
602
|
return /* @__PURE__ */ React.createElement(Button, assignProps({
|
|
581
603
|
"use": "primary",
|
|
582
604
|
"children": getI18nText("apply")
|
|
@@ -584,7 +606,9 @@ function Apply(props) {
|
|
|
584
606
|
}
|
|
585
607
|
function Reset(props) {
|
|
586
608
|
var _ref3 = arguments[0];
|
|
587
|
-
|
|
609
|
+
const {
|
|
610
|
+
getI18nText
|
|
611
|
+
} = props;
|
|
588
612
|
return /* @__PURE__ */ React.createElement(Button, assignProps({
|
|
589
613
|
"use": "tertiary",
|
|
590
614
|
"theme": "muted",
|
|
@@ -593,7 +617,10 @@ function Reset(props) {
|
|
|
593
617
|
}
|
|
594
618
|
function Trigger(props) {
|
|
595
619
|
var _ref5;
|
|
596
|
-
|
|
620
|
+
const {
|
|
621
|
+
Root: STrigger,
|
|
622
|
+
styles
|
|
623
|
+
} = props;
|
|
597
624
|
return _ref5 = sstyled(styles), /* @__PURE__ */ React.createElement(STrigger, _ref5.cn("STrigger", {
|
|
598
625
|
"render": Dropdown.Trigger,
|
|
599
626
|
"tag": LinkTrigger
|
|
@@ -601,7 +628,11 @@ function Trigger(props) {
|
|
|
601
628
|
}
|
|
602
629
|
function CompareToggle(props) {
|
|
603
630
|
var _ref6;
|
|
604
|
-
|
|
631
|
+
const {
|
|
632
|
+
Root: SCompareToggle,
|
|
633
|
+
styles,
|
|
634
|
+
getI18nText
|
|
635
|
+
} = props;
|
|
605
636
|
return _ref6 = sstyled(styles), /* @__PURE__ */ React.createElement(SCompareToggle, _ref6.cn("SCompareToggle", {
|
|
606
637
|
"render": Checkbox,
|
|
607
638
|
"label": getI18nText("compare")
|
|
@@ -609,7 +640,11 @@ function CompareToggle(props) {
|
|
|
609
640
|
}
|
|
610
641
|
function Header(props) {
|
|
611
642
|
var _ref7;
|
|
612
|
-
|
|
643
|
+
const {
|
|
644
|
+
Root: SRangeComparatorHeader,
|
|
645
|
+
Children,
|
|
646
|
+
styles
|
|
647
|
+
} = props;
|
|
613
648
|
return _ref7 = sstyled(styles), /* @__PURE__ */ React.createElement(SRangeComparatorHeader, _ref7.cn("SRangeComparatorHeader", {
|
|
614
649
|
"render": Flex,
|
|
615
650
|
"gap": 4,
|
|
@@ -618,7 +653,11 @@ function Header(props) {
|
|
|
618
653
|
}
|
|
619
654
|
function Body(props) {
|
|
620
655
|
var _ref8;
|
|
621
|
-
|
|
656
|
+
const {
|
|
657
|
+
Root: SBody,
|
|
658
|
+
Children,
|
|
659
|
+
styles
|
|
660
|
+
} = props;
|
|
622
661
|
return _ref8 = sstyled(styles), /* @__PURE__ */ React.createElement(SBody, _ref8.cn("SBody", {
|
|
623
662
|
"render": Flex,
|
|
624
663
|
"gap": 4
|
|
@@ -626,7 +665,11 @@ function Body(props) {
|
|
|
626
665
|
}
|
|
627
666
|
function Footer(props) {
|
|
628
667
|
var _ref9;
|
|
629
|
-
|
|
668
|
+
const {
|
|
669
|
+
Root: SFooter,
|
|
670
|
+
styles,
|
|
671
|
+
Children
|
|
672
|
+
} = props;
|
|
630
673
|
return _ref9 = sstyled(styles), /* @__PURE__ */ React.createElement(SFooter, _ref9.cn("SFooter", {
|
|
631
674
|
"render": Flex,
|
|
632
675
|
"gap": 2
|