@stenajs-webui/calendar 17.5.0 → 17.8.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.
Files changed (104) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/components/calendar/Calendar.d.ts +3 -3
  3. package/dist/components/calendar/CalendarMonth.d.ts +16 -16
  4. package/dist/components/calendar/CalendarMonthWithMonthTextHeader.d.ts +6 -6
  5. package/dist/components/calendar/CalendarTheme.d.ts +57 -57
  6. package/dist/components/calendar/CalendarWeek.d.ts +18 -18
  7. package/dist/components/calendar/DisabledDayWrapper.d.ts +7 -7
  8. package/dist/components/calendar/renderers/CalendarDay.d.ts +3 -3
  9. package/dist/components/calendar/renderers/WeekDayCell.d.ts +10 -10
  10. package/dist/components/calendar/renderers/WeekNumberCell.d.ts +13 -13
  11. package/dist/components/calendar-types/date-range-calendar/DateRangeCalendar.d.ts +11 -11
  12. package/dist/components/calendar-types/date-range-calendar/hooks/UseDateRangeCalendarState.d.ts +10 -10
  13. package/dist/components/calendar-types/date-range-calendar/hooks/UseDateRangeSelection.d.ts +3 -3
  14. package/dist/components/calendar-types/date-range-exclusion-calendar/DateRangeExclusionCalendar.d.ts +7 -7
  15. package/dist/components/calendar-types/date-range-exclusion-calendar/UseDateRangeExclusionSelection.d.ts +3 -3
  16. package/dist/components/calendar-types/multi-date-calendar/MultiDateCalendar.d.ts +8 -8
  17. package/dist/components/calendar-types/multi-date-calendar/UseMultiDateSelection.d.ts +3 -3
  18. package/dist/components/calendar-types/single-date-calendar/SingleDateCalendar.d.ts +7 -7
  19. package/dist/components/calendar-types/single-date-calendar/UseSingleDateSelection.d.ts +3 -3
  20. package/dist/components/calendar-types/single-week-calendar/SingleWeekCalendar.d.ts +8 -8
  21. package/dist/components/calendar-types/single-week-calendar/UseSingleWeekSelection.d.ts +3 -3
  22. package/dist/components/input-types/date-input/DateInput.d.ts +52 -52
  23. package/dist/components/input-types/date-input/UseDateInput.d.ts +6 -6
  24. package/dist/components/input-types/date-range-dual-text-input/DateRangeDualTextInput.d.ts +15 -15
  25. package/dist/components/input-types/date-range-dual-text-input/hooks/UseDateRangeEffects.d.ts +2 -2
  26. package/dist/components/input-types/date-range-dual-text-input/hooks/UseDateRangeHandlers.d.ts +11 -11
  27. package/dist/components/input-types/date-range-dual-text-input/hooks/UseInputStates.d.ts +17 -17
  28. package/dist/components/input-types/date-range-dual-text-input/hooks/UseUserInputHandlers.d.ts +13 -13
  29. package/dist/components/input-types/date-range-input/DateRangeInput.d.ts +51 -51
  30. package/dist/components/input-types/date-range-input/hooks/UseDateRangeInput.d.ts +16 -16
  31. package/dist/components/input-types/date-text-input/DateTextInput.d.ts +28 -28
  32. package/dist/components/input-types/date-time-input/DateTimeInput.d.ts +12 -12
  33. package/dist/components/input-types/date-time-input/hooks/UseDateRangeEffects.d.ts +2 -2
  34. package/dist/components/input-types/date-time-input/hooks/UseDateRangeHandlers.d.ts +11 -11
  35. package/dist/components/input-types/date-time-input/hooks/UseInputStates.d.ts +22 -22
  36. package/dist/components/input-types/date-time-input/hooks/UseUserInputHandlers.d.ts +12 -12
  37. package/dist/components/input-types/time-text-input/TimeTextInput.d.ts +15 -15
  38. package/dist/config/DefaultMaxDate.d.ts +1 -1
  39. package/dist/config/DefaultPopoverPlacement.d.ts +2 -2
  40. package/dist/features/calendar-with-month-year-pickers/CalendarPanelType.d.ts +1 -1
  41. package/dist/features/calendar-with-month-year-pickers/CalendarWithMonthYearPickers.d.ts +13 -13
  42. package/dist/features/date-range/hooks/UseDateRangeOnClickDayHandler.d.ts +4 -4
  43. package/dist/features/dual-text-input/DualTextInput.d.ts +44 -44
  44. package/dist/features/internal-panel-state/UseCalendarPopoverUpdater.d.ts +4 -4
  45. package/dist/features/internal-panel-state/UseInternalPanelState.d.ts +9 -9
  46. package/dist/features/month-picker/MonthPicker.d.ts +6 -6
  47. package/dist/features/month-picker/MonthPickerCell.d.ts +8 -8
  48. package/dist/features/month-switcher/CalendarWithMonthSwitcher.d.ts +15 -15
  49. package/dist/features/month-switcher/MonthSwitcherBelow.d.ts +12 -12
  50. package/dist/features/month-switcher/hooks/UseSelectedMonthStepperLogic.d.ts +6 -6
  51. package/dist/features/preset-picker/CalendarPreset.d.ts +14 -14
  52. package/dist/features/preset-picker/PresetFactory.d.ts +2 -2
  53. package/dist/features/preset-picker/PresetPicker.d.ts +6 -6
  54. package/dist/features/time-picker/TimePicker.d.ts +5 -5
  55. package/dist/features/time-picker/TimePickerCell.d.ts +10 -10
  56. package/dist/features/time-picker/TimePickerColumn.d.ts +10 -10
  57. package/dist/features/today-state/UseHighlightToday.d.ts +2 -2
  58. package/dist/features/year-picker/YearPicker.d.ts +6 -6
  59. package/dist/features/year-picker/YearPickerCell.d.ts +7 -7
  60. package/dist/index.d.ts +32 -32
  61. package/dist/index.es.js +2866 -2065
  62. package/dist/index.es.js.map +1 -1
  63. package/dist/index.js +1 -2155
  64. package/dist/index.js.map +1 -1
  65. package/dist/types/CalendarTypes.d.ts +133 -133
  66. package/dist/types/DateRange.d.ts +16 -16
  67. package/dist/types/InternalPanelAndFocusStateProps.d.ts +3 -3
  68. package/dist/util/calendar/CalendarDataFactory.d.ts +64 -64
  69. package/dist/util/calendar/StateHelper.d.ts +3 -3
  70. package/dist/util/calendar/StateModifier.d.ts +11 -11
  71. package/dist/util/date/DateFormats.d.ts +11 -11
  72. package/dist/util/date/DateListTools.d.ts +3 -3
  73. package/dist/util/date/DateMinMaxValidator.d.ts +1 -1
  74. package/dist/util/date-range/DateRangeTransformer.d.ts +3 -3
  75. package/dist/util/date-range/DateRangeValidator.d.ts +4 -4
  76. package/dist/util/time/OverlappingTimesValidator.d.ts +11 -11
  77. package/dist/util/time/TimeStringFormatValidator.d.ts +8 -8
  78. package/dist/util/time/TimeTransformer.d.ts +8 -8
  79. package/package.json +10 -11
  80. package/dist/components/calendar-types/date-range-calendar/DateRangeCalendar.stories.d.ts +0 -20
  81. package/dist/components/calendar-types/date-range-exclusion-calendar/DateRangeExclusionCalendar.stories.d.ts +0 -17
  82. package/dist/components/calendar-types/multi-date-calendar/MultiDateCalendar.stories.d.ts +0 -15
  83. package/dist/components/calendar-types/multi-date-calendar/__tests__/UseMultiDateSelection.test.d.ts +0 -1
  84. package/dist/components/calendar-types/single-date-calendar/SingleDateCalendar.stories.d.ts +0 -17
  85. package/dist/components/calendar-types/single-week-calendar/SingleWeekCalendar.stories.d.ts +0 -8
  86. package/dist/components/input-types/date-input/DateInput.stories.d.ts +0 -19
  87. package/dist/components/input-types/date-range-dual-text-input/DateRangeDualTextInput.stories.d.ts +0 -18
  88. package/dist/components/input-types/date-range-input/DateRangeInput.stories.d.ts +0 -17
  89. package/dist/components/input-types/date-text-input/DateTextInput.stories.d.ts +0 -19
  90. package/dist/components/input-types/date-time-input/DateTimeInput.stories.d.ts +0 -14
  91. package/dist/components/input-types/time-text-input/TimeTextInput.stories.d.ts +0 -15
  92. package/dist/features/month-picker/MonthPicker.stories.d.ts +0 -7
  93. package/dist/features/preset-picker/PresetPicker.stories.d.ts +0 -7
  94. package/dist/features/time-picker/TimePicker.stories.d.ts +0 -7
  95. package/dist/features/year-picker/YearPicker.stories.d.ts +0 -12
  96. package/dist/util/calendar/__tests__/CalendarDataFactory.test.d.ts +0 -1
  97. package/dist/util/calendar/__tests__/StateHelper.test.d.ts +0 -1
  98. package/dist/util/calendar/__tests__/StateModifier.test.d.ts +0 -1
  99. package/dist/util/date/__tests__/DateListTools.test.d.ts +0 -1
  100. package/dist/util/date/__tests__/DateMinMaxValidator.test.d.ts +0 -1
  101. package/dist/util/date-range/__tests__/DateRangeValidator.test.d.ts +0 -1
  102. package/dist/util/time/__tests__/OverlappingTimesValidator.test.d.ts +0 -1
  103. package/dist/util/time/__tests__/TimeStringFormatValidator.test.d.ts +0 -1
  104. package/dist/util/time/__tests__/TimeTransformer.test.d.ts +0 -1
package/dist/index.es.js CHANGED
@@ -1,2079 +1,2880 @@
1
- import * as React from 'react';
2
- import { useMemo, useCallback, useState, useEffect, useRef } from 'react';
3
- import { FlatButton, PrimaryButton, Icon, stenaArrowRight } from '@stenajs-webui/elements';
4
- import { Box, Text, Clickable, Row, Space, Spacing, Indent, Column, SeparatorLine, parseIntElseUndefined, useBoolean, useDelayedFalse } from '@stenajs-webui/core';
5
- 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';
6
- import { last, chunk, range, debounce } from 'lodash';
7
- import styled from '@emotion/styled';
8
- import { faAngleLeft } from '@fortawesome/free-solid-svg-icons/faAngleLeft';
9
- import { faAngleRight } from '@fortawesome/free-solid-svg-icons/faAngleRight';
10
- import { faAngleDoubleLeft } from '@fortawesome/free-solid-svg-icons/faAngleDoubleLeft';
11
- import { faAngleDoubleRight } from '@fortawesome/free-solid-svg-icons/faAngleDoubleRight';
12
- import { faCaretLeft } from '@fortawesome/free-solid-svg-icons/faCaretLeft';
13
- import { faCaretRight } from '@fortawesome/free-solid-svg-icons/faCaretRight';
14
- import { faCalendarAlt } from '@fortawesome/free-regular-svg-icons/faCalendarAlt';
15
- import { TextInput, TextInputBox } from '@stenajs-webui/forms';
16
- import { useTippyInstance, Popover } from '@stenajs-webui/tooltip';
17
- import { faCalendarAlt as faCalendarAlt$1 } from '@fortawesome/free-solid-svg-icons/faCalendarAlt';
18
- import { cssColor } from '@stenajs-webui/theme';
19
- import { faLongArrowAltRight } from '@fortawesome/free-solid-svg-icons/faLongArrowAltRight';
20
- import { faClock } from '@fortawesome/free-solid-svg-icons/faClock';
21
- import { faClock as faClock$1 } from '@fortawesome/free-regular-svg-icons/faClock';
22
- import { faAngleDown } from '@fortawesome/free-solid-svg-icons/faAngleDown';
23
-
24
- /*! *****************************************************************************
25
- Copyright (c) Microsoft Corporation.
26
-
27
- Permission to use, copy, modify, and/or distribute this software for any
28
- purpose with or without fee is hereby granted.
29
-
30
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
31
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
32
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
33
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
34
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
35
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
36
- PERFORMANCE OF THIS SOFTWARE.
37
- ***************************************************************************** */
38
-
39
- var __assign = function() {
40
- __assign = Object.assign || function __assign(t) {
41
- for (var s, i = 1, n = arguments.length; i < n; i++) {
42
- s = arguments[i];
43
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
44
- }
45
- return t;
46
- };
47
- return __assign.apply(this, arguments);
48
- };
49
-
50
- function __rest(s, e) {
51
- var t = {};
52
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
53
- t[p] = s[p];
54
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
55
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
56
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
57
- t[p[i]] = s[p[i]];
58
- }
59
- return t;
60
- }
61
-
62
- function __spreadArray(to, from, pack) {
63
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
64
- if (ar || !(i in from)) {
65
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
66
- ar[i] = from[i];
67
- }
68
- }
69
- return to.concat(ar || Array.prototype.slice.call(from));
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);
70
453
  }
