@stenajs-webui/calendar 17.6.0 → 17.9.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/CHANGELOG.md +24 -0
- package/dist/components/calendar/Calendar.d.ts +3 -3
- package/dist/components/calendar/CalendarMonth.d.ts +16 -16
- package/dist/components/calendar/CalendarMonthWithMonthTextHeader.d.ts +6 -6
- package/dist/components/calendar/CalendarTheme.d.ts +57 -57
- package/dist/components/calendar/CalendarWeek.d.ts +18 -18
- package/dist/components/calendar/DisabledDayWrapper.d.ts +7 -7
- package/dist/components/calendar/renderers/CalendarDay.d.ts +3 -3
- package/dist/components/calendar/renderers/WeekDayCell.d.ts +10 -10
- package/dist/components/calendar/renderers/WeekNumberCell.d.ts +13 -13
- package/dist/components/calendar-types/date-range-calendar/DateRangeCalendar.d.ts +11 -11
- package/dist/components/calendar-types/date-range-calendar/hooks/UseDateRangeCalendarState.d.ts +10 -10
- package/dist/components/calendar-types/date-range-calendar/hooks/UseDateRangeSelection.d.ts +3 -3
- package/dist/components/calendar-types/date-range-exclusion-calendar/DateRangeExclusionCalendar.d.ts +7 -7
- package/dist/components/calendar-types/date-range-exclusion-calendar/UseDateRangeExclusionSelection.d.ts +3 -3
- package/dist/components/calendar-types/multi-date-calendar/MultiDateCalendar.d.ts +8 -8
- package/dist/components/calendar-types/multi-date-calendar/UseMultiDateSelection.d.ts +3 -3
- package/dist/components/calendar-types/single-date-calendar/SingleDateCalendar.d.ts +7 -7
- package/dist/components/calendar-types/single-date-calendar/UseSingleDateSelection.d.ts +3 -3
- package/dist/components/calendar-types/single-week-calendar/SingleWeekCalendar.d.ts +8 -8
- package/dist/components/calendar-types/single-week-calendar/UseSingleWeekSelection.d.ts +3 -3
- package/dist/components/input-types/date-input/DateInput.d.ts +52 -52
- package/dist/components/input-types/date-input/UseDateInput.d.ts +6 -6
- package/dist/components/input-types/date-range-dual-text-input/DateRangeDualTextInput.d.ts +15 -15
- package/dist/components/input-types/date-range-dual-text-input/hooks/UseDateRangeEffects.d.ts +2 -2
- package/dist/components/input-types/date-range-dual-text-input/hooks/UseDateRangeHandlers.d.ts +11 -11
- package/dist/components/input-types/date-range-dual-text-input/hooks/UseInputStates.d.ts +17 -17
- package/dist/components/input-types/date-range-dual-text-input/hooks/UseUserInputHandlers.d.ts +13 -13
- package/dist/components/input-types/date-range-input/DateRangeInput.d.ts +51 -51
- package/dist/components/input-types/date-range-input/hooks/UseDateRangeInput.d.ts +16 -16
- package/dist/components/input-types/date-text-input/DateTextInput.d.ts +28 -28
- package/dist/components/input-types/date-time-input/DateTimeInput.d.ts +12 -12
- package/dist/components/input-types/date-time-input/hooks/UseDateRangeEffects.d.ts +2 -2
- package/dist/components/input-types/date-time-input/hooks/UseDateRangeHandlers.d.ts +11 -11
- package/dist/components/input-types/date-time-input/hooks/UseInputStates.d.ts +22 -22
- package/dist/components/input-types/date-time-input/hooks/UseUserInputHandlers.d.ts +12 -12
- package/dist/components/input-types/time-text-input/TimeTextInput.d.ts +15 -15
- package/dist/config/DefaultMaxDate.d.ts +1 -1
- package/dist/config/DefaultPopoverPlacement.d.ts +2 -2
- package/dist/features/calendar-with-month-year-pickers/CalendarPanelType.d.ts +1 -1
- package/dist/features/calendar-with-month-year-pickers/CalendarWithMonthYearPickers.d.ts +13 -13
- package/dist/features/date-range/hooks/UseDateRangeOnClickDayHandler.d.ts +4 -4
- package/dist/features/dual-text-input/DualTextInput.d.ts +44 -44
- package/dist/features/internal-panel-state/UseCalendarPopoverUpdater.d.ts +4 -4
- package/dist/features/internal-panel-state/UseInternalPanelState.d.ts +9 -9
- package/dist/features/month-picker/MonthPicker.d.ts +6 -6
- package/dist/features/month-picker/MonthPickerCell.d.ts +8 -8
- package/dist/features/month-switcher/CalendarWithMonthSwitcher.d.ts +15 -15
- package/dist/features/month-switcher/MonthSwitcherBelow.d.ts +12 -12
- package/dist/features/month-switcher/hooks/UseSelectedMonthStepperLogic.d.ts +6 -6
- package/dist/features/preset-picker/CalendarPreset.d.ts +14 -14
- package/dist/features/preset-picker/PresetFactory.d.ts +2 -2
- package/dist/features/preset-picker/PresetPicker.d.ts +6 -6
- package/dist/features/time-picker/TimePicker.d.ts +5 -5
- package/dist/features/time-picker/TimePickerCell.d.ts +10 -10
- package/dist/features/time-picker/TimePickerColumn.d.ts +10 -10
- package/dist/features/today-state/UseHighlightToday.d.ts +2 -2
- package/dist/features/year-picker/YearPicker.d.ts +6 -6
- package/dist/features/year-picker/YearPickerCell.d.ts +7 -7
- package/dist/index.d.ts +32 -32
- package/dist/index.es.js +2866 -2058
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1 -2148
- package/dist/index.js.map +1 -1
- package/dist/types/CalendarTypes.d.ts +133 -133
- package/dist/types/DateRange.d.ts +16 -16
- package/dist/types/InternalPanelAndFocusStateProps.d.ts +3 -3
- package/dist/util/calendar/CalendarDataFactory.d.ts +64 -64
- package/dist/util/calendar/StateHelper.d.ts +3 -3
- package/dist/util/calendar/StateModifier.d.ts +11 -11
- package/dist/util/date/DateFormats.d.ts +11 -11
- package/dist/util/date/DateListTools.d.ts +3 -3
- package/dist/util/date/DateMinMaxValidator.d.ts +1 -1
- package/dist/util/date-range/DateRangeTransformer.d.ts +3 -3
- package/dist/util/date-range/DateRangeValidator.d.ts +4 -4
- package/dist/util/time/OverlappingTimesValidator.d.ts +11 -11
- package/dist/util/time/TimeStringFormatValidator.d.ts +8 -8
- package/dist/util/time/TimeTransformer.d.ts +8 -8
- package/package.json +10 -11
- package/dist/components/calendar-types/date-range-calendar/DateRangeCalendar.stories.d.ts +0 -20
- package/dist/components/calendar-types/date-range-exclusion-calendar/DateRangeExclusionCalendar.stories.d.ts +0 -17
- package/dist/components/calendar-types/multi-date-calendar/MultiDateCalendar.stories.d.ts +0 -15
- package/dist/components/calendar-types/multi-date-calendar/__tests__/UseMultiDateSelection.test.d.ts +0 -1
- package/dist/components/calendar-types/single-date-calendar/SingleDateCalendar.stories.d.ts +0 -17
- package/dist/components/calendar-types/single-week-calendar/SingleWeekCalendar.stories.d.ts +0 -8
- package/dist/components/input-types/date-input/DateInput.stories.d.ts +0 -19
- package/dist/components/input-types/date-range-dual-text-input/DateRangeDualTextInput.stories.d.ts +0 -18
- package/dist/components/input-types/date-range-input/DateRangeInput.stories.d.ts +0 -17
- package/dist/components/input-types/date-text-input/DateTextInput.stories.d.ts +0 -19
- package/dist/components/input-types/date-time-input/DateTimeInput.stories.d.ts +0 -14
- package/dist/components/input-types/time-text-input/TimeTextInput.stories.d.ts +0 -15
- package/dist/features/month-picker/MonthPicker.stories.d.ts +0 -7
- package/dist/features/preset-picker/PresetPicker.stories.d.ts +0 -7
- package/dist/features/time-picker/TimePicker.stories.d.ts +0 -7
- package/dist/features/year-picker/YearPicker.stories.d.ts +0 -12
- package/dist/util/calendar/__tests__/CalendarDataFactory.test.d.ts +0 -1
- package/dist/util/calendar/__tests__/StateHelper.test.d.ts +0 -1
- package/dist/util/calendar/__tests__/StateModifier.test.d.ts +0 -1
- package/dist/util/date/__tests__/DateListTools.test.d.ts +0 -1
- package/dist/util/date/__tests__/DateMinMaxValidator.test.d.ts +0 -1
- package/dist/util/date-range/__tests__/DateRangeValidator.test.d.ts +0 -1
- package/dist/util/time/__tests__/OverlappingTimesValidator.test.d.ts +0 -1
- package/dist/util/time/__tests__/TimeStringFormatValidator.test.d.ts +0 -1
- package/dist/util/time/__tests__/TimeTransformer.test.d.ts +0 -1
package/dist/index.es.js
CHANGED
|
@@ -1,2072 +1,2880 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
1
|
+
(function(){ try {var elementStyle = document.createElement('style'); elementStyle.appendChild(document.createTextNode("._calendar_1w0de_1{--swui-calendar-day-width: 40px;--swui-calendar-day-height: 38px;--swui-calendar-day-border-radius: 4px;--swui-calendar-week-number-bg-color: transparent;--swui-calendar-week-number-text-color: var(--lhds-color-ui-500);--swui-calendar-week-number-clickable-text-color: var(--lhds-color-ui-500);--swui-calendar-week-day-text-color: var(--lhds-color-ui-500);--swui-calendar-week-day-clickable-text-color: var(--lhds-color-ui-500);--swui-calendar-wrapper-selected-border: var(--swui-primary-action-color);--swui-calendar-wrapper-selected-background: var(--swui-primary-action-color);--swui-calendar-wrapper-range-border: var(--lhds-color-blue-100);--swui-calendar-wrapper-range-background: var(--lhds-color-blue-100);--swui-calendar-wrapper-today-border: var(--lhds-color-ui-200);--swui-calendar-wrapper-today-background: var(--lhds-color-ui-200);--swui-calendar-text-selected-color: #fff;--swui-calendar-text-disabled-color: var(--swui-text-disabled-color);--swui-calendar-text-in-other-month-color: var(--swui-text-disabled-color)}._calendar_1w0de_1 table{border-spacing:0 4px}._calendar_1w0de_1 span{line-height:100%}._calendar_1w0de_1 tr td:last-child{border-top-right-radius:var(--swui-calendar-day-border-radius);border-bottom-right-radius:var(--swui-calendar-day-border-radius)}._calendar_1w0de_1 tr td:nth-child(2){border-top-left-radius:var(--swui-calendar-day-border-radius);border-bottom-left-radius:var(--swui-calendar-day-border-radius)}._calendar_1w0de_1 td{padding:0;width:var(--swui-calendar-day-width);height:var(--swui-calendar-day-height)}._timePicker_1w05d_1{overflow:hidden;width:180px}._timePickerColumn_1w05d_6{overflow-y:hidden;flex:1}._timePickerColumn_1w05d_6:hover{overflow-y:scroll}")); document.head.appendChild(elementStyle);} catch(e) {console.error('vite-plugin-css-injected-by-js', e);} })();import { FlatButton, stenaAngleLeft, stenaAngleRight, PrimaryButton, stenaCalendar, Icon, stenaClock, stenaAngleDown, stenaArrowRight } from "@stenajs-webui/elements";
|
|
2
|
+
import { Box, Text, Clickable, Row, Space, Spacing, Indent, Column, SeparatorLine, parseIntElseUndefined, useBoolean, useDelayedFalse } from "@stenajs-webui/core";
|
|
3
|
+
import { isAfter, eachDayOfInterval, isSameDay, endOfMonth, startOfMonth, min, addDays, max, subDays, format, getISOWeek, getDate, startOfISOWeek, addWeeks, getMonth, getYear, getISODay, addHours, isBefore, parse, addMonths, addYears, subMonths, subYears, isValid } from "date-fns";
|
|
4
|
+
import { last, chunk, range, debounce } from "lodash";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { useMemo, useCallback, useState, useEffect, useRef } from "react";
|
|
7
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
8
|
+
import styled from "@emotion/styled";
|
|
9
|
+
import { faAngleDoubleLeft } from "@fortawesome/free-solid-svg-icons/faAngleDoubleLeft";
|
|
10
|
+
import { faAngleDoubleRight } from "@fortawesome/free-solid-svg-icons/faAngleDoubleRight";
|
|
11
|
+
import { faCaretLeft } from "@fortawesome/free-solid-svg-icons/faCaretLeft";
|
|
12
|
+
import { faCaretRight } from "@fortawesome/free-solid-svg-icons/faCaretRight";
|
|
13
|
+
import { TextInput, TextInputBox } from "@stenajs-webui/forms";
|
|
14
|
+
import { useTippyInstance, Popover } from "@stenajs-webui/tooltip";
|
|
15
|
+
import { cssColor } from "@stenajs-webui/theme";
|
|
16
|
+
import { faLongArrowAltRight } from "@fortawesome/free-solid-svg-icons/faLongArrowAltRight";
|
|
17
|
+
const DateFormats = {
|
|
18
|
+
yearAndMonth: "yyyy-MM",
|
|
19
|
+
fullDate: "yyyy-MM-dd",
|
|
20
|
+
fullMonthName: "LLLL",
|
|
21
|
+
fullDateAndTime: "yyyy-MM-dd HH:mm",
|
|
22
|
+
fullDateAndTimeSystem: "yyyy-MM-ddTHH:MM",
|
|
23
|
+
weekDayName: "EEEE",
|
|
24
|
+
weekDayNameShort: "EEE",
|
|
25
|
+
dateAndMonth: "d MMM",
|
|
26
|
+
monthAndDate: "MMM do"
|
|
27
|
+
};
|
|
28
|
+
const buildDayStateForDateRange = (statePerMonth = {}, start, end) => {
|
|
29
|
+
if (start && end && isAfter(end, start)) {
|
|
30
|
+
return eachDayOfInterval({ start, end }).reduce((result, date) => {
|
|
31
|
+
const isFirstInRange = isSameDay(date, start);
|
|
32
|
+
const isLastInRange = isSameDay(date, end);
|
|
33
|
+
const highlights = isFirstInRange ? ["selected", "selectedStart", "range"] : isLastInRange ? ["selected", "selectedEnd", "range"] : ["range"];
|
|
34
|
+
return addDayStateHighlights(result, date, highlights);
|
|
35
|
+
}, statePerMonth);
|
|
36
|
+
}
|
|
37
|
+
let state = statePerMonth;
|
|
38
|
+
if (start) {
|
|
39
|
+
state = addDayStateHighlights(state, start, ["selected", "singleSelected"]);
|
|
40
|
+
}
|
|
41
|
+
if (end) {
|
|
42
|
+
state = addDayStateHighlights(state, end, ["selected", "singleSelected"]);
|
|
43
|
+
}
|
|
44
|
+
return state;
|
|
45
|
+
};
|
|
46
|
+
const buildDayStateForSingleMonth = (statePerMonth = {}, start, end, dateInFocus) => buildDayStateForRange(statePerMonth, start, end, startOfMonth(dateInFocus), endOfMonth(dateInFocus));
|
|
47
|
+
const buildDayStateForRange = (statePerMonth = {}, start, end, startLimit, endLimit) => {
|
|
48
|
+
if (start && end) {
|
|
49
|
+
return buildDayStateForDateRange(statePerMonth, max([start, subDays(startLimit, 1)]), min([end, addDays(endLimit, 1)]));
|
|
50
|
+
} else {
|
|
51
|
+
return buildDayStateForDateRange(statePerMonth, start, end);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const setDayStateValue = (state, date, values) => {
|
|
55
|
+
const monthString = format(date, DateFormats.yearAndMonth);
|
|
56
|
+
const weekNumber = getISOWeek(date);
|
|
57
|
+
const dayInMonth = getDate(date);
|
|
58
|
+
return {
|
|
59
|
+
...state,
|
|
60
|
+
[monthString]: {
|
|
61
|
+
...state && state[monthString],
|
|
62
|
+
[weekNumber]: {
|
|
63
|
+
...state && state[monthString] && state[monthString][weekNumber],
|
|
64
|
+
[dayInMonth]: {
|
|
65
|
+
...state && state[monthString] && state[monthString][weekNumber] && state[monthString][weekNumber][dayInMonth],
|
|
66
|
+
...values
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
const setDayStateValueFunction = (state, date, setter) => {
|
|
73
|
+
const monthString = format(date, DateFormats.yearAndMonth);
|
|
74
|
+
const weekNumber = getISOWeek(date);
|
|
75
|
+
const dayInMonth = getDate(date);
|
|
76
|
+
return {
|
|
77
|
+
...state,
|
|
78
|
+
[monthString]: {
|
|
79
|
+
...state && state[monthString],
|
|
80
|
+
[weekNumber]: {
|
|
81
|
+
...state && state[monthString] && state[monthString][weekNumber],
|
|
82
|
+
[dayInMonth]: {
|
|
83
|
+
...state && state[monthString] && state[monthString][weekNumber] && state[monthString][weekNumber][dayInMonth],
|
|
84
|
+
...setter(state && state[monthString] && state[monthString][weekNumber] && state[monthString][weekNumber][dayInMonth])
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
const addDayStateHighlights = (calendarState, date, highlights) => {
|
|
91
|
+
const month = date.getMonth() + 1;
|
|
92
|
+
const monthString = `${date.getFullYear()}-${month < 10 ? "0" : ""}${month}`;
|
|
93
|
+
const weekNumber = getISOWeek(date);
|
|
94
|
+
const dayInMonth = getDate(date);
|
|
95
|
+
const dayState = calendarState && calendarState[monthString] && calendarState[monthString][weekNumber] && calendarState[monthString][weekNumber][dayInMonth];
|
|
96
|
+
return {
|
|
97
|
+
...calendarState,
|
|
98
|
+
[monthString]: {
|
|
99
|
+
...calendarState && calendarState[monthString],
|
|
100
|
+
[weekNumber]: {
|
|
101
|
+
...calendarState && calendarState[monthString] && calendarState[monthString][weekNumber],
|
|
102
|
+
[dayInMonth]: addDayStateHighlightsOnSingleDay(dayState, highlights)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
const addDayStateHighlightsOnSingleDay = (dayState, highlights) => {
|
|
108
|
+
var _a;
|
|
109
|
+
return {
|
|
110
|
+
...dayState,
|
|
111
|
+
highlights: [...(_a = dayState == null ? void 0 : dayState.highlights) != null ? _a : [], ...highlights]
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
const addWeekStateHighlights = (calendarState, week, highlights) => {
|
|
115
|
+
const date = week.days[0].date;
|
|
116
|
+
const month = date.getMonth() + 1;
|
|
117
|
+
const monthString = `${date.getFullYear()}-${month < 10 ? "0" : ""}${month}`;
|
|
118
|
+
const weekNumber = week.weekNumber;
|
|
119
|
+
let state = calendarState;
|
|
120
|
+
week.days.forEach((day) => {
|
|
121
|
+
state = addDayStateHighlights(state, day.date, highlights);
|
|
122
|
+
});
|
|
123
|
+
const weekState = state && state[monthString] ? state[monthString][weekNumber] : void 0;
|
|
124
|
+
const newHighlights = weekState && weekState.highlights ? [...weekState.highlights, ...highlights] : highlights;
|
|
125
|
+
const newWeekState = {
|
|
126
|
+
...weekState,
|
|
127
|
+
highlights: newHighlights
|
|
128
|
+
};
|
|
129
|
+
return {
|
|
130
|
+
...state,
|
|
131
|
+
[monthString]: {
|
|
132
|
+
...calendarState && calendarState[monthString],
|
|
133
|
+
[weekNumber]: newWeekState
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
const addWeekRangeHighlights = (calendarState, week) => {
|
|
138
|
+
var _a;
|
|
139
|
+
if (!week.days.length) {
|
|
140
|
+
return { ...calendarState };
|
|
141
|
+
}
|
|
142
|
+
const startDate = week.days[0].date;
|
|
143
|
+
const endDate = (_a = last(week.days)) == null ? void 0 : _a.date;
|
|
144
|
+
return {
|
|
145
|
+
...buildDayStateForDateRange(calendarState, startDate, endDate)
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
const useHighlightToday = (enabled, statePerMonth) => {
|
|
149
|
+
return useMemo(() => {
|
|
150
|
+
return enabled ? addDayStateHighlights(statePerMonth, new Date(), ["today"]) : statePerMonth;
|
|
151
|
+
}, [enabled, statePerMonth]);
|
|
152
|
+
};
|
|
153
|
+
var Month = /* @__PURE__ */ ((Month2) => {
|
|
154
|
+
Month2[Month2["JANUARY"] = 0] = "JANUARY";
|
|
155
|
+
Month2[Month2["FEBRUARY"] = 1] = "FEBRUARY";
|
|
156
|
+
Month2[Month2["MARCH"] = 2] = "MARCH";
|
|
157
|
+
Month2[Month2["APRIL"] = 3] = "APRIL";
|
|
158
|
+
Month2[Month2["MAY"] = 4] = "MAY";
|
|
159
|
+
Month2[Month2["JUNE"] = 5] = "JUNE";
|
|
160
|
+
Month2[Month2["JULY"] = 6] = "JULY";
|
|
161
|
+
Month2[Month2["AUGUST"] = 7] = "AUGUST";
|
|
162
|
+
Month2[Month2["SEPTEMBER"] = 8] = "SEPTEMBER";
|
|
163
|
+
Month2[Month2["OCTOBER"] = 9] = "OCTOBER";
|
|
164
|
+
Month2[Month2["NOVEMBER"] = 10] = "NOVEMBER";
|
|
165
|
+
Month2[Month2["DECEMBER"] = 11] = "DECEMBER";
|
|
166
|
+
return Month2;
|
|
167
|
+
})(Month || {});
|
|
168
|
+
var WeekDay = /* @__PURE__ */ ((WeekDay2) => {
|
|
169
|
+
WeekDay2[WeekDay2["SUNDAY"] = 0] = "SUNDAY";
|
|
170
|
+
WeekDay2[WeekDay2["MONDAY"] = 1] = "MONDAY";
|
|
171
|
+
WeekDay2[WeekDay2["TUESDAY"] = 2] = "TUESDAY";
|
|
172
|
+
WeekDay2[WeekDay2["WEDNESDAY"] = 3] = "WEDNESDAY";
|
|
173
|
+
WeekDay2[WeekDay2["THURSDAY"] = 4] = "THURSDAY";
|
|
174
|
+
WeekDay2[WeekDay2["FRIDAY"] = 5] = "FRIDAY";
|
|
175
|
+
WeekDay2[WeekDay2["SATURDAY"] = 6] = "SATURDAY";
|
|
176
|
+
return WeekDay2;
|
|
177
|
+
})(WeekDay || {});
|
|
178
|
+
const getMonthsInYear = (year, startMonth, numMonths) => {
|
|
179
|
+
const months = [];
|
|
180
|
+
for (let i = 0; i < numMonths; i++) {
|
|
181
|
+
months.push(getMonthInYear(year, startMonth + i));
|
|
182
|
+
}
|
|
183
|
+
return months;
|
|
184
|
+
};
|
|
185
|
+
const getMonthInYear = (year, month) => {
|
|
186
|
+
const yearToUse = year + Math.floor(month / 12);
|
|
187
|
+
const monthToUse = month % 12;
|
|
188
|
+
const firstDayOfMonth = new Date(yearToUse, monthToUse, 1);
|
|
189
|
+
return {
|
|
190
|
+
monthString: format(firstDayOfMonth, DateFormats.yearAndMonth),
|
|
191
|
+
name: format(firstDayOfMonth, DateFormats.fullMonthName),
|
|
192
|
+
year: yearToUse,
|
|
193
|
+
monthInYear: monthToUse,
|
|
194
|
+
weeks: getWeeksForMonth(yearToUse, monthToUse)
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
const getWeeksForMonth = (year, month, forceSixWeeks = true) => {
|
|
198
|
+
const firstDayOfMonth = new Date(year, month, 1);
|
|
199
|
+
const firstDayOfFirstWeek = startOfISOWeek(firstDayOfMonth);
|
|
200
|
+
const weeks = [];
|
|
201
|
+
for (let i = 0; i < 6; i++) {
|
|
202
|
+
const week = getWeekForDate(addWeeks(firstDayOfFirstWeek, i));
|
|
203
|
+
if (i > 0 && week.startMonth !== month && !forceSixWeeks) {
|
|
204
|
+
return weeks;
|
|
205
|
+
}
|
|
206
|
+
weeks.push(week);
|
|
207
|
+
}
|
|
208
|
+
return weeks;
|
|
209
|
+
};
|
|
210
|
+
const getWeekForDate = (firstDayOfWeek) => {
|
|
211
|
+
const isLastWeekOfMonth = getMonth(addDays(firstDayOfWeek, 7)) !== getMonth(firstDayOfWeek);
|
|
212
|
+
return {
|
|
213
|
+
weekNumber: getISOWeek(firstDayOfWeek),
|
|
214
|
+
startMonth: getMonth(firstDayOfWeek),
|
|
215
|
+
startYear: getYear(firstDayOfWeek),
|
|
216
|
+
endMonth: getMonth(addDays(firstDayOfWeek, 6)),
|
|
217
|
+
endYear: getYear(addDays(firstDayOfWeek, 6)),
|
|
218
|
+
days: getDaysForWeekForDate(firstDayOfWeek),
|
|
219
|
+
isLastWeekOfMonth
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
const createDay = (date) => {
|
|
223
|
+
const dayOfWeek = getISODay(date);
|
|
224
|
+
return {
|
|
225
|
+
date,
|
|
226
|
+
name: format(date, "EEE"),
|
|
227
|
+
dateString: format(addHours(date, 12), DateFormats.fullDate),
|
|
228
|
+
weekNumber: getISOWeek(date),
|
|
229
|
+
year: getYear(date),
|
|
230
|
+
month: getMonth(date),
|
|
231
|
+
dayOfMonth: getDate(date),
|
|
232
|
+
dayOfWeek,
|
|
233
|
+
isFirstDayOfWeek: dayOfWeek === 1,
|
|
234
|
+
isLastDayOfWeek: dayOfWeek === 7,
|
|
235
|
+
isFirstDayOfMonth: isSameDay(startOfMonth(date), date),
|
|
236
|
+
isLastDayOfMonth: isSameDay(endOfMonth(date), date)
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
const getDaysForWeekForDate = (firstDayOfWeek) => {
|
|
240
|
+
return eachDayOfInterval({
|
|
241
|
+
start: firstDayOfWeek,
|
|
242
|
+
end: addDays(firstDayOfWeek, 6)
|
|
243
|
+
}).map(createDay);
|
|
244
|
+
};
|
|
245
|
+
const getStartDateOfISOWeek = (weekNumber, year) => {
|
|
246
|
+
const simple = new Date(year, 0, 1 + (weekNumber - 1) * 7);
|
|
247
|
+
const dayOfWeek = simple.getDay();
|
|
248
|
+
const isoWeekStart = simple;
|
|
249
|
+
if (dayOfWeek <= 4) {
|
|
250
|
+
isoWeekStart.setDate(simple.getDate() - simple.getDay() + 1);
|
|
251
|
+
} else {
|
|
252
|
+
isoWeekStart.setDate(simple.getDate() + 8 - simple.getDay());
|
|
253
|
+
}
|
|
254
|
+
return isoWeekStart;
|
|
255
|
+
};
|
|
256
|
+
const calculateOverflowingMonth = (year, month) => {
|
|
257
|
+
if (month > 11) {
|
|
258
|
+
return { year: year + Math.floor(month / 12), month: month % 12 };
|
|
259
|
+
}
|
|
260
|
+
if (month < 0) {
|
|
261
|
+
return { year: year + Math.floor(month / 12), month: 12 + month % 12 };
|
|
262
|
+
}
|
|
263
|
+
return { year, month };
|
|
264
|
+
};
|
|
265
|
+
const dayHasHighlight = (dayState, defaultHighlights, highlight) => {
|
|
266
|
+
if (defaultHighlights && defaultHighlights.indexOf(highlight) >= 0) {
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
if (dayState && dayState.highlights && dayState.highlights.indexOf(highlight) >= 0) {
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
return false;
|
|
273
|
+
};
|
|
274
|
+
const dayHighlightSelect = (dayState, defaultHighlights, highlightsOrBoolean, returnValues, fallbackValue) => {
|
|
275
|
+
if (highlightsOrBoolean.length !== returnValues.length) {
|
|
276
|
+
throw new Error("Select highlight failed, number of values do not equal number of highlights.");
|
|
277
|
+
}
|
|
278
|
+
if (highlightsOrBoolean.length === 0) {
|
|
279
|
+
return fallbackValue;
|
|
280
|
+
}
|
|
281
|
+
for (let i = 0; i < highlightsOrBoolean.length; i++) {
|
|
282
|
+
if (typeof highlightsOrBoolean[i] === "boolean" && highlightsOrBoolean[i]) {
|
|
283
|
+
return returnValues[i];
|
|
284
|
+
}
|
|
285
|
+
if (typeof highlightsOrBoolean[i] === "string" && dayHasHighlight(dayState, defaultHighlights, highlightsOrBoolean[i])) {
|
|
286
|
+
return returnValues[i];
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return fallbackValue;
|
|
290
|
+
};
|
|
291
|
+
const defaultWrapperStyleProvider = ({
|
|
292
|
+
selectedBackground,
|
|
293
|
+
todayBackground,
|
|
294
|
+
rangeBackground,
|
|
295
|
+
borderColor = "transparent"
|
|
296
|
+
}) => (defaultHighlights, dayState, day, _, month) => {
|
|
297
|
+
let style = {};
|
|
298
|
+
const backgroundColor = dayHighlightSelect(dayState, defaultHighlights, ["selected", "range", "today", day.month === month.monthInYear], [selectedBackground, rangeBackground, todayBackground, "#fff"], "transparent");
|
|
299
|
+
return {
|
|
300
|
+
...style,
|
|
301
|
+
backgroundColor,
|
|
302
|
+
borderTopLeftRadius: dayHighlightSelect(dayState, defaultHighlights, ["selectedStart", "singleSelected"], ["var(--swui-calendar-day-border-radius)", "var(--swui-calendar-day-border-radius)"], borderColor),
|
|
303
|
+
borderBottomLeftRadius: dayHighlightSelect(dayState, defaultHighlights, ["selectedStart", "singleSelected"], ["var(--swui-calendar-day-border-radius)", "var(--swui-calendar-day-border-radius)"], borderColor),
|
|
304
|
+
borderTopRightRadius: dayHighlightSelect(dayState, defaultHighlights, ["selectedEnd", "singleSelected"], ["var(--swui-calendar-day-border-radius)", "var(--swui-calendar-day-border-radius)"], borderColor),
|
|
305
|
+
borderBottomRightRadius: dayHighlightSelect(dayState, defaultHighlights, ["selectedEnd", "singleSelected"], ["var(--swui-calendar-day-border-radius)", "var(--swui-calendar-day-border-radius)"], borderColor),
|
|
306
|
+
boxSizing: "border-box"
|
|
307
|
+
};
|
|
308
|
+
};
|
|
309
|
+
const defaultTextPropsProvider = ({
|
|
310
|
+
selectedColor,
|
|
311
|
+
disabledColor,
|
|
312
|
+
inOtherMonthColor,
|
|
313
|
+
rangeTextColor
|
|
314
|
+
}) => {
|
|
315
|
+
return (defaultHighlights, dayState, day, _, month) => {
|
|
316
|
+
const isOtherMonth = day.month !== month.monthInYear;
|
|
317
|
+
const color = dayHighlightSelect(dayState, defaultHighlights, [isOtherMonth, "selected", "range", "enabled", "disabled"], [inOtherMonthColor, selectedColor, rangeTextColor, void 0, disabledColor]);
|
|
318
|
+
return {
|
|
319
|
+
color
|
|
320
|
+
};
|
|
321
|
+
};
|
|
322
|
+
};
|
|
323
|
+
const defaultCalendarTheme = {
|
|
324
|
+
width: "var(--swui-calendar-day-width)",
|
|
325
|
+
height: "var(--swui-calendar-day-height)",
|
|
326
|
+
WeekNumber: {
|
|
327
|
+
backgroundColor: "var(--swui-calendar-week-number-bg-color)",
|
|
328
|
+
textColor: "var(--swui-calendar-week-number-text-color)",
|
|
329
|
+
clickableTextColor: "var(--swui-calendar-week-number-clickable-text-color)",
|
|
330
|
+
show: true
|
|
331
|
+
},
|
|
332
|
+
WeekDay: {
|
|
333
|
+
textColor: "var(--swui-calendar-week-day-text-color)",
|
|
334
|
+
clickableTextColor: "var(--swui-calendar-week-day-clickable-text-color)"
|
|
335
|
+
},
|
|
336
|
+
CalendarDay: {
|
|
337
|
+
tdStyle: defaultWrapperStyleProvider({
|
|
338
|
+
selectedBackground: "var(--swui-calendar-wrapper-selected-background)",
|
|
339
|
+
rangeBackground: "var(--swui-calendar-wrapper-range-background)",
|
|
340
|
+
todayBackground: "var(--swui-calendar-wrapper-today-background)"
|
|
341
|
+
}),
|
|
342
|
+
textProps: defaultTextPropsProvider({
|
|
343
|
+
selectedColor: "var(--swui-calendar-text-selected-color)",
|
|
344
|
+
disabledColor: "var(--swui-calendar-text-disabled-color)",
|
|
345
|
+
inOtherMonthColor: "var(--swui-calendar-text-in-other-month-color)"
|
|
346
|
+
})
|
|
347
|
+
},
|
|
348
|
+
CalendarMonth: {
|
|
349
|
+
headerTextColor: "var(--swui-calendar-week-day-text-color)"
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
const extranetCalendarTheme = {
|
|
353
|
+
...defaultCalendarTheme,
|
|
354
|
+
width: "37px",
|
|
355
|
+
height: "37px"
|
|
356
|
+
};
|
|
357
|
+
const isDateInMinMaxRange = (date, min2, max2) => {
|
|
358
|
+
if (min2 && isBefore(date, min2)) {
|
|
359
|
+
return isSameDay(date, min2);
|
|
360
|
+
}
|
|
361
|
+
if (max2 && isAfter(date, max2)) {
|
|
362
|
+
return isSameDay(date, max2);
|
|
363
|
+
}
|
|
364
|
+
return true;
|
|
365
|
+
};
|
|
366
|
+
const DisabledDayWrapper = function DisabledDayWrapper2({
|
|
367
|
+
dayComponent: DayComponent,
|
|
368
|
+
minDate,
|
|
369
|
+
maxDate,
|
|
370
|
+
dayState,
|
|
371
|
+
day,
|
|
372
|
+
...props
|
|
373
|
+
}) {
|
|
374
|
+
const activeDayState = useMemo(() => !isDateInMinMaxRange(day.date, minDate, maxDate) ? addDayStateHighlightsOnSingleDay(dayState, ["disabled"]) : dayState, [day.date, dayState, maxDate, minDate]);
|
|
375
|
+
return /* @__PURE__ */ jsx(DayComponent, {
|
|
376
|
+
day,
|
|
377
|
+
...props,
|
|
378
|
+
dayState: activeDayState
|
|
379
|
+
});
|
|
380
|
+
};
|
|
381
|
+
const WeekNumberCell = ({
|
|
382
|
+
onClickWeek,
|
|
383
|
+
theme,
|
|
384
|
+
week,
|
|
385
|
+
background,
|
|
386
|
+
backgroundColor,
|
|
387
|
+
prefix
|
|
388
|
+
}) => {
|
|
389
|
+
const content = /* @__PURE__ */ jsxs(Box, {
|
|
390
|
+
width: theme.width,
|
|
391
|
+
height: theme.height,
|
|
392
|
+
justifyContent: "center",
|
|
393
|
+
alignItems: "center",
|
|
394
|
+
children: [background && /* @__PURE__ */ jsx(Box, {
|
|
395
|
+
position: "absolute",
|
|
396
|
+
children: background
|
|
397
|
+
}), /* @__PURE__ */ jsx(Box, {
|
|
398
|
+
position: "absolute",
|
|
399
|
+
children: /* @__PURE__ */ jsxs(Text, {
|
|
400
|
+
color: onClickWeek ? theme.WeekNumber.clickableTextColor : theme.WeekNumber.textColor,
|
|
401
|
+
children: [prefix, week.weekNumber]
|
|
402
|
+
})
|
|
403
|
+
})]
|
|
404
|
+
});
|
|
405
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
406
|
+
background: backgroundColor || theme.WeekNumber.backgroundColor,
|
|
407
|
+
position: "relative",
|
|
408
|
+
children: onClickWeek ? /* @__PURE__ */ jsx(Clickable, {
|
|
409
|
+
borderRadius: "var(--swui-calendar-day-border-radius)",
|
|
410
|
+
onClick: (ev) => onClickWeek(week, ev),
|
|
411
|
+
disableFocusHighlight: !onClickWeek,
|
|
412
|
+
children: content
|
|
413
|
+
}) : content
|
|
414
|
+
});
|
|
415
|
+
};
|
|
416
|
+
function CalendarWeek({
|
|
417
|
+
week,
|
|
418
|
+
month,
|
|
419
|
+
dayComponent,
|
|
420
|
+
statePerWeekDay,
|
|
421
|
+
userDataPerWeekDay,
|
|
422
|
+
minDate,
|
|
423
|
+
maxDate,
|
|
424
|
+
onClickWeek,
|
|
425
|
+
onClickDay,
|
|
426
|
+
theme,
|
|
427
|
+
renderWeekNumber,
|
|
428
|
+
extraDayContent,
|
|
429
|
+
defaultHighlights
|
|
430
|
+
}) {
|
|
431
|
+
return /* @__PURE__ */ jsxs("tr", {
|
|
432
|
+
children: [theme.WeekNumber.show && /* @__PURE__ */ jsx("td", {
|
|
433
|
+
children: renderWeekNumber ? renderWeekNumber(week, theme, onClickWeek) : /* @__PURE__ */ jsx(WeekNumberCell, {
|
|
434
|
+
week,
|
|
435
|
+
onClickWeek,
|
|
436
|
+
theme
|
|
437
|
+
})
|
|
438
|
+
}), week.days.map((day) => /* @__PURE__ */ jsx(DisabledDayWrapper, {
|
|
439
|
+
dayComponent,
|
|
440
|
+
day,
|
|
441
|
+
week,
|
|
442
|
+
month,
|
|
443
|
+
dayState: statePerWeekDay && statePerWeekDay[day.dayOfMonth],
|
|
444
|
+
userData: userDataPerWeekDay && userDataPerWeekDay[day.dayOfMonth],
|
|
445
|
+
onClickDay,
|
|
446
|
+
theme,
|
|
447
|
+
extraDayContent,
|
|
448
|
+
defaultHighlights,
|
|
449
|
+
minDate,
|
|
450
|
+
maxDate
|
|
451
|
+
}, day.dateString))]
|
|
452
|
+
}, week.weekNumber);
|
|
63
453
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
startMonth: getMonth(firstDayOfWeek),
|
|
251
|
-
startYear: getYear(firstDayOfWeek),
|
|
252
|
-
endMonth: getMonth(addDays(firstDayOfWeek, 6)),
|
|
253
|
-
endYear: getYear(addDays(firstDayOfWeek, 6)),
|
|
254
|
-
days: getDaysForWeekForDate(firstDayOfWeek),
|
|
255
|
-
isLastWeekOfMonth: isLastWeekOfMonth,
|
|
256
|
-
};
|
|
257
|
-
};
|
|
258
|
-
var createDay = function (date) {
|
|
259
|
-
var dayOfWeek = getISODay(date);
|
|
260
|
-
return {
|
|
261
|
-
date: date,
|
|
262
|
-
name: format(date, "EEE"),
|
|
263
|
-
dateString: format(addHours(date, 12), DateFormats.fullDate),
|
|
264
|
-
weekNumber: getISOWeek(date),
|
|
265
|
-
year: getYear(date),
|
|
266
|
-
month: getMonth(date),
|
|
267
|
-
dayOfMonth: getDate(date),
|
|
268
|
-
dayOfWeek: dayOfWeek,
|
|
269
|
-
isFirstDayOfWeek: dayOfWeek === 1,
|
|
270
|
-
isLastDayOfWeek: dayOfWeek === 7,
|
|
271
|
-
isFirstDayOfMonth: isSameDay(startOfMonth(date), date),
|
|
272
|
-
isLastDayOfMonth: isSameDay(endOfMonth(date), date),
|
|
273
|
-
};
|
|
274
|
-
};
|
|
275
|
-
var getDaysForWeekForDate = function (firstDayOfWeek) {
|
|
276
|
-
return eachDayOfInterval({
|
|
277
|
-
start: firstDayOfWeek,
|
|
278
|
-
end: addDays(firstDayOfWeek, 6),
|
|
279
|
-
}).map(createDay);
|
|
280
|
-
};
|
|
281
|
-
var getStartDateOfISOWeek = function (weekNumber, year) {
|
|
282
|
-
var simple = new Date(year, 0, 1 + (weekNumber - 1) * 7);
|
|
283
|
-
var dayOfWeek = simple.getDay();
|
|
284
|
-
var isoWeekStart = simple;
|
|
285
|
-
if (dayOfWeek <= 4) {
|
|
286
|
-
isoWeekStart.setDate(simple.getDate() - simple.getDay() + 1);
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
isoWeekStart.setDate(simple.getDate() + 8 - simple.getDay());
|
|
290
|
-
}
|
|
291
|
-
return isoWeekStart;
|
|
292
|
-
};
|
|
293
|
-
var calculateOverflowingMonth = function (year, month) {
|
|
294
|
-
if (month > Month.DECEMBER) {
|
|
295
|
-
return { year: year + Math.floor(month / 12), month: month % 12 };
|
|
296
|
-
}
|
|
297
|
-
if (month < Month.JANUARY) {
|
|
298
|
-
return { year: year + Math.floor(month / 12), month: 12 + (month % 12) };
|
|
299
|
-
}
|
|
300
|
-
return { year: year, month: month };
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
var dayHasHighlight = function (dayState, defaultHighlights, highlight) {
|
|
304
|
-
if (defaultHighlights && defaultHighlights.indexOf(highlight) >= 0) {
|
|
305
|
-
return true;
|
|
306
|
-
}
|
|
307
|
-
if (dayState &&
|
|
308
|
-
dayState.highlights &&
|
|
309
|
-
dayState.highlights.indexOf(highlight) >= 0) {
|
|
310
|
-
return true;
|
|
311
|
-
}
|
|
312
|
-
return false;
|
|
313
|
-
};
|
|
314
|
-
var dayHighlightSelect = function (dayState, defaultHighlights, highlightsOrBoolean, returnValues, fallbackValue) {
|
|
315
|
-
if (highlightsOrBoolean.length !== returnValues.length) {
|
|
316
|
-
throw new Error("Select highlight failed, number of values do not equal number of highlights.");
|
|
317
|
-
}
|
|
318
|
-
if (highlightsOrBoolean.length === 0) {
|
|
319
|
-
return fallbackValue;
|
|
320
|
-
}
|
|
321
|
-
for (var i = 0; i < highlightsOrBoolean.length; i++) {
|
|
322
|
-
if (typeof highlightsOrBoolean[i] === "boolean" && highlightsOrBoolean[i]) {
|
|
323
|
-
return returnValues[i];
|
|
324
|
-
}
|
|
325
|
-
if (typeof highlightsOrBoolean[i] === "string" &&
|
|
326
|
-
dayHasHighlight(dayState, defaultHighlights, highlightsOrBoolean[i])) {
|
|
327
|
-
return returnValues[i];
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
return fallbackValue;
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
var defaultWrapperStyleProvider = function (_a) {
|
|
334
|
-
var selectedBackground = _a.selectedBackground, todayBackground = _a.todayBackground, rangeBackground = _a.rangeBackground, _b = _a.borderColor, borderColor = _b === void 0 ? "transparent" : _b;
|
|
335
|
-
return function (defaultHighlights, dayState, day, _, month) {
|
|
336
|
-
var style = {};
|
|
337
|
-
var backgroundColor = dayHighlightSelect(dayState, defaultHighlights, ["selected", "range", "today", day.month === month.monthInYear], [selectedBackground, rangeBackground, todayBackground, "#fff"], "transparent");
|
|
338
|
-
return __assign(__assign({}, style), { backgroundColor: backgroundColor, borderTopLeftRadius: dayHighlightSelect(dayState, defaultHighlights, ["selectedStart", "singleSelected"], [
|
|
339
|
-
"var(--swui-calendar-day-border-radius)",
|
|
340
|
-
"var(--swui-calendar-day-border-radius)",
|
|
341
|
-
], borderColor), borderBottomLeftRadius: dayHighlightSelect(dayState, defaultHighlights, ["selectedStart", "singleSelected"], [
|
|
342
|
-
"var(--swui-calendar-day-border-radius)",
|
|
343
|
-
"var(--swui-calendar-day-border-radius)",
|
|
344
|
-
], borderColor), borderTopRightRadius: dayHighlightSelect(dayState, defaultHighlights, ["selectedEnd", "singleSelected"], [
|
|
345
|
-
"var(--swui-calendar-day-border-radius)",
|
|
346
|
-
"var(--swui-calendar-day-border-radius)",
|
|
347
|
-
], borderColor), borderBottomRightRadius: dayHighlightSelect(dayState, defaultHighlights, ["selectedEnd", "singleSelected"], [
|
|
348
|
-
"var(--swui-calendar-day-border-radius)",
|
|
349
|
-
"var(--swui-calendar-day-border-radius)",
|
|
350
|
-
], borderColor), boxSizing: "border-box" });
|
|
351
|
-
};
|
|
352
|
-
};
|
|
353
|
-
var defaultTextPropsProvider = function (_a) {
|
|
354
|
-
var selectedColor = _a.selectedColor, disabledColor = _a.disabledColor, inOtherMonthColor = _a.inOtherMonthColor, rangeTextColor = _a.rangeTextColor;
|
|
355
|
-
return function (defaultHighlights, dayState, day, _, month) {
|
|
356
|
-
var isOtherMonth = day.month !== month.monthInYear;
|
|
357
|
-
var color = dayHighlightSelect(dayState, defaultHighlights, [isOtherMonth, "selected", "range", "enabled", "disabled"], [
|
|
358
|
-
inOtherMonthColor,
|
|
359
|
-
selectedColor,
|
|
360
|
-
rangeTextColor,
|
|
361
|
-
undefined,
|
|
362
|
-
disabledColor,
|
|
363
|
-
]);
|
|
364
|
-
return {
|
|
365
|
-
color: color,
|
|
366
|
-
};
|
|
367
|
-
};
|
|
368
|
-
};
|
|
369
|
-
var defaultCalendarTheme = {
|
|
370
|
-
width: "var(--swui-calendar-day-width)",
|
|
371
|
-
height: "var(--swui-calendar-day-height)",
|
|
372
|
-
WeekNumber: {
|
|
373
|
-
backgroundColor: "var(--swui-calendar-week-number-bg-color)",
|
|
374
|
-
textColor: "var(--swui-calendar-week-number-text-color)",
|
|
375
|
-
clickableTextColor: "var(--swui-calendar-week-number-clickable-text-color)",
|
|
376
|
-
show: true,
|
|
377
|
-
},
|
|
378
|
-
WeekDay: {
|
|
379
|
-
textColor: "var(--swui-calendar-week-day-text-color)",
|
|
380
|
-
clickableTextColor: "var(--swui-calendar-week-day-clickable-text-color)",
|
|
381
|
-
},
|
|
382
|
-
CalendarDay: {
|
|
383
|
-
tdStyle: defaultWrapperStyleProvider({
|
|
384
|
-
selectedBackground: "var(--swui-calendar-wrapper-selected-background)",
|
|
385
|
-
rangeBackground: "var(--swui-calendar-wrapper-range-background)",
|
|
386
|
-
todayBackground: "var(--swui-calendar-wrapper-today-background)",
|
|
387
|
-
}),
|
|
388
|
-
textProps: defaultTextPropsProvider({
|
|
389
|
-
selectedColor: "var(--swui-calendar-text-selected-color)",
|
|
390
|
-
disabledColor: "var(--swui-calendar-text-disabled-color)",
|
|
391
|
-
inOtherMonthColor: "var(--swui-calendar-text-in-other-month-color)",
|
|
392
|
-
}),
|
|
393
|
-
},
|
|
394
|
-
CalendarMonth: {
|
|
395
|
-
headerTextColor: "var(--swui-calendar-week-day-text-color)",
|
|
396
|
-
},
|
|
397
|
-
};
|
|
398
|
-
var extranetCalendarTheme = __assign(__assign({}, defaultCalendarTheme), { width: "37px", height: "37px" });
|
|
399
|
-
|
|
400
|
-
var isDateInMinMaxRange = function (date, min, max) {
|
|
401
|
-
if (min && isBefore(date, min)) {
|
|
402
|
-
return isSameDay(date, min);
|
|
403
|
-
}
|
|
404
|
-
if (max && isAfter(date, max)) {
|
|
405
|
-
return isSameDay(date, max);
|
|
406
|
-
}
|
|
407
|
-
return true;
|
|
408
|
-
};
|
|
409
|
-
|
|
410
|
-
var DisabledDayWrapper = function DisabledDayWrapper(_a) {
|
|
411
|
-
var DayComponent = _a.dayComponent, minDate = _a.minDate, maxDate = _a.maxDate, dayState = _a.dayState, day = _a.day, props = __rest(_a, ["dayComponent", "minDate", "maxDate", "dayState", "day"]);
|
|
412
|
-
var activeDayState = useMemo(function () {
|
|
413
|
-
return !isDateInMinMaxRange(day.date, minDate, maxDate)
|
|
414
|
-
? addDayStateHighlightsOnSingleDay(dayState, ["disabled"])
|
|
415
|
-
: dayState;
|
|
416
|
-
}, [day.date, dayState, maxDate, minDate]);
|
|
417
|
-
return React.createElement(DayComponent, __assign({ day: day }, props, { dayState: activeDayState }));
|
|
418
|
-
};
|
|
419
|
-
|
|
420
|
-
var WeekNumberCell = function (_a) {
|
|
421
|
-
var onClickWeek = _a.onClickWeek, theme = _a.theme, week = _a.week, background = _a.background, backgroundColor = _a.backgroundColor, prefix = _a.prefix;
|
|
422
|
-
var content = (React.createElement(Box, { width: theme.width, height: theme.height, justifyContent: "center", alignItems: "center" },
|
|
423
|
-
background && React.createElement(Box, { position: "absolute" }, background),
|
|
424
|
-
React.createElement(Box, { position: "absolute" },
|
|
425
|
-
React.createElement(Text, { color: onClickWeek
|
|
426
|
-
? theme.WeekNumber.clickableTextColor
|
|
427
|
-
: theme.WeekNumber.textColor },
|
|
428
|
-
prefix,
|
|
429
|
-
week.weekNumber))));
|
|
430
|
-
return (React.createElement(Box, { background: backgroundColor || theme.WeekNumber.backgroundColor, position: "relative" }, onClickWeek ? (React.createElement(Clickable, { borderRadius: "var(--swui-calendar-day-border-radius)", onClick: function (ev) { return onClickWeek(week, ev); }, disableFocusHighlight: !onClickWeek }, content)) : (content)));
|
|
431
|
-
};
|
|
432
|
-
|
|
433
|
-
function CalendarWeek(_a) {
|
|
434
|
-
var week = _a.week, month = _a.month, dayComponent = _a.dayComponent, statePerWeekDay = _a.statePerWeekDay, userDataPerWeekDay = _a.userDataPerWeekDay, minDate = _a.minDate, maxDate = _a.maxDate, onClickWeek = _a.onClickWeek, onClickDay = _a.onClickDay, theme = _a.theme, renderWeekNumber = _a.renderWeekNumber, extraDayContent = _a.extraDayContent, defaultHighlights = _a.defaultHighlights;
|
|
435
|
-
return (React.createElement("tr", { key: week.weekNumber },
|
|
436
|
-
theme.WeekNumber.show && (React.createElement("td", null, renderWeekNumber ? (renderWeekNumber(week, theme, onClickWeek)) : (React.createElement(WeekNumberCell, { week: week, onClickWeek: onClickWeek, theme: theme })))),
|
|
437
|
-
week.days.map(function (day) { return (React.createElement(DisabledDayWrapper, { dayComponent: dayComponent, key: day.dateString, day: day, week: week, month: month, dayState: statePerWeekDay && statePerWeekDay[day.dayOfMonth], userData: userDataPerWeekDay && userDataPerWeekDay[day.dayOfMonth], onClickDay: onClickDay, theme: theme, extraDayContent: extraDayContent, defaultHighlights: defaultHighlights, minDate: minDate, maxDate: maxDate })); })));
|
|
454
|
+
const WeekDayCell = ({
|
|
455
|
+
onClickWeekDay,
|
|
456
|
+
day,
|
|
457
|
+
theme
|
|
458
|
+
}) => {
|
|
459
|
+
const content = /* @__PURE__ */ jsx(Box, {
|
|
460
|
+
width: theme.width,
|
|
461
|
+
height: theme.height,
|
|
462
|
+
justifyContent: "center",
|
|
463
|
+
alignItems: "center",
|
|
464
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
465
|
+
size: "small",
|
|
466
|
+
color: onClickWeekDay ? theme.WeekDay.clickableTextColor : theme.WeekDay.textColor,
|
|
467
|
+
children: day.name
|
|
468
|
+
})
|
|
469
|
+
});
|
|
470
|
+
if (onClickWeekDay) {
|
|
471
|
+
return /* @__PURE__ */ jsx(Clickable, {
|
|
472
|
+
borderRadius: "var(--swui-calendar-day-border-radius)",
|
|
473
|
+
onClick: (ev) => onClickWeekDay(day.dayOfWeek, ev),
|
|
474
|
+
disableFocusHighlight: !onClickWeekDay,
|
|
475
|
+
children: content
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
return content;
|
|
479
|
+
};
|
|
480
|
+
const CalendarDay = function CalendarDay2({
|
|
481
|
+
day,
|
|
482
|
+
week,
|
|
483
|
+
month,
|
|
484
|
+
dayState,
|
|
485
|
+
userData,
|
|
486
|
+
onClickDay,
|
|
487
|
+
theme,
|
|
488
|
+
extraDayContent: ExtraDayContent,
|
|
489
|
+
defaultHighlights
|
|
490
|
+
}) {
|
|
491
|
+
const content = /* @__PURE__ */ jsx(Box, {
|
|
492
|
+
width: "100%",
|
|
493
|
+
height: "100%",
|
|
494
|
+
justifyContent: "center",
|
|
495
|
+
alignItems: "center",
|
|
496
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
497
|
+
...theme.CalendarDay.textProps && theme.CalendarDay.textProps(defaultHighlights, dayState, day, week, month, userData),
|
|
498
|
+
children: day.dayOfMonth
|
|
499
|
+
})
|
|
500
|
+
});
|
|
501
|
+
const WrapperTd = styled.td({
|
|
502
|
+
...theme.CalendarDay.tdStyle && theme.CalendarDay.tdStyle(defaultHighlights, dayState, day, week, month, userData)
|
|
503
|
+
});
|
|
504
|
+
const InnerWrapperDiv = styled.div({
|
|
505
|
+
...theme.CalendarDay.innerWrapperStyle && theme.CalendarDay.innerWrapperStyle(defaultHighlights, dayState, day, week, month, userData),
|
|
506
|
+
width: "100%",
|
|
507
|
+
height: "100%"
|
|
508
|
+
});
|
|
509
|
+
const CellWrapperDiv = styled.div({
|
|
510
|
+
...theme.CalendarDay.cellWrapperStyle && theme.CalendarDay.cellWrapperStyle(defaultHighlights, dayState, day, week, month, userData),
|
|
511
|
+
width: "100%",
|
|
512
|
+
height: "100%",
|
|
513
|
+
position: "relative"
|
|
514
|
+
});
|
|
515
|
+
return /* @__PURE__ */ jsx(WrapperTd, {
|
|
516
|
+
children: /* @__PURE__ */ jsx(InnerWrapperDiv, {
|
|
517
|
+
children: /* @__PURE__ */ jsx(CellWrapperDiv, {
|
|
518
|
+
children: day.month === month.monthInYear && /* @__PURE__ */ jsxs(Fragment, {
|
|
519
|
+
children: [ExtraDayContent && /* @__PURE__ */ jsx(ExtraDayContent, {
|
|
520
|
+
week,
|
|
521
|
+
month,
|
|
522
|
+
day,
|
|
523
|
+
dayState,
|
|
524
|
+
theme,
|
|
525
|
+
userData
|
|
526
|
+
}), onClickDay && isClickable(defaultHighlights, dayState) ? /* @__PURE__ */ jsx(Clickable, {
|
|
527
|
+
onClick: (ev) => onClickDay(day, userData, ev),
|
|
528
|
+
style: {
|
|
529
|
+
width: "100%",
|
|
530
|
+
height: "100%"
|
|
531
|
+
},
|
|
532
|
+
borderRadius: "var(--swui-calendar-day-border-radius)",
|
|
533
|
+
children: content
|
|
534
|
+
}) : /* @__PURE__ */ jsx(Fragment, {
|
|
535
|
+
children: content
|
|
536
|
+
})]
|
|
537
|
+
})
|
|
538
|
+
})
|
|
539
|
+
})
|
|
540
|
+
});
|
|
541
|
+
};
|
|
542
|
+
const isClickable = (defaultHighlights, dayState) => !!dayHighlightSelect(dayState, defaultHighlights, ["enabled", "disabled"], [true, false], true);
|
|
543
|
+
function CalendarMonth({
|
|
544
|
+
month,
|
|
545
|
+
dayComponent = CalendarDay,
|
|
546
|
+
statePerWeek,
|
|
547
|
+
userDataPerWeek,
|
|
548
|
+
minDate,
|
|
549
|
+
maxDate,
|
|
550
|
+
onClickDay,
|
|
551
|
+
onClickWeek,
|
|
552
|
+
onClickWeekDay,
|
|
553
|
+
onClickMonth,
|
|
554
|
+
onClickYear,
|
|
555
|
+
renderWeekNumber,
|
|
556
|
+
renderWeekDay,
|
|
557
|
+
headerLeftContent,
|
|
558
|
+
headerRightContent,
|
|
559
|
+
theme = defaultCalendarTheme,
|
|
560
|
+
extraDayContent,
|
|
561
|
+
defaultHighlights
|
|
562
|
+
}) {
|
|
563
|
+
const showWeekNumber = theme.WeekNumber.show;
|
|
564
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
565
|
+
children: /* @__PURE__ */ jsxs(Box, {
|
|
566
|
+
alignItems: "stretch",
|
|
567
|
+
children: [/* @__PURE__ */ jsxs(Row, {
|
|
568
|
+
justifyContent: "space-between",
|
|
569
|
+
alignItems: "center",
|
|
570
|
+
height: "32px",
|
|
571
|
+
children: [/* @__PURE__ */ jsx(Box, {
|
|
572
|
+
alignItems: "center",
|
|
573
|
+
children: headerLeftContent
|
|
574
|
+
}), /* @__PURE__ */ jsxs(Row, {
|
|
575
|
+
alignItems: "center",
|
|
576
|
+
children: [/* @__PURE__ */ jsx(Row, {
|
|
577
|
+
width: "104px",
|
|
578
|
+
justifyContent: "center",
|
|
579
|
+
children: onClickMonth ? /* @__PURE__ */ jsx(FlatButton, {
|
|
580
|
+
onClick: () => onClickMonth(month),
|
|
581
|
+
label: month.name
|
|
582
|
+
}) : /* @__PURE__ */ jsx(Text, {
|
|
583
|
+
children: month.name
|
|
584
|
+
})
|
|
585
|
+
}), /* @__PURE__ */ jsx(Space, {}), /* @__PURE__ */ jsx(Row, {
|
|
586
|
+
width: "64px",
|
|
587
|
+
justifyContent: "center",
|
|
588
|
+
children: onClickYear ? /* @__PURE__ */ jsx(FlatButton, {
|
|
589
|
+
onClick: () => onClickYear(month.year),
|
|
590
|
+
label: String(month.year)
|
|
591
|
+
}) : /* @__PURE__ */ jsx(Text, {
|
|
592
|
+
children: month.year
|
|
593
|
+
})
|
|
594
|
+
})]
|
|
595
|
+
}), /* @__PURE__ */ jsx(Box, {
|
|
596
|
+
alignItems: "center",
|
|
597
|
+
children: headerRightContent
|
|
598
|
+
})]
|
|
599
|
+
}), /* @__PURE__ */ jsx("table", {
|
|
600
|
+
children: /* @__PURE__ */ jsxs("tbody", {
|
|
601
|
+
children: [/* @__PURE__ */ jsxs("tr", {
|
|
602
|
+
children: [showWeekNumber && /* @__PURE__ */ jsx("td", {
|
|
603
|
+
children: /* @__PURE__ */ jsx(Box, {
|
|
604
|
+
width: theme.width,
|
|
605
|
+
height: theme.height,
|
|
606
|
+
justifyContent: "center",
|
|
607
|
+
alignItems: "center",
|
|
608
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
609
|
+
size: "small",
|
|
610
|
+
color: theme.CalendarMonth.headerTextColor,
|
|
611
|
+
children: "W"
|
|
612
|
+
})
|
|
613
|
+
})
|
|
614
|
+
}), month.weeks[0].days.map((day) => /* @__PURE__ */ jsx("td", {
|
|
615
|
+
children: renderWeekDay ? renderWeekDay(day.name, theme, onClickWeekDay) : /* @__PURE__ */ jsx(WeekDayCell, {
|
|
616
|
+
day,
|
|
617
|
+
onClickWeekDay,
|
|
618
|
+
theme
|
|
619
|
+
})
|
|
620
|
+
}, day.name))]
|
|
621
|
+
}), month.weeks.map((week) => /* @__PURE__ */ jsx(CalendarWeek, {
|
|
622
|
+
month,
|
|
623
|
+
week,
|
|
624
|
+
dayComponent,
|
|
625
|
+
statePerWeekDay: statePerWeek && statePerWeek[week.weekNumber],
|
|
626
|
+
userDataPerWeekDay: userDataPerWeek && userDataPerWeek[week.weekNumber],
|
|
627
|
+
onClickDay,
|
|
628
|
+
onClickWeek,
|
|
629
|
+
theme,
|
|
630
|
+
renderWeekNumber,
|
|
631
|
+
extraDayContent,
|
|
632
|
+
defaultHighlights,
|
|
633
|
+
minDate,
|
|
634
|
+
maxDate
|
|
635
|
+
}, week.weekNumber))]
|
|
636
|
+
})
|
|
637
|
+
})]
|
|
638
|
+
})
|
|
639
|
+
});
|
|
438
640
|
}
|
|
439
|
-
|
|
440
|
-
var
|
|
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
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
641
|
+
const calendar = "_calendar_1w0de_1";
|
|
642
|
+
var styles$1 = {
|
|
643
|
+
calendar
|
|
644
|
+
};
|
|
645
|
+
function CalendarPanel({
|
|
646
|
+
monthRows,
|
|
647
|
+
dayComponent = CalendarDay,
|
|
648
|
+
userDataPerMonth,
|
|
649
|
+
statePerMonth,
|
|
650
|
+
minDate,
|
|
651
|
+
maxDate,
|
|
652
|
+
onClickDay,
|
|
653
|
+
onClickWeekDay,
|
|
654
|
+
onClickWeek,
|
|
655
|
+
onClickMonth,
|
|
656
|
+
onClickYear,
|
|
657
|
+
renderWeekDay,
|
|
658
|
+
renderWeekNumber,
|
|
659
|
+
headerLeftContent,
|
|
660
|
+
headerRightContent,
|
|
661
|
+
extraDayContent,
|
|
662
|
+
defaultHighlights,
|
|
663
|
+
theme = defaultCalendarTheme
|
|
664
|
+
}) {
|
|
665
|
+
const minDateObj = useMemo(() => minDate ? parse(minDate, "yyyy-MM-dd", new Date()) : void 0, [minDate]);
|
|
666
|
+
const maxDateObj = useMemo(() => maxDate ? parse(maxDate, "yyyy-MM-dd", new Date()) : void 0, [maxDate]);
|
|
667
|
+
return /* @__PURE__ */ jsx("div", {
|
|
668
|
+
className: styles$1.calendar,
|
|
669
|
+
children: monthRows.map((monthRow, rowIndex) => /* @__PURE__ */ jsx(Spacing, {
|
|
670
|
+
children: /* @__PURE__ */ jsx(Row, {
|
|
671
|
+
children: monthRow.map((month, index) => /* @__PURE__ */ jsxs(React.Fragment, {
|
|
672
|
+
children: [index > 0 && /* @__PURE__ */ jsx(Space, {}), /* @__PURE__ */ jsx(CalendarMonth, {
|
|
673
|
+
month,
|
|
674
|
+
dayComponent,
|
|
675
|
+
userDataPerWeek: userDataPerMonth && userDataPerMonth[month.monthString],
|
|
676
|
+
statePerWeek: statePerMonth && statePerMonth[month.monthString],
|
|
677
|
+
onClickDay,
|
|
678
|
+
onClickWeekDay,
|
|
679
|
+
onClickWeek,
|
|
680
|
+
onClickMonth,
|
|
681
|
+
onClickYear,
|
|
682
|
+
theme,
|
|
683
|
+
renderWeekNumber,
|
|
684
|
+
renderWeekDay,
|
|
685
|
+
headerLeftContent,
|
|
686
|
+
headerRightContent,
|
|
687
|
+
extraDayContent,
|
|
688
|
+
defaultHighlights,
|
|
689
|
+
minDate: minDateObj,
|
|
690
|
+
maxDate: maxDateObj
|
|
691
|
+
})]
|
|
692
|
+
}, month.name))
|
|
693
|
+
})
|
|
694
|
+
}, rowIndex))
|
|
695
|
+
});
|
|
493
696
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
697
|
+
function Calendar(props) {
|
|
698
|
+
const initialDate = getInitialDate(props.year, props.month, props.date);
|
|
699
|
+
const {
|
|
700
|
+
year,
|
|
701
|
+
month
|
|
702
|
+
} = calculateOverflowingMonth(initialDate.year, initialDate.month);
|
|
703
|
+
const monthRows = getMonthRows(year, month, props.numMonths, props.monthsPerRow);
|
|
704
|
+
const statePerMonth = useHighlightToday(props.highlightToday, props.statePerMonth);
|
|
705
|
+
return /* @__PURE__ */ jsx(CalendarPanel, {
|
|
706
|
+
year,
|
|
707
|
+
month,
|
|
708
|
+
monthRows,
|
|
709
|
+
...props,
|
|
710
|
+
statePerMonth
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
const getInitialDate = (year, month, date) => {
|
|
714
|
+
if (month && year) {
|
|
715
|
+
return {
|
|
716
|
+
month,
|
|
717
|
+
year
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
if (date) {
|
|
721
|
+
return {
|
|
722
|
+
month: getMonth(date),
|
|
723
|
+
year: getYear(date)
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
const now = new Date();
|
|
727
|
+
return {
|
|
728
|
+
month: getMonth(now),
|
|
729
|
+
year: getYear(now)
|
|
730
|
+
};
|
|
731
|
+
};
|
|
732
|
+
const getMonthRows = (year, month, numMonths, monthsPerRow) => {
|
|
733
|
+
if (numMonths == null) {
|
|
734
|
+
return [[getMonthInYear(year, month)]];
|
|
735
|
+
}
|
|
736
|
+
if (monthsPerRow == null) {
|
|
737
|
+
return [getMonthsInYear(year, month, numMonths)];
|
|
738
|
+
}
|
|
739
|
+
return chunk(getMonthsInYear(year, month, numMonths), monthsPerRow);
|
|
740
|
+
};
|
|
741
|
+
const useSelectedMonthStepperLogic = (dateInFocus, setDateInFocus, monthsPerRow, numMonths) => {
|
|
742
|
+
const nextMonth = useCallback(() => {
|
|
743
|
+
var _a;
|
|
744
|
+
const d = addMonths(dateInFocus, (_a = monthsPerRow != null ? monthsPerRow : numMonths) != null ? _a : 1);
|
|
745
|
+
setDateInFocus == null ? void 0 : setDateInFocus(d);
|
|
746
|
+
}, [setDateInFocus, dateInFocus, monthsPerRow, numMonths]);
|
|
747
|
+
const nextYear = useCallback(() => {
|
|
748
|
+
const d = addYears(dateInFocus, 1);
|
|
749
|
+
setDateInFocus == null ? void 0 : setDateInFocus(d);
|
|
750
|
+
}, [setDateInFocus, dateInFocus]);
|
|
751
|
+
const prevMonth = useCallback(() => {
|
|
752
|
+
var _a;
|
|
753
|
+
const d = subMonths(dateInFocus, (_a = monthsPerRow != null ? monthsPerRow : numMonths) != null ? _a : 1);
|
|
754
|
+
setDateInFocus == null ? void 0 : setDateInFocus(d);
|
|
755
|
+
}, [setDateInFocus, dateInFocus, monthsPerRow, numMonths]);
|
|
756
|
+
const prevYear = useCallback(() => {
|
|
757
|
+
const d = subYears(dateInFocus, 1);
|
|
758
|
+
setDateInFocus == null ? void 0 : setDateInFocus(d);
|
|
759
|
+
}, [setDateInFocus, dateInFocus]);
|
|
760
|
+
return {
|
|
761
|
+
nextMonth,
|
|
762
|
+
prevMonth,
|
|
763
|
+
nextYear,
|
|
764
|
+
prevYear
|
|
765
|
+
};
|
|
766
|
+
};
|
|
767
|
+
const WithMonthSwitcherBelow = ({
|
|
768
|
+
children,
|
|
769
|
+
prevMonth,
|
|
770
|
+
nextMonth,
|
|
771
|
+
prevYear,
|
|
772
|
+
nextYear
|
|
773
|
+
}) => /* @__PURE__ */ jsxs("div", {
|
|
774
|
+
children: [children, /* @__PURE__ */ jsx(Indent, {
|
|
775
|
+
children: /* @__PURE__ */ jsxs(Row, {
|
|
776
|
+
children: [/* @__PURE__ */ jsx(FlatButton, {
|
|
777
|
+
onClick: prevYear,
|
|
778
|
+
leftIcon: faAngleDoubleLeft
|
|
779
|
+
}), /* @__PURE__ */ jsx(Space, {}), /* @__PURE__ */ jsx(FlatButton, {
|
|
780
|
+
onClick: prevMonth,
|
|
781
|
+
leftIcon: stenaAngleLeft
|
|
782
|
+
}), /* @__PURE__ */ jsx(Indent, {
|
|
783
|
+
num: 2
|
|
784
|
+
}), /* @__PURE__ */ jsx(FlatButton, {
|
|
785
|
+
onClick: nextMonth,
|
|
786
|
+
leftIcon: stenaAngleRight
|
|
787
|
+
}), /* @__PURE__ */ jsx(Space, {}), /* @__PURE__ */ jsx(FlatButton, {
|
|
788
|
+
onClick: nextYear,
|
|
789
|
+
leftIcon: faAngleDoubleRight
|
|
790
|
+
})]
|
|
791
|
+
})
|
|
792
|
+
}), /* @__PURE__ */ jsx(Space, {})]
|
|
793
|
+
});
|
|
794
|
+
const MonthPickerCell = ({
|
|
795
|
+
value,
|
|
796
|
+
onValueChange,
|
|
797
|
+
month
|
|
798
|
+
}) => {
|
|
799
|
+
const label = useMemo(() => {
|
|
800
|
+
const now = new Date(2e3, month, 1);
|
|
801
|
+
return format(now, "MMM");
|
|
802
|
+
}, [month]);
|
|
803
|
+
return /* @__PURE__ */ jsx(Row, {
|
|
804
|
+
width: "64px",
|
|
805
|
+
justifyContent: "center",
|
|
806
|
+
spacing: 0.5,
|
|
807
|
+
indent: 0.5,
|
|
808
|
+
children: value === month ? /* @__PURE__ */ jsx(PrimaryButton, {
|
|
809
|
+
label,
|
|
810
|
+
onClick: () => onValueChange && onValueChange(month)
|
|
811
|
+
}) : /* @__PURE__ */ jsx(FlatButton, {
|
|
812
|
+
label,
|
|
813
|
+
onClick: () => onValueChange && onValueChange(month)
|
|
814
|
+
})
|
|
815
|
+
});
|
|
816
|
+
};
|
|
817
|
+
const monthMatrix = [[Month.JANUARY, Month.FEBRUARY, Month.MARCH], [Month.APRIL, Month.MAY, Month.JUNE], [Month.JULY, Month.AUGUST, Month.SEPTEMBER], [Month.OCTOBER, Month.NOVEMBER, Month.DECEMBER]];
|
|
818
|
+
const MonthPicker = ({
|
|
819
|
+
value,
|
|
820
|
+
onValueChange
|
|
821
|
+
}) => {
|
|
822
|
+
return /* @__PURE__ */ jsx(Column, {
|
|
823
|
+
children: monthMatrix.map((monthRow) => /* @__PURE__ */ jsx(Row, {
|
|
824
|
+
children: monthRow.map((month) => /* @__PURE__ */ jsx(MonthPickerCell, {
|
|
825
|
+
month,
|
|
826
|
+
onValueChange,
|
|
827
|
+
value
|
|
828
|
+
}, month))
|
|
829
|
+
}, monthRow[0]))
|
|
830
|
+
});
|
|
831
|
+
};
|
|
832
|
+
const createStandardDateRangePresets = (now) => [
|
|
833
|
+
{
|
|
834
|
+
label: "Past",
|
|
835
|
+
presets: [
|
|
836
|
+
{ label: "Last 3 days", startDate: now, endDate: subDays(now, 2) },
|
|
837
|
+
{ label: "Last 7 days", startDate: now, endDate: subDays(now, 6) },
|
|
838
|
+
{ label: "Last 30 days", startDate: now, endDate: subDays(now, 29) },
|
|
839
|
+
{ label: "Last 45 days", startDate: now, endDate: subDays(now, 44) }
|
|
840
|
+
]
|
|
841
|
+
},
|
|
842
|
+
{
|
|
843
|
+
label: "Future",
|
|
844
|
+
presets: [
|
|
845
|
+
{ label: "Next 3 days", startDate: now, endDate: addDays(now, 2) },
|
|
846
|
+
{ label: "Next 7 days", startDate: now, endDate: addDays(now, 6) },
|
|
847
|
+
{ label: "Next 30 days", startDate: now, endDate: addDays(now, 29) },
|
|
848
|
+
{ label: "Next 45 days", startDate: now, endDate: addDays(now, 44) }
|
|
849
|
+
]
|
|
850
|
+
}
|
|
851
|
+
];
|
|
852
|
+
const PresetPicker = ({
|
|
853
|
+
onClickPreset
|
|
854
|
+
}) => {
|
|
855
|
+
var _a;
|
|
856
|
+
const [pageIndex, setPageIndex] = useState(0);
|
|
857
|
+
const pages = useMemo(() => createStandardDateRangePresets(new Date()), []);
|
|
858
|
+
const currentPage = (_a = pages[pageIndex]) != null ? _a : pages[0];
|
|
859
|
+
return /* @__PURE__ */ jsxs(Column, {
|
|
860
|
+
children: [/* @__PURE__ */ jsxs(Row, {
|
|
861
|
+
justifyContent: "space-between",
|
|
862
|
+
alignItems: "center",
|
|
863
|
+
width: "200px",
|
|
864
|
+
children: [/* @__PURE__ */ jsx(FlatButton, {
|
|
865
|
+
size: "small",
|
|
866
|
+
leftIcon: stenaAngleLeft,
|
|
867
|
+
disabled: pageIndex === 0,
|
|
868
|
+
onClick: () => setPageIndex(pageIndex - 1)
|
|
869
|
+
}), /* @__PURE__ */ jsx(Text, {
|
|
870
|
+
children: currentPage.label
|
|
871
|
+
}), /* @__PURE__ */ jsx(FlatButton, {
|
|
872
|
+
size: "small",
|
|
873
|
+
leftIcon: stenaAngleRight,
|
|
874
|
+
disabled: pageIndex === pages.length - 1,
|
|
875
|
+
onClick: () => setPageIndex(pageIndex + 1)
|
|
876
|
+
})]
|
|
877
|
+
}), /* @__PURE__ */ jsx(Space, {}), /* @__PURE__ */ jsx(Column, {
|
|
878
|
+
alignItems: "center",
|
|
879
|
+
children: currentPage.presets.map((preset) => /* @__PURE__ */ jsxs(React.Fragment, {
|
|
880
|
+
children: [/* @__PURE__ */ jsx(PrimaryButton, {
|
|
881
|
+
label: preset.label,
|
|
882
|
+
onClick: () => onClickPreset(preset)
|
|
883
|
+
}), /* @__PURE__ */ jsx(Space, {})]
|
|
884
|
+
}, preset.label))
|
|
885
|
+
})]
|
|
886
|
+
});
|
|
887
|
+
};
|
|
888
|
+
const YearPickerCell = ({
|
|
889
|
+
value,
|
|
890
|
+
onValueChange,
|
|
891
|
+
year
|
|
892
|
+
}) => {
|
|
893
|
+
const label = String(year);
|
|
894
|
+
return /* @__PURE__ */ jsx(Row, {
|
|
895
|
+
width: "64px",
|
|
896
|
+
justifyContent: "center",
|
|
897
|
+
spacing: 0.5,
|
|
898
|
+
indent: 0.5,
|
|
899
|
+
children: value === year ? /* @__PURE__ */ jsx(PrimaryButton, {
|
|
900
|
+
label,
|
|
901
|
+
onClick: () => onValueChange == null ? void 0 : onValueChange(year)
|
|
902
|
+
}) : /* @__PURE__ */ jsx(FlatButton, {
|
|
903
|
+
label,
|
|
904
|
+
onClick: () => onValueChange == null ? void 0 : onValueChange(year)
|
|
905
|
+
})
|
|
906
|
+
});
|
|
907
|
+
};
|
|
908
|
+
const YearPicker = ({
|
|
909
|
+
value,
|
|
910
|
+
onValueChange,
|
|
911
|
+
initialLastYear
|
|
912
|
+
}) => {
|
|
913
|
+
const [lastYear, setLastYear] = useState(() => {
|
|
914
|
+
if (value) {
|
|
915
|
+
return value + 4;
|
|
510
916
|
}
|
|
511
|
-
|
|
512
|
-
|
|
917
|
+
return initialLastYear != null ? initialLastYear : new Date().getFullYear() + 4;
|
|
918
|
+
});
|
|
919
|
+
const yearRows = useMemo(() => {
|
|
920
|
+
const startYear = lastYear - 11;
|
|
921
|
+
return chunk(range(startYear, lastYear + 1), 3);
|
|
922
|
+
}, [lastYear]);
|
|
923
|
+
useEffect(() => {
|
|
924
|
+
setLastYear((prev) => calculateLastYearInFocus(value, prev));
|
|
925
|
+
}, [value]);
|
|
926
|
+
return /* @__PURE__ */ jsxs(Row, {
|
|
927
|
+
children: [/* @__PURE__ */ jsx(Column, {
|
|
928
|
+
justifyContent: "center",
|
|
929
|
+
children: /* @__PURE__ */ jsx(FlatButton, {
|
|
930
|
+
leftIcon: faCaretLeft,
|
|
931
|
+
onClick: () => setLastYear(lastYear - 3)
|
|
932
|
+
})
|
|
933
|
+
}), /* @__PURE__ */ jsx(Column, {
|
|
934
|
+
children: yearRows.map((yearRow) => /* @__PURE__ */ jsx(Row, {
|
|
935
|
+
children: yearRow.map((year) => /* @__PURE__ */ jsx(YearPickerCell, {
|
|
936
|
+
year,
|
|
937
|
+
onValueChange,
|
|
938
|
+
value
|
|
939
|
+
}, year))
|
|
940
|
+
}, yearRow[0]))
|
|
941
|
+
}), /* @__PURE__ */ jsx(Column, {
|
|
942
|
+
justifyContent: "center",
|
|
943
|
+
children: /* @__PURE__ */ jsx(FlatButton, {
|
|
944
|
+
leftIcon: faCaretRight,
|
|
945
|
+
onClick: () => setLastYear(lastYear + 3)
|
|
946
|
+
})
|
|
947
|
+
})]
|
|
948
|
+
});
|
|
949
|
+
};
|
|
950
|
+
const calculateLastYearInFocus = (value, lastYear) => {
|
|
951
|
+
if (value == null) {
|
|
952
|
+
return lastYear;
|
|
513
953
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
954
|
+
if (value > lastYear) {
|
|
955
|
+
const yearDiff = value - lastYear;
|
|
956
|
+
const remaining = yearDiff % 3;
|
|
957
|
+
const yearsToAdd = yearDiff - remaining + 3;
|
|
958
|
+
return lastYear + yearsToAdd;
|
|
959
|
+
}
|
|
960
|
+
const startYear = lastYear - 11;
|
|
961
|
+
if (value < startYear) {
|
|
962
|
+
const yearDiff = startYear - value;
|
|
963
|
+
const remaining = yearDiff % 3;
|
|
964
|
+
const yearsToSubtract = yearDiff - remaining + 3;
|
|
965
|
+
return lastYear - yearsToSubtract;
|
|
966
|
+
}
|
|
967
|
+
return lastYear;
|
|
968
|
+
};
|
|
969
|
+
const CalendarWithMonthYearPickers = function CalendarWithMonthYearPickers2({
|
|
970
|
+
dateInFocus,
|
|
971
|
+
setDateInFocus,
|
|
972
|
+
currentPanel,
|
|
973
|
+
setCurrentPanel,
|
|
974
|
+
...props
|
|
975
|
+
}) {
|
|
976
|
+
const onChangeSelectedMonth = useCallback((selectedMonth) => {
|
|
977
|
+
const newDate = dateInFocus ? new Date(dateInFocus) : new Date();
|
|
978
|
+
newDate.setMonth(selectedMonth);
|
|
979
|
+
if (setDateInFocus) {
|
|
980
|
+
setDateInFocus(newDate);
|
|
981
|
+
}
|
|
982
|
+
setCurrentPanel("calendar");
|
|
983
|
+
}, [dateInFocus, setDateInFocus, setCurrentPanel]);
|
|
984
|
+
const onChangeSelectedYear = useCallback((selectedYear) => {
|
|
985
|
+
const newDate = dateInFocus ? new Date(dateInFocus) : new Date();
|
|
986
|
+
newDate.setFullYear(selectedYear);
|
|
987
|
+
if (setDateInFocus) {
|
|
988
|
+
setDateInFocus(newDate);
|
|
989
|
+
}
|
|
990
|
+
setCurrentPanel("calendar");
|
|
991
|
+
}, [dateInFocus, setDateInFocus, setCurrentPanel]);
|
|
992
|
+
const onClickYear = useCallback(() => {
|
|
993
|
+
setCurrentPanel("year");
|
|
994
|
+
}, [setCurrentPanel]);
|
|
995
|
+
const onClickMonth = useCallback(() => {
|
|
996
|
+
setCurrentPanel("month");
|
|
997
|
+
}, [setCurrentPanel]);
|
|
998
|
+
switch (currentPanel) {
|
|
999
|
+
case "calendar":
|
|
1000
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
1001
|
+
children: /* @__PURE__ */ jsx(Calendar, {
|
|
1002
|
+
...props,
|
|
1003
|
+
date: dateInFocus,
|
|
1004
|
+
onClickYear,
|
|
1005
|
+
onClickMonth
|
|
1006
|
+
})
|
|
1007
|
+
});
|
|
1008
|
+
case "month":
|
|
1009
|
+
return /* @__PURE__ */ jsx(MonthPicker, {
|
|
1010
|
+
value: dateInFocus.getMonth(),
|
|
1011
|
+
onValueChange: onChangeSelectedMonth
|
|
1012
|
+
});
|
|
1013
|
+
case "year":
|
|
1014
|
+
return /* @__PURE__ */ jsx(YearPicker, {
|
|
1015
|
+
value: dateInFocus.getFullYear(),
|
|
1016
|
+
onValueChange: onChangeSelectedYear
|
|
1017
|
+
});
|
|
1018
|
+
case "presets":
|
|
1019
|
+
return /* @__PURE__ */ jsx(PresetPicker, {
|
|
1020
|
+
onClickPreset: () => {
|
|
1021
|
+
}
|
|
1022
|
+
});
|
|
1023
|
+
default:
|
|
1024
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
1025
|
+
children: /* @__PURE__ */ jsx(PrimaryButton, {
|
|
1026
|
+
label: "Show calendar",
|
|
1027
|
+
onClick: () => setCurrentPanel("calendar")
|
|
1028
|
+
})
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
};
|
|
1032
|
+
const noop = () => {
|
|
1033
|
+
};
|
|
1034
|
+
function CalendarWithMonthSwitcher({
|
|
1035
|
+
monthSwitcherPlacement,
|
|
1036
|
+
theme = defaultCalendarTheme,
|
|
1037
|
+
dateInFocus,
|
|
1038
|
+
setDateInFocus,
|
|
1039
|
+
currentPanel,
|
|
1040
|
+
setCurrentPanel,
|
|
1041
|
+
onSelectPreset = noop,
|
|
1042
|
+
hideYearPagination = false,
|
|
1043
|
+
...calendarProps
|
|
1044
|
+
}) {
|
|
1045
|
+
const {
|
|
1046
|
+
nextMonth,
|
|
1047
|
+
prevMonth,
|
|
1048
|
+
nextYear,
|
|
1049
|
+
prevYear
|
|
1050
|
+
} = useSelectedMonthStepperLogic(dateInFocus, setDateInFocus, calendarProps.monthsPerRow, calendarProps.numMonths);
|
|
1051
|
+
const placement = fallbackIfNoPlacement(monthSwitcherPlacement, calendarProps.numMonths);
|
|
1052
|
+
switch (placement) {
|
|
1053
|
+
case "below": {
|
|
1054
|
+
return /* @__PURE__ */ jsx(WithMonthSwitcherBelow, {
|
|
1055
|
+
theme,
|
|
1056
|
+
nextMonth,
|
|
1057
|
+
prevMonth,
|
|
1058
|
+
nextYear,
|
|
1059
|
+
prevYear,
|
|
1060
|
+
children: /* @__PURE__ */ jsx(Calendar, {
|
|
1061
|
+
...calendarProps,
|
|
1062
|
+
theme,
|
|
1063
|
+
date: dateInFocus
|
|
1064
|
+
})
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
case "header": {
|
|
1068
|
+
return /* @__PURE__ */ jsx(Column, {
|
|
1069
|
+
children: /* @__PURE__ */ jsx(CalendarWithMonthYearPickers, {
|
|
1070
|
+
...calendarProps,
|
|
1071
|
+
theme,
|
|
1072
|
+
dateInFocus,
|
|
1073
|
+
setDateInFocus,
|
|
1074
|
+
currentPanel,
|
|
1075
|
+
setCurrentPanel,
|
|
1076
|
+
onSelectPreset,
|
|
1077
|
+
headerLeftContent: /* @__PURE__ */ jsxs(Row, {
|
|
1078
|
+
alignItems: "center",
|
|
1079
|
+
children: [!hideYearPagination && /* @__PURE__ */ jsx(FlatButton, {
|
|
1080
|
+
size: "small",
|
|
1081
|
+
onClick: prevYear,
|
|
1082
|
+
leftIcon: faAngleDoubleLeft
|
|
1083
|
+
}), /* @__PURE__ */ jsx(Space, {}), /* @__PURE__ */ jsx(FlatButton, {
|
|
1084
|
+
size: "small",
|
|
1085
|
+
onClick: prevMonth,
|
|
1086
|
+
leftIcon: stenaAngleLeft
|
|
1087
|
+
})]
|
|
1088
|
+
}),
|
|
1089
|
+
headerRightContent: /* @__PURE__ */ jsxs(Row, {
|
|
1090
|
+
alignItems: "center",
|
|
1091
|
+
children: [/* @__PURE__ */ jsx(FlatButton, {
|
|
1092
|
+
size: "small",
|
|
1093
|
+
onClick: nextMonth,
|
|
1094
|
+
leftIcon: stenaAngleRight
|
|
1095
|
+
}), /* @__PURE__ */ jsx(Space, {}), !hideYearPagination && /* @__PURE__ */ jsx(FlatButton, {
|
|
1096
|
+
size: "small",
|
|
1097
|
+
onClick: nextYear,
|
|
1098
|
+
leftIcon: faAngleDoubleRight
|
|
1099
|
+
})]
|
|
1100
|
+
})
|
|
1101
|
+
})
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
default: {
|
|
1105
|
+
return /* @__PURE__ */ jsx(Calendar, {
|
|
1106
|
+
...calendarProps,
|
|
1107
|
+
theme,
|
|
1108
|
+
date: dateInFocus
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
519
1111
|
}
|
|
520
1112
|
}
|
|
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
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
};
|
|
613
|
-
|
|
614
|
-
var MonthPickerCell = function (_a) {
|
|
615
|
-
var value = _a.value, onValueChange = _a.onValueChange, month = _a.month;
|
|
616
|
-
var label = useMemo(function () {
|
|
617
|
-
var now = new Date(2000, month, 1);
|
|
618
|
-
return format(now, "MMM");
|
|
619
|
-
}, [month]);
|
|
620
|
-
return (React.createElement(Row, { width: "64px", justifyContent: "center", spacing: 0.5, indent: 0.5 }, value === month ? (React.createElement(PrimaryButton, { label: label, onClick: function () { return onValueChange && onValueChange(month); } })) : (React.createElement(FlatButton, { label: label, onClick: function () { return onValueChange && onValueChange(month); } }))));
|
|
621
|
-
};
|
|
622
|
-
|
|
623
|
-
var monthMatrix = [
|
|
624
|
-
[Month.JANUARY, Month.FEBRUARY, Month.MARCH],
|
|
625
|
-
[Month.APRIL, Month.MAY, Month.JUNE],
|
|
626
|
-
[Month.JULY, Month.AUGUST, Month.SEPTEMBER],
|
|
627
|
-
[Month.OCTOBER, Month.NOVEMBER, Month.DECEMBER],
|
|
628
|
-
];
|
|
629
|
-
var MonthPicker = function (_a) {
|
|
630
|
-
var value = _a.value, onValueChange = _a.onValueChange;
|
|
631
|
-
return (React.createElement(Column, null, monthMatrix.map(function (monthRow) { return (React.createElement(Row, { key: monthRow[0] }, monthRow.map(function (month) { return (React.createElement(MonthPickerCell, { key: month, month: month, onValueChange: onValueChange, value: value })); }))); })));
|
|
632
|
-
};
|
|
633
|
-
|
|
634
|
-
var createStandardDateRangePresets = function (now) { return [
|
|
635
|
-
{
|
|
636
|
-
label: "Past",
|
|
637
|
-
presets: [
|
|
638
|
-
{ label: "Last 3 days", startDate: now, endDate: subDays(now, 2) },
|
|
639
|
-
{ label: "Last 7 days", startDate: now, endDate: subDays(now, 6) },
|
|
640
|
-
{ label: "Last 30 days", startDate: now, endDate: subDays(now, 29) },
|
|
641
|
-
{ label: "Last 45 days", startDate: now, endDate: subDays(now, 44) },
|
|
642
|
-
],
|
|
643
|
-
},
|
|
644
|
-
{
|
|
645
|
-
label: "Future",
|
|
646
|
-
presets: [
|
|
647
|
-
{ label: "Next 3 days", startDate: now, endDate: addDays(now, 2) },
|
|
648
|
-
{ label: "Next 7 days", startDate: now, endDate: addDays(now, 6) },
|
|
649
|
-
{ label: "Next 30 days", startDate: now, endDate: addDays(now, 29) },
|
|
650
|
-
{ label: "Next 45 days", startDate: now, endDate: addDays(now, 44) },
|
|
651
|
-
],
|
|
652
|
-
},
|
|
653
|
-
]; };
|
|
654
|
-
|
|
655
|
-
var PresetPicker = function (_a) {
|
|
656
|
-
var _b;
|
|
657
|
-
var onClickPreset = _a.onClickPreset;
|
|
658
|
-
var _c = useState(0), pageIndex = _c[0], setPageIndex = _c[1];
|
|
659
|
-
var pages = useMemo(function () { return createStandardDateRangePresets(new Date()); }, []);
|
|
660
|
-
var currentPage = (_b = pages[pageIndex]) !== null && _b !== void 0 ? _b : pages[0];
|
|
661
|
-
return (React.createElement(Column, null,
|
|
662
|
-
React.createElement(Row, { justifyContent: "space-between", alignItems: "center", width: "200px" },
|
|
663
|
-
React.createElement(FlatButton, { size: "small", leftIcon: stenaAngleLeft, disabled: pageIndex === 0, onClick: function () { return setPageIndex(pageIndex - 1); } }),
|
|
664
|
-
React.createElement(Text, null, currentPage.label),
|
|
665
|
-
React.createElement(FlatButton, { size: "small", leftIcon: stenaAngleRight, disabled: pageIndex === pages.length - 1, onClick: function () { return setPageIndex(pageIndex + 1); } })),
|
|
666
|
-
React.createElement(Space, null),
|
|
667
|
-
React.createElement(Column, { alignItems: "center" }, currentPage.presets.map(function (preset) { return (React.createElement(React.Fragment, { key: preset.label },
|
|
668
|
-
React.createElement(PrimaryButton, { label: preset.label, onClick: function () { return onClickPreset(preset); } }),
|
|
669
|
-
React.createElement(Space, null))); }))));
|
|
670
|
-
};
|
|
671
|
-
|
|
672
|
-
var YearPickerCell = function (_a) {
|
|
673
|
-
var value = _a.value, onValueChange = _a.onValueChange, year = _a.year;
|
|
674
|
-
var label = String(year);
|
|
675
|
-
return (React.createElement(Row, { width: "64px", justifyContent: "center", spacing: 0.5, indent: 0.5 }, value === year ? (React.createElement(PrimaryButton, { label: label, onClick: function () { return onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(year); } })) : (React.createElement(FlatButton, { label: label, onClick: function () { return onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(year); } }))));
|
|
676
|
-
};
|
|
677
|
-
|
|
678
|
-
var YearPicker = function (_a) {
|
|
679
|
-
var value = _a.value, onValueChange = _a.onValueChange, initialLastYear = _a.initialLastYear;
|
|
680
|
-
var _b = useState(function () {
|
|
681
|
-
if (value) {
|
|
682
|
-
return value + 4;
|
|
683
|
-
}
|
|
684
|
-
return initialLastYear !== null && initialLastYear !== void 0 ? initialLastYear : new Date().getFullYear() + 4;
|
|
685
|
-
}), lastYear = _b[0], setLastYear = _b[1];
|
|
686
|
-
var yearRows = useMemo(function () {
|
|
687
|
-
var startYear = lastYear - 11;
|
|
688
|
-
return chunk(range(startYear, lastYear + 1), 3);
|
|
689
|
-
}, [lastYear]);
|
|
690
|
-
useEffect(function () {
|
|
691
|
-
setLastYear(function (prev) { return calculateLastYearInFocus(value, prev); });
|
|
692
|
-
}, [value]);
|
|
693
|
-
return (React.createElement(Row, null,
|
|
694
|
-
React.createElement(Column, { justifyContent: "center" },
|
|
695
|
-
React.createElement(FlatButton, { leftIcon: faCaretLeft, onClick: function () { return setLastYear(lastYear - 3); } })),
|
|
696
|
-
React.createElement(Column, null, yearRows.map(function (yearRow) { return (React.createElement(Row, { key: yearRow[0] }, yearRow.map(function (year) { return (React.createElement(YearPickerCell, { key: year, year: year, onValueChange: onValueChange, value: value })); }))); })),
|
|
697
|
-
React.createElement(Column, { justifyContent: "center" },
|
|
698
|
-
React.createElement(FlatButton, { leftIcon: faCaretRight, onClick: function () { return setLastYear(lastYear + 3); } }))));
|
|
699
|
-
};
|
|
700
|
-
var calculateLastYearInFocus = function (value, lastYear) {
|
|
701
|
-
if (value == null) {
|
|
702
|
-
return lastYear;
|
|
703
|
-
}
|
|
704
|
-
if (value > lastYear) {
|
|
705
|
-
var yearDiff = value - lastYear;
|
|
706
|
-
var remaining = yearDiff % 3;
|
|
707
|
-
var yearsToAdd = yearDiff - remaining + 3;
|
|
708
|
-
return lastYear + yearsToAdd;
|
|
709
|
-
}
|
|
710
|
-
var startYear = lastYear - 11;
|
|
711
|
-
if (value < startYear) {
|
|
712
|
-
var yearDiff = startYear - value;
|
|
713
|
-
var remaining = yearDiff % 3;
|
|
714
|
-
var yearsToSubtract = yearDiff - remaining + 3;
|
|
715
|
-
return lastYear - yearsToSubtract;
|
|
716
|
-
}
|
|
717
|
-
return lastYear;
|
|
718
|
-
};
|
|
719
|
-
|
|
720
|
-
var CalendarWithMonthYearPickers = function CalendarWithMonthYearPickers(_a) {
|
|
721
|
-
var dateInFocus = _a.dateInFocus, setDateInFocus = _a.setDateInFocus, currentPanel = _a.currentPanel, setCurrentPanel = _a.setCurrentPanel, props = __rest(_a, ["dateInFocus", "setDateInFocus", "currentPanel", "setCurrentPanel"]);
|
|
722
|
-
var onChangeSelectedMonth = useCallback(function (selectedMonth) {
|
|
723
|
-
var newDate = dateInFocus ? new Date(dateInFocus) : new Date();
|
|
724
|
-
newDate.setMonth(selectedMonth);
|
|
725
|
-
if (setDateInFocus) {
|
|
726
|
-
setDateInFocus(newDate);
|
|
727
|
-
}
|
|
728
|
-
setCurrentPanel("calendar");
|
|
729
|
-
}, [dateInFocus, setDateInFocus, setCurrentPanel]);
|
|
730
|
-
var onChangeSelectedYear = useCallback(function (selectedYear) {
|
|
731
|
-
var newDate = dateInFocus ? new Date(dateInFocus) : new Date();
|
|
732
|
-
newDate.setFullYear(selectedYear);
|
|
733
|
-
if (setDateInFocus) {
|
|
734
|
-
setDateInFocus(newDate);
|
|
735
|
-
}
|
|
736
|
-
setCurrentPanel("calendar");
|
|
737
|
-
}, [dateInFocus, setDateInFocus, setCurrentPanel]);
|
|
738
|
-
var onClickYear = useCallback(function () {
|
|
739
|
-
setCurrentPanel("year");
|
|
740
|
-
}, [setCurrentPanel]);
|
|
741
|
-
var onClickMonth = useCallback(function () {
|
|
742
|
-
setCurrentPanel("month");
|
|
743
|
-
}, [setCurrentPanel]);
|
|
744
|
-
switch (currentPanel) {
|
|
745
|
-
case "calendar":
|
|
746
|
-
return (React.createElement(React.Fragment, null,
|
|
747
|
-
React.createElement(Calendar, __assign({}, props, { date: dateInFocus, onClickYear: onClickYear, onClickMonth: onClickMonth }))));
|
|
748
|
-
case "month":
|
|
749
|
-
return (React.createElement(MonthPicker, { value: dateInFocus.getMonth(), onValueChange: onChangeSelectedMonth }));
|
|
750
|
-
case "year":
|
|
751
|
-
return (React.createElement(YearPicker, { value: dateInFocus.getFullYear(), onValueChange: onChangeSelectedYear }));
|
|
752
|
-
case "presets":
|
|
753
|
-
return React.createElement(PresetPicker, { onClickPreset: function () { } });
|
|
754
|
-
default:
|
|
755
|
-
return (React.createElement(Box, null,
|
|
756
|
-
React.createElement(PrimaryButton, { label: "Show calendar", onClick: function () { return setCurrentPanel("calendar"); } })));
|
|
757
|
-
}
|
|
758
|
-
};
|
|
759
|
-
|
|
760
|
-
var noop = function () { };
|
|
761
|
-
function CalendarWithMonthSwitcher(_a) {
|
|
762
|
-
var monthSwitcherPlacement = _a.monthSwitcherPlacement, _b = _a.theme, theme = _b === void 0 ? defaultCalendarTheme : _b, dateInFocus = _a.dateInFocus, setDateInFocus = _a.setDateInFocus, currentPanel = _a.currentPanel, setCurrentPanel = _a.setCurrentPanel, _c = _a.onSelectPreset, onSelectPreset = _c === void 0 ? noop : _c, _d = _a.hideYearPagination, hideYearPagination = _d === void 0 ? false : _d, calendarProps = __rest(_a, ["monthSwitcherPlacement", "theme", "dateInFocus", "setDateInFocus", "currentPanel", "setCurrentPanel", "onSelectPreset", "hideYearPagination"]);
|
|
763
|
-
var _e = useSelectedMonthStepperLogic(dateInFocus, setDateInFocus, calendarProps.monthsPerRow, calendarProps.numMonths), nextMonth = _e.nextMonth, prevMonth = _e.prevMonth, nextYear = _e.nextYear, prevYear = _e.prevYear;
|
|
764
|
-
var placement = fallbackIfNoPlacement(monthSwitcherPlacement, calendarProps.numMonths);
|
|
765
|
-
switch (placement) {
|
|
766
|
-
case "below": {
|
|
767
|
-
return (React.createElement(WithMonthSwitcherBelow, { theme: theme, nextMonth: nextMonth, prevMonth: prevMonth, nextYear: nextYear, prevYear: prevYear },
|
|
768
|
-
React.createElement(Calendar, __assign({}, calendarProps, { theme: theme, date: dateInFocus }))));
|
|
769
|
-
}
|
|
770
|
-
case "header": {
|
|
771
|
-
return (React.createElement(Column, null,
|
|
772
|
-
React.createElement(CalendarWithMonthYearPickers, __assign({}, calendarProps, { theme: theme, dateInFocus: dateInFocus, setDateInFocus: setDateInFocus, currentPanel: currentPanel, setCurrentPanel: setCurrentPanel, onSelectPreset: onSelectPreset, headerLeftContent: React.createElement(Row, { alignItems: "center" },
|
|
773
|
-
!hideYearPagination && (React.createElement(FlatButton, { size: "small", onClick: prevYear, leftIcon: faAngleDoubleLeft })),
|
|
774
|
-
React.createElement(Space, null),
|
|
775
|
-
React.createElement(FlatButton, { size: "small", onClick: prevMonth, leftIcon: stenaAngleLeft })), headerRightContent: React.createElement(Row, { alignItems: "center" },
|
|
776
|
-
React.createElement(FlatButton, { size: "small", onClick: nextMonth, leftIcon: stenaAngleRight }),
|
|
777
|
-
React.createElement(Space, null),
|
|
778
|
-
!hideYearPagination && (React.createElement(FlatButton, { size: "small", onClick: nextYear, leftIcon: faAngleDoubleRight }))) }))));
|
|
779
|
-
}
|
|
780
|
-
default: {
|
|
781
|
-
return (React.createElement(Calendar, __assign({}, calendarProps, { theme: theme, date: dateInFocus })));
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
var fallbackIfNoPlacement = function (monthSwitcherPlacement, numMonths) {
|
|
786
|
-
return monthSwitcherPlacement || (numMonths || 1) > 1 ? "below" : "header";
|
|
787
|
-
};
|
|
788
|
-
|
|
789
|
-
var dateRangeToStrings = function (dateRange) { return ({
|
|
790
|
-
startDate: dateRange.startDate
|
|
791
|
-
? format(dateRange.startDate, "yyyy-MM-dd")
|
|
792
|
-
: undefined,
|
|
793
|
-
endDate: dateRange.endDate
|
|
794
|
-
? format(dateRange.endDate, "yyyy-MM-dd")
|
|
795
|
-
: undefined,
|
|
796
|
-
}); };
|
|
797
|
-
var stringsToDateRange = function (_a) {
|
|
798
|
-
var startDate = _a.startDate, endDate = _a.endDate;
|
|
799
|
-
var now = new Date();
|
|
800
|
-
return {
|
|
801
|
-
startDate: startDate ? parse(startDate, "yyyy-MM-dd", now) : undefined,
|
|
802
|
-
endDate: endDate ? parse(endDate, "yyyy-MM-dd", now) : undefined,
|
|
803
|
-
};
|
|
804
|
-
};
|
|
805
|
-
|
|
806
|
-
var isDateRangeInvalid = function (_a) {
|
|
807
|
-
var startDate = _a.startDate, endDate = _a.endDate;
|
|
808
|
-
return Boolean(startDate &&
|
|
809
|
-
endDate &&
|
|
810
|
-
!isSameDay(startDate, endDate) &&
|
|
811
|
-
isAfter(startDate, endDate));
|
|
812
|
-
};
|
|
813
|
-
var toggleDatesIfEndIsEarlierThanStart = function (dateRange) {
|
|
814
|
-
if (isDateRangeInvalid(dateRange)) {
|
|
815
|
-
return {
|
|
816
|
-
startDate: dateRange.endDate,
|
|
817
|
-
endDate: dateRange.startDate,
|
|
818
|
-
};
|
|
819
|
-
}
|
|
820
|
-
return dateRange;
|
|
821
|
-
};
|
|
822
|
-
var toggleDateStringsIfEndIsEarlierThanStart = function (dateRange) {
|
|
823
|
-
if (dateRange.startDate && dateRange.endDate) {
|
|
824
|
-
return dateRangeToStrings(toggleDatesIfEndIsEarlierThanStart(stringsToDateRange(dateRange)));
|
|
825
|
-
}
|
|
826
|
-
return dateRange;
|
|
827
|
-
};
|
|
828
|
-
|
|
829
|
-
var useDateRangeOnClickDayHandler = function (value, onValueChange, focusedInput, setFocusedInput) {
|
|
830
|
-
return useCallback(function (day) {
|
|
831
|
-
var dateRange = {
|
|
832
|
-
startDate: focusedInput === "startDate" ? day.date : value === null || value === void 0 ? void 0 : value.startDate,
|
|
833
|
-
endDate: focusedInput === "endDate" ? day.date : value === null || value === void 0 ? void 0 : value.endDate,
|
|
834
|
-
};
|
|
835
|
-
if (!isDateRangeInvalid(dateRange)) {
|
|
836
|
-
setFocusedInput(focusedInput === "startDate" ? "endDate" : "startDate");
|
|
837
|
-
}
|
|
838
|
-
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(toggleDatesIfEndIsEarlierThanStart(dateRange));
|
|
839
|
-
}, [
|
|
840
|
-
focusedInput,
|
|
841
|
-
onValueChange,
|
|
842
|
-
setFocusedInput,
|
|
843
|
-
value === null || value === void 0 ? void 0 : value.endDate,
|
|
844
|
-
value === null || value === void 0 ? void 0 : value.startDate,
|
|
845
|
-
]);
|
|
846
|
-
};
|
|
847
|
-
|
|
848
|
-
var useInternalPanelState = function (onChangePanel) {
|
|
849
|
-
var _a = useState("calendar"), currentPanel = _a[0], _setCurrentPanel = _a[1];
|
|
850
|
-
var setCurrentPanel = useCallback(function (currentPanel) {
|
|
851
|
-
_setCurrentPanel(currentPanel);
|
|
852
|
-
onChangePanel === null || onChangePanel === void 0 ? void 0 : onChangePanel(currentPanel);
|
|
853
|
-
}, [onChangePanel]);
|
|
854
|
-
return {
|
|
855
|
-
currentPanel: currentPanel,
|
|
856
|
-
setCurrentPanel: setCurrentPanel,
|
|
857
|
-
};
|
|
858
|
-
};
|
|
859
|
-
|
|
860
|
-
var useDateRangeSelection = function (_a) {
|
|
861
|
-
var focusedInput = _a.focusedInput, value = _a.value, onValueChange = _a.onValueChange, setFocusedInput = _a.setFocusedInput, statePerMonth = _a.statePerMonth, onChangePanel = _a.onChangePanel;
|
|
862
|
-
var _b = useInternalPanelState(onChangePanel), currentPanel = _b.currentPanel, setCurrentPanel = _b.setCurrentPanel;
|
|
863
|
-
var _c = useState(function () { return new Date(); }), dateInFocus = _c[0], setDateInFocus = _c[1];
|
|
864
|
-
var onClickDay = useDateRangeOnClickDayHandler(value, onValueChange, focusedInput, setFocusedInput);
|
|
865
|
-
var statePerMonthWithSelection = useMemo(function () {
|
|
866
|
-
return buildDayStateForDateRange(statePerMonth, value === null || value === void 0 ? void 0 : value.startDate, value === null || value === void 0 ? void 0 : value.endDate);
|
|
867
|
-
}, [statePerMonth, value === null || value === void 0 ? void 0 : value.endDate, value === null || value === void 0 ? void 0 : value.startDate]);
|
|
868
|
-
return {
|
|
869
|
-
onClickDay: onClickDay,
|
|
870
|
-
statePerMonth: statePerMonthWithSelection,
|
|
871
|
-
currentPanel: currentPanel,
|
|
872
|
-
setCurrentPanel: setCurrentPanel,
|
|
873
|
-
setDateInFocus: setDateInFocus,
|
|
874
|
-
dateInFocus: dateInFocus,
|
|
875
|
-
};
|
|
876
|
-
};
|
|
877
|
-
|
|
878
|
-
function DateRangeCalendar(props) {
|
|
879
|
-
var dateRangeSelectionProps = useDateRangeSelection(props);
|
|
880
|
-
return (React.createElement(CalendarWithMonthSwitcher, __assign({}, props, dateRangeSelectionProps)));
|
|
1113
|
+
const fallbackIfNoPlacement = (monthSwitcherPlacement, numMonths) => {
|
|
1114
|
+
return monthSwitcherPlacement || (numMonths || 1) > 1 ? "below" : "header";
|
|
1115
|
+
};
|
|
1116
|
+
const dateRangeToStrings = (dateRange) => ({
|
|
1117
|
+
startDate: dateRange.startDate ? format(dateRange.startDate, "yyyy-MM-dd") : void 0,
|
|
1118
|
+
endDate: dateRange.endDate ? format(dateRange.endDate, "yyyy-MM-dd") : void 0
|
|
1119
|
+
});
|
|
1120
|
+
const stringsToDateRange = ({
|
|
1121
|
+
startDate,
|
|
1122
|
+
endDate
|
|
1123
|
+
}) => {
|
|
1124
|
+
const now = new Date();
|
|
1125
|
+
return {
|
|
1126
|
+
startDate: startDate ? parse(startDate, "yyyy-MM-dd", now) : void 0,
|
|
1127
|
+
endDate: endDate ? parse(endDate, "yyyy-MM-dd", now) : void 0
|
|
1128
|
+
};
|
|
1129
|
+
};
|
|
1130
|
+
const isDateRangeInvalid = ({
|
|
1131
|
+
startDate,
|
|
1132
|
+
endDate
|
|
1133
|
+
}) => Boolean(startDate && endDate && !isSameDay(startDate, endDate) && isAfter(startDate, endDate));
|
|
1134
|
+
const toggleDatesIfEndIsEarlierThanStart = (dateRange) => {
|
|
1135
|
+
if (isDateRangeInvalid(dateRange)) {
|
|
1136
|
+
return {
|
|
1137
|
+
startDate: dateRange.endDate,
|
|
1138
|
+
endDate: dateRange.startDate
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
return dateRange;
|
|
1142
|
+
};
|
|
1143
|
+
const toggleDateStringsIfEndIsEarlierThanStart = (dateRange) => {
|
|
1144
|
+
if (dateRange.startDate && dateRange.endDate) {
|
|
1145
|
+
return dateRangeToStrings(toggleDatesIfEndIsEarlierThanStart(stringsToDateRange(dateRange)));
|
|
1146
|
+
}
|
|
1147
|
+
return dateRange;
|
|
1148
|
+
};
|
|
1149
|
+
const useDateRangeOnClickDayHandler = (value, onValueChange, focusedInput, setFocusedInput) => {
|
|
1150
|
+
return useCallback((day) => {
|
|
1151
|
+
const dateRange = {
|
|
1152
|
+
startDate: focusedInput === "startDate" ? day.date : value == null ? void 0 : value.startDate,
|
|
1153
|
+
endDate: focusedInput === "endDate" ? day.date : value == null ? void 0 : value.endDate
|
|
1154
|
+
};
|
|
1155
|
+
if (!isDateRangeInvalid(dateRange)) {
|
|
1156
|
+
setFocusedInput(focusedInput === "startDate" ? "endDate" : "startDate");
|
|
1157
|
+
}
|
|
1158
|
+
onValueChange == null ? void 0 : onValueChange(toggleDatesIfEndIsEarlierThanStart(dateRange));
|
|
1159
|
+
}, [
|
|
1160
|
+
focusedInput,
|
|
1161
|
+
onValueChange,
|
|
1162
|
+
setFocusedInput,
|
|
1163
|
+
value == null ? void 0 : value.endDate,
|
|
1164
|
+
value == null ? void 0 : value.startDate
|
|
1165
|
+
]);
|
|
1166
|
+
};
|
|
1167
|
+
const useInternalPanelState = (onChangePanel) => {
|
|
1168
|
+
const [currentPanel, _setCurrentPanel] = useState("calendar");
|
|
1169
|
+
const setCurrentPanel = useCallback((currentPanel2) => {
|
|
1170
|
+
_setCurrentPanel(currentPanel2);
|
|
1171
|
+
onChangePanel == null ? void 0 : onChangePanel(currentPanel2);
|
|
1172
|
+
}, [onChangePanel]);
|
|
1173
|
+
return {
|
|
1174
|
+
currentPanel,
|
|
1175
|
+
setCurrentPanel
|
|
1176
|
+
};
|
|
1177
|
+
};
|
|
1178
|
+
const useDateRangeSelection = ({
|
|
1179
|
+
focusedInput,
|
|
1180
|
+
value,
|
|
1181
|
+
onValueChange,
|
|
1182
|
+
setFocusedInput,
|
|
1183
|
+
statePerMonth,
|
|
1184
|
+
onChangePanel
|
|
1185
|
+
}) => {
|
|
1186
|
+
const { currentPanel, setCurrentPanel } = useInternalPanelState(onChangePanel);
|
|
1187
|
+
const [dateInFocus, setDateInFocus] = useState(() => new Date());
|
|
1188
|
+
const onClickDay = useDateRangeOnClickDayHandler(value, onValueChange, focusedInput, setFocusedInput);
|
|
1189
|
+
const statePerMonthWithSelection = useMemo(() => buildDayStateForDateRange(statePerMonth, value == null ? void 0 : value.startDate, value == null ? void 0 : value.endDate), [statePerMonth, value == null ? void 0 : value.endDate, value == null ? void 0 : value.startDate]);
|
|
1190
|
+
return {
|
|
1191
|
+
onClickDay,
|
|
1192
|
+
statePerMonth: statePerMonthWithSelection,
|
|
1193
|
+
currentPanel,
|
|
1194
|
+
setCurrentPanel,
|
|
1195
|
+
setDateInFocus,
|
|
1196
|
+
dateInFocus
|
|
1197
|
+
};
|
|
1198
|
+
};
|
|
1199
|
+
function DateRangeCalendar(props) {
|
|
1200
|
+
const dateRangeSelectionProps = useDateRangeSelection(props);
|
|
1201
|
+
return /* @__PURE__ */ jsx(CalendarWithMonthSwitcher, {
|
|
1202
|
+
...props,
|
|
1203
|
+
...dateRangeSelectionProps
|
|
1204
|
+
});
|
|
881
1205
|
}
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
1206
|
+
const useDateRangeCalendarState = () => {
|
|
1207
|
+
const [startDate, setStartDate] = useState();
|
|
1208
|
+
const [endDate, setEndDate] = useState();
|
|
1209
|
+
const [focusedInput, setFocusedInput] = useState("startDate");
|
|
1210
|
+
return {
|
|
1211
|
+
startDate,
|
|
1212
|
+
setStartDate,
|
|
1213
|
+
endDate,
|
|
1214
|
+
setEndDate,
|
|
1215
|
+
focusedInput,
|
|
1216
|
+
setFocusedInput
|
|
1217
|
+
};
|
|
1218
|
+
};
|
|
1219
|
+
const useSingleDateSelection = ({
|
|
1220
|
+
onChange,
|
|
1221
|
+
value,
|
|
1222
|
+
statePerMonth,
|
|
1223
|
+
onChangePanel
|
|
1224
|
+
}) => {
|
|
1225
|
+
const { currentPanel, setCurrentPanel } = useInternalPanelState(onChangePanel);
|
|
1226
|
+
const [dateInFocus, setDateInFocus] = useState(() => value != null ? value : new Date());
|
|
1227
|
+
const onClickDay = useCallback((day) => {
|
|
1228
|
+
if (onChange) {
|
|
1229
|
+
onChange(day.date);
|
|
1230
|
+
}
|
|
1231
|
+
}, [onChange]);
|
|
1232
|
+
const statePerMonthWithSelectedDate = useMemo(() => value ? addDayStateHighlights(statePerMonth, value, [
|
|
1233
|
+
"selected",
|
|
1234
|
+
"singleSelected"
|
|
1235
|
+
]) : statePerMonth, [statePerMonth, value]);
|
|
1236
|
+
return {
|
|
1237
|
+
onClickDay,
|
|
1238
|
+
statePerMonth: statePerMonthWithSelectedDate,
|
|
1239
|
+
date: value,
|
|
1240
|
+
currentPanel,
|
|
1241
|
+
setCurrentPanel,
|
|
1242
|
+
dateInFocus,
|
|
1243
|
+
setDateInFocus
|
|
1244
|
+
};
|
|
1245
|
+
};
|
|
1246
|
+
function SingleDateCalendar(props) {
|
|
1247
|
+
const singleDateSelectionProps = useSingleDateSelection(props);
|
|
1248
|
+
return /* @__PURE__ */ jsx(CalendarWithMonthSwitcher, {
|
|
1249
|
+
...props,
|
|
1250
|
+
...singleDateSelectionProps
|
|
1251
|
+
});
|
|
928
1252
|
}
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
}
|
|
952
|
-
return
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
1253
|
+
const useMultiDateSelection = ({
|
|
1254
|
+
onChange,
|
|
1255
|
+
value,
|
|
1256
|
+
statePerMonth,
|
|
1257
|
+
onChangePanel
|
|
1258
|
+
}) => {
|
|
1259
|
+
const { currentPanel, setCurrentPanel } = useInternalPanelState(onChangePanel);
|
|
1260
|
+
const [dateInFocus, setDateInFocus] = useState(() => new Date());
|
|
1261
|
+
const onClickDay = useCallback((day) => {
|
|
1262
|
+
if (!onChange) {
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
const isSelected = value && value.find((d) => isSameDay(d, day.date));
|
|
1266
|
+
if (value && isSelected) {
|
|
1267
|
+
onChange(value.filter((v) => !isSameDay(v, day.date)));
|
|
1268
|
+
} else {
|
|
1269
|
+
onChange([...value || [], day.date]);
|
|
1270
|
+
}
|
|
1271
|
+
}, [onChange, value]);
|
|
1272
|
+
const statePerMonthWithSelectedDate = useMemo(() => {
|
|
1273
|
+
if (!value) {
|
|
1274
|
+
return statePerMonth;
|
|
1275
|
+
}
|
|
1276
|
+
return value.reduce((stateSum, date) => addDayStateHighlights(stateSum, date, ["selected"]), statePerMonth);
|
|
1277
|
+
}, [statePerMonth, value]);
|
|
1278
|
+
return {
|
|
1279
|
+
onClickDay,
|
|
1280
|
+
statePerMonth: statePerMonthWithSelectedDate,
|
|
1281
|
+
currentPanel,
|
|
1282
|
+
setCurrentPanel,
|
|
1283
|
+
dateInFocus,
|
|
1284
|
+
setDateInFocus
|
|
1285
|
+
};
|
|
1286
|
+
};
|
|
1287
|
+
function MultiDateCalendar(props) {
|
|
1288
|
+
const selectionProps = useMultiDateSelection(props);
|
|
1289
|
+
return /* @__PURE__ */ jsx(CalendarWithMonthSwitcher, {
|
|
1290
|
+
...props,
|
|
1291
|
+
...selectionProps
|
|
1292
|
+
});
|
|
965
1293
|
}
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
};
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
function SingleWeekCalendar(props) {
|
|
1028
|
-
|
|
1029
|
-
|
|
1294
|
+
const useSingleWeekSelection = ({
|
|
1295
|
+
onChange,
|
|
1296
|
+
value,
|
|
1297
|
+
statePerMonth,
|
|
1298
|
+
onChangePanel
|
|
1299
|
+
}) => {
|
|
1300
|
+
const [dateInFocus, setDateInFocus] = useState(() => {
|
|
1301
|
+
const week = getWeekDataFromWeekString(value);
|
|
1302
|
+
if (!week) {
|
|
1303
|
+
return new Date();
|
|
1304
|
+
}
|
|
1305
|
+
return week.days[0].date;
|
|
1306
|
+
});
|
|
1307
|
+
const { currentPanel, setCurrentPanel } = useInternalPanelState(onChangePanel);
|
|
1308
|
+
const onClickDay = useCallback((day) => {
|
|
1309
|
+
if (onChange) {
|
|
1310
|
+
onChange(getWeekStringFromWeekData(getWeekForDate(day.date)));
|
|
1311
|
+
}
|
|
1312
|
+
}, [onChange]);
|
|
1313
|
+
const onClickWeek = useCallback((week) => {
|
|
1314
|
+
if (onChange) {
|
|
1315
|
+
onChange(getWeekStringFromWeekData(week));
|
|
1316
|
+
}
|
|
1317
|
+
}, [onChange]);
|
|
1318
|
+
const statePerMonthWithSelection = useMemo(() => {
|
|
1319
|
+
const weekData = getWeekDataFromWeekString(value);
|
|
1320
|
+
return weekData ? addWeekRangeHighlights(statePerMonth, weekData) : statePerMonth;
|
|
1321
|
+
}, [value, statePerMonth]);
|
|
1322
|
+
const date = useMemo(() => {
|
|
1323
|
+
const week = getWeekDataFromWeekString(value);
|
|
1324
|
+
if (!week) {
|
|
1325
|
+
return new Date();
|
|
1326
|
+
}
|
|
1327
|
+
return week.days[0].date;
|
|
1328
|
+
}, [value]);
|
|
1329
|
+
return {
|
|
1330
|
+
statePerMonth: statePerMonthWithSelection,
|
|
1331
|
+
date,
|
|
1332
|
+
dateInFocus,
|
|
1333
|
+
setDateInFocus,
|
|
1334
|
+
onClickDay,
|
|
1335
|
+
onClickWeek,
|
|
1336
|
+
currentPanel,
|
|
1337
|
+
setCurrentPanel
|
|
1338
|
+
};
|
|
1339
|
+
};
|
|
1340
|
+
const getWeekStringFromWeekData = (week) => {
|
|
1341
|
+
if (!week) {
|
|
1342
|
+
return void 0;
|
|
1343
|
+
}
|
|
1344
|
+
return `${week.endYear}-${week.weekNumber}`;
|
|
1345
|
+
};
|
|
1346
|
+
const getWeekDataFromWeekString = (week) => {
|
|
1347
|
+
if (!week) {
|
|
1348
|
+
return void 0;
|
|
1349
|
+
}
|
|
1350
|
+
const parts = week.split("-");
|
|
1351
|
+
const weekNumber = parseInt(parts[1], 10);
|
|
1352
|
+
const year = parseInt(parts[0], 10);
|
|
1353
|
+
return getWeekForDate(getStartDateOfISOWeek(weekNumber, year));
|
|
1354
|
+
};
|
|
1355
|
+
function SingleWeekCalendar(props) {
|
|
1356
|
+
const singleWeekSelectionProps = useSingleWeekSelection(props);
|
|
1357
|
+
return /* @__PURE__ */ jsx(CalendarWithMonthSwitcher, {
|
|
1358
|
+
...props,
|
|
1359
|
+
...singleWeekSelectionProps
|
|
1360
|
+
});
|
|
1030
1361
|
}
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
var
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
var selectionProps = useDateRangeExclusionSelection(props);
|
|
1103
|
-
return React.createElement(CalendarWithMonthSwitcher, __assign({}, props, selectionProps));
|
|
1362
|
+
const removeDateIfExist = (list, date) => list.filter((item) => !isSameDay(item, date));
|
|
1363
|
+
const listContainsDate = (list, date) => !!list.find((item) => isSameDay(item, date));
|
|
1364
|
+
const useDateRangeExclusionSelection = ({
|
|
1365
|
+
value,
|
|
1366
|
+
onValueChange,
|
|
1367
|
+
statePerMonth,
|
|
1368
|
+
onChangePanel
|
|
1369
|
+
}) => {
|
|
1370
|
+
const [dateRange, setDateRange] = useState();
|
|
1371
|
+
const [focusedInput, setFocusedInput] = useState("startDate");
|
|
1372
|
+
const { currentPanel, setCurrentPanel } = useInternalPanelState(onChangePanel);
|
|
1373
|
+
const [dateInFocus, setDateInFocus] = useState(() => {
|
|
1374
|
+
var _a;
|
|
1375
|
+
return (_a = focusedInput && (value == null ? void 0 : value[focusedInput])) != null ? _a : new Date();
|
|
1376
|
+
});
|
|
1377
|
+
const onChangeHandler = useCallback((value2) => {
|
|
1378
|
+
setDateRange(value2);
|
|
1379
|
+
const { startDate, endDate } = value2;
|
|
1380
|
+
if (onValueChange) {
|
|
1381
|
+
if (startDate && endDate) {
|
|
1382
|
+
const dates = eachDayOfInterval({ start: startDate, end: endDate });
|
|
1383
|
+
onValueChange(dates);
|
|
1384
|
+
} else if (startDate) {
|
|
1385
|
+
onValueChange([startDate]);
|
|
1386
|
+
} else if (endDate) {
|
|
1387
|
+
onValueChange([endDate]);
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
}, [onValueChange]);
|
|
1391
|
+
const onClickDayRange = useDateRangeOnClickDayHandler(dateRange, onChangeHandler, focusedInput, setFocusedInput);
|
|
1392
|
+
const onClickDay = useCallback((day, userData, ev) => {
|
|
1393
|
+
if (onValueChange) {
|
|
1394
|
+
if (ev.ctrlKey || ev.metaKey) {
|
|
1395
|
+
if (!value) {
|
|
1396
|
+
onValueChange([day.date]);
|
|
1397
|
+
} else if (listContainsDate(value, day.date)) {
|
|
1398
|
+
onValueChange(removeDateIfExist(value, day.date));
|
|
1399
|
+
} else {
|
|
1400
|
+
onValueChange([...value, day.date]);
|
|
1401
|
+
}
|
|
1402
|
+
} else {
|
|
1403
|
+
onClickDayRange(day, userData, ev);
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
}, [onValueChange, onClickDayRange, value]);
|
|
1407
|
+
const statePerMonthWithSelectedDate = useMemo(() => {
|
|
1408
|
+
return addHighlighting(statePerMonth, value);
|
|
1409
|
+
}, [statePerMonth, value]);
|
|
1410
|
+
return {
|
|
1411
|
+
onClickDay,
|
|
1412
|
+
statePerMonth: statePerMonthWithSelectedDate,
|
|
1413
|
+
currentPanel,
|
|
1414
|
+
setCurrentPanel,
|
|
1415
|
+
dateInFocus,
|
|
1416
|
+
setDateInFocus
|
|
1417
|
+
};
|
|
1418
|
+
};
|
|
1419
|
+
const addHighlighting = (statePerMonth, dateList) => {
|
|
1420
|
+
if (!dateList) {
|
|
1421
|
+
return statePerMonth;
|
|
1422
|
+
}
|
|
1423
|
+
return dateList.reduce((statePerMonth2, date) => {
|
|
1424
|
+
return addDayStateHighlights(statePerMonth2, date, ["selected"]);
|
|
1425
|
+
}, statePerMonth);
|
|
1426
|
+
};
|
|
1427
|
+
function DateRangeExclusionCalendar(props) {
|
|
1428
|
+
const selectionProps = useDateRangeExclusionSelection(props);
|
|
1429
|
+
return /* @__PURE__ */ jsx(CalendarWithMonthSwitcher, {
|
|
1430
|
+
...props,
|
|
1431
|
+
...selectionProps
|
|
1432
|
+
});
|
|
1104
1433
|
}
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
var _a
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
}
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
};
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
};
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
}
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
}
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
};
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
return {
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
};
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
return
|
|
1544
|
-
}
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
}
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
}
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
};
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
}
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
},
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
};
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
var
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
1434
|
+
const defaultPopoverPlacement = "bottom";
|
|
1435
|
+
const useCalendarPopoverUpdater = () => {
|
|
1436
|
+
const [tippyRef, tippyInstanceRef] = useTippyInstance();
|
|
1437
|
+
const onChangePanel = useCallback(() => {
|
|
1438
|
+
var _a, _b;
|
|
1439
|
+
(_b = (_a = tippyInstanceRef.current) == null ? void 0 : _a.popperInstance) == null ? void 0 : _b.update();
|
|
1440
|
+
}, [tippyInstanceRef]);
|
|
1441
|
+
return {
|
|
1442
|
+
onChangePanel,
|
|
1443
|
+
tippyRef
|
|
1444
|
+
};
|
|
1445
|
+
};
|
|
1446
|
+
const useDateInput = (onChange, onClose, openOnMount) => {
|
|
1447
|
+
const [showingCalendar, setShowingCalendar] = useState(openOnMount || false);
|
|
1448
|
+
const showCalendar = useCallback(() => {
|
|
1449
|
+
setShowingCalendar(true);
|
|
1450
|
+
return true;
|
|
1451
|
+
}, [setShowingCalendar]);
|
|
1452
|
+
const hideCalendar = useCallback(() => {
|
|
1453
|
+
setShowingCalendar(false);
|
|
1454
|
+
if (onClose) {
|
|
1455
|
+
onClose();
|
|
1456
|
+
}
|
|
1457
|
+
}, [setShowingCalendar, onClose]);
|
|
1458
|
+
const onSelectDate = useCallback((date) => {
|
|
1459
|
+
if (onChange) {
|
|
1460
|
+
onChange(date);
|
|
1461
|
+
}
|
|
1462
|
+
setTimeout(hideCalendar, 150);
|
|
1463
|
+
}, [onChange, hideCalendar]);
|
|
1464
|
+
return {
|
|
1465
|
+
showCalendar,
|
|
1466
|
+
hideCalendar,
|
|
1467
|
+
showingCalendar,
|
|
1468
|
+
onSelectDate
|
|
1469
|
+
};
|
|
1470
|
+
};
|
|
1471
|
+
const defaultMaxDate = "2999-12-31";
|
|
1472
|
+
const DateInput = ({
|
|
1473
|
+
displayFormat = DateFormats.fullDate,
|
|
1474
|
+
placeholder = "Enter date",
|
|
1475
|
+
value,
|
|
1476
|
+
zIndex = 100,
|
|
1477
|
+
calendarTheme = defaultCalendarTheme,
|
|
1478
|
+
calendarProps,
|
|
1479
|
+
openOnMount,
|
|
1480
|
+
onClose,
|
|
1481
|
+
onChange,
|
|
1482
|
+
portalTarget,
|
|
1483
|
+
variant,
|
|
1484
|
+
width,
|
|
1485
|
+
minDate,
|
|
1486
|
+
maxDate = defaultMaxDate,
|
|
1487
|
+
disabled
|
|
1488
|
+
}) => {
|
|
1489
|
+
const {
|
|
1490
|
+
hideCalendar,
|
|
1491
|
+
showingCalendar,
|
|
1492
|
+
onSelectDate,
|
|
1493
|
+
showCalendar
|
|
1494
|
+
} = useDateInput(onChange, onClose, openOnMount);
|
|
1495
|
+
const {
|
|
1496
|
+
tippyRef,
|
|
1497
|
+
onChangePanel
|
|
1498
|
+
} = useCalendarPopoverUpdater();
|
|
1499
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
1500
|
+
width,
|
|
1501
|
+
children: /* @__PURE__ */ jsx(Popover, {
|
|
1502
|
+
arrow: false,
|
|
1503
|
+
lazy: true,
|
|
1504
|
+
visible: showingCalendar,
|
|
1505
|
+
onClickOutside: hideCalendar,
|
|
1506
|
+
placement: defaultPopoverPlacement,
|
|
1507
|
+
zIndex,
|
|
1508
|
+
appendTo: portalTarget != null ? portalTarget : "parent",
|
|
1509
|
+
tippyRef,
|
|
1510
|
+
disabled,
|
|
1511
|
+
content: /* @__PURE__ */ jsx(SingleDateCalendar, {
|
|
1512
|
+
...calendarProps,
|
|
1513
|
+
onChange: onSelectDate,
|
|
1514
|
+
value,
|
|
1515
|
+
theme: calendarTheme,
|
|
1516
|
+
onChangePanel,
|
|
1517
|
+
minDate,
|
|
1518
|
+
maxDate
|
|
1519
|
+
}),
|
|
1520
|
+
children: /* @__PURE__ */ jsx(TextInput, {
|
|
1521
|
+
type: "date",
|
|
1522
|
+
contentRight: /* @__PURE__ */ jsx(Row, {
|
|
1523
|
+
alignItems: "center",
|
|
1524
|
+
children: /* @__PURE__ */ jsx(FlatButton, {
|
|
1525
|
+
size: "small",
|
|
1526
|
+
disabled,
|
|
1527
|
+
leftIcon: stenaCalendar,
|
|
1528
|
+
onClick: showCalendar
|
|
1529
|
+
})
|
|
1530
|
+
}),
|
|
1531
|
+
onFocus: showCalendar,
|
|
1532
|
+
onClickRight: showCalendar,
|
|
1533
|
+
value: value ? format(value, displayFormat) : "",
|
|
1534
|
+
placeholder,
|
|
1535
|
+
size: 9,
|
|
1536
|
+
disabled,
|
|
1537
|
+
autoFocus: openOnMount,
|
|
1538
|
+
variant,
|
|
1539
|
+
min: minDate,
|
|
1540
|
+
max: maxDate
|
|
1541
|
+
})
|
|
1542
|
+
})
|
|
1543
|
+
});
|
|
1544
|
+
};
|
|
1545
|
+
const useDateRangeInput = (value, onValueChange) => {
|
|
1546
|
+
const startDateInputRef = useRef(null);
|
|
1547
|
+
const endDateInputRef = useRef(null);
|
|
1548
|
+
const [showingCalendar, setShowingCalendar] = useState(false);
|
|
1549
|
+
const [focusedInput, setFocusedInput] = useState(void 0);
|
|
1550
|
+
const showCalendarStartDate = useCallback(() => {
|
|
1551
|
+
setFocusedInput("startDate");
|
|
1552
|
+
setShowingCalendar(true);
|
|
1553
|
+
return true;
|
|
1554
|
+
}, [setFocusedInput, setShowingCalendar]);
|
|
1555
|
+
const showCalendarEndDate = useCallback(() => {
|
|
1556
|
+
setFocusedInput("endDate");
|
|
1557
|
+
setShowingCalendar(true);
|
|
1558
|
+
return true;
|
|
1559
|
+
}, [setFocusedInput, setShowingCalendar]);
|
|
1560
|
+
const hideCalendar = useCallback(() => {
|
|
1561
|
+
setShowingCalendar(false);
|
|
1562
|
+
}, [setShowingCalendar]);
|
|
1563
|
+
const onClickDay = useCallback((day) => {
|
|
1564
|
+
if (focusedInput === "startDate") {
|
|
1565
|
+
onValueChange == null ? void 0 : onValueChange({
|
|
1566
|
+
startDate: day.date,
|
|
1567
|
+
endDate: value == null ? void 0 : value.endDate
|
|
1568
|
+
});
|
|
1569
|
+
if (!(value == null ? void 0 : value.endDate)) {
|
|
1570
|
+
setFocusedInput("endDate");
|
|
1571
|
+
endDateInputRef.current && endDateInputRef.current.focus();
|
|
1572
|
+
} else {
|
|
1573
|
+
setTimeout(hideCalendar, 150);
|
|
1574
|
+
}
|
|
1575
|
+
} else if (focusedInput === "endDate") {
|
|
1576
|
+
onValueChange == null ? void 0 : onValueChange({
|
|
1577
|
+
startDate: value == null ? void 0 : value.startDate,
|
|
1578
|
+
endDate: day.date
|
|
1579
|
+
});
|
|
1580
|
+
if (!(value == null ? void 0 : value.startDate)) {
|
|
1581
|
+
setFocusedInput("startDate");
|
|
1582
|
+
startDateInputRef.current && startDateInputRef.current.focus();
|
|
1583
|
+
} else {
|
|
1584
|
+
setTimeout(hideCalendar, 150);
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
}, [focusedInput, onValueChange, setFocusedInput, hideCalendar, value]);
|
|
1588
|
+
const startDateIsAfterEnd = useMemo(() => (value == null ? void 0 : value.startDate) && (value == null ? void 0 : value.endDate) && isAfter(value.startDate, value.endDate), [value == null ? void 0 : value.startDate, value == null ? void 0 : value.endDate]);
|
|
1589
|
+
return {
|
|
1590
|
+
showingCalendar,
|
|
1591
|
+
hideCalendar,
|
|
1592
|
+
showCalendarEndDate,
|
|
1593
|
+
showCalendarStartDate,
|
|
1594
|
+
focusedInput,
|
|
1595
|
+
setFocusedInput,
|
|
1596
|
+
startDateInputRef,
|
|
1597
|
+
endDateInputRef,
|
|
1598
|
+
onClickDay,
|
|
1599
|
+
startDateIsAfterEnd
|
|
1600
|
+
};
|
|
1601
|
+
};
|
|
1602
|
+
const DateRangeInput = ({
|
|
1603
|
+
displayFormat = DateFormats.fullDate,
|
|
1604
|
+
placeholderStartDate = "Start date",
|
|
1605
|
+
placeholderEndDate = "End date",
|
|
1606
|
+
portalTarget,
|
|
1607
|
+
value,
|
|
1608
|
+
onValueChange,
|
|
1609
|
+
zIndex = 100,
|
|
1610
|
+
width,
|
|
1611
|
+
calendarTheme = defaultCalendarTheme,
|
|
1612
|
+
calendarProps,
|
|
1613
|
+
minDate,
|
|
1614
|
+
maxDate = defaultMaxDate,
|
|
1615
|
+
disabled
|
|
1616
|
+
}) => {
|
|
1617
|
+
const [dateInFocus, setDateInFocus] = useState(() => {
|
|
1618
|
+
var _a;
|
|
1619
|
+
return (_a = focusedInput && (value == null ? void 0 : value[focusedInput])) != null ? _a : new Date();
|
|
1620
|
+
});
|
|
1621
|
+
const [currentPanel, setCurrentPanel] = useState("calendar");
|
|
1622
|
+
const {
|
|
1623
|
+
hideCalendar,
|
|
1624
|
+
showCalendarEndDate,
|
|
1625
|
+
showCalendarStartDate,
|
|
1626
|
+
showingCalendar,
|
|
1627
|
+
focusedInput,
|
|
1628
|
+
startDateInputRef,
|
|
1629
|
+
endDateInputRef,
|
|
1630
|
+
onClickDay,
|
|
1631
|
+
startDateIsAfterEnd
|
|
1632
|
+
} = useDateRangeInput(value, onValueChange);
|
|
1633
|
+
const statePerMonth = useMemo(() => buildDayStateForDateRange(void 0, value == null ? void 0 : value.startDate, value == null ? void 0 : value.endDate), [value]);
|
|
1634
|
+
return /* @__PURE__ */ jsx(Popover, {
|
|
1635
|
+
arrow: false,
|
|
1636
|
+
lazy: true,
|
|
1637
|
+
disabled,
|
|
1638
|
+
visible: showingCalendar,
|
|
1639
|
+
zIndex,
|
|
1640
|
+
placement: defaultPopoverPlacement,
|
|
1641
|
+
appendTo: portalTarget != null ? portalTarget : "parent",
|
|
1642
|
+
onClickOutside: hideCalendar,
|
|
1643
|
+
content: /* @__PURE__ */ jsx(CalendarWithMonthSwitcher, {
|
|
1644
|
+
...calendarProps,
|
|
1645
|
+
dateInFocus,
|
|
1646
|
+
setDateInFocus,
|
|
1647
|
+
statePerMonth,
|
|
1648
|
+
theme: calendarTheme,
|
|
1649
|
+
onClickDay,
|
|
1650
|
+
currentPanel,
|
|
1651
|
+
setCurrentPanel,
|
|
1652
|
+
minDate,
|
|
1653
|
+
maxDate
|
|
1654
|
+
}),
|
|
1655
|
+
children: /* @__PURE__ */ jsxs(Row, {
|
|
1656
|
+
alignItems: "center",
|
|
1657
|
+
children: [/* @__PURE__ */ jsx(TextInput, {
|
|
1658
|
+
iconLeft: stenaCalendar,
|
|
1659
|
+
onFocus: showCalendarStartDate,
|
|
1660
|
+
value: (value == null ? void 0 : value.startDate) ? format(value.startDate, displayFormat) : "",
|
|
1661
|
+
placeholder: placeholderStartDate,
|
|
1662
|
+
width,
|
|
1663
|
+
disabled,
|
|
1664
|
+
inputRef: startDateInputRef,
|
|
1665
|
+
size: 9,
|
|
1666
|
+
variant: startDateIsAfterEnd ? "error" : void 0
|
|
1667
|
+
}), /* @__PURE__ */ jsx(Space, {}), /* @__PURE__ */ jsx(Icon, {
|
|
1668
|
+
icon: faLongArrowAltRight,
|
|
1669
|
+
color: cssColor("--lhds-color-ui-500"),
|
|
1670
|
+
size: 14
|
|
1671
|
+
}), /* @__PURE__ */ jsx(Space, {}), /* @__PURE__ */ jsx(TextInput, {
|
|
1672
|
+
iconLeft: stenaCalendar,
|
|
1673
|
+
onFocus: showCalendarEndDate,
|
|
1674
|
+
value: (value == null ? void 0 : value.endDate) ? format(value.endDate, displayFormat) : "",
|
|
1675
|
+
placeholder: placeholderEndDate,
|
|
1676
|
+
width,
|
|
1677
|
+
disabled,
|
|
1678
|
+
inputRef: endDateInputRef,
|
|
1679
|
+
size: 9,
|
|
1680
|
+
variant: startDateIsAfterEnd ? "error" : void 0
|
|
1681
|
+
})]
|
|
1682
|
+
})
|
|
1683
|
+
});
|
|
1684
|
+
};
|
|
1685
|
+
const DateTextInput = ({
|
|
1686
|
+
calendarProps,
|
|
1687
|
+
closeOnCalendarSelectDate = true,
|
|
1688
|
+
dateFormat = DateFormats.fullDate,
|
|
1689
|
+
disableCalender = false,
|
|
1690
|
+
onValueChange,
|
|
1691
|
+
placeholder = "yyyy-mm-dd",
|
|
1692
|
+
portalTarget,
|
|
1693
|
+
value,
|
|
1694
|
+
width = "130px",
|
|
1695
|
+
zIndex = 100,
|
|
1696
|
+
calendarTheme = defaultCalendarTheme,
|
|
1697
|
+
hideCalenderIcon = false,
|
|
1698
|
+
minDate,
|
|
1699
|
+
maxDate = defaultMaxDate,
|
|
1700
|
+
variant,
|
|
1701
|
+
...props
|
|
1702
|
+
}) => {
|
|
1703
|
+
const [open, setOpen] = useState(false);
|
|
1704
|
+
const {
|
|
1705
|
+
tippyRef,
|
|
1706
|
+
onChangePanel
|
|
1707
|
+
} = useCalendarPopoverUpdater();
|
|
1708
|
+
const toggleCalendar = useCallback(() => {
|
|
1709
|
+
setOpen(!open);
|
|
1710
|
+
}, [setOpen, open]);
|
|
1711
|
+
const hideCalendar = useCallback(() => {
|
|
1712
|
+
setOpen(false);
|
|
1713
|
+
}, [setOpen]);
|
|
1714
|
+
const onValueChangeHandler = useCallback((value2) => {
|
|
1715
|
+
if (onValueChange) {
|
|
1716
|
+
onValueChange(value2);
|
|
1717
|
+
}
|
|
1718
|
+
}, [onValueChange]);
|
|
1719
|
+
const onCalendarSelectDate = useCallback((date) => {
|
|
1720
|
+
if (date) {
|
|
1721
|
+
onValueChangeHandler(format(date, dateFormat));
|
|
1722
|
+
if (closeOnCalendarSelectDate) {
|
|
1723
|
+
setTimeout(() => setOpen(!open), 200);
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
}, [onValueChangeHandler, dateFormat, closeOnCalendarSelectDate, setOpen, open]);
|
|
1727
|
+
const inValidInput = !!value && !/^[-/\\.0-9]+$/.test(value);
|
|
1728
|
+
const dateIsValid = !!value && isValid(parse(value, dateFormat, new Date()));
|
|
1729
|
+
const userInputCorrectLength = !!value && value.length >= dateFormat.length;
|
|
1730
|
+
const invalid = userInputCorrectLength && !dateIsValid || inValidInput;
|
|
1731
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
1732
|
+
width,
|
|
1733
|
+
children: /* @__PURE__ */ jsx(Popover, {
|
|
1734
|
+
arrow: false,
|
|
1735
|
+
lazy: true,
|
|
1736
|
+
visible: open,
|
|
1737
|
+
zIndex,
|
|
1738
|
+
appendTo: portalTarget != null ? portalTarget : "parent",
|
|
1739
|
+
placement: defaultPopoverPlacement,
|
|
1740
|
+
onClickOutside: hideCalendar,
|
|
1741
|
+
tippyRef,
|
|
1742
|
+
content: /* @__PURE__ */ jsx(SingleDateCalendar, {
|
|
1743
|
+
...calendarProps,
|
|
1744
|
+
onChange: onCalendarSelectDate,
|
|
1745
|
+
onChangePanel,
|
|
1746
|
+
value: value && dateIsValid ? parse(value, dateFormat, new Date()) : void 0,
|
|
1747
|
+
minDate,
|
|
1748
|
+
maxDate,
|
|
1749
|
+
theme: calendarTheme
|
|
1750
|
+
}),
|
|
1751
|
+
children: /* @__PURE__ */ jsx(TextInput, {
|
|
1752
|
+
...props,
|
|
1753
|
+
variant: invalid ? "error" : variant,
|
|
1754
|
+
disableContentPaddingRight: true,
|
|
1755
|
+
contentRight: !hideCalenderIcon ? /* @__PURE__ */ jsx(Row, {
|
|
1756
|
+
alignItems: "center",
|
|
1757
|
+
indent: 0.5,
|
|
1758
|
+
children: /* @__PURE__ */ jsx(FlatButton, {
|
|
1759
|
+
size: "small",
|
|
1760
|
+
disabled: props.disabled,
|
|
1761
|
+
leftIcon: stenaCalendar,
|
|
1762
|
+
onClick: toggleCalendar
|
|
1763
|
+
})
|
|
1764
|
+
}) : void 0,
|
|
1765
|
+
onValueChange: onValueChangeHandler,
|
|
1766
|
+
placeholder,
|
|
1767
|
+
value: value || "",
|
|
1768
|
+
min: minDate,
|
|
1769
|
+
max: maxDate,
|
|
1770
|
+
size: 10
|
|
1771
|
+
})
|
|
1772
|
+
})
|
|
1773
|
+
});
|
|
1774
|
+
};
|
|
1775
|
+
const formatHours = (hours2) => {
|
|
1776
|
+
if (hours2 === "") {
|
|
1777
|
+
return "00";
|
|
1778
|
+
}
|
|
1779
|
+
const h = parseInt(hours2, 10);
|
|
1780
|
+
if (isNaN(h)) {
|
|
1781
|
+
throw new Error("Hours is not a number");
|
|
1782
|
+
}
|
|
1783
|
+
if (h < 0 || h > 23) {
|
|
1784
|
+
throw new Error("Hours is an invalid number");
|
|
1785
|
+
}
|
|
1786
|
+
switch (hours2.length) {
|
|
1787
|
+
case 1:
|
|
1788
|
+
return `0${h}`;
|
|
1789
|
+
case 2:
|
|
1790
|
+
return hours2;
|
|
1791
|
+
default:
|
|
1792
|
+
throw new Error("Invalid hour string");
|
|
1793
|
+
}
|
|
1794
|
+
};
|
|
1795
|
+
const formatMinutes = (minutes2) => {
|
|
1796
|
+
if (minutes2 === "") {
|
|
1797
|
+
return "00";
|
|
1798
|
+
}
|
|
1799
|
+
const m = parseInt(minutes2, 10);
|
|
1800
|
+
if (isNaN(m)) {
|
|
1801
|
+
throw new Error("Minutes is not a number");
|
|
1802
|
+
}
|
|
1803
|
+
if (m < 0 || m > 59) {
|
|
1804
|
+
throw new Error("Minutes is an invalid number");
|
|
1805
|
+
}
|
|
1806
|
+
switch (minutes2.length) {
|
|
1807
|
+
case 1:
|
|
1808
|
+
return `0${m}`;
|
|
1809
|
+
case 2:
|
|
1810
|
+
return minutes2;
|
|
1811
|
+
default:
|
|
1812
|
+
throw new Error("Invalid minute string");
|
|
1813
|
+
}
|
|
1814
|
+
};
|
|
1815
|
+
const formatTimeString = (time) => {
|
|
1816
|
+
if (!validUserInput(time)) {
|
|
1817
|
+
return { time, success: false };
|
|
1818
|
+
}
|
|
1819
|
+
const arr = time && time.split(/-|:|,|;|[/]|[.]| /);
|
|
1820
|
+
if (arr && arr.length === 2) {
|
|
1821
|
+
try {
|
|
1822
|
+
const hours2 = formatHours(arr[0]);
|
|
1823
|
+
const minutes2 = formatMinutes(arr[1]);
|
|
1824
|
+
return { time: `${hours2}:${minutes2}`, success: true };
|
|
1825
|
+
} catch {
|
|
1826
|
+
return { time, success: false };
|
|
1827
|
+
}
|
|
1828
|
+
} else if (arr && arr.length === 1) {
|
|
1829
|
+
let hours2 = 0;
|
|
1830
|
+
let minutes2 = 0;
|
|
1831
|
+
switch (time.length) {
|
|
1832
|
+
case 1:
|
|
1833
|
+
return { time: `0${time}:00`, success: true };
|
|
1834
|
+
case 2:
|
|
1835
|
+
const timeNumber = parseInt(arr[0], 10);
|
|
1836
|
+
if (timeNumber >= 0 && timeNumber < 24) {
|
|
1837
|
+
return { time: `${time}:00`, success: true };
|
|
1838
|
+
} else if (timeNumber >= 24 && timeNumber < 59) {
|
|
1839
|
+
return { time: `00:${time}`, success: true };
|
|
1840
|
+
}
|
|
1841
|
+
return { time, success: false };
|
|
1842
|
+
case 3:
|
|
1843
|
+
minutes2 = parseInt(time.substr(1, 2), 10);
|
|
1844
|
+
if (minutes2 >= 0 && minutes2 <= 59) {
|
|
1845
|
+
return {
|
|
1846
|
+
time: `0${time.substr(0, 1)}:${time.substr(1, 2)}`,
|
|
1847
|
+
success: true
|
|
1848
|
+
};
|
|
1849
|
+
}
|
|
1850
|
+
return { time, success: false };
|
|
1851
|
+
case 4:
|
|
1852
|
+
hours2 = parseInt(time.substr(0, 2), 10);
|
|
1853
|
+
minutes2 = parseInt(time.substr(2, 2), 10);
|
|
1854
|
+
if (hours2 < 0 || hours2 > 23) {
|
|
1855
|
+
return { time, success: false };
|
|
1856
|
+
}
|
|
1857
|
+
if (minutes2 < 0 || minutes2 > 59) {
|
|
1858
|
+
return { time, success: false };
|
|
1859
|
+
}
|
|
1860
|
+
return {
|
|
1861
|
+
time: `${time.substr(0, 2)}:${time.substr(2, 2)}`,
|
|
1862
|
+
success: true
|
|
1863
|
+
};
|
|
1864
|
+
default:
|
|
1865
|
+
return { time, success: false };
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
return { time, success: false };
|
|
1869
|
+
};
|
|
1870
|
+
const validUserInput = (input) => {
|
|
1871
|
+
if (input) {
|
|
1872
|
+
return /^[-:.,/; 0-9]+$/.test(input);
|
|
1873
|
+
}
|
|
1874
|
+
return true;
|
|
1875
|
+
};
|
|
1876
|
+
const TimeTextInput = ({
|
|
1877
|
+
onValueChange,
|
|
1878
|
+
showPlaceholder = true,
|
|
1879
|
+
useIcon = true,
|
|
1880
|
+
value,
|
|
1881
|
+
width = "85px",
|
|
1882
|
+
variant,
|
|
1883
|
+
...props
|
|
1884
|
+
}) => {
|
|
1885
|
+
const [valid, setValid] = useState(() => validUserInput(value));
|
|
1886
|
+
const timeFormat = "hh:mm";
|
|
1887
|
+
const onBlur = useCallback(() => {
|
|
1888
|
+
if (value) {
|
|
1889
|
+
const formattedResult = formatTimeString(value);
|
|
1890
|
+
setValid(formattedResult.success);
|
|
1891
|
+
if (formattedResult.success) {
|
|
1892
|
+
if (onValueChange) {
|
|
1893
|
+
onValueChange(formattedResult.time);
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
}, [value, onValueChange, setValid]);
|
|
1898
|
+
const onChangeHandler = useCallback((ev) => {
|
|
1899
|
+
const time = ev.target.value;
|
|
1900
|
+
const validInput = validUserInput(time);
|
|
1901
|
+
setValid(validInput && time.length <= timeFormat.length);
|
|
1902
|
+
if (onValueChange) {
|
|
1903
|
+
onValueChange(time);
|
|
1904
|
+
}
|
|
1905
|
+
}, [onValueChange, setValid]);
|
|
1906
|
+
return /* @__PURE__ */ jsx(TextInput, {
|
|
1907
|
+
...props,
|
|
1908
|
+
type: "time",
|
|
1909
|
+
variant: !valid ? "error" : variant,
|
|
1910
|
+
iconLeft: useIcon ? stenaClock : void 0,
|
|
1911
|
+
value,
|
|
1912
|
+
placeholder: showPlaceholder ? timeFormat : void 0,
|
|
1913
|
+
onChange: onChangeHandler,
|
|
1914
|
+
onBlur,
|
|
1915
|
+
width
|
|
1916
|
+
});
|
|
1917
|
+
};
|
|
1918
|
+
const DualTextInput = ({
|
|
1919
|
+
autoFocusLeft,
|
|
1920
|
+
autoFocusRight,
|
|
1921
|
+
onEsc,
|
|
1922
|
+
onEnter,
|
|
1923
|
+
onValueChangeLeft,
|
|
1924
|
+
onValueChangeRight,
|
|
1925
|
+
separatorIcon,
|
|
1926
|
+
placeholderLeft,
|
|
1927
|
+
placeholderRight,
|
|
1928
|
+
typeLeft,
|
|
1929
|
+
typeRight,
|
|
1930
|
+
onChangeLeft,
|
|
1931
|
+
onChangeRight,
|
|
1932
|
+
valueLeft,
|
|
1933
|
+
valueRight,
|
|
1934
|
+
minLeft,
|
|
1935
|
+
maxLeft,
|
|
1936
|
+
minRight,
|
|
1937
|
+
maxRight,
|
|
1938
|
+
onClickLeft,
|
|
1939
|
+
onClickRight,
|
|
1940
|
+
onClickCalendar,
|
|
1941
|
+
onClickArrowDown,
|
|
1942
|
+
onBlurLeft,
|
|
1943
|
+
onBlurRight,
|
|
1944
|
+
onFocusLeft,
|
|
1945
|
+
onFocusRight,
|
|
1946
|
+
inputRefLeft,
|
|
1947
|
+
inputRefRight,
|
|
1948
|
+
variant,
|
|
1949
|
+
variantLeft,
|
|
1950
|
+
variantRight,
|
|
1951
|
+
onBlur,
|
|
1952
|
+
showPresets,
|
|
1953
|
+
widthLeft,
|
|
1954
|
+
widthRight,
|
|
1955
|
+
disabled
|
|
1956
|
+
}) => {
|
|
1957
|
+
const focusCounter = useRef(0);
|
|
1958
|
+
const tryTriggerOnBlur = useMemo(() => debounce((focusCounter2) => {
|
|
1959
|
+
if (focusCounter2 === 0) {
|
|
1960
|
+
onBlur == null ? void 0 : onBlur();
|
|
1961
|
+
}
|
|
1962
|
+
}, 10), [onBlur]);
|
|
1963
|
+
const focusLeftHandler = useCallback((ev) => {
|
|
1964
|
+
focusCounter.current++;
|
|
1965
|
+
tryTriggerOnBlur(focusCounter.current);
|
|
1966
|
+
if (onFocusLeft) {
|
|
1967
|
+
onFocusLeft(ev);
|
|
1968
|
+
}
|
|
1969
|
+
}, [onFocusLeft, focusCounter, tryTriggerOnBlur]);
|
|
1970
|
+
const focusRightHandler = useCallback((ev) => {
|
|
1971
|
+
focusCounter.current++;
|
|
1972
|
+
tryTriggerOnBlur(focusCounter.current);
|
|
1973
|
+
if (onFocusRight) {
|
|
1974
|
+
onFocusRight(ev);
|
|
1975
|
+
}
|
|
1976
|
+
}, [onFocusRight, focusCounter, tryTriggerOnBlur]);
|
|
1977
|
+
const blurLeftHandler = useCallback((ev) => {
|
|
1978
|
+
focusCounter.current--;
|
|
1979
|
+
tryTriggerOnBlur(focusCounter.current);
|
|
1980
|
+
if (onBlurLeft) {
|
|
1981
|
+
onBlurLeft(ev);
|
|
1982
|
+
}
|
|
1983
|
+
}, [onBlurLeft, focusCounter, tryTriggerOnBlur]);
|
|
1984
|
+
const blurRightHandler = useCallback((ev) => {
|
|
1985
|
+
focusCounter.current--;
|
|
1986
|
+
tryTriggerOnBlur(focusCounter.current);
|
|
1987
|
+
if (onBlurRight) {
|
|
1988
|
+
onBlurRight(ev);
|
|
1989
|
+
}
|
|
1990
|
+
}, [onBlurRight, focusCounter, tryTriggerOnBlur]);
|
|
1991
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
1992
|
+
children: /* @__PURE__ */ jsxs(TextInputBox, {
|
|
1993
|
+
disableContentPaddingRight: true,
|
|
1994
|
+
disabled,
|
|
1995
|
+
variant,
|
|
1996
|
+
contentRight: /* @__PURE__ */ jsxs(Row, {
|
|
1997
|
+
alignItems: "center",
|
|
1998
|
+
children: [/* @__PURE__ */ jsx(Indent, {
|
|
1999
|
+
num: 0.5,
|
|
2000
|
+
children: /* @__PURE__ */ jsx(FlatButton, {
|
|
2001
|
+
leftIcon: stenaCalendar,
|
|
2002
|
+
onClick: onClickCalendar,
|
|
2003
|
+
disabled,
|
|
2004
|
+
size: "small"
|
|
2005
|
+
})
|
|
2006
|
+
}), showPresets ? /* @__PURE__ */ jsxs(Fragment, {
|
|
2007
|
+
children: [/* @__PURE__ */ jsx(Row, {
|
|
2008
|
+
height: "22px",
|
|
2009
|
+
children: /* @__PURE__ */ jsx(SeparatorLine, {
|
|
2010
|
+
vertical: true
|
|
2011
|
+
})
|
|
2012
|
+
}), /* @__PURE__ */ jsx(Indent, {
|
|
2013
|
+
num: 0.5,
|
|
2014
|
+
children: /* @__PURE__ */ jsx(FlatButton, {
|
|
2015
|
+
leftIcon: stenaAngleDown,
|
|
2016
|
+
onClick: onClickArrowDown,
|
|
2017
|
+
disabled,
|
|
2018
|
+
size: "small"
|
|
2019
|
+
})
|
|
2020
|
+
})]
|
|
2021
|
+
}) : null]
|
|
2022
|
+
}),
|
|
2023
|
+
children: [/* @__PURE__ */ jsx(Box, {
|
|
2024
|
+
width: widthLeft,
|
|
2025
|
+
children: /* @__PURE__ */ jsx(TextInput, {
|
|
2026
|
+
onEsc,
|
|
2027
|
+
onEnter,
|
|
2028
|
+
onClick: onClickLeft,
|
|
2029
|
+
disabled,
|
|
2030
|
+
hideBorder: true,
|
|
2031
|
+
placeholder: placeholderLeft,
|
|
2032
|
+
value: valueLeft,
|
|
2033
|
+
onValueChange: onValueChangeLeft,
|
|
2034
|
+
onChange: onChangeLeft,
|
|
2035
|
+
onBlur: blurLeftHandler,
|
|
2036
|
+
onFocus: focusLeftHandler,
|
|
2037
|
+
inputRef: inputRefLeft,
|
|
2038
|
+
variant: variantLeft,
|
|
2039
|
+
type: typeLeft,
|
|
2040
|
+
autoFocus: autoFocusLeft,
|
|
2041
|
+
min: minLeft,
|
|
2042
|
+
max: maxLeft
|
|
2043
|
+
})
|
|
2044
|
+
}), /* @__PURE__ */ jsx(Row, {
|
|
2045
|
+
indent: 0.5,
|
|
2046
|
+
alignItems: "center",
|
|
2047
|
+
justifyContent: "center",
|
|
2048
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
2049
|
+
icon: separatorIcon,
|
|
2050
|
+
size: 12,
|
|
2051
|
+
color: cssColor("--lhds-color-ui-500")
|
|
2052
|
+
})
|
|
2053
|
+
}), /* @__PURE__ */ jsx(Box, {
|
|
2054
|
+
width: widthRight,
|
|
2055
|
+
children: /* @__PURE__ */ jsx(TextInput, {
|
|
2056
|
+
onEsc,
|
|
2057
|
+
onEnter,
|
|
2058
|
+
onClick: onClickRight,
|
|
2059
|
+
disabled,
|
|
2060
|
+
hideBorder: true,
|
|
2061
|
+
placeholder: placeholderRight,
|
|
2062
|
+
value: valueRight,
|
|
2063
|
+
onValueChange: onValueChangeRight,
|
|
2064
|
+
onChange: onChangeRight,
|
|
2065
|
+
onBlur: blurRightHandler,
|
|
2066
|
+
onFocus: focusRightHandler,
|
|
2067
|
+
inputRef: inputRefRight,
|
|
2068
|
+
variant: variantRight,
|
|
2069
|
+
type: typeRight,
|
|
2070
|
+
autoFocus: autoFocusRight,
|
|
2071
|
+
min: minRight,
|
|
2072
|
+
max: maxRight
|
|
2073
|
+
})
|
|
2074
|
+
})]
|
|
2075
|
+
})
|
|
2076
|
+
});
|
|
2077
|
+
};
|
|
2078
|
+
const transformTimeStringToNumber = (time) => {
|
|
2079
|
+
if (time == null) {
|
|
2080
|
+
throw new Error("Time is not set.");
|
|
2081
|
+
}
|
|
2082
|
+
if (time === "") {
|
|
2083
|
+
throw new Error("Time is empty.");
|
|
2084
|
+
}
|
|
2085
|
+
const parts = time.split(":");
|
|
2086
|
+
if (parts.length !== 2) {
|
|
2087
|
+
throw new Error("Invalid time.");
|
|
2088
|
+
}
|
|
2089
|
+
if (parts[1].length !== 2) {
|
|
2090
|
+
throw new Error("Invalid time.");
|
|
2091
|
+
}
|
|
2092
|
+
if (parts[0].length < 1 || parts[0].length > 2) {
|
|
2093
|
+
throw new Error("Invalid time.");
|
|
2094
|
+
}
|
|
2095
|
+
const hours2 = parseInt(parts[0], 10);
|
|
2096
|
+
const minutes2 = parseInt(parts[1], 10);
|
|
2097
|
+
if (isNaN(hours2)) {
|
|
2098
|
+
throw new Error("Invalid time.");
|
|
2099
|
+
}
|
|
2100
|
+
if (isNaN(minutes2)) {
|
|
2101
|
+
throw new Error("Invalid time.");
|
|
2102
|
+
}
|
|
2103
|
+
if (hours2 < 0 || hours2 > 23) {
|
|
2104
|
+
throw new Error("Invalid time.");
|
|
2105
|
+
}
|
|
2106
|
+
if (minutes2 < 0 || minutes2 > 59) {
|
|
2107
|
+
throw new Error("Invalid time.");
|
|
2108
|
+
}
|
|
2109
|
+
return hours2 * 100 + minutes2;
|
|
2110
|
+
};
|
|
2111
|
+
const isValidTimeString = (time) => {
|
|
2112
|
+
try {
|
|
2113
|
+
transformTimeStringToNumber(time);
|
|
2114
|
+
return true;
|
|
2115
|
+
} catch (e) {
|
|
2116
|
+
return false;
|
|
2117
|
+
}
|
|
2118
|
+
};
|
|
2119
|
+
const getHoursAndMinutesFromTimeString = (value) => {
|
|
2120
|
+
if (value && isValidTimeString(value)) {
|
|
2121
|
+
const p = value.split(":");
|
|
2122
|
+
return {
|
|
2123
|
+
hour: parseIntElseUndefined(p[0]),
|
|
2124
|
+
minute: parseIntElseUndefined(p[1])
|
|
2125
|
+
};
|
|
2126
|
+
}
|
|
2127
|
+
return {
|
|
2128
|
+
hour: void 0,
|
|
2129
|
+
minute: void 0
|
|
2130
|
+
};
|
|
2131
|
+
};
|
|
2132
|
+
const transformTimeInDateToTimeString = (date) => `${formatHours(String(date.getHours()))}:${formatMinutes(String(date.getMinutes()))}`;
|
|
2133
|
+
const timePicker = "_timePicker_1w05d_1";
|
|
2134
|
+
const timePickerColumn = "_timePickerColumn_1w05d_6";
|
|
2135
|
+
var styles = {
|
|
2136
|
+
timePicker,
|
|
2137
|
+
timePickerColumn
|
|
2138
|
+
};
|
|
2139
|
+
const TimePickerCell = ({
|
|
2140
|
+
onClick,
|
|
2141
|
+
item,
|
|
2142
|
+
selected,
|
|
2143
|
+
columnRef,
|
|
2144
|
+
canScrollRef
|
|
2145
|
+
}) => {
|
|
2146
|
+
const ref = useRef(null);
|
|
2147
|
+
useEffect(function scrollToSelectedItem() {
|
|
2148
|
+
if (selected && columnRef.current && ref.current && canScrollRef.current) {
|
|
2149
|
+
const targetScroll = ref.current.scrollHeight * Math.max(item - 2, 0);
|
|
2150
|
+
columnRef.current.scrollTo(0, targetScroll);
|
|
2151
|
+
canScrollRef.current = false;
|
|
2152
|
+
}
|
|
2153
|
+
}, [columnRef, item, selected, canScrollRef]);
|
|
2154
|
+
return /* @__PURE__ */ jsx(Row, {
|
|
2155
|
+
width: "64px",
|
|
2156
|
+
justifyContent: "center",
|
|
2157
|
+
spacing: 0.5,
|
|
2158
|
+
indent: 0.5,
|
|
2159
|
+
ref,
|
|
2160
|
+
children: selected ? /* @__PURE__ */ jsx(PrimaryButton, {
|
|
2161
|
+
label: String(item),
|
|
2162
|
+
onClick: () => onClick && onClick(item)
|
|
2163
|
+
}) : /* @__PURE__ */ jsx(FlatButton, {
|
|
2164
|
+
label: String(item),
|
|
2165
|
+
onClick: () => onClick && onClick(item)
|
|
2166
|
+
})
|
|
2167
|
+
});
|
|
2168
|
+
};
|
|
2169
|
+
const TimePickerColumn = ({
|
|
2170
|
+
onClick,
|
|
2171
|
+
items,
|
|
2172
|
+
selectedItem,
|
|
2173
|
+
canScrollRef
|
|
2174
|
+
}) => {
|
|
2175
|
+
const columnRef = useRef(null);
|
|
2176
|
+
return /* @__PURE__ */ jsx(Column, {
|
|
2177
|
+
className: styles.timePickerColumn,
|
|
2178
|
+
ref: columnRef,
|
|
2179
|
+
children: items.map((item) => /* @__PURE__ */ jsx(TimePickerCell, {
|
|
2180
|
+
item,
|
|
2181
|
+
onClick,
|
|
2182
|
+
selected: item === selectedItem,
|
|
2183
|
+
columnRef,
|
|
2184
|
+
canScrollRef
|
|
2185
|
+
}, item))
|
|
2186
|
+
});
|
|
2187
|
+
};
|
|
2188
|
+
const hours = range(0, 24);
|
|
2189
|
+
const minutes = range(0, 60);
|
|
2190
|
+
const TimePicker = ({
|
|
2191
|
+
value,
|
|
2192
|
+
onValueChange
|
|
2193
|
+
}) => {
|
|
2194
|
+
const canScrollRef = useRef(true);
|
|
2195
|
+
const [hour, setHour] = useState(void 0);
|
|
2196
|
+
const [minute, setMinute] = useState(void 0);
|
|
2197
|
+
useEffect(() => {
|
|
2198
|
+
if (value) {
|
|
2199
|
+
const {
|
|
2200
|
+
minute: minute2,
|
|
2201
|
+
hour: hour2
|
|
2202
|
+
} = getHoursAndMinutesFromTimeString(value);
|
|
2203
|
+
setHour(hour2);
|
|
2204
|
+
setMinute(minute2);
|
|
2205
|
+
}
|
|
2206
|
+
}, [value]);
|
|
2207
|
+
const onClickHour = useCallback((h) => {
|
|
2208
|
+
setHour(h);
|
|
2209
|
+
onValueChange == null ? void 0 : onValueChange(`${formatHours(String(h != null ? h : 0))}:${formatMinutes(String(minute != null ? minute : 0))}`);
|
|
2210
|
+
}, [minute, onValueChange]);
|
|
2211
|
+
const onClickMinutes = useCallback((m) => {
|
|
2212
|
+
setMinute(m);
|
|
2213
|
+
onValueChange == null ? void 0 : onValueChange(`${formatHours(String(hour != null ? hour : 0))}:${formatMinutes(String(m != null ? m : 0))}`);
|
|
2214
|
+
}, [hour, onValueChange]);
|
|
2215
|
+
return /* @__PURE__ */ jsxs(Row, {
|
|
2216
|
+
className: styles.timePicker,
|
|
2217
|
+
children: [/* @__PURE__ */ jsx(TimePickerColumn, {
|
|
2218
|
+
items: hours,
|
|
2219
|
+
onClick: onClickHour,
|
|
2220
|
+
selectedItem: hour,
|
|
2221
|
+
canScrollRef
|
|
2222
|
+
}), /* @__PURE__ */ jsx(Indent, {}), /* @__PURE__ */ jsx(TimePickerColumn, {
|
|
2223
|
+
items: minutes,
|
|
2224
|
+
onClick: onClickMinutes,
|
|
2225
|
+
selectedItem: minute,
|
|
2226
|
+
canScrollRef
|
|
2227
|
+
})]
|
|
2228
|
+
});
|
|
2229
|
+
};
|
|
2230
|
+
const useDateRangeEffects$1 = (date, setDateInFocus, dateInputRef) => {
|
|
2231
|
+
useEffect(function moveFocusedDateWhenDateChanges() {
|
|
2232
|
+
if (date) {
|
|
2233
|
+
setDateInFocus(date);
|
|
2234
|
+
}
|
|
2235
|
+
}, [date, setDateInFocus]);
|
|
2236
|
+
useEffect(function updateDateFieldWhenValueChanges() {
|
|
2237
|
+
if (dateInputRef.current) {
|
|
2238
|
+
if (date) {
|
|
2239
|
+
dateInputRef.current.valueAsDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
|
|
2240
|
+
} else {
|
|
2241
|
+
dateInputRef.current.valueAsDate = null;
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
}, [date, dateInputRef]);
|
|
2245
|
+
};
|
|
2246
|
+
const useDateRangeHandlers$1 = (date, onValueChange, {
|
|
2247
|
+
setDateInFocus,
|
|
2248
|
+
showCalendarInternal,
|
|
2249
|
+
hideCalendarInternal,
|
|
2250
|
+
setFirstFocusedInput,
|
|
2251
|
+
setCurrentPanel,
|
|
2252
|
+
localTime,
|
|
2253
|
+
setLocalTime,
|
|
2254
|
+
localDate,
|
|
2255
|
+
setLocalDate
|
|
2256
|
+
}, dateInputRef) => {
|
|
2257
|
+
const onChangeDate = useCallback((incomingDate) => {
|
|
2258
|
+
if (!incomingDate) {
|
|
2259
|
+
return;
|
|
2260
|
+
}
|
|
2261
|
+
const newDate = new Date(incomingDate);
|
|
2262
|
+
if (date) {
|
|
2263
|
+
newDate.setHours(date.getHours());
|
|
2264
|
+
newDate.setMinutes(date.getMinutes());
|
|
2265
|
+
onValueChange == null ? void 0 : onValueChange(newDate);
|
|
2266
|
+
setLocalDate(void 0);
|
|
2267
|
+
} else if (localTime) {
|
|
2268
|
+
const { minute, hour } = getHoursAndMinutesFromTimeString(localTime);
|
|
2269
|
+
newDate.setHours(hour != null ? hour : 0);
|
|
2270
|
+
newDate.setMinutes(minute != null ? minute : 0);
|
|
2271
|
+
onValueChange == null ? void 0 : onValueChange(newDate);
|
|
2272
|
+
setLocalDate(void 0);
|
|
2273
|
+
} else {
|
|
2274
|
+
setLocalDate(newDate);
|
|
2275
|
+
}
|
|
2276
|
+
setDateInFocus(newDate);
|
|
2277
|
+
if (dateInputRef.current) {
|
|
2278
|
+
dateInputRef.current.valueAsDate = newDate;
|
|
2279
|
+
}
|
|
2280
|
+
}, [date, dateInputRef, localTime, onValueChange, setDateInFocus, setLocalDate]);
|
|
2281
|
+
const onChangeTime = useCallback((time) => {
|
|
2282
|
+
if (!time) {
|
|
2283
|
+
return;
|
|
2284
|
+
}
|
|
2285
|
+
if (date) {
|
|
2286
|
+
const newTime = getHoursAndMinutesFromTimeString(time);
|
|
2287
|
+
const newDate = new Date(date);
|
|
2288
|
+
newDate.setHours(newTime.hour || 0);
|
|
2289
|
+
newDate.setMinutes(newTime.minute || 0);
|
|
2290
|
+
onValueChange == null ? void 0 : onValueChange(newDate);
|
|
2291
|
+
setLocalTime(void 0);
|
|
2292
|
+
} else if (localDate) {
|
|
2293
|
+
const newTime = getHoursAndMinutesFromTimeString(time);
|
|
2294
|
+
const newDate = new Date(localDate);
|
|
2295
|
+
newDate.setHours(newTime.hour || 0);
|
|
2296
|
+
newDate.setMinutes(newTime.minute || 0);
|
|
2297
|
+
onValueChange == null ? void 0 : onValueChange(newDate);
|
|
2298
|
+
setLocalTime(void 0);
|
|
2299
|
+
} else {
|
|
2300
|
+
setLocalTime(time);
|
|
2301
|
+
}
|
|
2302
|
+
}, [onValueChange, date, localDate, setLocalTime]);
|
|
2303
|
+
const inputLeftChangeHandler = useCallback((ev) => {
|
|
2304
|
+
if (ev.target.value[0] !== "0") {
|
|
2305
|
+
onChangeDate(ev.target.valueAsDate);
|
|
2306
|
+
}
|
|
2307
|
+
}, [onChangeDate]);
|
|
2308
|
+
const inputRightChangeHandler = useCallback((ev) => onChangeTime(ev.target.value), [onChangeTime]);
|
|
2309
|
+
const showCalendar = useCallback(() => {
|
|
2310
|
+
if (date) {
|
|
2311
|
+
setDateInFocus(date);
|
|
2312
|
+
} else {
|
|
2313
|
+
setDateInFocus(new Date());
|
|
2314
|
+
}
|
|
2315
|
+
setCurrentPanel("calendar");
|
|
2316
|
+
showCalendarInternal();
|
|
2317
|
+
}, [date, setCurrentPanel, showCalendarInternal, setDateInFocus]);
|
|
2318
|
+
const hideCalendar = useCallback(() => {
|
|
2319
|
+
setFirstFocusedInput(void 0);
|
|
2320
|
+
hideCalendarInternal();
|
|
2321
|
+
}, [setFirstFocusedInput, hideCalendarInternal]);
|
|
2322
|
+
return {
|
|
2323
|
+
inputLeftChangeHandler,
|
|
2324
|
+
inputRightChangeHandler,
|
|
2325
|
+
hideCalendar,
|
|
2326
|
+
showCalendar,
|
|
2327
|
+
onChangeTime,
|
|
2328
|
+
onChangeDate
|
|
2329
|
+
};
|
|
2330
|
+
};
|
|
2331
|
+
const useInputStates$1 = (date) => {
|
|
2332
|
+
const [localDate, setLocalDate] = useState(void 0);
|
|
2333
|
+
const [localTime, setLocalTime] = useState(void 0);
|
|
2334
|
+
const [isCalendarVisible, showCalendarInternal, hideCalendarInternal] = useBoolean(false);
|
|
2335
|
+
const [isTimePickerVisible, showTimePicker, hideTimePicker] = useBoolean(false);
|
|
2336
|
+
const [firstFocusedInput, setFirstFocusedInput] = useState(void 0);
|
|
2337
|
+
const [dateInFocus, setDateInFocus] = useState(() => date != null ? date : new Date());
|
|
2338
|
+
const [currentPanel, setCurrentPanel] = useState("calendar");
|
|
2339
|
+
return {
|
|
2340
|
+
isCalendarVisible,
|
|
2341
|
+
showCalendarInternal,
|
|
2342
|
+
hideCalendarInternal,
|
|
2343
|
+
firstFocusedInput,
|
|
2344
|
+
setFirstFocusedInput,
|
|
2345
|
+
dateInFocus,
|
|
2346
|
+
setDateInFocus,
|
|
2347
|
+
currentPanel,
|
|
2348
|
+
setCurrentPanel,
|
|
2349
|
+
isTimePickerVisible,
|
|
2350
|
+
showTimePicker,
|
|
2351
|
+
hideTimePicker,
|
|
2352
|
+
localDate,
|
|
2353
|
+
setLocalDate,
|
|
2354
|
+
localTime,
|
|
2355
|
+
setLocalTime
|
|
2356
|
+
};
|
|
2357
|
+
};
|
|
2358
|
+
const useUserInputHandlers$1 = (onChangeDate, dateInputRef, showCalendar, hideCalendar, {
|
|
2359
|
+
isCalendarVisible,
|
|
2360
|
+
setCurrentPanel,
|
|
2361
|
+
showTimePicker,
|
|
2362
|
+
hideTimePicker
|
|
2363
|
+
}) => {
|
|
2364
|
+
const onFocusLeft = useCallback(() => {
|
|
2365
|
+
if (!isCalendarVisible) {
|
|
2366
|
+
showCalendar();
|
|
2367
|
+
}
|
|
2368
|
+
setCurrentPanel("calendar");
|
|
2369
|
+
hideTimePicker();
|
|
2370
|
+
}, [hideTimePicker, isCalendarVisible, setCurrentPanel, showCalendar]);
|
|
2371
|
+
const onFocusRight = useCallback(() => {
|
|
2372
|
+
hideCalendar();
|
|
2373
|
+
showTimePicker();
|
|
2374
|
+
}, [hideCalendar, showTimePicker]);
|
|
2375
|
+
const onClickDay = useCallback((day) => {
|
|
2376
|
+
onChangeDate(day.date);
|
|
2377
|
+
hideCalendar();
|
|
2378
|
+
showTimePicker();
|
|
2379
|
+
}, [onChangeDate, hideCalendar, showTimePicker]);
|
|
2380
|
+
const onClickArrowButton = useCallback(() => {
|
|
2381
|
+
setCurrentPanel("presets");
|
|
2382
|
+
showCalendar();
|
|
2383
|
+
}, [setCurrentPanel, showCalendar]);
|
|
2384
|
+
const onClickCalendarButton = useCallback(() => {
|
|
2385
|
+
var _a;
|
|
2386
|
+
if (isCalendarVisible) {
|
|
2387
|
+
hideCalendar();
|
|
2388
|
+
} else {
|
|
2389
|
+
(_a = dateInputRef.current) == null ? void 0 : _a.focus();
|
|
2390
|
+
setCurrentPanel("calendar");
|
|
2391
|
+
showCalendar();
|
|
2392
|
+
}
|
|
2393
|
+
}, [
|
|
2394
|
+
isCalendarVisible,
|
|
2395
|
+
hideCalendar,
|
|
2396
|
+
dateInputRef,
|
|
2397
|
+
setCurrentPanel,
|
|
2398
|
+
showCalendar
|
|
2399
|
+
]);
|
|
2400
|
+
const onKeyDownHandler = useCallback((ev) => {
|
|
2401
|
+
if (ev.key === "Escape") {
|
|
2402
|
+
hideCalendar();
|
|
2403
|
+
}
|
|
2404
|
+
}, [hideCalendar]);
|
|
2405
|
+
return {
|
|
2406
|
+
onFocusLeft,
|
|
2407
|
+
onFocusRight,
|
|
2408
|
+
onClickDay,
|
|
2409
|
+
onClickArrowButton,
|
|
2410
|
+
onClickCalendarButton,
|
|
2411
|
+
onKeyDownHandler
|
|
2412
|
+
};
|
|
2413
|
+
};
|
|
2414
|
+
const DateTimeInput = ({
|
|
2415
|
+
value,
|
|
2416
|
+
onValueChange,
|
|
2417
|
+
onEnter,
|
|
2418
|
+
onEsc,
|
|
2419
|
+
onBlur,
|
|
2420
|
+
autoFocus,
|
|
2421
|
+
minDate,
|
|
2422
|
+
widthLeft = 128,
|
|
2423
|
+
widthRight = 80,
|
|
2424
|
+
maxDate = defaultMaxDate,
|
|
2425
|
+
variant,
|
|
2426
|
+
disabled
|
|
2427
|
+
}) => {
|
|
2428
|
+
const dateInputRef = useRef(null);
|
|
2429
|
+
const timeInputRef = useRef(null);
|
|
2430
|
+
const states = useInputStates$1(value);
|
|
2431
|
+
const {
|
|
2432
|
+
setCurrentPanel,
|
|
2433
|
+
currentPanel,
|
|
2434
|
+
isCalendarVisible,
|
|
2435
|
+
dateInFocus,
|
|
2436
|
+
setDateInFocus,
|
|
2437
|
+
isTimePickerVisible,
|
|
2438
|
+
hideTimePicker,
|
|
2439
|
+
localTime,
|
|
2440
|
+
localDate
|
|
2441
|
+
} = states;
|
|
2442
|
+
const {
|
|
2443
|
+
showCalendar,
|
|
2444
|
+
hideCalendar,
|
|
2445
|
+
inputLeftChangeHandler,
|
|
2446
|
+
inputRightChangeHandler,
|
|
2447
|
+
onChangeTime,
|
|
2448
|
+
onChangeDate
|
|
2449
|
+
} = useDateRangeHandlers$1(value, onValueChange, states, dateInputRef);
|
|
2450
|
+
const {
|
|
2451
|
+
onKeyDownHandler,
|
|
2452
|
+
onFocusRight,
|
|
2453
|
+
onFocusLeft,
|
|
2454
|
+
onClickDay,
|
|
2455
|
+
onClickCalendarButton,
|
|
2456
|
+
onClickArrowButton
|
|
2457
|
+
} = useUserInputHandlers$1(onChangeDate, dateInputRef, showCalendar, hideCalendar, states);
|
|
2458
|
+
useDateRangeEffects$1(value, setDateInFocus, dateInputRef);
|
|
2459
|
+
const statePerMonth = useMemo(() => {
|
|
2460
|
+
const dateToHighlight = value || localDate;
|
|
2461
|
+
if (!dateToHighlight) {
|
|
2462
|
+
return {};
|
|
2463
|
+
}
|
|
2464
|
+
return addDayStateHighlights(void 0, dateToHighlight, ["singleSelected", "selected"]);
|
|
2465
|
+
}, [localDate, value]);
|
|
2466
|
+
const hideAll = useCallback(() => {
|
|
2467
|
+
hideCalendar();
|
|
2468
|
+
hideTimePicker();
|
|
2469
|
+
}, [hideCalendar, hideTimePicker]);
|
|
2470
|
+
const timeValue = useMemo(() => value ? transformTimeInDateToTimeString(value) : localTime, [value, localTime]);
|
|
2471
|
+
const delayedIsCalendarVisible = useDelayedFalse(isCalendarVisible, 300);
|
|
2472
|
+
const delayedIsTimePickerVisible = useDelayedFalse(isTimePickerVisible, 300);
|
|
2473
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
2474
|
+
onKeyDown: onKeyDownHandler,
|
|
2475
|
+
children: /* @__PURE__ */ jsx(Popover, {
|
|
2476
|
+
arrow: false,
|
|
2477
|
+
lazy: true,
|
|
2478
|
+
disabled,
|
|
2479
|
+
placement: defaultPopoverPlacement,
|
|
2480
|
+
visible: isCalendarVisible || isTimePickerVisible,
|
|
2481
|
+
onClickOutside: hideAll,
|
|
2482
|
+
content: (delayedIsCalendarVisible || delayedIsTimePickerVisible) && /* @__PURE__ */ jsx(Column, {
|
|
2483
|
+
children: delayedIsCalendarVisible ? /* @__PURE__ */ jsx(CalendarWithMonthSwitcher, {
|
|
2484
|
+
statePerMonth,
|
|
2485
|
+
onClickDay,
|
|
2486
|
+
dateInFocus,
|
|
2487
|
+
setDateInFocus,
|
|
2488
|
+
currentPanel,
|
|
2489
|
+
setCurrentPanel,
|
|
2490
|
+
minDate,
|
|
2491
|
+
maxDate
|
|
2492
|
+
}) : delayedIsTimePickerVisible ? /* @__PURE__ */ jsxs(Column, {
|
|
2493
|
+
children: [/* @__PURE__ */ jsx(Column, {
|
|
2494
|
+
overflow: "hidden",
|
|
2495
|
+
height: "250px",
|
|
2496
|
+
children: /* @__PURE__ */ jsx(TimePicker, {
|
|
2497
|
+
value: timeValue != null ? timeValue : "",
|
|
2498
|
+
onValueChange: onChangeTime
|
|
2499
|
+
})
|
|
2500
|
+
}), /* @__PURE__ */ jsx(Space, {}), /* @__PURE__ */ jsx(Row, {
|
|
2501
|
+
justifyContent: "flex-end",
|
|
2502
|
+
children: /* @__PURE__ */ jsx(PrimaryButton, {
|
|
2503
|
+
label: "Done",
|
|
2504
|
+
onClick: hideTimePicker
|
|
2505
|
+
})
|
|
2506
|
+
})]
|
|
2507
|
+
}) : null
|
|
2508
|
+
}),
|
|
2509
|
+
children: /* @__PURE__ */ jsx(DualTextInput, {
|
|
2510
|
+
autoFocusLeft: autoFocus,
|
|
2511
|
+
onEsc,
|
|
2512
|
+
onEnter,
|
|
2513
|
+
onBlur,
|
|
2514
|
+
disabled,
|
|
2515
|
+
separatorIcon: stenaClock,
|
|
2516
|
+
typeLeft: "date",
|
|
2517
|
+
typeRight: "time",
|
|
2518
|
+
placeholderLeft: "yyyy-mm-dd",
|
|
2519
|
+
placeholderRight: "hh:mm",
|
|
2520
|
+
onChangeLeft: inputLeftChangeHandler,
|
|
2521
|
+
onChangeRight: inputRightChangeHandler,
|
|
2522
|
+
onClickArrowDown: onClickArrowButton,
|
|
2523
|
+
onClickCalendar: onClickCalendarButton,
|
|
2524
|
+
onFocusLeft,
|
|
2525
|
+
onFocusRight,
|
|
2526
|
+
onClickLeft: onFocusLeft,
|
|
2527
|
+
onClickRight: onFocusRight,
|
|
2528
|
+
inputRefLeft: dateInputRef,
|
|
2529
|
+
inputRefRight: timeInputRef,
|
|
2530
|
+
valueRight: timeValue != null ? timeValue : "",
|
|
2531
|
+
widthLeft,
|
|
2532
|
+
widthRight,
|
|
2533
|
+
minLeft: minDate,
|
|
2534
|
+
maxLeft: maxDate,
|
|
2535
|
+
variant
|
|
2536
|
+
})
|
|
2537
|
+
})
|
|
2538
|
+
});
|
|
2539
|
+
};
|
|
2540
|
+
const useDateRangeEffects = (startDate, endDate, setDateInFocus, startDateInputRef, endDateInputRef) => {
|
|
2541
|
+
useEffect(function moveFocusedDateWhenStartDateChanges() {
|
|
2542
|
+
if (startDate) {
|
|
2543
|
+
setDateInFocus(startDate);
|
|
2544
|
+
}
|
|
2545
|
+
}, [startDate, setDateInFocus]);
|
|
2546
|
+
useEffect(function moveFocusedDateWhenEndDateChanges() {
|
|
2547
|
+
if (endDate) {
|
|
2548
|
+
setDateInFocus(endDate);
|
|
2549
|
+
}
|
|
2550
|
+
}, [endDate, setDateInFocus]);
|
|
2551
|
+
useEffect(function updateStartDateFieldWhenValueChanges() {
|
|
2552
|
+
if (startDateInputRef.current) {
|
|
2553
|
+
if (startDate) {
|
|
2554
|
+
startDateInputRef.current.valueAsDate = new Date(Date.UTC(startDate.getFullYear(), startDate.getMonth(), startDate.getDate()));
|
|
2555
|
+
} else {
|
|
2556
|
+
startDateInputRef.current.valueAsDate = null;
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2559
|
+
}, [startDate, startDateInputRef]);
|
|
2560
|
+
useEffect(function updateEndDateFieldWhenValueChanges() {
|
|
2561
|
+
if (endDateInputRef.current) {
|
|
2562
|
+
if (endDate) {
|
|
2563
|
+
endDateInputRef.current.valueAsDate = new Date(Date.UTC(endDate.getFullYear(), endDate.getMonth(), endDate.getDate()));
|
|
2564
|
+
} else {
|
|
2565
|
+
endDateInputRef.current.valueAsDate = null;
|
|
2566
|
+
}
|
|
2567
|
+
}
|
|
2568
|
+
}, [endDate, endDateInputRef]);
|
|
2569
|
+
};
|
|
2570
|
+
const useDateRangeHandlers = (startDate, endDate, onValueChange, {
|
|
2571
|
+
setDateInFocus,
|
|
2572
|
+
showCalendarInternal,
|
|
2573
|
+
hideCalendarInternal,
|
|
2574
|
+
setFirstFocusedInput,
|
|
2575
|
+
setCurrentPanel
|
|
2576
|
+
}) => {
|
|
2577
|
+
const inputLeftChangeHandler = useCallback((ev) => {
|
|
2578
|
+
var _a;
|
|
2579
|
+
if (ev.target.value[0] !== "0") {
|
|
2580
|
+
onValueChange == null ? void 0 : onValueChange({
|
|
2581
|
+
startDate: (_a = ev.target.valueAsDate) != null ? _a : void 0,
|
|
2582
|
+
endDate
|
|
2583
|
+
});
|
|
2584
|
+
}
|
|
2585
|
+
}, [onValueChange, endDate]);
|
|
2586
|
+
const inputRightChangeHandler = useCallback((ev) => {
|
|
2587
|
+
var _a;
|
|
2588
|
+
if (ev.target.value[0] !== "0") {
|
|
2589
|
+
onValueChange == null ? void 0 : onValueChange({
|
|
2590
|
+
startDate,
|
|
2591
|
+
endDate: (_a = ev.target.valueAsDate) != null ? _a : void 0
|
|
2592
|
+
});
|
|
2593
|
+
}
|
|
2594
|
+
}, [onValueChange, startDate]);
|
|
2595
|
+
const showCalendar = useCallback(() => {
|
|
2596
|
+
if (startDate) {
|
|
2597
|
+
setDateInFocus(startDate);
|
|
2598
|
+
} else if (endDate) {
|
|
2599
|
+
setDateInFocus(endDate);
|
|
2600
|
+
} else {
|
|
2601
|
+
setDateInFocus(new Date());
|
|
2602
|
+
}
|
|
2603
|
+
setCurrentPanel("calendar");
|
|
2604
|
+
showCalendarInternal();
|
|
2605
|
+
}, [
|
|
2606
|
+
startDate,
|
|
2607
|
+
endDate,
|
|
2608
|
+
setCurrentPanel,
|
|
2609
|
+
showCalendarInternal,
|
|
2610
|
+
setDateInFocus
|
|
2611
|
+
]);
|
|
2612
|
+
const hideCalendar = useCallback(() => {
|
|
2613
|
+
setFirstFocusedInput(void 0);
|
|
2614
|
+
hideCalendarInternal();
|
|
2615
|
+
}, [setFirstFocusedInput, hideCalendarInternal]);
|
|
2616
|
+
return {
|
|
2617
|
+
inputLeftChangeHandler,
|
|
2618
|
+
inputRightChangeHandler,
|
|
2619
|
+
hideCalendar,
|
|
2620
|
+
setDateInFocus,
|
|
2621
|
+
setCurrentPanel,
|
|
2622
|
+
showCalendar
|
|
2623
|
+
};
|
|
2624
|
+
};
|
|
2625
|
+
const useInputStates = (startDate, endDate) => {
|
|
2626
|
+
const [isCalendarVisible, showCalendarInternal, hideCalendarInternal] = useBoolean(false);
|
|
2627
|
+
const [firstFocusedInput, setFirstFocusedInput] = useState(void 0);
|
|
2628
|
+
const [focusedInput, setFocusedInput] = useState("startDate");
|
|
2629
|
+
const [dateInFocus, setDateInFocus] = useState(() => {
|
|
2630
|
+
const fromValue = focusedInput === "startDate" ? startDate : focusedInput === "endDate" ? endDate : void 0;
|
|
2631
|
+
return fromValue != null ? fromValue : new Date();
|
|
2632
|
+
});
|
|
2633
|
+
const [currentPanel, setCurrentPanel] = useState("calendar");
|
|
2634
|
+
return {
|
|
2635
|
+
isCalendarVisible,
|
|
2636
|
+
showCalendarInternal,
|
|
2637
|
+
hideCalendarInternal,
|
|
2638
|
+
firstFocusedInput,
|
|
2639
|
+
setFirstFocusedInput,
|
|
2640
|
+
focusedInput,
|
|
2641
|
+
setFocusedInput,
|
|
2642
|
+
dateInFocus,
|
|
2643
|
+
setDateInFocus,
|
|
2644
|
+
currentPanel,
|
|
2645
|
+
setCurrentPanel
|
|
2646
|
+
};
|
|
2647
|
+
};
|
|
2648
|
+
const useUserInputHandlers = (startDate, endDate, onValueChange, startDateInputRef, endDateInputRef, showCalendar, hideCalendar, {
|
|
2649
|
+
firstFocusedInput,
|
|
2650
|
+
setFirstFocusedInput,
|
|
2651
|
+
isCalendarVisible,
|
|
2652
|
+
setFocusedInput,
|
|
2653
|
+
focusedInput,
|
|
2654
|
+
setCurrentPanel
|
|
2655
|
+
}) => {
|
|
2656
|
+
const onFocusLeft = useCallback(() => {
|
|
2657
|
+
if (firstFocusedInput == null) {
|
|
2658
|
+
setFirstFocusedInput("startDate");
|
|
2659
|
+
}
|
|
2660
|
+
setFocusedInput("startDate");
|
|
2661
|
+
if (!isCalendarVisible) {
|
|
2662
|
+
showCalendar();
|
|
2663
|
+
}
|
|
2664
|
+
}, [
|
|
2665
|
+
isCalendarVisible,
|
|
2666
|
+
setFocusedInput,
|
|
2667
|
+
showCalendar,
|
|
2668
|
+
setFirstFocusedInput,
|
|
2669
|
+
firstFocusedInput
|
|
2670
|
+
]);
|
|
2671
|
+
const onFocusRight = useCallback(() => {
|
|
2672
|
+
if (firstFocusedInput == null) {
|
|
2673
|
+
setFirstFocusedInput("endDate");
|
|
2674
|
+
}
|
|
2675
|
+
setFocusedInput("endDate");
|
|
2676
|
+
if (!isCalendarVisible) {
|
|
2677
|
+
showCalendar();
|
|
2678
|
+
}
|
|
2679
|
+
}, [
|
|
2680
|
+
isCalendarVisible,
|
|
2681
|
+
setFocusedInput,
|
|
2682
|
+
showCalendar,
|
|
2683
|
+
setFirstFocusedInput,
|
|
2684
|
+
firstFocusedInput
|
|
2685
|
+
]);
|
|
2686
|
+
const onClickDay = useCallback((day) => {
|
|
2687
|
+
var _a, _b, _c, _d;
|
|
2688
|
+
if (focusedInput === "startDate") {
|
|
2689
|
+
if (endDate != null && isAfter(day.date, endDate)) {
|
|
2690
|
+
onValueChange == null ? void 0 : onValueChange({
|
|
2691
|
+
startDate: day.date,
|
|
2692
|
+
endDate: void 0
|
|
2693
|
+
});
|
|
2694
|
+
setFocusedInput("endDate");
|
|
2695
|
+
(_a = endDateInputRef.current) == null ? void 0 : _a.focus();
|
|
2696
|
+
} else {
|
|
2697
|
+
onValueChange == null ? void 0 : onValueChange({
|
|
2698
|
+
startDate: day.date,
|
|
2699
|
+
endDate
|
|
2700
|
+
});
|
|
2701
|
+
if (firstFocusedInput === "startDate") {
|
|
2702
|
+
setFocusedInput("endDate");
|
|
2703
|
+
(_b = endDateInputRef.current) == null ? void 0 : _b.focus();
|
|
2704
|
+
} else {
|
|
2705
|
+
setTimeout(hideCalendar, 50);
|
|
2706
|
+
}
|
|
2707
|
+
}
|
|
2708
|
+
} else if (focusedInput === "endDate") {
|
|
2709
|
+
if (!startDate) {
|
|
2710
|
+
onValueChange == null ? void 0 : onValueChange({
|
|
2711
|
+
startDate,
|
|
2712
|
+
endDate: day.date
|
|
2713
|
+
});
|
|
2714
|
+
setFocusedInput("startDate");
|
|
2715
|
+
(_c = startDateInputRef.current) == null ? void 0 : _c.focus();
|
|
2716
|
+
} else if (isAfter(startDate, day.date)) {
|
|
2717
|
+
onValueChange == null ? void 0 : onValueChange({
|
|
2718
|
+
startDate: day.date,
|
|
2719
|
+
endDate: void 0
|
|
2720
|
+
});
|
|
2721
|
+
setFocusedInput("endDate");
|
|
2722
|
+
(_d = endDateInputRef.current) == null ? void 0 : _d.focus();
|
|
2723
|
+
} else {
|
|
2724
|
+
onValueChange == null ? void 0 : onValueChange({
|
|
2725
|
+
startDate,
|
|
2726
|
+
endDate: day.date
|
|
2727
|
+
});
|
|
2728
|
+
setTimeout(hideCalendar, 50);
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
}, [
|
|
2732
|
+
focusedInput,
|
|
2733
|
+
onValueChange,
|
|
2734
|
+
endDate,
|
|
2735
|
+
firstFocusedInput,
|
|
2736
|
+
setFocusedInput,
|
|
2737
|
+
endDateInputRef,
|
|
2738
|
+
hideCalendar,
|
|
2739
|
+
startDate,
|
|
2740
|
+
startDateInputRef
|
|
2741
|
+
]);
|
|
2742
|
+
const onClickArrowButton = useCallback(() => {
|
|
2743
|
+
setCurrentPanel("presets");
|
|
2744
|
+
showCalendar();
|
|
2745
|
+
}, [setCurrentPanel, showCalendar]);
|
|
2746
|
+
const onClickCalendarButton = useCallback(() => {
|
|
2747
|
+
var _a;
|
|
2748
|
+
if (isCalendarVisible) {
|
|
2749
|
+
hideCalendar();
|
|
2750
|
+
} else {
|
|
2751
|
+
setFocusedInput("startDate");
|
|
2752
|
+
setFirstFocusedInput("startDate");
|
|
2753
|
+
(_a = startDateInputRef.current) == null ? void 0 : _a.focus();
|
|
2754
|
+
setCurrentPanel("calendar");
|
|
2755
|
+
showCalendar();
|
|
2756
|
+
}
|
|
2757
|
+
}, [
|
|
2758
|
+
isCalendarVisible,
|
|
2759
|
+
hideCalendar,
|
|
2760
|
+
setFocusedInput,
|
|
2761
|
+
setFirstFocusedInput,
|
|
2762
|
+
startDateInputRef,
|
|
2763
|
+
setCurrentPanel,
|
|
2764
|
+
showCalendar
|
|
2765
|
+
]);
|
|
2766
|
+
const onKeyDownHandler = useCallback((ev) => {
|
|
2767
|
+
if (ev.key === "Escape") {
|
|
2768
|
+
hideCalendar();
|
|
2769
|
+
}
|
|
2770
|
+
}, [hideCalendar]);
|
|
2771
|
+
return {
|
|
2772
|
+
onFocusLeft,
|
|
2773
|
+
onFocusRight,
|
|
2774
|
+
onClickDay,
|
|
2775
|
+
onClickArrowButton,
|
|
2776
|
+
onClickCalendarButton,
|
|
2777
|
+
onKeyDownHandler
|
|
2778
|
+
};
|
|
2779
|
+
};
|
|
2780
|
+
const DateRangeDualTextInput = ({
|
|
2781
|
+
value,
|
|
2782
|
+
onValueChange,
|
|
2783
|
+
autoFocus,
|
|
2784
|
+
onBlur,
|
|
2785
|
+
onEnter,
|
|
2786
|
+
onEsc,
|
|
2787
|
+
minDate,
|
|
2788
|
+
maxDate = defaultMaxDate,
|
|
2789
|
+
calendarProps,
|
|
2790
|
+
widthLeft = 128,
|
|
2791
|
+
widthRight = 128,
|
|
2792
|
+
variant,
|
|
2793
|
+
disabled
|
|
2794
|
+
}) => {
|
|
2795
|
+
const {
|
|
2796
|
+
startDate,
|
|
2797
|
+
endDate
|
|
2798
|
+
} = value || {};
|
|
2799
|
+
const startDateInputRef = useRef(null);
|
|
2800
|
+
const endDateInputRef = useRef(null);
|
|
2801
|
+
const states = useInputStates(startDate, endDate);
|
|
2802
|
+
const {
|
|
2803
|
+
dateInFocus,
|
|
2804
|
+
setDateInFocus,
|
|
2805
|
+
isCalendarVisible,
|
|
2806
|
+
currentPanel,
|
|
2807
|
+
setCurrentPanel
|
|
2808
|
+
} = states;
|
|
2809
|
+
const {
|
|
2810
|
+
showCalendar,
|
|
2811
|
+
hideCalendar,
|
|
2812
|
+
inputLeftChangeHandler,
|
|
2813
|
+
inputRightChangeHandler
|
|
2814
|
+
} = useDateRangeHandlers(startDate, endDate, onValueChange, states);
|
|
2815
|
+
const {
|
|
2816
|
+
onKeyDownHandler,
|
|
2817
|
+
onFocusRight,
|
|
2818
|
+
onFocusLeft,
|
|
2819
|
+
onClickDay,
|
|
2820
|
+
onClickCalendarButton,
|
|
2821
|
+
onClickArrowButton
|
|
2822
|
+
} = useUserInputHandlers(startDate, endDate, onValueChange, startDateInputRef, endDateInputRef, showCalendar, hideCalendar, states);
|
|
2823
|
+
useDateRangeEffects(startDate, endDate, setDateInFocus, startDateInputRef, endDateInputRef);
|
|
2824
|
+
const startDateIsAfterEnd = useMemo(() => startDate && endDate && isAfter(startDate, endDate), [startDate, endDate]);
|
|
2825
|
+
const statePerMonth = useMemo(() => buildDayStateForSingleMonth(calendarProps == null ? void 0 : calendarProps.statePerMonth, startDate, endDate, dateInFocus), [calendarProps == null ? void 0 : calendarProps.statePerMonth, startDate, endDate, dateInFocus]);
|
|
2826
|
+
const delayedIsCalendarVisible = useDelayedFalse(isCalendarVisible, 300);
|
|
2827
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
2828
|
+
onKeyDown: onKeyDownHandler,
|
|
2829
|
+
children: /* @__PURE__ */ jsx(Popover, {
|
|
2830
|
+
arrow: false,
|
|
2831
|
+
lazy: true,
|
|
2832
|
+
disabled,
|
|
2833
|
+
placement: defaultPopoverPlacement,
|
|
2834
|
+
onClickOutside: hideCalendar,
|
|
2835
|
+
visible: isCalendarVisible,
|
|
2836
|
+
content: delayedIsCalendarVisible && /* @__PURE__ */ jsx(CalendarWithMonthSwitcher, {
|
|
2837
|
+
onClickDay,
|
|
2838
|
+
dateInFocus,
|
|
2839
|
+
setDateInFocus,
|
|
2840
|
+
currentPanel,
|
|
2841
|
+
setCurrentPanel,
|
|
2842
|
+
minDate,
|
|
2843
|
+
maxDate,
|
|
2844
|
+
...calendarProps,
|
|
2845
|
+
statePerMonth
|
|
2846
|
+
}),
|
|
2847
|
+
children: /* @__PURE__ */ jsx(DualTextInput, {
|
|
2848
|
+
autoFocusLeft: autoFocus,
|
|
2849
|
+
onEsc,
|
|
2850
|
+
onEnter,
|
|
2851
|
+
onBlur,
|
|
2852
|
+
disabled,
|
|
2853
|
+
separatorIcon: stenaArrowRight,
|
|
2854
|
+
typeLeft: "date",
|
|
2855
|
+
typeRight: "date",
|
|
2856
|
+
placeholderLeft: "Start date",
|
|
2857
|
+
placeholderRight: "End date",
|
|
2858
|
+
onChangeLeft: inputLeftChangeHandler,
|
|
2859
|
+
onChangeRight: inputRightChangeHandler,
|
|
2860
|
+
onClickArrowDown: onClickArrowButton,
|
|
2861
|
+
onClickCalendar: onClickCalendarButton,
|
|
2862
|
+
onFocusLeft,
|
|
2863
|
+
onFocusRight,
|
|
2864
|
+
onClickLeft: onFocusLeft,
|
|
2865
|
+
onClickRight: onFocusRight,
|
|
2866
|
+
inputRefLeft: startDateInputRef,
|
|
2867
|
+
inputRefRight: endDateInputRef,
|
|
2868
|
+
variant: startDateIsAfterEnd ? "error" : variant,
|
|
2869
|
+
widthLeft,
|
|
2870
|
+
widthRight,
|
|
2871
|
+
minLeft: minDate,
|
|
2872
|
+
maxLeft: maxDate,
|
|
2873
|
+
minRight: minDate,
|
|
2874
|
+
maxRight: maxDate
|
|
2875
|
+
})
|
|
2876
|
+
})
|
|
2877
|
+
});
|
|
2878
|
+
};
|
|
2071
2879
|
export { Calendar, CalendarDay, DateInput, DateRangeCalendar, DateRangeDualTextInput, DateRangeExclusionCalendar, DateRangeInput, DateTextInput, DateTimeInput, Month, MonthPicker, MultiDateCalendar, PresetPicker, SingleDateCalendar, SingleWeekCalendar, TimeTextInput, WeekDay, WeekDayCell, WeekNumberCell, YearPicker, addDayStateHighlights, addDayStateHighlightsOnSingleDay, addWeekRangeHighlights, addWeekStateHighlights, buildDayStateForDateRange, buildDayStateForRange, buildDayStateForSingleMonth, calculateOverflowingMonth, createDay, dateRangeToStrings, dayHasHighlight, dayHighlightSelect, defaultCalendarTheme, defaultTextPropsProvider, defaultWrapperStyleProvider, extranetCalendarTheme, getDaysForWeekForDate, getMonthInYear, getMonthsInYear, getStartDateOfISOWeek, getWeekForDate, getWeeksForMonth, isDateRangeInvalid, setDayStateValue, setDayStateValueFunction, stringsToDateRange, toggleDateStringsIfEndIsEarlierThanStart, toggleDatesIfEndIsEarlierThanStart, useDateRangeCalendarState, useDateRangeExclusionSelection, useDateRangeSelection, useMultiDateSelection, useSingleDateSelection, useSingleWeekSelection };
|
|
2072
2880
|
//# sourceMappingURL=index.es.js.map
|