71
-
72
- var DateFormats = {
73
- yearAndMonth: "yyyy-MM",
74
- fullDate: "yyyy-MM-dd",
75
- fullMonthName: "LLLL",
76
- fullDateAndTime: "yyyy-MM-dd HH:mm",
77
- fullDateAndTimeSystem: "yyyy-MM-ddTHH:MM",
78
- weekDayName: "EEEE",
79
- weekDayNameShort: "EEE",
80
- dateAndMonth: "d MMM",
81
- monthAndDate: "MMM do", // Jan 2nd
82
- };
83
-
84
- var buildDayStateForDateRange = function (statePerMonth, start, end) {
85
- if (statePerMonth === void 0) { statePerMonth = {}; }
86
- if (start && end && isAfter(end, start)) {
87
- return eachDayOfInterval({ start: start, end: end }).reduce(function (result, date) {
88
- var isFirstInRange = isSameDay(date, start);
89
- var isLastInRange = isSameDay(date, end);
90
- var highlights = isFirstInRange
91
- ? ["selected", "selectedStart", "range"]
92
- : isLastInRange
93
- ? ["selected", "selectedEnd", "range"]
94
- : ["range"];
95
- return addDayStateHighlights(result, date, highlights);
96
- }, statePerMonth);
97
- }
98
- var state = statePerMonth;
99
- if (start) {
100
- state = addDayStateHighlights(state, start, ["selected", "singleSelected"]);
101
- }
102
- if (end) {
103
- state = addDayStateHighlights(state, end, ["selected", "singleSelected"]);
104
- }
105
- return state;
106
- };
107
- var buildDayStateForSingleMonth = function (statePerMonth, start, end, dateInFocus) {
108
- if (statePerMonth === void 0) { statePerMonth = {}; }
109
- return buildDayStateForRange(statePerMonth, start, end, startOfMonth(dateInFocus), endOfMonth(dateInFocus));
110
- };
111
- var buildDayStateForRange = function (statePerMonth, start, end, startLimit, endLimit) {
112
- if (statePerMonth === void 0) { statePerMonth = {}; }
113
- if (start && end) {
114
- return buildDayStateForDateRange(statePerMonth, max([start, subDays(startLimit, 1)]), min([end, addDays(endLimit, 1)]));
115
- }
116
- else {
117
- return buildDayStateForDateRange(statePerMonth, start, end);
118
- }
119
- };
120
- var setDayStateValue = function (state, date, values) {
121
- var _a, _b, _c;
122
- var monthString = format(date, DateFormats.yearAndMonth);
123
- var weekNumber = getISOWeek(date);
124
- var dayInMonth = getDate(date);
125
- return __assign(__assign({}, state), (_a = {}, _a[monthString] = __assign(__assign({}, (state && state[monthString])), (_b = {}, _b[weekNumber] = __assign(__assign({}, (state && state[monthString] && state[monthString][weekNumber])), (_c = {}, _c[dayInMonth] = __assign(__assign({}, (state &&
126
- state[monthString] &&
127
- state[monthString][weekNumber] &&
128
- state[monthString][weekNumber][dayInMonth])), values), _c)), _b)), _a));
129
- };
130
- var setDayStateValueFunction = function (state, date, setter) {
131
- var _a, _b, _c;
132
- var monthString = format(date, DateFormats.yearAndMonth);
133
- var weekNumber = getISOWeek(date);
134
- var dayInMonth = getDate(date);
135
- return __assign(__assign({}, state), (_a = {}, _a[monthString] = __assign(__assign({}, (state && state[monthString])), (_b = {}, _b[weekNumber] = __assign(__assign({}, (state && state[monthString] && state[monthString][weekNumber])), (_c = {}, _c[dayInMonth] = __assign(__assign({}, (state &&
136
- state[monthString] &&
137
- state[monthString][weekNumber] &&
138
- state[monthString][weekNumber][dayInMonth])), setter(state &&
139
- state[monthString] &&
140
- state[monthString][weekNumber] &&
141
- state[monthString][weekNumber][dayInMonth])), _c)), _b)), _a));
142
- };
143
- var addDayStateHighlights = function (calendarState, date, highlights) {
144
- var _a, _b, _c;
145
- var month = date.getMonth() + 1;
146
- var monthString = "".concat(date.getFullYear(), "-").concat(month < 10 ? "0" : "").concat(month);
147
- var weekNumber = getISOWeek(date);
148
- var dayInMonth = getDate(date);
149
- var dayState = calendarState &&
150
- calendarState[monthString] &&
151
- calendarState[monthString][weekNumber] &&
152
- calendarState[monthString][weekNumber][dayInMonth];
153
- return __assign(__assign({}, calendarState), (_a = {}, _a[monthString] = __assign(__assign({}, (calendarState && calendarState[monthString])), (_b = {}, _b[weekNumber] = __assign(__assign({}, (calendarState &&
154
- calendarState[monthString] &&
155
- calendarState[monthString][weekNumber])), (_c = {}, _c[dayInMonth] = addDayStateHighlightsOnSingleDay(dayState, highlights), _c)), _b)), _a));
156
- };
157
- var addDayStateHighlightsOnSingleDay = function (dayState, highlights) {
158
- var _a;
159
- return __assign(__assign({}, dayState), { highlights: __spreadArray(__spreadArray([], ((_a = dayState === null || dayState === void 0 ? void 0 : dayState.highlights) !== null && _a !== void 0 ? _a : []), true), highlights, true) });
160
- };
161
- var addWeekStateHighlights = function (calendarState, week, highlights) {
162
- var _a, _b;
163
- var date = week.days[0].date;
164
- var month = date.getMonth() + 1;
165
- var monthString = "".concat(date.getFullYear(), "-").concat(month < 10 ? "0" : "").concat(month);
166
- var weekNumber = week.weekNumber;
167
- var state = calendarState;
168
- week.days.forEach(function (day) {
169
- state = addDayStateHighlights(state, day.date, highlights);
170
- });
171
- var weekState = state && state[monthString] ? state[monthString][weekNumber] : undefined;
172
- var newHighlights = weekState && weekState.highlights
173
- ? __spreadArray(__spreadArray([], weekState.highlights, true), highlights, true) : highlights;
174
- var newWeekState = __assign(__assign({}, weekState), { highlights: newHighlights });
175
- return __assign(__assign({}, state), (_a = {}, _a[monthString] = __assign(__assign({}, (calendarState && calendarState[monthString])), (_b = {}, _b[weekNumber] = newWeekState, _b)), _a));
176
- };
177
- var addWeekRangeHighlights = function (calendarState, week) {
178
- var _a;
179
- if (!week.days.length) {
180
- return __assign({}, calendarState);
181
- }
182
- var startDate = week.days[0].date;
183
- var endDate = (_a = last(week.days)) === null || _a === void 0 ? void 0 : _a.date;
184
- return __assign({}, buildDayStateForDateRange(calendarState, startDate, endDate));
185
- };
186
-
187
- var useHighlightToday = function (enabled, statePerMonth) {
188
- return useMemo(function () {
189
- return enabled
190
- ? addDayStateHighlights(statePerMonth, new Date(), ["today"])
191
- : statePerMonth;
192
- }, [enabled, statePerMonth]);
193
- };
194
-
195
- var Month;
196
- (function (Month) {
197
- Month[Month["JANUARY"] = 0] = "JANUARY";
198
- Month[Month["FEBRUARY"] = 1] = "FEBRUARY";
199
- Month[Month["MARCH"] = 2] = "MARCH";
200
- Month[Month["APRIL"] = 3] = "APRIL";
201
- Month[Month["MAY"] = 4] = "MAY";
202
- Month[Month["JUNE"] = 5] = "JUNE";
203
- Month[Month["JULY"] = 6] = "JULY";
204
- Month[Month["AUGUST"] = 7] = "AUGUST";
205
- Month[Month["SEPTEMBER"] = 8] = "SEPTEMBER";
206
- Month[Month["OCTOBER"] = 9] = "OCTOBER";
207
- Month[Month["NOVEMBER"] = 10] = "NOVEMBER";
208
- Month[Month["DECEMBER"] = 11] = "DECEMBER";
209
- })(Month || (Month = {}));
210
- var WeekDay;
211
- (function (WeekDay) {
212
- WeekDay[WeekDay["SUNDAY"] = 0] = "SUNDAY";
213
- WeekDay[WeekDay["MONDAY"] = 1] = "MONDAY";
214
- WeekDay[WeekDay["TUESDAY"] = 2] = "TUESDAY";
215
- WeekDay[WeekDay["WEDNESDAY"] = 3] = "WEDNESDAY";
216
- WeekDay[WeekDay["THURSDAY"] = 4] = "THURSDAY";
217
- WeekDay[WeekDay["FRIDAY"] = 5] = "FRIDAY";
218
- WeekDay[WeekDay["SATURDAY"] = 6] = "SATURDAY";
219
- })(WeekDay || (WeekDay = {}));
220
- var getMonthsInYear = function (year, startMonth, numMonths) {
221
- var months = [];
222
- for (var i = 0; i < numMonths; i++) {
223
- months.push(getMonthInYear(year, startMonth + i));
224
- }
225
- return months;
226
- };
227
- var getMonthInYear = function (year, month) {
228
- var yearToUse = year + Math.floor(month / 12);
229
- var monthToUse = month % 12;
230
- var firstDayOfMonth = new Date(yearToUse, monthToUse, 1);
231
- return {
232
- monthString: format(firstDayOfMonth, DateFormats.yearAndMonth),
233
- name: format(firstDayOfMonth, DateFormats.fullMonthName),
234
- year: yearToUse,
235
- monthInYear: monthToUse,
236
- weeks: getWeeksForMonth(yearToUse, monthToUse),
237
- };
238
- };
239
- var getWeeksForMonth = function (year, month, forceSixWeeks) {
240
- if (forceSixWeeks === void 0) { forceSixWeeks = true; }
241
- var firstDayOfMonth = new Date(year, month, 1);
242
- var firstDayOfFirstWeek = startOfISOWeek(firstDayOfMonth);
243
- var weeks = [];
244
- for (var i = 0; i < 6; i++) {
245
- var week = getWeekForDate(addWeeks(firstDayOfFirstWeek, i));
246
- if (i > 0 && week.startMonth !== month && !forceSixWeeks) {
247
- return weeks;
248
- }
249
- weeks.push(week);
250
- }
251
- return weeks;
252
- };
253
- var getWeekForDate = function (firstDayOfWeek) {
254
- var isLastWeekOfMonth = getMonth(addDays(firstDayOfWeek, 7)) !== getMonth(firstDayOfWeek);
255
- return {
256
- weekNumber: getISOWeek(firstDayOfWeek),
257
- startMonth: getMonth(firstDayOfWeek),
258
- startYear: getYear(firstDayOfWeek),
259
- endMonth: getMonth(addDays(firstDayOfWeek, 6)),
260
- endYear: getYear(addDays(firstDayOfWeek, 6)),
261
- days: getDaysForWeekForDate(firstDayOfWeek),
262
- isLastWeekOfMonth: isLastWeekOfMonth,
263
- };
264
- };
265
- var createDay = function (date) {
266
- var dayOfWeek = getISODay(date);
267
- return {
268
- date: date,
269
- name: format(date, "EEE"),
270
- dateString: format(addHours(date, 12), DateFormats.fullDate),
271
- weekNumber: getISOWeek(date),
272
- year: getYear(date),
273
- month: getMonth(date),
274
- dayOfMonth: getDate(date),
275
- dayOfWeek: dayOfWeek,
276
- isFirstDayOfWeek: dayOfWeek === 1,
277
- isLastDayOfWeek: dayOfWeek === 7,
278
- isFirstDayOfMonth: isSameDay(startOfMonth(date), date),
279
- isLastDayOfMonth: isSameDay(endOfMonth(date), date),
280
- };
281
- };
282
- var getDaysForWeekForDate = function (firstDayOfWeek) {
283
- return eachDayOfInterval({
284
- start: firstDayOfWeek,
285
- end: addDays(firstDayOfWeek, 6),
286
- }).map(createDay);
287
- };
288
- var getStartDateOfISOWeek = function (weekNumber, year) {
289
- var simple = new Date(year, 0, 1 + (weekNumber - 1) * 7);
290
- var dayOfWeek = simple.getDay();
291
- var isoWeekStart = simple;
292
- if (dayOfWeek <= 4) {
293
- isoWeekStart.setDate(simple.getDate() - simple.getDay() + 1);
294
- }
295
- else {
296
- isoWeekStart.setDate(simple.getDate() + 8 - simple.getDay());
297
- }
298
- return isoWeekStart;
299
- };
300
- var calculateOverflowingMonth = function (year, month) {
301
- if (month > Month.DECEMBER) {
302
- return { year: year + Math.floor(month / 12), month: month % 12 };
303
- }
304
- if (month < Month.JANUARY) {
305
- return { year: year + Math.floor(month / 12), month: 12 + (month % 12) };
306
- }
307
- return { year: year, month: month };
308
- };
309
-
310
- var dayHasHighlight = function (dayState, defaultHighlights, highlight) {
311
- if (defaultHighlights && defaultHighlights.indexOf(highlight) >= 0) {
312
- return true;
313
- }
314
- if (dayState &&
315
- dayState.highlights &&
316
- dayState.highlights.indexOf(highlight) >= 0) {
317
- return true;
318
- }
319
- return false;
320
- };
321
- var dayHighlightSelect = function (dayState, defaultHighlights, highlightsOrBoolean, returnValues, fallbackValue) {
322
- if (highlightsOrBoolean.length !== returnValues.length) {
323
- throw new Error("Select highlight failed, number of values do not equal number of highlights.");
324
- }
325
- if (highlightsOrBoolean.length === 0) {
326
- return fallbackValue;
327
- }
328
- for (var i = 0; i < highlightsOrBoolean.length; i++) {
329
- if (typeof highlightsOrBoolean[i] === "boolean" && highlightsOrBoolean[i]) {
330
- return returnValues[i];
331
- }
332
- if (typeof highlightsOrBoolean[i] === "string" &&
333
- dayHasHighlight(dayState, defaultHighlights, highlightsOrBoolean[i])) {
334
- return returnValues[i];
335
- }
336
- }
337
- return fallbackValue;
338
- };
339
-
340
- var defaultWrapperStyleProvider = function (_a) {
341
- var selectedBackground = _a.selectedBackground, todayBackground = _a.todayBackground, rangeBackground = _a.rangeBackground, _b = _a.borderColor, borderColor = _b === void 0 ? "transparent" : _b;
342
- return function (defaultHighlights, dayState, day, _, month) {
343
- var style = {};
344
- var backgroundColor = dayHighlightSelect(dayState, defaultHighlights, ["selected", "range", "today", day.month === month.monthInYear], [selectedBackground, rangeBackground, todayBackground, "#fff"], "transparent");
345
- return __assign(__assign({}, style), { backgroundColor: backgroundColor, borderTopLeftRadius: dayHighlightSelect(dayState, defaultHighlights, ["selectedStart", "singleSelected"], [
346
- "var(--swui-calendar-day-border-radius)",
347
- "var(--swui-calendar-day-border-radius)",
348
- ], borderColor), borderBottomLeftRadius: dayHighlightSelect(dayState, defaultHighlights, ["selectedStart", "singleSelected"], [
349
- "var(--swui-calendar-day-border-radius)",
350
- "var(--swui-calendar-day-border-radius)",
351
- ], borderColor), borderTopRightRadius: dayHighlightSelect(dayState, defaultHighlights, ["selectedEnd", "singleSelected"], [
352
- "var(--swui-calendar-day-border-radius)",
353
- "var(--swui-calendar-day-border-radius)",
354
- ], borderColor), borderBottomRightRadius: dayHighlightSelect(dayState, defaultHighlights, ["selectedEnd", "singleSelected"], [
355
- "var(--swui-calendar-day-border-radius)",
356
- "var(--swui-calendar-day-border-radius)",
357
- ], borderColor), boxSizing: "border-box" });
358
- };
359
- };
360
- var defaultTextPropsProvider = function (_a) {
361
- var selectedColor = _a.selectedColor, disabledColor = _a.disabledColor, inOtherMonthColor = _a.inOtherMonthColor, rangeTextColor = _a.rangeTextColor;
362
- return function (defaultHighlights, dayState, day, _, month) {
363
- var isOtherMonth = day.month !== month.monthInYear;
364
- var color = dayHighlightSelect(dayState, defaultHighlights, [isOtherMonth, "selected", "range", "enabled", "disabled"], [
365
- inOtherMonthColor,
366
- selectedColor,
367
- rangeTextColor,
368
- undefined,
369
- disabledColor,
370
- ]);
371
- return {
372
- color: color,
373
- };
374
- };
375
- };
376
- var defaultCalendarTheme = {
377
- width: "var(--swui-calendar-day-width)",
378
- height: "var(--swui-calendar-day-height)",
379
- WeekNumber: {
380
- backgroundColor: "var(--swui-calendar-week-number-bg-color)",
381
- textColor: "var(--swui-calendar-week-number-text-color)",
382
- clickableTextColor: "var(--swui-calendar-week-number-clickable-text-color)",
383
- show: true,
384
- },
385
- WeekDay: {
386
- textColor: "var(--swui-calendar-week-day-text-color)",
387
- clickableTextColor: "var(--swui-calendar-week-day-clickable-text-color)",
388
- },
389
- CalendarDay: {
390
- tdStyle: defaultWrapperStyleProvider({
391
- selectedBackground: "var(--swui-calendar-wrapper-selected-background)",
392
- rangeBackground: "var(--swui-calendar-wrapper-range-background)",
393
- todayBackground: "var(--swui-calendar-wrapper-today-background)",
394
- }),
395
- textProps: defaultTextPropsProvider({
396
- selectedColor: "var(--swui-calendar-text-selected-color)",
397
- disabledColor: "var(--swui-calendar-text-disabled-color)",
398
- inOtherMonthColor: "var(--swui-calendar-text-in-other-month-color)",
399
- }),
400
- },
401
- CalendarMonth: {
402
- headerTextColor: "var(--swui-calendar-week-day-text-color)",
403
- },
404
- };
405
- var extranetCalendarTheme = __assign(__assign({}, defaultCalendarTheme), { width: "37px", height: "37px" });
406
-
407
- var isDateInMinMaxRange = function (date, min, max) {
408
- if (min && isBefore(date, min)) {
409
- return isSameDay(date, min);
410
- }
411
- if (max && isAfter(date, max)) {
412
- return isSameDay(date, max);
413
- }
414
- return true;
415
- };
416
-
417
- var DisabledDayWrapper = function DisabledDayWrapper(_a) {
418
- var DayComponent = _a.dayComponent, minDate = _a.minDate, maxDate = _a.maxDate, dayState = _a.dayState, day = _a.day, props = __rest(_a, ["dayComponent", "minDate", "maxDate", "dayState", "day"]);
419
- var activeDayState = useMemo(function () {
420
- return !isDateInMinMaxRange(day.date, minDate, maxDate)
421
- ? addDayStateHighlightsOnSingleDay(dayState, ["disabled"])
422
- : dayState;
423
- }, [day.date, dayState, maxDate, minDate]);
424
- return React.createElement(DayComponent, __assign({ day: day }, props, { dayState: activeDayState }));
425
- };
426
-
427
- var WeekNumberCell = function (_a) {
428
- var onClickWeek = _a.onClickWeek, theme = _a.theme, week = _a.week, background = _a.background, backgroundColor = _a.backgroundColor, prefix = _a.prefix;
429
- var content = (React.createElement(Box, { width: theme.width, height: theme.height, justifyContent: "center", alignItems: "center" },
430
- background && React.createElement(Box, { position: "absolute" }, background),
431
- React.createElement(Box, { position: "absolute" },
432
- React.createElement(Text, { color: onClickWeek
433
- ? theme.WeekNumber.clickableTextColor
434
- : theme.WeekNumber.textColor },
435
- prefix,
436
- week.weekNumber))));
437
- 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)));
438
- };
439
-
440
- function CalendarWeek(_a) {
441
- 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;
442
- return (React.createElement("tr", { key: week.weekNumber },
443
- theme.WeekNumber.show && (React.createElement("td", null, renderWeekNumber ? (renderWeekNumber(week, theme, onClickWeek)) : (React.createElement(WeekNumberCell, { week: week, onClickWeek: onClickWeek, theme: theme })))),
444
- 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
+ });
445
640
  }
446
-
447
- var WeekDayCell = function (_a) {
448
- var onClickWeekDay = _a.onClickWeekDay, day = _a.day, theme = _a.theme;
449
- var content = (React.createElement(Box, { width: theme.width, height: theme.height, justifyContent: "center", alignItems: "center" },
450
- React.createElement(Text, { size: "small", color: onClickWeekDay
451
- ? theme.WeekDay.clickableTextColor
452
- : theme.WeekDay.textColor }, day.name)));
453
- if (onClickWeekDay) {
454
- return (React.createElement(Clickable, { borderRadius: "var(--swui-calendar-day-border-radius)", onClick: function (ev) { return onClickWeekDay(day.dayOfWeek, ev); }, disableFocusHighlight: !onClickWeekDay }, content));
455
- }
456
- return content;
457
- };
458
-
459
- var CalendarDay = function CalendarDay(_a) {
460
- var day = _a.day, week = _a.week, month = _a.month, dayState = _a.dayState, userData = _a.userData, onClickDay = _a.onClickDay, theme = _a.theme, ExtraDayContent = _a.extraDayContent, defaultHighlights = _a.defaultHighlights;
461
- var content = (React.createElement(Box, { width: "100%", height: "100%", justifyContent: "center", alignItems: "center" },
462
- React.createElement(Text, __assign({}, (theme.CalendarDay.textProps &&
463
- theme.CalendarDay.textProps(defaultHighlights, dayState, day, week, month, userData))), day.dayOfMonth)));
464
- var WrapperTd = styled.td(__assign({}, (theme.CalendarDay.tdStyle &&
465
- theme.CalendarDay.tdStyle(defaultHighlights, dayState, day, week, month, userData))));
466
- var InnerWrapperDiv = styled.div(__assign(__assign({}, (theme.CalendarDay.innerWrapperStyle &&
467
- theme.CalendarDay.innerWrapperStyle(defaultHighlights, dayState, day, week, month, userData))), { width: "100%", height: "100%" }));
468
- var CellWrapperDiv = styled.div(__assign(__assign({}, (theme.CalendarDay.cellWrapperStyle &&
469
- theme.CalendarDay.cellWrapperStyle(defaultHighlights, dayState, day, week, month, userData))), { width: "100%", height: "100%", position: "relative" }));
470
- return (React.createElement(WrapperTd, null,
471
- React.createElement(InnerWrapperDiv, null,
472
- React.createElement(CellWrapperDiv, null, day.month === month.monthInYear && (React.createElement(React.Fragment, null,
473
- ExtraDayContent && (React.createElement(ExtraDayContent, { week: week, month: month, day: day, dayState: dayState, theme: theme, userData: userData })),
474
- onClickDay && isClickable(defaultHighlights, dayState) ? (React.createElement(Clickable, { onClick: function (ev) { return onClickDay(day, userData, ev); }, style: { width: "100%", height: "100%" }, borderRadius: "var(--swui-calendar-day-border-radius)" }, content)) : (React.createElement(React.Fragment, null, content))))))));
475
- };
476
- var isClickable = function (defaultHighlights, dayState) {
477
- return !!dayHighlightSelect(dayState, defaultHighlights, ["enabled", "disabled"], [true, false], true);
478
- };
479
-
480
- function CalendarMonth(_a) {
481
- var month = _a.month, _b = _a.dayComponent, dayComponent = _b === void 0 ? CalendarDay : _b, statePerWeek = _a.statePerWeek, userDataPerWeek = _a.userDataPerWeek, minDate = _a.minDate, maxDate = _a.maxDate, onClickDay = _a.onClickDay, onClickWeek = _a.onClickWeek, onClickWeekDay = _a.onClickWeekDay, onClickMonth = _a.onClickMonth, onClickYear = _a.onClickYear, renderWeekNumber = _a.renderWeekNumber, renderWeekDay = _a.renderWeekDay, headerLeftContent = _a.headerLeftContent, headerRightContent = _a.headerRightContent, _c = _a.theme, theme = _c === void 0 ? defaultCalendarTheme : _c, extraDayContent = _a.extraDayContent, defaultHighlights = _a.defaultHighlights;
482
- var showWeekNumber = theme.WeekNumber.show;
483
- return (React.createElement(React.Fragment, null,
484
- React.createElement(Box, { alignItems: "stretch" },
485
- React.createElement(Row, { justifyContent: "space-between", alignItems: "center", height: "32px" },
486
- React.createElement(Box, { alignItems: "center" }, headerLeftContent),
487
- React.createElement(Row, { alignItems: "center" },
488
- React.createElement(Row, { width: "104px", justifyContent: "center" }, onClickMonth ? (React.createElement(FlatButton, { onClick: function () { return onClickMonth(month); }, label: month.name })) : (React.createElement(Text, null, month.name))),
489
- React.createElement(Space, null),
490
- React.createElement(Row, { width: "64px", justifyContent: "center" }, onClickYear ? (React.createElement(FlatButton, { onClick: function () { return onClickYear(month.year); }, label: String(month.year) })) : (React.createElement(Text, null, month.year)))),
491
- React.createElement(Box, { alignItems: "center" }, headerRightContent)),
492
- React.createElement("table", null,
493
- React.createElement("tbody", null,
494
- React.createElement("tr", null,
495
- showWeekNumber && (React.createElement("td", null,
496
- React.createElement(Box, { width: theme.width, height: theme.height, justifyContent: "center", alignItems: "center" },
497
- React.createElement(Text, { size: "small", color: theme.CalendarMonth.headerTextColor }, "W")))),
498
- month.weeks[0].days.map(function (day) { return (React.createElement("td", { key: day.name }, renderWeekDay ? (renderWeekDay(day.name, theme, onClickWeekDay)) : (React.createElement(WeekDayCell, { day: day, onClickWeekDay: onClickWeekDay, theme: theme })))); })),
499
- month.weeks.map(function (week) { return (React.createElement(CalendarWeek, { key: week.weekNumber, month: month, week: week, dayComponent: dayComponent, statePerWeekDay: statePerWeek && statePerWeek[week.weekNumber], userDataPerWeekDay: userDataPerWeek && userDataPerWeek[week.weekNumber], onClickDay: onClickDay, onClickWeek: onClickWeek, theme: theme, renderWeekNumber: renderWeekNumber, extraDayContent: extraDayContent, defaultHighlights: defaultHighlights, minDate: minDate, maxDate: maxDate })); }))))));
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
+ });
500
696
  }
501
-
502
- function styleInject(css, ref) {
503
- if ( ref === void 0 ) ref = {};
504
- var insertAt = ref.insertAt;
505
-
506
- if (!css || typeof document === 'undefined') { return; }
507
-
508
- var head = document.head || document.getElementsByTagName('head')[0];
509
- var style = document.createElement('style');
510
- style.type = 'text/css';
511
-
512
- if (insertAt === 'top') {
513
- if (head.firstChild) {
514
- head.insertBefore(style, head.firstChild);
515
- } else {
516
- head.appendChild(style);
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;
517
916
  }
518
- } else {
519
- head.appendChild(style);
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;
520
953
  }
521
-
522
- if (style.styleSheet) {
523
- style.styleSheet.cssText = css;
524
- } else {
525
- style.appendChild(document.createTextNode(css));
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
+ }
526
1111
  }
527
1112
  }
528
-
529
- var css_248z$1 = ".Calendar-module_calendar__Ztvgm {\n --swui-calendar-day-width: 40px;\n --swui-calendar-day-height: 38px;\n --swui-calendar-day-border-radius: 4px;\n\n /* Week number */\n\n --swui-calendar-week-number-bg-color: transparent;\n --swui-calendar-week-number-text-color: var(--lhds-color-ui-500);\n --swui-calendar-week-number-clickable-text-color: var(--lhds-color-ui-500);\n\n /* Week day */\n\n --swui-calendar-week-day-text-color: var(--lhds-color-ui-500);\n --swui-calendar-week-day-clickable-text-color: var(--lhds-color-ui-500);\n\n /* Wrapper */\n\n --swui-calendar-wrapper-selected-border: var(--swui-primary-action-color);\n --swui-calendar-wrapper-selected-background: var(--swui-primary-action-color);\n --swui-calendar-wrapper-range-border: var(--lhds-color-blue-100);\n --swui-calendar-wrapper-range-background: var(--lhds-color-blue-100);\n --swui-calendar-wrapper-today-border: var(--lhds-color-ui-200);\n --swui-calendar-wrapper-today-background: var(--lhds-color-ui-200);\n\n /* Text */\n\n --swui-calendar-text-selected-color: #fff;\n --swui-calendar-text-disabled-color: var(--swui-text-disabled-color);\n --swui-calendar-text-in-other-month-color: var(--swui-text-disabled-color);\n}\n\n .Calendar-module_calendar__Ztvgm table {\n border-spacing: 0 4px;\n }\n\n .Calendar-module_calendar__Ztvgm span {\n line-height: 100%;\n }\n\n .Calendar-module_calendar__Ztvgm tr td:last-child {\n border-top-right-radius: var(--swui-calendar-day-border-radius);\n border-bottom-right-radius: var(--swui-calendar-day-border-radius);\n }\n\n .Calendar-module_calendar__Ztvgm tr td:nth-child(2) {\n border-top-left-radius: var(--swui-calendar-day-border-radius);\n border-bottom-left-radius: var(--swui-calendar-day-border-radius);\n }\n\n .Calendar-module_calendar__Ztvgm td {\n padding: 0;\n width: var(--swui-calendar-day-width);\n height: var(--swui-calendar-day-height);\n }\n";
530
- var styles$1 = {"calendar":"Calendar-module_calendar__Ztvgm"};
531
- styleInject(css_248z$1);
532
-
533
- function CalendarPanel(_a) {
534
- var monthRows = _a.monthRows, _b = _a.dayComponent, dayComponent = _b === void 0 ? CalendarDay : _b, userDataPerMonth = _a.userDataPerMonth, statePerMonth = _a.statePerMonth, minDate = _a.minDate, maxDate = _a.maxDate, onClickDay = _a.onClickDay, onClickWeekDay = _a.onClickWeekDay, onClickWeek = _a.onClickWeek, onClickMonth = _a.onClickMonth, onClickYear = _a.onClickYear, renderWeekDay = _a.renderWeekDay, renderWeekNumber = _a.renderWeekNumber, headerLeftContent = _a.headerLeftContent, headerRightContent = _a.headerRightContent, extraDayContent = _a.extraDayContent, defaultHighlights = _a.defaultHighlights, _c = _a.theme, theme = _c === void 0 ? defaultCalendarTheme : _c;
535
- var minDateObj = useMemo(function () { return (minDate ? parse(minDate, "yyyy-MM-dd", new Date()) : undefined); }, [minDate]);
536
- var maxDateObj = useMemo(function () { return (maxDate ? parse(maxDate, "yyyy-MM-dd", new Date()) : undefined); }, [maxDate]);
537
- return (React.createElement("div", { className: styles$1.calendar }, monthRows.map(function (monthRow, rowIndex) { return (React.createElement(Spacing, { key: rowIndex },
538
- React.createElement(Row, null, monthRow.map(function (month, index) { return (React.createElement(React.Fragment, { key: month.name },
539
- index > 0 && React.createElement(Space, null),
540
- React.createElement(CalendarMonth, { month: month, dayComponent: dayComponent, userDataPerWeek: userDataPerMonth && userDataPerMonth[month.monthString], statePerWeek: statePerMonth && statePerMonth[month.monthString], onClickDay: onClickDay, onClickWeekDay: onClickWeekDay, onClickWeek: onClickWeek, onClickMonth: onClickMonth, onClickYear: onClickYear, theme: theme, renderWeekNumber: renderWeekNumber, renderWeekDay: renderWeekDay, headerLeftContent: headerLeftContent, headerRightContent: headerRightContent, extraDayContent: extraDayContent, defaultHighlights: defaultHighlights, minDate: minDateObj, maxDate: maxDateObj }))); })))); })));
541
- }
542
- function Calendar(props) {
543
- var initialDate = getInitialDate(props.year, props.month, props.date);
544
- var _a = calculateOverflowingMonth(initialDate.year, initialDate.month), year = _a.year, month = _a.month;
545
- var monthRows = getMonthRows(year, month, props.numMonths, props.monthsPerRow);
546
- var statePerMonth = useHighlightToday(props.highlightToday, props.statePerMonth);
547
- return (React.createElement(CalendarPanel, __assign({ year: year, month: month, monthRows: monthRows }, props, { statePerMonth: statePerMonth })));
548
- }
549
- var getInitialDate = function (year, month, date) {
550
- if (month && year) {
551
- return {
552
- month: month,
553
- year: year,
554
- };
555
- }
556
- if (date) {
557
- return {
558
- month: getMonth(date),
559
- year: getYear(date),
560
- };
561
- }
562
- var now = new Date();
563
- return {
564
- month: getMonth(now),
565
- year: getYear(now),
566
- };
567
- };
568
- var getMonthRows = function (year, month, numMonths, monthsPerRow) {
569
- if (numMonths == null) {
570
- return [[getMonthInYear(year, month)]];
571
- }
572
- if (monthsPerRow == null) {
573
- return [getMonthsInYear(year, month, numMonths)];
574
- }
575
- return chunk(getMonthsInYear(year, month, numMonths), monthsPerRow);
576
- };
577
-
578
- var useSelectedMonthStepperLogic = function (dateInFocus, setDateInFocus, monthsPerRow, numMonths) {
579
- var nextMonth = useCallback(function () {
580
- var _a;
581
- var d = addMonths(dateInFocus, (_a = monthsPerRow !== null && monthsPerRow !== void 0 ? monthsPerRow : numMonths) !== null && _a !== void 0 ? _a : 1);
582
- setDateInFocus === null || setDateInFocus === void 0 ? void 0 : setDateInFocus(d);
583
- }, [setDateInFocus, dateInFocus, monthsPerRow, numMonths]);
584
- var nextYear = useCallback(function () {
585
- var d = addYears(dateInFocus, 1);
586
- setDateInFocus === null || setDateInFocus === void 0 ? void 0 : setDateInFocus(d);
587
- }, [setDateInFocus, dateInFocus]);
588
- var prevMonth = useCallback(function () {
589
- var _a;
590
- var d = subMonths(dateInFocus, (_a = monthsPerRow !== null && monthsPerRow !== void 0 ? monthsPerRow : numMonths) !== null && _a !== void 0 ? _a : 1);
591
- setDateInFocus === null || setDateInFocus === void 0 ? void 0 : setDateInFocus(d);
592
- }, [setDateInFocus, dateInFocus, monthsPerRow, numMonths]);
593
- var prevYear = useCallback(function () {
594
- var d = subYears(dateInFocus, 1);
595
- setDateInFocus === null || setDateInFocus === void 0 ? void 0 : setDateInFocus(d);
596
- }, [setDateInFocus, dateInFocus]);
597
- return {
598
- nextMonth: nextMonth,
599
- prevMonth: prevMonth,
600
- nextYear: nextYear,
601
- prevYear: prevYear,
602
- };
603
- };
604
-
605
- var WithMonthSwitcherBelow = function (_a) {
606
- var children = _a.children, prevMonth = _a.prevMonth, nextMonth = _a.nextMonth, prevYear = _a.prevYear, nextYear = _a.nextYear;
607
- return (React.createElement("div", null,
608
- children,
609
- React.createElement(Indent, null,
610
- React.createElement(Row, null,
611
- React.createElement(FlatButton, { onClick: prevYear, leftIcon: faAngleDoubleLeft }),
612
- React.createElement(Space, null),
613
- React.createElement(FlatButton, { onClick: prevMonth, leftIcon: faAngleLeft }),
614
- React.createElement(Indent, { num: 2 }),
615
- React.createElement(FlatButton, { onClick: nextMonth, leftIcon: faAngleRight }),
616
- React.createElement(Space, null),
617
- React.createElement(FlatButton, { onClick: nextYear, leftIcon: faAngleDoubleRight }))),
618
- React.createElement(Space, null)));
619
- };
620
-
621
- var MonthPickerCell = function (_a) {
622
- var value = _a.value, onValueChange = _a.onValueChange, month = _a.month;
623
- var label = useMemo(function () {
624
- var now = new Date(2000, month, 1);
625
- return format(now, "MMM");
626
- }, [month]);
627
- 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); } }))));
628
- };
629
-
630
- var monthMatrix = [
631
- [Month.JANUARY, Month.FEBRUARY, Month.MARCH],
632
- [Month.APRIL, Month.MAY, Month.JUNE],
633
- [Month.JULY, Month.AUGUST, Month.SEPTEMBER],
634
- [Month.OCTOBER, Month.NOVEMBER, Month.DECEMBER],
635
- ];
636
- var MonthPicker = function (_a) {
637
- var value = _a.value, onValueChange = _a.onValueChange;
638
- 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 })); }))); })));
639
- };
640
-
641
- var createStandardDateRangePresets = function (now) { return [
642
- {
643
- label: "Past",
644
- presets: [
645
- { label: "Last 3 days", startDate: now, endDate: subDays(now, 2) },
646
- { label: "Last 7 days", startDate: now, endDate: subDays(now, 6) },
647
- { label: "Last 30 days", startDate: now, endDate: subDays(now, 29) },
648
- { label: "Last 45 days", startDate: now, endDate: subDays(now, 44) },
649
- ],
650
- },
651
- {
652
- label: "Future",
653
- presets: [
654
- { label: "Next 3 days", startDate: now, endDate: addDays(now, 2) },
655
- { label: "Next 7 days", startDate: now, endDate: addDays(now, 6) },
656
- { label: "Next 30 days", startDate: now, endDate: addDays(now, 29) },
657
- { label: "Next 45 days", startDate: now, endDate: addDays(now, 44) },
658
- ],
659
- },
660
- ]; };
661
-
662
- var PresetPicker = function (_a) {
663
- var _b;
664
- var onClickPreset = _a.onClickPreset;
665
- var _c = useState(0), pageIndex = _c[0], setPageIndex = _c[1];
666
- var pages = useMemo(function () { return createStandardDateRangePresets(new Date()); }, []);
667
- var currentPage = (_b = pages[pageIndex]) !== null && _b !== void 0 ? _b : pages[0];
668
- return (React.createElement(Column, null,
669
- React.createElement(Row, { justifyContent: "space-between", alignItems: "center", width: "200px" },
670
- React.createElement(FlatButton, { size: "small", leftIcon: faAngleLeft, disabled: pageIndex === 0, onClick: function () { return setPageIndex(pageIndex - 1); } }),
671
- React.createElement(Text, null, currentPage.label),
672
- React.createElement(FlatButton, { size: "small", leftIcon: faAngleRight, disabled: pageIndex === pages.length - 1, onClick: function () { return setPageIndex(pageIndex + 1); } })),
673
- React.createElement(Space, null),
674
- React.createElement(Column, { alignItems: "center" }, currentPage.presets.map(function (preset) { return (React.createElement(React.Fragment, { key: preset.label },
675
- React.createElement(PrimaryButton, { label: preset.label, onClick: function () { return onClickPreset(preset); } }),
676
- React.createElement(Space, null))); }))));
677
- };
678
-
679
- var YearPickerCell = function (_a) {
680
- var value = _a.value, onValueChange = _a.onValueChange, year = _a.year;
681
- var label = String(year);
682
- 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); } }))));
683
- };
684
-
685
- var YearPicker = function (_a) {
686
- var value = _a.value, onValueChange = _a.onValueChange, initialLastYear = _a.initialLastYear;
687
- var _b = useState(function () {
688
- if (value) {
689
- return value + 4;
690
- }
691
- return initialLastYear !== null && initialLastYear !== void 0 ? initialLastYear : new Date().getFullYear() + 4;
692
- }), lastYear = _b[0], setLastYear = _b[1];
693
- var yearRows = useMemo(function () {
694
- var startYear = lastYear - 11;
695
- return chunk(range(startYear, lastYear + 1), 3);
696
- }, [lastYear]);
697
- useEffect(function () {
698
- setLastYear(function (prev) { return calculateLastYearInFocus(value, prev); });
699
- }, [value]);
700
- return (React.createElement(Row, null,
701
- React.createElement(Column, { justifyContent: "center" },
702
- React.createElement(FlatButton, { leftIcon: faCaretLeft, onClick: function () { return setLastYear(lastYear - 3); } })),
703
- 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 })); }))); })),
704
- React.createElement(Column, { justifyContent: "center" },
705
- React.createElement(FlatButton, { leftIcon: faCaretRight, onClick: function () { return setLastYear(lastYear + 3); } }))));
706
- };
707
- var calculateLastYearInFocus = function (value, lastYear) {
708
- if (value == null) {
709
- return lastYear;
710
- }
711
- if (value > lastYear) {
712
- var yearDiff = value - lastYear;
713
- var remaining = yearDiff % 3;
714
- var yearsToAdd = yearDiff - remaining + 3;
715
- return lastYear + yearsToAdd;
716
- }
717
- var startYear = lastYear - 11;
718
- if (value < startYear) {
719
- var yearDiff = startYear - value;
720
- var remaining = yearDiff % 3;
721
- var yearsToSubtract = yearDiff - remaining + 3;
722
- return lastYear - yearsToSubtract;
723
- }
724
- return lastYear;
725
- };
726
-
727
- var CalendarWithMonthYearPickers = function CalendarWithMonthYearPickers(_a) {
728
- var dateInFocus = _a.dateInFocus, setDateInFocus = _a.setDateInFocus, currentPanel = _a.currentPanel, setCurrentPanel = _a.setCurrentPanel, props = __rest(_a, ["dateInFocus", "setDateInFocus", "currentPanel", "setCurrentPanel"]);
729
- var onChangeSelectedMonth = useCallback(function (selectedMonth) {
730
- var newDate = dateInFocus ? new Date(dateInFocus) : new Date();
731
- newDate.setMonth(selectedMonth);
732
- if (setDateInFocus) {
733
- setDateInFocus(newDate);
734
- }
735
- setCurrentPanel("calendar");
736
- }, [dateInFocus, setDateInFocus, setCurrentPanel]);
737
- var onChangeSelectedYear = useCallback(function (selectedYear) {
738
- var newDate = dateInFocus ? new Date(dateInFocus) : new Date();
739
- newDate.setFullYear(selectedYear);
740
- if (setDateInFocus) {
741
- setDateInFocus(newDate);
742
- }
743
- setCurrentPanel("calendar");
744
- }, [dateInFocus, setDateInFocus, setCurrentPanel]);
745
- var onClickYear = useCallback(function () {
746
- setCurrentPanel("year");
747
- }, [setCurrentPanel]);
748
- var onClickMonth = useCallback(function () {
749
- setCurrentPanel("month");
750
- }, [setCurrentPanel]);
751
- switch (currentPanel) {
752
- case "calendar":
753
- return (React.createElement(React.Fragment, null,
754
- React.createElement(Calendar, __assign({}, props, { date: dateInFocus, onClickYear: onClickYear, onClickMonth: onClickMonth }))));
755
- case "month":
756
- return (React.createElement(MonthPicker, { value: dateInFocus.getMonth(), onValueChange: onChangeSelectedMonth }));
757
- case "year":
758
- return (React.createElement(YearPicker, { value: dateInFocus.getFullYear(), onValueChange: onChangeSelectedYear }));
759
- case "presets":
760
- return React.createElement(PresetPicker, { onClickPreset: function () { } });
761
- default:
762
- return (React.createElement(Box, null,
763
- React.createElement(PrimaryButton, { label: "Show calendar", onClick: function () { return setCurrentPanel("calendar"); } })));
764
- }
765
- };
766
-
767
- var noop = function () { };
768
- function CalendarWithMonthSwitcher(_a) {
769
- 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"]);
770
- var _e = useSelectedMonthStepperLogic(dateInFocus, setDateInFocus, calendarProps.monthsPerRow, calendarProps.numMonths), nextMonth = _e.nextMonth, prevMonth = _e.prevMonth, nextYear = _e.nextYear, prevYear = _e.prevYear;
771
- var placement = fallbackIfNoPlacement(monthSwitcherPlacement, calendarProps.numMonths);
772
- switch (placement) {
773
- case "below": {
774
- return (React.createElement(WithMonthSwitcherBelow, { theme: theme, nextMonth: nextMonth, prevMonth: prevMonth, nextYear: nextYear, prevYear: prevYear },
775
- React.createElement(Calendar, __assign({}, calendarProps, { theme: theme, date: dateInFocus }))));
776
- }
777
- case "header": {
778
- return (React.createElement(Column, null,
779
- React.createElement(CalendarWithMonthYearPickers, __assign({}, calendarProps, { theme: theme, dateInFocus: dateInFocus, setDateInFocus: setDateInFocus, currentPanel: currentPanel, setCurrentPanel: setCurrentPanel, onSelectPreset: onSelectPreset, headerLeftContent: React.createElement(Row, { alignItems: "center" },
780
- !hideYearPagination && (React.createElement(FlatButton, { size: "small", onClick: prevYear, leftIcon: faAngleDoubleLeft })),
781
- React.createElement(Space, null),
782
- React.createElement(FlatButton, { size: "small", onClick: prevMonth, leftIcon: faAngleLeft })), headerRightContent: React.createElement(Row, { alignItems: "center" },
783
- React.createElement(FlatButton, { size: "small", onClick: nextMonth, leftIcon: faAngleRight }),
784
- React.createElement(Space, null),
785
- !hideYearPagination && (React.createElement(FlatButton, { size: "small", onClick: nextYear, leftIcon: faAngleDoubleRight }))) }))));
786
- }
787
- default: {
788
- return (React.createElement(Calendar, __assign({}, calendarProps, { theme: theme, date: dateInFocus })));
789
- }
790
- }
791
- }
792
- var fallbackIfNoPlacement = function (monthSwitcherPlacement, numMonths) {
793
- return monthSwitcherPlacement || (numMonths || 1) > 1 ? "below" : "header";
794
- };
795
-
796
- var dateRangeToStrings = function (dateRange) { return ({
797
- startDate: dateRange.startDate
798
- ? format(dateRange.startDate, "yyyy-MM-dd")
799
- : undefined,
800
- endDate: dateRange.endDate
801
- ? format(dateRange.endDate, "yyyy-MM-dd")
802
- : undefined,
803
- }); };
804
- var stringsToDateRange = function (_a) {
805
- var startDate = _a.startDate, endDate = _a.endDate;
806
- var now = new Date();
807
- return {
808
- startDate: startDate ? parse(startDate, "yyyy-MM-dd", now) : undefined,
809
- endDate: endDate ? parse(endDate, "yyyy-MM-dd", now) : undefined,
810
- };
811
- };
812
-
813
- var isDateRangeInvalid = function (_a) {
814
- var startDate = _a.startDate, endDate = _a.endDate;
815
- return Boolean(startDate &&
816
- endDate &&
817
- !isSameDay(startDate, endDate) &&
818
- isAfter(startDate, endDate));
819
- };
820
- var toggleDatesIfEndIsEarlierThanStart = function (dateRange) {
821
- if (isDateRangeInvalid(dateRange)) {
822
- return {
823
- startDate: dateRange.endDate,
824
- endDate: dateRange.startDate,
825
- };
826
- }
827
- return dateRange;
828
- };
829
- var toggleDateStringsIfEndIsEarlierThanStart = function (dateRange) {
830
- if (dateRange.startDate && dateRange.endDate) {
831
- return dateRangeToStrings(toggleDatesIfEndIsEarlierThanStart(stringsToDateRange(dateRange)));
832
- }
833
- return dateRange;
834
- };
835
-
836
- var useDateRangeOnClickDayHandler = function (value, onValueChange, focusedInput, setFocusedInput) {
837
- return useCallback(function (day) {
838
- var dateRange = {
839
- startDate: focusedInput === "startDate" ? day.date : value === null || value === void 0 ? void 0 : value.startDate,
840
- endDate: focusedInput === "endDate" ? day.date : value === null || value === void 0 ? void 0 : value.endDate,
841
- };
842
- if (!isDateRangeInvalid(dateRange)) {
843
- setFocusedInput(focusedInput === "startDate" ? "endDate" : "startDate");
844
- }
845
- onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(toggleDatesIfEndIsEarlierThanStart(dateRange));
846
- }, [
847
- focusedInput,
848
- onValueChange,
849
- setFocusedInput,
850
- value === null || value === void 0 ? void 0 : value.endDate,
851
- value === null || value === void 0 ? void 0 : value.startDate,
852
- ]);
853
- };
854
-
855
- var useInternalPanelState = function (onChangePanel) {
856
- var _a = useState("calendar"), currentPanel = _a[0], _setCurrentPanel = _a[1];
857
- var setCurrentPanel = useCallback(function (currentPanel) {
858
- _setCurrentPanel(currentPanel);
859
- onChangePanel === null || onChangePanel === void 0 ? void 0 : onChangePanel(currentPanel);
860
- }, [onChangePanel]);
861
- return {
862
- currentPanel: currentPanel,
863
- setCurrentPanel: setCurrentPanel,
864
- };
865
- };
866
-
867
- var useDateRangeSelection = function (_a) {
868
- var focusedInput = _a.focusedInput, value = _a.value, onValueChange = _a.onValueChange, setFocusedInput = _a.setFocusedInput, statePerMonth = _a.statePerMonth, onChangePanel = _a.onChangePanel;
869
- var _b = useInternalPanelState(onChangePanel), currentPanel = _b.currentPanel, setCurrentPanel = _b.setCurrentPanel;
870
- var _c = useState(function () { return new Date(); }), dateInFocus = _c[0], setDateInFocus = _c[1];
871
- var onClickDay = useDateRangeOnClickDayHandler(value, onValueChange, focusedInput, setFocusedInput);
872
- var statePerMonthWithSelection = useMemo(function () {
873
- return buildDayStateForDateRange(statePerMonth, value === null || value === void 0 ? void 0 : value.startDate, value === null || value === void 0 ? void 0 : value.endDate);
874
- }, [statePerMonth, value === null || value === void 0 ? void 0 : value.endDate, value === null || value === void 0 ? void 0 : value.startDate]);
875
- return {
876
- onClickDay: onClickDay,
877
- statePerMonth: statePerMonthWithSelection,
878
- currentPanel: currentPanel,
879
- setCurrentPanel: setCurrentPanel,
880
- setDateInFocus: setDateInFocus,
881
- dateInFocus: dateInFocus,
882
- };
883
- };
884
-
885
- function DateRangeCalendar(props) {
886
- var dateRangeSelectionProps = useDateRangeSelection(props);
887
- 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
+ });
888
1205
  }
889
-
890
- var useDateRangeCalendarState = function () {
891
- var _a = useState(), startDate = _a[0], setStartDate = _a[1];
892
- var _b = useState(), endDate = _b[0], setEndDate = _b[1];
893
- var _c = useState("startDate"), focusedInput = _c[0], setFocusedInput = _c[1];
894
- return {
895
- startDate: startDate,
896
- setStartDate: setStartDate,
897
- endDate: endDate,
898
- setEndDate: setEndDate,
899
- focusedInput: focusedInput,
900
- setFocusedInput: setFocusedInput,
901
- };
902
- };
903
-
904
- var useSingleDateSelection = function (_a) {
905
- var onChange = _a.onChange, value = _a.value, statePerMonth = _a.statePerMonth, onChangePanel = _a.onChangePanel;
906
- var _b = useInternalPanelState(onChangePanel), currentPanel = _b.currentPanel, setCurrentPanel = _b.setCurrentPanel;
907
- var _c = useState(function () { return value !== null && value !== void 0 ? value : new Date(); }), dateInFocus = _c[0], setDateInFocus = _c[1];
908
- var onClickDay = useCallback(function (day) {
909
- if (onChange) {
910
- onChange(day.date);
911
- }
912
- }, [onChange]);
913
- var statePerMonthWithSelectedDate = useMemo(function () {
914
- return value
915
- ? addDayStateHighlights(statePerMonth, value, [
916
- "selected",
917
- "singleSelected",
918
- ])
919
- : statePerMonth;
920
- }, [statePerMonth, value]);
921
- return {
922
- onClickDay: onClickDay,
923
- statePerMonth: statePerMonthWithSelectedDate,
924
- date: value,
925
- currentPanel: currentPanel,
926
- setCurrentPanel: setCurrentPanel,
927
- dateInFocus: dateInFocus,
928
- setDateInFocus: setDateInFocus,
929
- };
930
- };
931
-
932
- function SingleDateCalendar(props) {
933
- var singleDateSelectionProps = useSingleDateSelection(props);
934
- return (React.createElement(CalendarWithMonthSwitcher, __assign({}, props, singleDateSelectionProps)));
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
+ });
935
1252
  }
936
-
937
- var useMultiDateSelection = function (_a) {
938
- var onChange = _a.onChange, value = _a.value, statePerMonth = _a.statePerMonth, onChangePanel = _a.onChangePanel;
939
- var _b = useInternalPanelState(onChangePanel), currentPanel = _b.currentPanel, setCurrentPanel = _b.setCurrentPanel;
940
- var _c = useState(function () { return new Date(); }), dateInFocus = _c[0], setDateInFocus = _c[1];
941
- var onClickDay = useCallback(function (day) {
942
- if (!onChange) {
943
- return;
944
- }
945
- var isSelected = value && value.find(function (d) { return isSameDay(d, day.date); });
946
- if (value && isSelected) {
947
- onChange(value.filter(function (v) { return !isSameDay(v, day.date); }));
948
- }
949
- else {
950
- onChange(__spreadArray(__spreadArray([], (value || []), true), [day.date], false));
951
- }
952
- }, [onChange, value]);
953
- var statePerMonthWithSelectedDate = useMemo(function () {
954
- if (!value) {
955
- return statePerMonth;
956
- }
957
- return value.reduce(function (stateSum, date) { return addDayStateHighlights(stateSum, date, ["selected"]); }, statePerMonth);
958
- }, [statePerMonth, value]);
959
- return {
960
- onClickDay: onClickDay,
961
- statePerMonth: statePerMonthWithSelectedDate,
962
- currentPanel: currentPanel,
963
- setCurrentPanel: setCurrentPanel,
964
- dateInFocus: dateInFocus,
965
- setDateInFocus: setDateInFocus,
966
- };
967
- };
968
-
969
- function MultiDateCalendar(props) {
970
- var selectionProps = useMultiDateSelection(props);
971
- return React.createElement(CalendarWithMonthSwitcher, __assign({}, props, selectionProps));
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
+ });
972
1293
  }
973
-
974
- var useSingleWeekSelection = function (_a) {
975
- var onChange = _a.onChange, value = _a.value, statePerMonth = _a.statePerMonth, onChangePanel = _a.onChangePanel;
976
- var _b = useState(function () {
977
- var week = getWeekDataFromWeekString(value);
978
- if (!week) {
979
- return new Date();
980
- }
981
- return week.days[0].date;
982
- }), dateInFocus = _b[0], setDateInFocus = _b[1];
983
- var _c = useInternalPanelState(onChangePanel), currentPanel = _c.currentPanel, setCurrentPanel = _c.setCurrentPanel;
984
- var onClickDay = useCallback(function (day) {
985
- if (onChange) {
986
- onChange(getWeekStringFromWeekData(getWeekForDate(day.date)));
987
- }
988
- }, [onChange]);
989
- var onClickWeek = useCallback(function (week) {
990
- if (onChange) {
991
- onChange(getWeekStringFromWeekData(week));
992
- }
993
- }, [onChange]);
994
- var statePerMonthWithSelection = useMemo(function () {
995
- var weekData = getWeekDataFromWeekString(value);
996
- return weekData
997
- ? addWeekRangeHighlights(statePerMonth, weekData)
998
- : statePerMonth;
999
- }, [value, statePerMonth]);
1000
- var date = useMemo(function () {
1001
- var week = getWeekDataFromWeekString(value);
1002
- if (!week) {
1003
- return new Date();
1004
- }
1005
- return week.days[0].date;
1006
- }, [value]);
1007
- return {
1008
- statePerMonth: statePerMonthWithSelection,
1009
- date: date,
1010
- dateInFocus: dateInFocus,
1011
- setDateInFocus: setDateInFocus,
1012
- onClickDay: onClickDay,
1013
- onClickWeek: onClickWeek,
1014
- currentPanel: currentPanel,
1015
- setCurrentPanel: setCurrentPanel,
1016
- };
1017
- };
1018
- var getWeekStringFromWeekData = function (week) {
1019
- if (!week) {
1020
- return undefined;
1021
- }
1022
- return "".concat(week.endYear, "-").concat(week.weekNumber);
1023
- };
1024
- var getWeekDataFromWeekString = function (week) {
1025
- if (!week) {
1026
- return undefined;
1027
- }
1028
- var parts = week.split("-");
1029
- var weekNumber = parseInt(parts[1], 10);
1030
- var year = parseInt(parts[0], 10);
1031
- return getWeekForDate(getStartDateOfISOWeek(weekNumber, year));
1032
- };
1033
-
1034
- function SingleWeekCalendar(props) {
1035
- var singleWeekSelectionProps = useSingleWeekSelection(props);
1036
- return (React.createElement(CalendarWithMonthSwitcher, __assign({}, props, singleWeekSelectionProps)));
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
+ });
1037
1361
  }
1038
-
1039
- var removeDateIfExist = function (list, date) {
1040
- return list.filter(function (item) { return !isSameDay(item, date); });
1041
- };
1042
- var listContainsDate = function (list, date) {
1043
- return !!list.find(function (item) { return isSameDay(item, date); });
1044
- };
1045
-
1046
- var useDateRangeExclusionSelection = function (_a) {
1047
- var value = _a.value, onValueChange = _a.onValueChange, statePerMonth = _a.statePerMonth, onChangePanel = _a.onChangePanel;
1048
- var _b = useState(), dateRange = _b[0], setDateRange = _b[1];
1049
- var _c = useState("startDate"), focusedInput = _c[0], setFocusedInput = _c[1];
1050
- var _d = useInternalPanelState(onChangePanel), currentPanel = _d.currentPanel, setCurrentPanel = _d.setCurrentPanel;
1051
- var _e = useState(function () { var _a; return (_a = (focusedInput && (value === null || value === void 0 ? void 0 : value[focusedInput]))) !== null && _a !== void 0 ? _a : new Date(); }), dateInFocus = _e[0], setDateInFocus = _e[1];
1052
- var onChangeHandler = useCallback(function (value) {
1053
- setDateRange(value);
1054
- var startDate = value.startDate, endDate = value.endDate;
1055
- if (onValueChange) {
1056
- if (startDate && endDate) {
1057
- var dates = eachDayOfInterval({ start: startDate, end: endDate });
1058
- onValueChange(dates);
1059
- }
1060
- else if (startDate) {
1061
- onValueChange([startDate]);
1062
- }
1063
- else if (endDate) {
1064
- onValueChange([endDate]);
1065
- }
1066
- }
1067
- }, [onValueChange]);
1068
- var onClickDayRange = useDateRangeOnClickDayHandler(dateRange, onChangeHandler, focusedInput, setFocusedInput);
1069
- var onClickDay = useCallback(function (day, userData, ev) {
1070
- if (onValueChange) {
1071
- if (ev.ctrlKey || ev.metaKey) {
1072
- if (!value) {
1073
- onValueChange([day.date]);
1074
- }
1075
- else if (listContainsDate(value, day.date)) {
1076
- onValueChange(removeDateIfExist(value, day.date));
1077
- }
1078
- else {
1079
- onValueChange(__spreadArray(__spreadArray([], value, true), [day.date], false));
1080
- }
1081
- }
1082
- else {
1083
- onClickDayRange(day, userData, ev);
1084
- }
1085
- }
1086
- }, [onValueChange, onClickDayRange, value]);
1087
- var statePerMonthWithSelectedDate = useMemo(function () {
1088
- return addHighlighting(statePerMonth, value);
1089
- }, [statePerMonth, value]);
1090
- return {
1091
- onClickDay: onClickDay,
1092
- statePerMonth: statePerMonthWithSelectedDate,
1093
- currentPanel: currentPanel,
1094
- setCurrentPanel: setCurrentPanel,
1095
- dateInFocus: dateInFocus,
1096
- setDateInFocus: setDateInFocus,
1097
- };
1098
- };
1099
- var addHighlighting = function (statePerMonth, dateList) {
1100
- if (!dateList) {
1101
- return statePerMonth;
1102
- }
1103
- return dateList.reduce(function (statePerMonth, date) {
1104
- return addDayStateHighlights(statePerMonth, date, ["selected"]);
1105
- }, statePerMonth);
1106
- };
1107
-
1108
- function DateRangeExclusionCalendar(props) {
1109
- var selectionProps = useDateRangeExclusionSelection(props);
1110
- 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
+ });
1111
1433
  }
1112
-
1113
- var defaultPopoverPlacement = "bottom";
1114
-
1115
- var useCalendarPopoverUpdater = function () {
1116
- var _a = useTippyInstance(), tippyRef = _a[0], tippyInstanceRef = _a[1];
1117
- var onChangePanel = useCallback(function () {
1118
- var _a, _b;
1119
- (_b = (_a = tippyInstanceRef.current) === null || _a === void 0 ? void 0 : _a.popperInstance) === null || _b === void 0 ? void 0 : _b.update();
1120
- }, [tippyInstanceRef]);
1121
- return {
1122
- onChangePanel: onChangePanel,
1123
- tippyRef: tippyRef,
1124
- };
1125
- };
1126
-
1127
- var useDateInput = function (onChange, onClose, openOnMount) {
1128
- var _a = useState(openOnMount || false), showingCalendar = _a[0], setShowingCalendar = _a[1];
1129
- var showCalendar = useCallback(function () {
1130
- setShowingCalendar(true);
1131
- return true;
1132
- }, [setShowingCalendar]);
1133
- var hideCalendar = useCallback(function () {
1134
- setShowingCalendar(false);
1135
- if (onClose) {
1136
- onClose();
1137
- }
1138
- }, [setShowingCalendar, onClose]);
1139
- var onSelectDate = useCallback(function (date) {
1140
- if (onChange) {
1141
- onChange(date);
1142
- }
1143
- setTimeout(hideCalendar, 150);
1144
- }, [onChange, hideCalendar]);
1145
- return {
1146
- showCalendar: showCalendar,
1147
- hideCalendar: hideCalendar,
1148
- showingCalendar: showingCalendar,
1149
- onSelectDate: onSelectDate,
1150
- };
1151
- };
1152
-
1153
- var defaultMaxDate = "2999-12-31";
1154
-
1155
- var DateInput = function (_a) {
1156
- var _b = _a.displayFormat, displayFormat = _b === void 0 ? DateFormats.fullDate : _b, _c = _a.placeholder, placeholder = _c === void 0 ? "Enter date" : _c, value = _a.value, _d = _a.zIndex, zIndex = _d === void 0 ? 100 : _d, _e = _a.calendarTheme, calendarTheme = _e === void 0 ? defaultCalendarTheme : _e, calendarProps = _a.calendarProps, openOnMount = _a.openOnMount, onClose = _a.onClose, onChange = _a.onChange, portalTarget = _a.portalTarget, variant = _a.variant, width = _a.width, minDate = _a.minDate, _f = _a.maxDate, maxDate = _f === void 0 ? defaultMaxDate : _f, disabled = _a.disabled;
1157
- var _g = useDateInput(onChange, onClose, openOnMount), hideCalendar = _g.hideCalendar, showingCalendar = _g.showingCalendar, onSelectDate = _g.onSelectDate, showCalendar = _g.showCalendar;
1158
- var _h = useCalendarPopoverUpdater(), tippyRef = _h.tippyRef, onChangePanel = _h.onChangePanel;
1159
- return (React.createElement(Box, { width: width },
1160
- React.createElement(Popover, { arrow: false, lazy: true, visible: showingCalendar, onClickOutside: hideCalendar, placement: defaultPopoverPlacement, zIndex: zIndex, appendTo: portalTarget !== null && portalTarget !== void 0 ? portalTarget : "parent", tippyRef: tippyRef, disabled: disabled, content: React.createElement(SingleDateCalendar, __assign({}, calendarProps, { onChange: onSelectDate, value: value, theme: calendarTheme, onChangePanel: onChangePanel, minDate: minDate, maxDate: maxDate })) },
1161
- React.createElement(TextInput, { type: "date", contentRight: React.createElement(Row, { alignItems: "center" },
1162
- React.createElement(FlatButton, { size: "small", disabled: disabled, leftIcon: faCalendarAlt, onClick: showCalendar })), onFocus: showCalendar, onClickRight: showCalendar, value: value ? format(value, displayFormat) : "", placeholder: placeholder, size: 9, disabled: disabled, autoFocus: openOnMount, variant: variant, min: minDate, max: maxDate }))));
1163
- };
1164
-
1165
- var useDateRangeInput = function (value, onValueChange) {
1166
- var startDateInputRef = useRef(null);
1167
- var endDateInputRef = useRef(null);
1168
- var _a = useState(false), showingCalendar = _a[0], setShowingCalendar = _a[1];
1169
- var _b = useState(undefined), focusedInput = _b[0], setFocusedInput = _b[1];
1170
- var showCalendarStartDate = useCallback(function () {
1171
- setFocusedInput("startDate");
1172
- setShowingCalendar(true);
1173
- return true;
1174
- }, [setFocusedInput, setShowingCalendar]);
1175
- var showCalendarEndDate = useCallback(function () {
1176
- setFocusedInput("endDate");
1177
- setShowingCalendar(true);
1178
- return true;
1179
- }, [setFocusedInput, setShowingCalendar]);
1180
- var hideCalendar = useCallback(function () {
1181
- setShowingCalendar(false);
1182
- }, [setShowingCalendar]);
1183
- var onClickDay = useCallback(function (day) {
1184
- if (focusedInput === "startDate") {
1185
- onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange({
1186
- startDate: day.date,
1187
- endDate: value === null || value === void 0 ? void 0 : value.endDate,
1188
- });
1189
- if (!(value === null || value === void 0 ? void 0 : value.endDate)) {
1190
- setFocusedInput("endDate");
1191
- endDateInputRef.current && endDateInputRef.current.focus();
1192
- }
1193
- else {
1194
- setTimeout(hideCalendar, 150);
1195
- }
1196
- }
1197
- else if (focusedInput === "endDate") {
1198
- onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange({
1199
- startDate: value === null || value === void 0 ? void 0 : value.startDate,
1200
- endDate: day.date,
1201
- });
1202
- if (!(value === null || value === void 0 ? void 0 : value.startDate)) {
1203
- setFocusedInput("startDate");
1204
- startDateInputRef.current && startDateInputRef.current.focus();
1205
- }
1206
- else {
1207
- setTimeout(hideCalendar, 150);
1208
- }
1209
- }
1210
- }, [focusedInput, onValueChange, setFocusedInput, hideCalendar, value]);
1211
- var startDateIsAfterEnd = useMemo(function () {
1212
- return (value === null || value === void 0 ? void 0 : value.startDate) &&
1213
- (value === null || value === void 0 ? void 0 : value.endDate) &&
1214
- isAfter(value.startDate, value.endDate);
1215
- }, [value === null || value === void 0 ? void 0 : value.startDate, value === null || value === void 0 ? void 0 : value.endDate]);
1216
- return {
1217
- showingCalendar: showingCalendar,
1218
- hideCalendar: hideCalendar,
1219
- showCalendarEndDate: showCalendarEndDate,
1220
- showCalendarStartDate: showCalendarStartDate,
1221
- focusedInput: focusedInput,
1222
- setFocusedInput: setFocusedInput,
1223
- startDateInputRef: startDateInputRef,
1224
- endDateInputRef: endDateInputRef,
1225
- onClickDay: onClickDay,
1226
- startDateIsAfterEnd: startDateIsAfterEnd,
1227
- };
1228
- };
1229
-
1230
- /**
1231
- * @deprecated Please use DateRangeDualTextInput instead.
1232
- */
1233
- var DateRangeInput = function (_a) {
1234
- var _b = _a.displayFormat, displayFormat = _b === void 0 ? DateFormats.fullDate : _b, _c = _a.placeholderStartDate, placeholderStartDate = _c === void 0 ? "Start date" : _c, _d = _a.placeholderEndDate, placeholderEndDate = _d === void 0 ? "End date" : _d, portalTarget = _a.portalTarget, value = _a.value, onValueChange = _a.onValueChange, _e = _a.zIndex, zIndex = _e === void 0 ? 100 : _e, width = _a.width, _f = _a.calendarTheme, calendarTheme = _f === void 0 ? defaultCalendarTheme : _f, calendarProps = _a.calendarProps, minDate = _a.minDate, _g = _a.maxDate, maxDate = _g === void 0 ? defaultMaxDate : _g, disabled = _a.disabled;
1235
- var _h = useState(function () { var _a; return (_a = (focusedInput && (value === null || value === void 0 ? void 0 : value[focusedInput]))) !== null && _a !== void 0 ? _a : new Date(); }), dateInFocus = _h[0], setDateInFocus = _h[1];
1236
- var _j = useState("calendar"), currentPanel = _j[0], setCurrentPanel = _j[1];
1237
- var _k = useDateRangeInput(value, onValueChange), hideCalendar = _k.hideCalendar, showCalendarEndDate = _k.showCalendarEndDate, showCalendarStartDate = _k.showCalendarStartDate, showingCalendar = _k.showingCalendar, focusedInput = _k.focusedInput, startDateInputRef = _k.startDateInputRef, endDateInputRef = _k.endDateInputRef, onClickDay = _k.onClickDay, startDateIsAfterEnd = _k.startDateIsAfterEnd;
1238
- var statePerMonth = useMemo(function () {
1239
- return buildDayStateForDateRange(undefined, value === null || value === void 0 ? void 0 : value.startDate, value === null || value === void 0 ? void 0 : value.endDate);
1240
- }, [value]);
1241
- return (React.createElement(Popover, { arrow: false, lazy: true, disabled: disabled, visible: showingCalendar, zIndex: zIndex, placement: defaultPopoverPlacement, appendTo: portalTarget !== null && portalTarget !== void 0 ? portalTarget : "parent", onClickOutside: hideCalendar, content: React.createElement(CalendarWithMonthSwitcher, __assign({}, calendarProps, { dateInFocus: dateInFocus, setDateInFocus: setDateInFocus, statePerMonth: statePerMonth, theme: calendarTheme, onClickDay: onClickDay, currentPanel: currentPanel, setCurrentPanel: setCurrentPanel, minDate: minDate, maxDate: maxDate })) },
1242
- React.createElement(Row, { alignItems: "center" },
1243
- React.createElement(TextInput, { iconLeft: faCalendarAlt$1, onFocus: showCalendarStartDate, value: (value === null || value === void 0 ? void 0 : value.startDate) ? format(value.startDate, displayFormat) : "", placeholder: placeholderStartDate, width: width, disabled: disabled, inputRef: startDateInputRef, size: 9, variant: startDateIsAfterEnd ? "error" : undefined }),
1244
- React.createElement(Space, null),
1245
- React.createElement(Icon, { icon: faLongArrowAltRight, color: cssColor("--lhds-color-ui-500"), size: 14 }),
1246
- React.createElement(Space, null),
1247
- React.createElement(TextInput, { iconLeft: faCalendarAlt$1, onFocus: showCalendarEndDate, value: (value === null || value === void 0 ? void 0 : value.endDate) ? format(value.endDate, displayFormat) : "", placeholder: placeholderEndDate, width: width, disabled: disabled, inputRef: endDateInputRef, size: 9, variant: startDateIsAfterEnd ? "error" : undefined }))));
1248
- };
1249
-
1250
- var DateTextInput = function (_a) {
1251
- var calendarProps = _a.calendarProps, _b = _a.closeOnCalendarSelectDate, closeOnCalendarSelectDate = _b === void 0 ? true : _b, _c = _a.dateFormat, dateFormat = _c === void 0 ? DateFormats.fullDate : _c; _a.disableCalender; var onValueChange = _a.onValueChange, _e = _a.placeholder, placeholder = _e === void 0 ? "yyyy-mm-dd" : _e, portalTarget = _a.portalTarget, value = _a.value, _f = _a.width, width = _f === void 0 ? "130px" : _f, _g = _a.zIndex, zIndex = _g === void 0 ? 100 : _g, _h = _a.calendarTheme, calendarTheme = _h === void 0 ? defaultCalendarTheme : _h, _j = _a.hideCalenderIcon, hideCalenderIcon = _j === void 0 ? false : _j, minDate = _a.minDate, _k = _a.maxDate, maxDate = _k === void 0 ? defaultMaxDate : _k, variant = _a.variant, props = __rest(_a, ["calendarProps", "closeOnCalendarSelectDate", "dateFormat", "disableCalender", "onValueChange", "placeholder", "portalTarget", "value", "width", "zIndex", "calendarTheme", "hideCalenderIcon", "minDate", "maxDate", "variant"]);
1252
- var _l = useState(false), open = _l[0], setOpen = _l[1];
1253
- var _m = useCalendarPopoverUpdater(), tippyRef = _m.tippyRef, onChangePanel = _m.onChangePanel;
1254
- var toggleCalendar = useCallback(function () {
1255
- setOpen(!open);
1256
- }, [setOpen, open]);
1257
- var hideCalendar = useCallback(function () {
1258
- setOpen(false);
1259
- }, [setOpen]);
1260
- var onValueChangeHandler = useCallback(function (value) {
1261
- if (onValueChange) {
1262
- onValueChange(value);
1263
- }
1264
- }, [onValueChange]);
1265
- var onCalendarSelectDate = useCallback(function (date) {
1266
- if (date) {
1267
- onValueChangeHandler(format(date, dateFormat));
1268
- if (closeOnCalendarSelectDate) {
1269
- setTimeout(function () { return setOpen(!open); }, 200);
1270
- }
1271
- }
1272
- }, [onValueChangeHandler, dateFormat, closeOnCalendarSelectDate, setOpen, open]);
1273
- var inValidInput = !!value && !/^[-/\\.0-9]+$/.test(value);
1274
- var dateIsValid = !!value && isValid(parse(value, dateFormat, new Date()));
1275
- var userInputCorrectLength = !!value && value.length >= dateFormat.length;
1276
- var invalid = (userInputCorrectLength && !dateIsValid) || inValidInput;
1277
- return (React.createElement(Box, { width: width },
1278
- React.createElement(Popover, { arrow: false, lazy: true, visible: open, zIndex: zIndex, appendTo: portalTarget !== null && portalTarget !== void 0 ? portalTarget : "parent", placement: defaultPopoverPlacement, onClickOutside: hideCalendar, tippyRef: tippyRef, content: React.createElement(SingleDateCalendar, __assign({}, calendarProps, { onChange: onCalendarSelectDate, onChangePanel: onChangePanel, value: value && dateIsValid
1279
- ? parse(value, dateFormat, new Date())
1280
- : undefined, minDate: minDate, maxDate: maxDate, theme: calendarTheme })) },
1281
- React.createElement(TextInput, __assign({}, props, { variant: invalid ? "error" : variant, disableContentPaddingRight: true, contentRight: !hideCalenderIcon ? (React.createElement(Row, { alignItems: "center", indent: 0.5 },
1282
- React.createElement(FlatButton, { size: "small", disabled: props.disabled, leftIcon: faCalendarAlt$1, onClick: toggleCalendar }))) : undefined, onValueChange: onValueChangeHandler, placeholder: placeholder, value: value || "", min: minDate, max: maxDate, size: 10 })))));
1283
- };
1284
-
1285
- var formatHours = function (hours) {
1286
- if (hours === "") {
1287
- return "00";
1288
- }
1289
- var h = parseInt(hours, 10);
1290
- if (isNaN(h)) {
1291
- throw new Error("Hours is not a number");
1292
- }
1293
- if (h < 0 || h > 23) {
1294
- throw new Error("Hours is an invalid number");
1295
- }
1296
- switch (hours.length) {
1297
- case 1:
1298
- return "0".concat(h);
1299
- case 2:
1300
- return hours;
1301
- default:
1302
- throw new Error("Invalid hour string");
1303
- }
1304
- };
1305
- var formatMinutes = function (minutes) {
1306
- if (minutes === "") {
1307
- return "00";
1308
- }
1309
- var m = parseInt(minutes, 10);
1310
- if (isNaN(m)) {
1311
- throw new Error("Minutes is not a number");
1312
- }
1313
- if (m < 0 || m > 59) {
1314
- throw new Error("Minutes is an invalid number");
1315
- }
1316
- switch (minutes.length) {
1317
- case 1:
1318
- return "0".concat(m);
1319
- case 2:
1320
- return minutes;
1321
- default:
1322
- throw new Error("Invalid minute string");
1323
- }
1324
- };
1325
- var formatTimeString = function (time) {
1326
- if (!validUserInput(time)) {
1327
- return { time: time, success: false };
1328
- }
1329
- var arr = time && time.split(/-|:|,|;|[/]|[.]| /); // consider all these chars as user input separator
1330
- if (arr && arr.length === 2) {
1331
- try {
1332
- var hours = formatHours(arr[0]);
1333
- var minutes = formatMinutes(arr[1]);
1334
- return { time: "".concat(hours, ":").concat(minutes), success: true };
1335
- }
1336
- catch (_a) {
1337
- return { time: time, success: false };
1338
- }
1339
- }
1340
- else if (arr && arr.length === 1) {
1341
- var hours = 0;
1342
- var minutes = 0;
1343
- switch (time.length) {
1344
- case 1:
1345
- return { time: "0".concat(time, ":00"), success: true };
1346
- case 2:
1347
- var timeNumber = parseInt(arr[0], 10);
1348
- if (timeNumber >= 0 && timeNumber < 24) {
1349
- return { time: "".concat(time, ":00"), success: true };
1350
- }
1351
- else if (timeNumber >= 24 && timeNumber < 59) {
1352
- return { time: "00:".concat(time), success: true };
1353
- }
1354
- return { time: time, success: false };
1355
- case 3:
1356
- minutes = parseInt(time.substr(1, 2), 10);
1357
- if (minutes >= 0 && minutes <= 59) {
1358
- return {
1359
- time: "0".concat(time.substr(0, 1), ":").concat(time.substr(1, 2)),
1360
- success: true,
1361
- };
1362
- }
1363
- return { time: time, success: false };
1364
- case 4:
1365
- hours = parseInt(time.substr(0, 2), 10);
1366
- minutes = parseInt(time.substr(2, 2), 10);
1367
- if (hours < 0 || hours > 23) {
1368
- return { time: time, success: false };
1369
- }
1370
- if (minutes < 0 || minutes > 59) {
1371
- return { time: time, success: false };
1372
- }
1373
- return {
1374
- time: "".concat(time.substr(0, 2), ":").concat(time.substr(2, 2)),
1375
- success: true,
1376
- };
1377
- default:
1378
- return { time: time, success: false };
1379
- }
1380
- }
1381
- return { time: time, success: false };
1382
- };
1383
- var validUserInput = function (input) {
1384
- if (input) {
1385
- return /^[-:.,/; 0-9]+$/.test(input);
1386
- }
1387
- return true;
1388
- };
1389
-
1390
- /**
1391
- * @deprecated
1392
- */
1393
- var TimeTextInput = function (_a) {
1394
- var onValueChange = _a.onValueChange, _b = _a.showPlaceholder, showPlaceholder = _b === void 0 ? true : _b, _c = _a.useIcon, useIcon = _c === void 0 ? true : _c, value = _a.value, _d = _a.width, width = _d === void 0 ? "85px" : _d, variant = _a.variant, props = __rest(_a, ["onValueChange", "showPlaceholder", "useIcon", "value", "width", "variant"]);
1395
- var _e = useState(function () { return validUserInput(value); }), valid = _e[0], setValid = _e[1];
1396
- var timeFormat = "hh:mm";
1397
- var onBlur = useCallback(function () {
1398
- if (value) {
1399
- var formattedResult = formatTimeString(value);
1400
- setValid(formattedResult.success);
1401
- if (formattedResult.success) {
1402
- if (onValueChange) {
1403
- onValueChange(formattedResult.time);
1404
- }
1405
- }
1406
- }
1407
- }, [value, onValueChange, setValid]);
1408
- var onChangeHandler = useCallback(function (ev) {
1409
- var time = ev.target.value;
1410
- var validInput = validUserInput(time);
1411
- setValid(validInput && time.length <= timeFormat.length);
1412
- if (onValueChange) {
1413
- onValueChange(time);
1414
- }
1415
- }, [onValueChange, setValid]);
1416
- return (React.createElement(TextInput, __assign({}, props, { type: "time", variant: !valid ? "error" : variant, iconLeft: useIcon ? faClock : undefined, value: value, placeholder: showPlaceholder ? timeFormat : undefined, onChange: onChangeHandler, onBlur: onBlur, width: width })));
1417
- };
1418
-
1419
- var DualTextInput = function (_a) {
1420
- var autoFocusLeft = _a.autoFocusLeft, autoFocusRight = _a.autoFocusRight, onEsc = _a.onEsc, onEnter = _a.onEnter, onValueChangeLeft = _a.onValueChangeLeft, onValueChangeRight = _a.onValueChangeRight, separatorIcon = _a.separatorIcon, placeholderLeft = _a.placeholderLeft, placeholderRight = _a.placeholderRight, typeLeft = _a.typeLeft, typeRight = _a.typeRight, onChangeLeft = _a.onChangeLeft, onChangeRight = _a.onChangeRight, valueLeft = _a.valueLeft, valueRight = _a.valueRight, minLeft = _a.minLeft, maxLeft = _a.maxLeft, minRight = _a.minRight, maxRight = _a.maxRight, onClickLeft = _a.onClickLeft, onClickRight = _a.onClickRight, onClickCalendar = _a.onClickCalendar, onClickArrowDown = _a.onClickArrowDown, onBlurLeft = _a.onBlurLeft, onBlurRight = _a.onBlurRight, onFocusLeft = _a.onFocusLeft, onFocusRight = _a.onFocusRight, inputRefLeft = _a.inputRefLeft, inputRefRight = _a.inputRefRight, variant = _a.variant, variantLeft = _a.variantLeft, variantRight = _a.variantRight, onBlur = _a.onBlur, showPresets = _a.showPresets, widthLeft = _a.widthLeft, widthRight = _a.widthRight, disabled = _a.disabled;
1421
- var focusCounter = useRef(0);
1422
- var tryTriggerOnBlur = useMemo(function () {
1423
- return debounce(function (focusCounter) {
1424
- if (focusCounter === 0) {
1425
- onBlur === null || onBlur === void 0 ? void 0 : onBlur();
1426
- }
1427
- }, 10);
1428
- }, [onBlur]);
1429
- var focusLeftHandler = useCallback(function (ev) {
1430
- focusCounter.current++;
1431
- tryTriggerOnBlur(focusCounter.current);
1432
- if (onFocusLeft) {
1433
- onFocusLeft(ev);
1434
- }
1435
- }, [onFocusLeft, focusCounter, tryTriggerOnBlur]);
1436
- var focusRightHandler = useCallback(function (ev) {
1437
- focusCounter.current++;
1438
- tryTriggerOnBlur(focusCounter.current);
1439
- if (onFocusRight) {
1440
- onFocusRight(ev);
1441
- }
1442
- }, [onFocusRight, focusCounter, tryTriggerOnBlur]);
1443
- var blurLeftHandler = useCallback(function (ev) {
1444
- focusCounter.current--;
1445
- tryTriggerOnBlur(focusCounter.current);
1446
- if (onBlurLeft) {
1447
- onBlurLeft(ev);
1448
- }
1449
- }, [onBlurLeft, focusCounter, tryTriggerOnBlur]);
1450
- var blurRightHandler = useCallback(function (ev) {
1451
- focusCounter.current--;
1452
- tryTriggerOnBlur(focusCounter.current);
1453
- if (onBlurRight) {
1454
- onBlurRight(ev);
1455
- }
1456
- }, [onBlurRight, focusCounter, tryTriggerOnBlur]);
1457
- return (React.createElement(Box, null,
1458
- React.createElement(TextInputBox, { disableContentPaddingRight: true, disabled: disabled, variant: variant, contentRight: React.createElement(Row, { alignItems: "center" },
1459
- React.createElement(Indent, { num: 0.5 },
1460
- React.createElement(FlatButton, { leftIcon: faCalendarAlt, onClick: onClickCalendar, disabled: disabled, size: "small" })),
1461
- showPresets ? (React.createElement(React.Fragment, null,
1462
- React.createElement(Row, { height: "22px" },
1463
- React.createElement(SeparatorLine, { vertical: true })),
1464
- React.createElement(Indent, { num: 0.5 },
1465
- React.createElement(FlatButton, { leftIcon: faAngleDown, onClick: onClickArrowDown, disabled: disabled, size: "small" })))) : null) },
1466
- React.createElement(Box, { width: widthLeft },
1467
- React.createElement(TextInput, { onEsc: onEsc, onEnter: onEnter, onClick: onClickLeft, disabled: disabled, hideBorder: true, placeholder: placeholderLeft, value: valueLeft, onValueChange: onValueChangeLeft, onChange: onChangeLeft, onBlur: blurLeftHandler, onFocus: focusLeftHandler, inputRef: inputRefLeft, variant: variantLeft, type: typeLeft, autoFocus: autoFocusLeft, min: minLeft, max: maxLeft })),
1468
- React.createElement(Row, { indent: 0.5, alignItems: "center", justifyContent: "center" },
1469
- React.createElement(Icon, { icon: separatorIcon, size: 12, color: cssColor("--lhds-color-ui-500") })),
1470
- React.createElement(Box, { width: widthRight },
1471
- React.createElement(TextInput, { onEsc: onEsc, onEnter: onEnter, onClick: onClickRight, disabled: disabled, hideBorder: true, placeholder: placeholderRight, value: valueRight, onValueChange: onValueChangeRight, onChange: onChangeRight, onBlur: blurRightHandler, onFocus: focusRightHandler, inputRef: inputRefRight, variant: variantRight, type: typeRight, autoFocus: autoFocusRight, min: minRight, max: maxRight })))));
1472
- };
1473
-
1474
- var transformTimeStringToNumber = function (time) {
1475
- if (time == null) {
1476
- throw new Error("Time is not set.");
1477
- }
1478
- if (time === "") {
1479
- throw new Error("Time is empty.");
1480
- }
1481
- var parts = time.split(":");
1482
- if (parts.length !== 2) {
1483
- throw new Error("Invalid time.");
1484
- }
1485
- if (parts[1].length !== 2) {
1486
- throw new Error("Invalid time.");
1487
- }
1488
- if (parts[0].length < 1 || parts[0].length > 2) {
1489
- throw new Error("Invalid time.");
1490
- }
1491
- var hours = parseInt(parts[0], 10);
1492
- var minutes = parseInt(parts[1], 10);
1493
- if (isNaN(hours)) {
1494
- throw new Error("Invalid time.");
1495
- }
1496
- if (isNaN(minutes)) {
1497
- throw new Error("Invalid time.");
1498
- }
1499
- if (hours < 0 || hours > 23) {
1500
- throw new Error("Invalid time.");
1501
- }
1502
- if (minutes < 0 || minutes > 59) {
1503
- throw new Error("Invalid time.");
1504
- }
1505
- return hours * 100 + minutes;
1506
- };
1507
- var isValidTimeString = function (time) {
1508
- try {
1509
- transformTimeStringToNumber(time);
1510
- return true;
1511
- }
1512
- catch (e) {
1513
- return false;
1514
- }
1515
- };
1516
- var getHoursAndMinutesFromTimeString = function (value) {
1517
- if (value && isValidTimeString(value)) {
1518
- var p = value.split(":");
1519
- return {
1520
- hour: parseIntElseUndefined(p[0]),
1521
- minute: parseIntElseUndefined(p[1]),
1522
- };
1523
- }
1524
- return {
1525
- hour: undefined,
1526
- minute: undefined,
1527
- };
1528
- };
1529
- var transformTimeInDateToTimeString = function (date) {
1530
- return "".concat(formatHours(String(date.getHours())), ":").concat(formatMinutes(String(date.getMinutes())));
1531
- };
1532
-
1533
- var css_248z = ".TimePicker-module_timePicker__1ElGu {\n overflow: hidden;\n width: 180px;\n}\n\n.TimePicker-module_timePickerColumn__2vfuE {\n overflow-y: hidden;\n flex: 1;\n}\n\n.TimePicker-module_timePickerColumn__2vfuE:hover {\n overflow-y: scroll;\n }\n";
1534
- var styles = {"timePicker":"TimePicker-module_timePicker__1ElGu","timePickerColumn":"TimePicker-module_timePickerColumn__2vfuE"};
1535
- styleInject(css_248z);
1536
-
1537
- var TimePickerCell = function (_a) {
1538
- var onClick = _a.onClick, item = _a.item, selected = _a.selected, columnRef = _a.columnRef, canScrollRef = _a.canScrollRef;
1539
- var ref = useRef(null);
1540
- useEffect(function scrollToSelectedItem() {
1541
- if (selected &&
1542
- columnRef.current &&
1543
- ref.current &&
1544
- canScrollRef.current) {
1545
- var targetScroll = ref.current.scrollHeight * Math.max(item - 2, 0);
1546
- columnRef.current.scrollTo(0, targetScroll);
1547
- canScrollRef.current = false;
1548
- }
1549
- }, [columnRef, item, selected, canScrollRef]);
1550
- return (React.createElement(Row, { width: "64px", justifyContent: "center", spacing: 0.5, indent: 0.5, ref: ref }, selected ? (React.createElement(PrimaryButton, { label: String(item), onClick: function () { return onClick && onClick(item); } })) : (React.createElement(FlatButton, { label: String(item), onClick: function () { return onClick && onClick(item); } }))));
1551
- };
1552
-
1553
- var TimePickerColumn = function (_a) {
1554
- var onClick = _a.onClick, items = _a.items, selectedItem = _a.selectedItem, canScrollRef = _a.canScrollRef;
1555
- var columnRef = useRef(null);
1556
- return (React.createElement(Column, { className: styles.timePickerColumn, ref: columnRef }, items.map(function (item) { return (React.createElement(TimePickerCell, { key: item, item: item, onClick: onClick, selected: item === selectedItem, columnRef: columnRef, canScrollRef: canScrollRef })); })));
1557
- };
1558
-
1559
- var hours = range(0, 24);
1560
- var minutes = range(0, 60);
1561
- var TimePicker = function (_a) {
1562
- var value = _a.value, onValueChange = _a.onValueChange;
1563
- var canScrollRef = useRef(true);
1564
- var _b = useState(undefined), hour = _b[0], setHour = _b[1];
1565
- var _c = useState(undefined), minute = _c[0], setMinute = _c[1];
1566
- useEffect(function () {
1567
- if (value) {
1568
- var _a = getHoursAndMinutesFromTimeString(value), minute_1 = _a.minute, hour_1 = _a.hour;
1569
- setHour(hour_1);
1570
- setMinute(minute_1);
1571
- }
1572
- }, [value]);
1573
- var onClickHour = useCallback(function (h) {
1574
- setHour(h);
1575
- onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange("".concat(formatHours(String(h !== null && h !== void 0 ? h : 0)), ":").concat(formatMinutes(String(minute !== null && minute !== void 0 ? minute : 0))));
1576
- }, [minute, onValueChange]);
1577
- var onClickMinutes = useCallback(function (m) {
1578
- setMinute(m);
1579
- onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange("".concat(formatHours(String(hour !== null && hour !== void 0 ? hour : 0)), ":").concat(formatMinutes(String(m !== null && m !== void 0 ? m : 0))));
1580
- }, [hour, onValueChange]);
1581
- return (React.createElement(Row, { className: styles.timePicker },
1582
- React.createElement(TimePickerColumn, { items: hours, onClick: onClickHour, selectedItem: hour, canScrollRef: canScrollRef }),
1583
- React.createElement(Indent, null),
1584
- React.createElement(TimePickerColumn, { items: minutes, onClick: onClickMinutes, selectedItem: minute, canScrollRef: canScrollRef })));
1585
- };
1586
-
1587
- var useDateRangeEffects$1 = function (date, setDateInFocus, dateInputRef) {
1588
- useEffect(function moveFocusedDateWhenDateChanges() {
1589
- if (date) {
1590
- setDateInFocus(date);
1591
- }
1592
- }, [date, setDateInFocus]);
1593
- useEffect(function updateDateFieldWhenValueChanges() {
1594
- if (dateInputRef.current) {
1595
- if (date) {
1596
- dateInputRef.current.valueAsDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
1597
- }
1598
- else {
1599
- dateInputRef.current.valueAsDate = null;
1600
- }
1601
- }
1602
- }, [date, dateInputRef]);
1603
- };
1604
-
1605
- var useDateRangeHandlers$1 = function (date, onValueChange, _a, dateInputRef) {
1606
- var setDateInFocus = _a.setDateInFocus, showCalendarInternal = _a.showCalendarInternal, hideCalendarInternal = _a.hideCalendarInternal, setFirstFocusedInput = _a.setFirstFocusedInput, setCurrentPanel = _a.setCurrentPanel, localTime = _a.localTime, setLocalTime = _a.setLocalTime, localDate = _a.localDate, setLocalDate = _a.setLocalDate;
1607
- var onChangeDate = useCallback(function (incomingDate) {
1608
- if (!incomingDate) {
1609
- return;
1610
- }
1611
- var newDate = new Date(incomingDate);
1612
- if (date) {
1613
- // Full date is available
1614
- newDate.setHours(date.getHours());
1615
- newDate.setMinutes(date.getMinutes());
1616
- onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(newDate);
1617
- setLocalDate(undefined);
1618
- }
1619
- else if (localTime) {
1620
- // Only time has been selected
1621
- var _a = getHoursAndMinutesFromTimeString(localTime), minute = _a.minute, hour = _a.hour;
1622
- newDate.setHours(hour !== null && hour !== void 0 ? hour : 0);
1623
- newDate.setMinutes(minute !== null && minute !== void 0 ? minute : 0);
1624
- onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(newDate);
1625
- setLocalDate(undefined);
1626
- }
1627
- else {
1628
- // Nothing has been selected
1629
- setLocalDate(newDate);
1630
- }
1631
- setDateInFocus(newDate);
1632
- if (dateInputRef.current) {
1633
- dateInputRef.current.valueAsDate = newDate;
1634
- }
1635
- }, [date, dateInputRef, localTime, onValueChange, setDateInFocus, setLocalDate]);
1636
- var onChangeTime = useCallback(function (time) {
1637
- if (!time) {
1638
- return;
1639
- }
1640
- if (date) {
1641
- // Full date is available
1642
- var newTime = getHoursAndMinutesFromTimeString(time);
1643
- var newDate = new Date(date);
1644
- newDate.setHours(newTime.hour || 0);
1645
- newDate.setMinutes(newTime.minute || 0);
1646
- onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(newDate);
1647
- setLocalTime(undefined);
1648
- }
1649
- else if (localDate) {
1650
- // Only date has already been selected
1651
- var newTime = getHoursAndMinutesFromTimeString(time);
1652
- var newDate = new Date(localDate);
1653
- newDate.setHours(newTime.hour || 0);
1654
- newDate.setMinutes(newTime.minute || 0);
1655
- onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(newDate);
1656
- setLocalTime(undefined);
1657
- }
1658
- else {
1659
- // Nothing has been selected
1660
- setLocalTime(time);
1661
- }
1662
- }, [onValueChange, date, localDate, setLocalTime]);
1663
- var inputLeftChangeHandler = useCallback(function (ev) {
1664
- if (ev.target.value[0] !== "0") {
1665
- onChangeDate(ev.target.valueAsDate);
1666
- }
1667
- }, [onChangeDate]);
1668
- var inputRightChangeHandler = useCallback(function (ev) { return onChangeTime(ev.target.value); }, [onChangeTime]);
1669
- var showCalendar = useCallback(function () {
1670
- if (date) {
1671
- setDateInFocus(date);
1672
- }
1673
- else {
1674
- setDateInFocus(new Date());
1675
- }
1676
- setCurrentPanel("calendar");
1677
- showCalendarInternal();
1678
- }, [date, setCurrentPanel, showCalendarInternal, setDateInFocus]);
1679
- var hideCalendar = useCallback(function () {
1680
- setFirstFocusedInput(undefined);
1681
- hideCalendarInternal();
1682
- }, [setFirstFocusedInput, hideCalendarInternal]);
1683
- return {
1684
- inputLeftChangeHandler: inputLeftChangeHandler,
1685
- inputRightChangeHandler: inputRightChangeHandler,
1686
- hideCalendar: hideCalendar,
1687
- showCalendar: showCalendar,
1688
- onChangeTime: onChangeTime,
1689
- onChangeDate: onChangeDate,
1690
- };
1691
- };
1692
-
1693
- var useInputStates$1 = function (date) {
1694
- var _a = useState(undefined), localDate = _a[0], setLocalDate = _a[1];
1695
- var _b = useState(undefined), localTime = _b[0], setLocalTime = _b[1];
1696
- var _c = useBoolean(false), isCalendarVisible = _c[0], showCalendarInternal = _c[1], hideCalendarInternal = _c[2];
1697
- var _d = useBoolean(false), isTimePickerVisible = _d[0], showTimePicker = _d[1], hideTimePicker = _d[2];
1698
- var _e = useState(undefined), firstFocusedInput = _e[0], setFirstFocusedInput = _e[1];
1699
- var _f = useState(function () { return date !== null && date !== void 0 ? date : new Date(); }), dateInFocus = _f[0], setDateInFocus = _f[1];
1700
- var _g = useState("calendar"), currentPanel = _g[0], setCurrentPanel = _g[1];
1701
- return {
1702
- isCalendarVisible: isCalendarVisible,
1703
- showCalendarInternal: showCalendarInternal,
1704
- hideCalendarInternal: hideCalendarInternal,
1705
- firstFocusedInput: firstFocusedInput,
1706
- setFirstFocusedInput: setFirstFocusedInput,
1707
- dateInFocus: dateInFocus,
1708
- setDateInFocus: setDateInFocus,
1709
- currentPanel: currentPanel,
1710
- setCurrentPanel: setCurrentPanel,
1711
- isTimePickerVisible: isTimePickerVisible,
1712
- showTimePicker: showTimePicker,
1713
- hideTimePicker: hideTimePicker,
1714
- localDate: localDate,
1715
- setLocalDate: setLocalDate,
1716
- localTime: localTime,
1717
- setLocalTime: setLocalTime,
1718
- };
1719
- };
1720
-
1721
- var useUserInputHandlers$1 = function (onChangeDate, dateInputRef, showCalendar, hideCalendar, _a) {
1722
- var isCalendarVisible = _a.isCalendarVisible, setCurrentPanel = _a.setCurrentPanel, showTimePicker = _a.showTimePicker, hideTimePicker = _a.hideTimePicker;
1723
- var onFocusLeft = useCallback(function () {
1724
- if (!isCalendarVisible) {
1725
- showCalendar();
1726
- }
1727
- setCurrentPanel("calendar");
1728
- hideTimePicker();
1729
- }, [hideTimePicker, isCalendarVisible, setCurrentPanel, showCalendar]);
1730
- var onFocusRight = useCallback(function () {
1731
- hideCalendar();
1732
- showTimePicker();
1733
- }, [hideCalendar, showTimePicker]);
1734
- var onClickDay = useCallback(function (day) {
1735
- onChangeDate(day.date);
1736
- hideCalendar();
1737
- showTimePicker();
1738
- }, [onChangeDate, hideCalendar, showTimePicker]);
1739
- var onClickArrowButton = useCallback(function () {
1740
- setCurrentPanel("presets");
1741
- showCalendar();
1742
- }, [setCurrentPanel, showCalendar]);
1743
- var onClickCalendarButton = useCallback(function () {
1744
- var _a;
1745
- if (isCalendarVisible) {
1746
- hideCalendar();
1747
- }
1748
- else {
1749
- (_a = dateInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
1750
- setCurrentPanel("calendar");
1751
- showCalendar();
1752
- }
1753
- }, [
1754
- isCalendarVisible,
1755
- hideCalendar,
1756
- dateInputRef,
1757
- setCurrentPanel,
1758
- showCalendar,
1759
- ]);
1760
- var onKeyDownHandler = useCallback(function (ev) {
1761
- if (ev.key === "Escape") {
1762
- hideCalendar();
1763
- }
1764
- }, [hideCalendar]);
1765
- return {
1766
- onFocusLeft: onFocusLeft,
1767
- onFocusRight: onFocusRight,
1768
- onClickDay: onClickDay,
1769
- onClickArrowButton: onClickArrowButton,
1770
- onClickCalendarButton: onClickCalendarButton,
1771
- onKeyDownHandler: onKeyDownHandler,
1772
- };
1773
- };
1774
-
1775
- var DateTimeInput = function (_a) {
1776
- var value = _a.value, onValueChange = _a.onValueChange, onEnter = _a.onEnter, onEsc = _a.onEsc, onBlur = _a.onBlur, autoFocus = _a.autoFocus, minDate = _a.minDate, _b = _a.widthLeft, widthLeft = _b === void 0 ? 128 : _b, _c = _a.widthRight, widthRight = _c === void 0 ? 80 : _c, _d = _a.maxDate, maxDate = _d === void 0 ? defaultMaxDate : _d, variant = _a.variant, disabled = _a.disabled;
1777
- var dateInputRef = useRef(null);
1778
- var timeInputRef = useRef(null);
1779
- var states = useInputStates$1(value);
1780
- var setCurrentPanel = states.setCurrentPanel, currentPanel = states.currentPanel, isCalendarVisible = states.isCalendarVisible, dateInFocus = states.dateInFocus, setDateInFocus = states.setDateInFocus, isTimePickerVisible = states.isTimePickerVisible, hideTimePicker = states.hideTimePicker, localTime = states.localTime, localDate = states.localDate;
1781
- var _e = useDateRangeHandlers$1(value, onValueChange, states, dateInputRef), showCalendar = _e.showCalendar, hideCalendar = _e.hideCalendar, inputLeftChangeHandler = _e.inputLeftChangeHandler, inputRightChangeHandler = _e.inputRightChangeHandler, onChangeTime = _e.onChangeTime, onChangeDate = _e.onChangeDate;
1782
- var _f = useUserInputHandlers$1(onChangeDate, dateInputRef, showCalendar, hideCalendar, states), onKeyDownHandler = _f.onKeyDownHandler, onFocusRight = _f.onFocusRight, onFocusLeft = _f.onFocusLeft, onClickDay = _f.onClickDay, onClickCalendarButton = _f.onClickCalendarButton, onClickArrowButton = _f.onClickArrowButton;
1783
- useDateRangeEffects$1(value, setDateInFocus, dateInputRef);
1784
- var statePerMonth = useMemo(function () {
1785
- var dateToHighlight = value || localDate;
1786
- if (!dateToHighlight) {
1787
- return {};
1788
- }
1789
- return addDayStateHighlights(undefined, dateToHighlight, [
1790
- "singleSelected",
1791
- "selected",
1792
- ]);
1793
- }, [localDate, value]);
1794
- var hideAll = useCallback(function () {
1795
- hideCalendar();
1796
- hideTimePicker();
1797
- }, [hideCalendar, hideTimePicker]);
1798
- var timeValue = useMemo(function () { return (value ? transformTimeInDateToTimeString(value) : localTime); }, [value, localTime]);
1799
- var delayedIsCalendarVisible = useDelayedFalse(isCalendarVisible, 300);
1800
- var delayedIsTimePickerVisible = useDelayedFalse(isTimePickerVisible, 300);
1801
- return (React.createElement(Box, { onKeyDown: onKeyDownHandler },
1802
- React.createElement(Popover, { arrow: false, lazy: true, disabled: disabled, placement: defaultPopoverPlacement, visible: isCalendarVisible || isTimePickerVisible, onClickOutside: hideAll, content: (delayedIsCalendarVisible || delayedIsTimePickerVisible) && (React.createElement(Column, null, delayedIsCalendarVisible ? (React.createElement(CalendarWithMonthSwitcher, { statePerMonth: statePerMonth, onClickDay: onClickDay, dateInFocus: dateInFocus, setDateInFocus: setDateInFocus, currentPanel: currentPanel, setCurrentPanel: setCurrentPanel, minDate: minDate, maxDate: maxDate })) : delayedIsTimePickerVisible ? (React.createElement(Column, null,
1803
- React.createElement(Column, { overflow: "hidden", height: "250px" },
1804
- React.createElement(TimePicker, { value: timeValue !== null && timeValue !== void 0 ? timeValue : "", onValueChange: onChangeTime })),
1805
- React.createElement(Space, null),
1806
- React.createElement(Row, { justifyContent: "flex-end" },
1807
- React.createElement(PrimaryButton, { label: "Done", onClick: hideTimePicker })))) : null)) },
1808
- React.createElement(DualTextInput, { autoFocusLeft: autoFocus, onEsc: onEsc, onEnter: onEnter, onBlur: onBlur, disabled: disabled, separatorIcon: faClock$1, typeLeft: "date", typeRight: "time", placeholderLeft: "yyyy-mm-dd", placeholderRight: "hh:mm", onChangeLeft: inputLeftChangeHandler, onChangeRight: inputRightChangeHandler, onClickArrowDown: onClickArrowButton, onClickCalendar: onClickCalendarButton, onFocusLeft: onFocusLeft, onFocusRight: onFocusRight, onClickLeft: onFocusLeft, onClickRight: onFocusRight, inputRefLeft: dateInputRef, inputRefRight: timeInputRef, valueRight: timeValue !== null && timeValue !== void 0 ? timeValue : "", widthLeft: widthLeft, widthRight: widthRight, minLeft: minDate, maxLeft: maxDate, variant: variant }))));
1809
- };
1810
-
1811
- var useDateRangeEffects = function (startDate, endDate, setDateInFocus, startDateInputRef, endDateInputRef) {
1812
- useEffect(function moveFocusedDateWhenStartDateChanges() {
1813
- if (startDate) {
1814
- setDateInFocus(startDate);
1815
- }
1816
- }, [startDate, setDateInFocus]);
1817
- useEffect(function moveFocusedDateWhenEndDateChanges() {
1818
- if (endDate) {
1819
- setDateInFocus(endDate);
1820
- }
1821
- }, [endDate, setDateInFocus]);
1822
- useEffect(function updateStartDateFieldWhenValueChanges() {
1823
- if (startDateInputRef.current) {
1824
- if (startDate) {
1825
- startDateInputRef.current.valueAsDate = new Date(Date.UTC(startDate.getFullYear(), startDate.getMonth(), startDate.getDate()));
1826
- }
1827
- else {
1828
- startDateInputRef.current.valueAsDate = null;
1829
- }
1830
- }
1831
- }, [startDate, startDateInputRef]);
1832
- useEffect(function updateEndDateFieldWhenValueChanges() {
1833
- if (endDateInputRef.current) {
1834
- if (endDate) {
1835
- endDateInputRef.current.valueAsDate = new Date(Date.UTC(endDate.getFullYear(), endDate.getMonth(), endDate.getDate()));
1836
- }
1837
- else {
1838
- endDateInputRef.current.valueAsDate = null;
1839
- }
1840
- }
1841
- }, [endDate, endDateInputRef]);
1842
- };
1843
-
1844
- var useDateRangeHandlers = function (startDate, endDate, onValueChange, _a) {
1845
- var setDateInFocus = _a.setDateInFocus, showCalendarInternal = _a.showCalendarInternal, hideCalendarInternal = _a.hideCalendarInternal, setFirstFocusedInput = _a.setFirstFocusedInput, setCurrentPanel = _a.setCurrentPanel;
1846
- var inputLeftChangeHandler = useCallback(function (ev) {
1847
- var _a;
1848
- if (ev.target.value[0] !== "0") {
1849
- onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange({
1850
- startDate: (_a = ev.target.valueAsDate) !== null && _a !== void 0 ? _a : undefined,
1851
- endDate: endDate,
1852
- });
1853
- }
1854
- }, [onValueChange, endDate]);
1855
- var inputRightChangeHandler = useCallback(function (ev) {
1856
- var _a;
1857
- if (ev.target.value[0] !== "0") {
1858
- onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange({
1859
- startDate: startDate,
1860
- endDate: (_a = ev.target.valueAsDate) !== null && _a !== void 0 ? _a : undefined,
1861
- });
1862
- }
1863
- }, [onValueChange, startDate]);
1864
- var showCalendar = useCallback(function () {
1865
- if (startDate) {
1866
- setDateInFocus(startDate);
1867
- }
1868
- else if (endDate) {
1869
- setDateInFocus(endDate);
1870
- }
1871
- else {
1872
- setDateInFocus(new Date());
1873
- }
1874
- setCurrentPanel("calendar");
1875
- showCalendarInternal();
1876
- }, [
1877
- startDate,
1878
- endDate,
1879
- setCurrentPanel,
1880
- showCalendarInternal,
1881
- setDateInFocus,
1882
- ]);
1883
- var hideCalendar = useCallback(function () {
1884
- setFirstFocusedInput(undefined);
1885
- hideCalendarInternal();
1886
- }, [setFirstFocusedInput, hideCalendarInternal]);
1887
- return {
1888
- inputLeftChangeHandler: inputLeftChangeHandler,
1889
- inputRightChangeHandler: inputRightChangeHandler,
1890
- hideCalendar: hideCalendar,
1891
- setDateInFocus: setDateInFocus,
1892
- setCurrentPanel: setCurrentPanel,
1893
- showCalendar: showCalendar,
1894
- };
1895
- };
1896
-
1897
- var useInputStates = function (startDate, endDate) {
1898
- var _a = useBoolean(false), isCalendarVisible = _a[0], showCalendarInternal = _a[1], hideCalendarInternal = _a[2];
1899
- var _b = useState(undefined), firstFocusedInput = _b[0], setFirstFocusedInput = _b[1];
1900
- var _c = useState("startDate"), focusedInput = _c[0], setFocusedInput = _c[1];
1901
- var _d = useState(function () {
1902
- var fromValue = focusedInput === "startDate"
1903
- ? startDate
1904
- : focusedInput === "endDate"
1905
- ? endDate
1906
- : undefined;
1907
- return fromValue !== null && fromValue !== void 0 ? fromValue : new Date();
1908
- }), dateInFocus = _d[0], setDateInFocus = _d[1];
1909
- var _e = useState("calendar"), currentPanel = _e[0], setCurrentPanel = _e[1];
1910
- return {
1911
- isCalendarVisible: isCalendarVisible,
1912
- showCalendarInternal: showCalendarInternal,
1913
- hideCalendarInternal: hideCalendarInternal,
1914
- firstFocusedInput: firstFocusedInput,
1915
- setFirstFocusedInput: setFirstFocusedInput,
1916
- focusedInput: focusedInput,
1917
- setFocusedInput: setFocusedInput,
1918
- dateInFocus: dateInFocus,
1919
- setDateInFocus: setDateInFocus,
1920
- currentPanel: currentPanel,
1921
- setCurrentPanel: setCurrentPanel,
1922
- };
1923
- };
1924
-
1925
- var useUserInputHandlers = function (startDate, endDate, onValueChange, startDateInputRef, endDateInputRef, showCalendar, hideCalendar, _a) {
1926
- var firstFocusedInput = _a.firstFocusedInput, setFirstFocusedInput = _a.setFirstFocusedInput, isCalendarVisible = _a.isCalendarVisible, setFocusedInput = _a.setFocusedInput, focusedInput = _a.focusedInput, setCurrentPanel = _a.setCurrentPanel;
1927
- var onFocusLeft = useCallback(function () {
1928
- if (firstFocusedInput == null) {
1929
- setFirstFocusedInput("startDate");
1930
- }
1931
- setFocusedInput("startDate");
1932
- if (!isCalendarVisible) {
1933
- showCalendar();
1934
- }
1935
- }, [
1936
- isCalendarVisible,
1937
- setFocusedInput,
1938
- showCalendar,
1939
- setFirstFocusedInput,
1940
- firstFocusedInput,
1941
- ]);
1942
- var onFocusRight = useCallback(function () {
1943
- if (firstFocusedInput == null) {
1944
- setFirstFocusedInput("endDate");
1945
- }
1946
- setFocusedInput("endDate");
1947
- if (!isCalendarVisible) {
1948
- showCalendar();
1949
- }
1950
- }, [
1951
- isCalendarVisible,
1952
- setFocusedInput,
1953
- showCalendar,
1954
- setFirstFocusedInput,
1955
- firstFocusedInput,
1956
- ]);
1957
- var onClickDay = useCallback(function (day) {
1958
- var _a, _b, _c, _d;
1959
- if (focusedInput === "startDate") {
1960
- if (endDate != null && isAfter(day.date, endDate)) {
1961
- onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange({
1962
- startDate: day.date,
1963
- endDate: undefined,
1964
- });
1965
- setFocusedInput("endDate");
1966
- (_a = endDateInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
1967
- }
1968
- else {
1969
- onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange({
1970
- startDate: day.date,
1971
- endDate: endDate,
1972
- });
1973
- if (firstFocusedInput === "startDate") {
1974
- setFocusedInput("endDate");
1975
- (_b = endDateInputRef.current) === null || _b === void 0 ? void 0 : _b.focus();
1976
- }
1977
- else {
1978
- setTimeout(hideCalendar, 50);
1979
- }
1980
- }
1981
- }
1982
- else if (focusedInput === "endDate") {
1983
- if (!startDate) {
1984
- onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange({
1985
- startDate: startDate,
1986
- endDate: day.date,
1987
- });
1988
- setFocusedInput("startDate");
1989
- (_c = startDateInputRef.current) === null || _c === void 0 ? void 0 : _c.focus();
1990
- }
1991
- else if (isAfter(startDate, day.date)) {
1992
- onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange({
1993
- startDate: day.date,
1994
- endDate: undefined,
1995
- });
1996
- setFocusedInput("endDate");
1997
- (_d = endDateInputRef.current) === null || _d === void 0 ? void 0 : _d.focus();
1998
- }
1999
- else {
2000
- onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange({
2001
- startDate: startDate,
2002
- endDate: day.date,
2003
- });
2004
- setTimeout(hideCalendar, 50);
2005
- }
2006
- }
2007
- }, [
2008
- focusedInput,
2009
- onValueChange,
2010
- endDate,
2011
- firstFocusedInput,
2012
- setFocusedInput,
2013
- endDateInputRef,
2014
- hideCalendar,
2015
- startDate,
2016
- startDateInputRef,
2017
- ]);
2018
- var onClickArrowButton = useCallback(function () {
2019
- setCurrentPanel("presets");
2020
- showCalendar();
2021
- }, [setCurrentPanel, showCalendar]);
2022
- var onClickCalendarButton = useCallback(function () {
2023
- var _a;
2024
- if (isCalendarVisible) {
2025
- hideCalendar();
2026
- }
2027
- else {
2028
- setFocusedInput("startDate");
2029
- setFirstFocusedInput("startDate");
2030
- (_a = startDateInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
2031
- setCurrentPanel("calendar");
2032
- showCalendar();
2033
- }
2034
- }, [
2035
- isCalendarVisible,
2036
- hideCalendar,
2037
- setFocusedInput,
2038
- setFirstFocusedInput,
2039
- startDateInputRef,
2040
- setCurrentPanel,
2041
- showCalendar,
2042
- ]);
2043
- var onKeyDownHandler = useCallback(function (ev) {
2044
- if (ev.key === "Escape") {
2045
- hideCalendar();
2046
- }
2047
- }, [hideCalendar]);
2048
- return {
2049
- onFocusLeft: onFocusLeft,
2050
- onFocusRight: onFocusRight,
2051
- onClickDay: onClickDay,
2052
- onClickArrowButton: onClickArrowButton,
2053
- onClickCalendarButton: onClickCalendarButton,
2054
- onKeyDownHandler: onKeyDownHandler,
2055
- };
2056
- };
2057
-
2058
- var DateRangeDualTextInput = function (_a) {
2059
- var value = _a.value, onValueChange = _a.onValueChange, autoFocus = _a.autoFocus, onBlur = _a.onBlur, onEnter = _a.onEnter, onEsc = _a.onEsc, minDate = _a.minDate, _b = _a.maxDate, maxDate = _b === void 0 ? defaultMaxDate : _b, calendarProps = _a.calendarProps, _c = _a.widthLeft, widthLeft = _c === void 0 ? 128 : _c, _d = _a.widthRight, widthRight = _d === void 0 ? 128 : _d, variant = _a.variant, disabled = _a.disabled;
2060
- var _e = value || {}, startDate = _e.startDate, endDate = _e.endDate;
2061
- var startDateInputRef = useRef(null);
2062
- var endDateInputRef = useRef(null);
2063
- var states = useInputStates(startDate, endDate);
2064
- var dateInFocus = states.dateInFocus, setDateInFocus = states.setDateInFocus, isCalendarVisible = states.isCalendarVisible, currentPanel = states.currentPanel, setCurrentPanel = states.setCurrentPanel;
2065
- var _f = useDateRangeHandlers(startDate, endDate, onValueChange, states), showCalendar = _f.showCalendar, hideCalendar = _f.hideCalendar, inputLeftChangeHandler = _f.inputLeftChangeHandler, inputRightChangeHandler = _f.inputRightChangeHandler;
2066
- var _g = useUserInputHandlers(startDate, endDate, onValueChange, startDateInputRef, endDateInputRef, showCalendar, hideCalendar, states), onKeyDownHandler = _g.onKeyDownHandler, onFocusRight = _g.onFocusRight, onFocusLeft = _g.onFocusLeft, onClickDay = _g.onClickDay, onClickCalendarButton = _g.onClickCalendarButton, onClickArrowButton = _g.onClickArrowButton;
2067
- useDateRangeEffects(startDate, endDate, setDateInFocus, startDateInputRef, endDateInputRef);
2068
- var startDateIsAfterEnd = useMemo(function () { return startDate && endDate && isAfter(startDate, endDate); }, [startDate, endDate]);
2069
- var statePerMonth = useMemo(function () {
2070
- return buildDayStateForSingleMonth(calendarProps === null || calendarProps === void 0 ? void 0 : calendarProps.statePerMonth, startDate, endDate, dateInFocus);
2071
- }, [calendarProps === null || calendarProps === void 0 ? void 0 : calendarProps.statePerMonth, startDate, endDate, dateInFocus]);
2072
- var delayedIsCalendarVisible = useDelayedFalse(isCalendarVisible, 300);
2073
- return (React.createElement(Box, { onKeyDown: onKeyDownHandler },
2074
- React.createElement(Popover, { arrow: false, lazy: true, disabled: disabled, placement: defaultPopoverPlacement, onClickOutside: hideCalendar, visible: isCalendarVisible, content: delayedIsCalendarVisible && (React.createElement(CalendarWithMonthSwitcher, __assign({ onClickDay: onClickDay, dateInFocus: dateInFocus, setDateInFocus: setDateInFocus, currentPanel: currentPanel, setCurrentPanel: setCurrentPanel, minDate: minDate, maxDate: maxDate }, calendarProps, { statePerMonth: statePerMonth }))) },
2075
- React.createElement(DualTextInput, { autoFocusLeft: autoFocus, onEsc: onEsc, onEnter: onEnter, onBlur: onBlur, disabled: disabled, separatorIcon: stenaArrowRight, typeLeft: "date", typeRight: "date", placeholderLeft: "Start date", placeholderRight: "End date", onChangeLeft: inputLeftChangeHandler, onChangeRight: inputRightChangeHandler, onClickArrowDown: onClickArrowButton, onClickCalendar: onClickCalendarButton, onFocusLeft: onFocusLeft, onFocusRight: onFocusRight, onClickLeft: onFocusLeft, onClickRight: onFocusRight, inputRefLeft: startDateInputRef, inputRefRight: endDateInputRef, variant: startDateIsAfterEnd ? "error" : variant, widthLeft: widthLeft, widthRight: widthRight, minLeft: minDate, maxLeft: maxDate, minRight: minDate, maxRight: maxDate }))));
2076
- };
2077
-
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
+ };
2078
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 };
2079
2880
  //# sourceMappingURL=index.es.js.map