@redis-ui/components 46.1.3 → 47.0.1

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 (163) hide show
  1. package/dist/Badge/Badge.cjs +3 -2
  2. package/dist/Badge/Badge.d.ts +1 -1
  3. package/dist/Badge/Badge.js +4 -2
  4. package/dist/Toast/Toaster.style.cjs +2 -2
  5. package/dist/Toast/Toaster.style.js +2 -2
  6. package/dist/Toast/core/mapping.helpers.cjs +1 -1
  7. package/dist/Toast/core/mapping.helpers.js +1 -1
  8. package/dist/index.cjs +1 -5
  9. package/dist/index.d.ts +0 -1
  10. package/dist/index.js +2 -4
  11. package/dist/node_modules/react-loading-skeleton/dist/index.cjs +2 -1
  12. package/dist/node_modules/react-loading-skeleton/dist/index.js +2 -1
  13. package/dist/{packages/components/node_modules → node_modules}/react-toastify/dist/react-toastify.esm.cjs +3 -3
  14. package/dist/{packages/components/node_modules → node_modules}/react-toastify/dist/react-toastify.esm.js +2 -2
  15. package/package.json +2 -4
  16. package/skills/redis-ui-components/SKILL.md +0 -1
  17. package/skills/redis-ui-components/references/Badge.md +18 -0
  18. package/dist/DatePicker/DatePicker.cjs +0 -32
  19. package/dist/DatePicker/DatePicker.d.ts +0 -6
  20. package/dist/DatePicker/DatePicker.js +0 -31
  21. package/dist/DatePicker/DatePicker.style.cjs +0 -251
  22. package/dist/DatePicker/DatePicker.style.d.ts +0 -3
  23. package/dist/DatePicker/DatePicker.style.js +0 -249
  24. package/dist/DatePicker/DatePicker.types.d.ts +0 -17
  25. package/dist/DatePicker/DatePicker.types.js +0 -1
  26. package/dist/DatePicker/DatePicker.utils.cjs +0 -7
  27. package/dist/DatePicker/DatePicker.utils.d.ts +0 -2
  28. package/dist/DatePicker/DatePicker.utils.js +0 -6
  29. package/dist/DatePicker/RangeDatePicker.cjs +0 -30
  30. package/dist/DatePicker/RangeDatePicker.d.ts +0 -3
  31. package/dist/DatePicker/RangeDatePicker.js +0 -29
  32. package/dist/DatePicker/components/CustomDropdown/CustomDropdown.cjs +0 -34
  33. package/dist/DatePicker/components/CustomDropdown/CustomDropdown.d.ts +0 -3
  34. package/dist/DatePicker/components/CustomDropdown/CustomDropdown.js +0 -32
  35. package/dist/DatePicker/components/CustomLeftIcon/CustomLeftIcon.cjs +0 -11
  36. package/dist/DatePicker/components/CustomLeftIcon/CustomLeftIcon.d.ts +0 -2
  37. package/dist/DatePicker/components/CustomLeftIcon/CustomLeftIcon.js +0 -10
  38. package/dist/DatePicker/components/CustomRightIcon/CustomRightIcon.cjs +0 -11
  39. package/dist/DatePicker/components/CustomRightIcon/CustomRightIcon.d.ts +0 -2
  40. package/dist/DatePicker/components/CustomRightIcon/CustomRightIcon.js +0 -10
  41. package/dist/DatePicker/index.d.ts +0 -3
  42. package/dist/DatePicker/index.js +0 -2
  43. package/dist/node_modules/date-fns/_lib/addLeadingZeros.cjs +0 -6
  44. package/dist/node_modules/date-fns/_lib/addLeadingZeros.js +0 -6
  45. package/dist/node_modules/date-fns/_lib/defaultOptions.cjs +0 -7
  46. package/dist/node_modules/date-fns/_lib/defaultOptions.js +0 -7
  47. package/dist/node_modules/date-fns/_lib/format/formatters.cjs +0 -418
  48. package/dist/node_modules/date-fns/_lib/format/formatters.js +0 -418
  49. package/dist/node_modules/date-fns/_lib/format/lightFormatters.cjs +0 -45
  50. package/dist/node_modules/date-fns/_lib/format/lightFormatters.js +0 -45
  51. package/dist/node_modules/date-fns/_lib/format/longFormatters.cjs +0 -45
  52. package/dist/node_modules/date-fns/_lib/format/longFormatters.js +0 -45
  53. package/dist/node_modules/date-fns/_lib/getTimezoneOffsetInMilliseconds.cjs +0 -21
  54. package/dist/node_modules/date-fns/_lib/getTimezoneOffsetInMilliseconds.js +0 -21
  55. package/dist/node_modules/date-fns/_lib/protectedTokens.cjs +0 -28
  56. package/dist/node_modules/date-fns/_lib/protectedTokens.js +0 -26
  57. package/dist/node_modules/date-fns/addDays.cjs +0 -32
  58. package/dist/node_modules/date-fns/addDays.js +0 -32
  59. package/dist/node_modules/date-fns/addMonths.cjs +0 -42
  60. package/dist/node_modules/date-fns/addMonths.js +0 -42
  61. package/dist/node_modules/date-fns/addWeeks.cjs +0 -27
  62. package/dist/node_modules/date-fns/addWeeks.js +0 -27
  63. package/dist/node_modules/date-fns/addYears.cjs +0 -27
  64. package/dist/node_modules/date-fns/addYears.js +0 -27
  65. package/dist/node_modules/date-fns/constants.cjs +0 -39
  66. package/dist/node_modules/date-fns/constants.js +0 -38
  67. package/dist/node_modules/date-fns/constructFrom.cjs +0 -37
  68. package/dist/node_modules/date-fns/constructFrom.js +0 -37
  69. package/dist/node_modules/date-fns/differenceInCalendarDays.cjs +0 -45
  70. package/dist/node_modules/date-fns/differenceInCalendarDays.js +0 -45
  71. package/dist/node_modules/date-fns/differenceInCalendarMonths.cjs +0 -34
  72. package/dist/node_modules/date-fns/differenceInCalendarMonths.js +0 -34
  73. package/dist/node_modules/date-fns/differenceInCalendarWeeks.cjs +0 -50
  74. package/dist/node_modules/date-fns/differenceInCalendarWeeks.js +0 -50
  75. package/dist/node_modules/date-fns/endOfISOWeek.cjs +0 -29
  76. package/dist/node_modules/date-fns/endOfISOWeek.js +0 -29
  77. package/dist/node_modules/date-fns/endOfMonth.cjs +0 -31
  78. package/dist/node_modules/date-fns/endOfMonth.js +0 -31
  79. package/dist/node_modules/date-fns/endOfWeek.cjs +0 -44
  80. package/dist/node_modules/date-fns/endOfWeek.js +0 -44
  81. package/dist/node_modules/date-fns/format.cjs +0 -357
  82. package/dist/node_modules/date-fns/format.js +0 -357
  83. package/dist/node_modules/date-fns/getDayOfYear.cjs +0 -29
  84. package/dist/node_modules/date-fns/getDayOfYear.js +0 -29
  85. package/dist/node_modules/date-fns/getDaysInMonth.cjs +0 -33
  86. package/dist/node_modules/date-fns/getDaysInMonth.js +0 -33
  87. package/dist/node_modules/date-fns/getISOWeek.cjs +0 -33
  88. package/dist/node_modules/date-fns/getISOWeek.js +0 -33
  89. package/dist/node_modules/date-fns/getISOWeekYear.cjs +0 -43
  90. package/dist/node_modules/date-fns/getISOWeekYear.js +0 -43
  91. package/dist/node_modules/date-fns/getUnixTime.cjs +0 -26
  92. package/dist/node_modules/date-fns/getUnixTime.js +0 -26
  93. package/dist/node_modules/date-fns/getWeek.cjs +0 -51
  94. package/dist/node_modules/date-fns/getWeek.js +0 -51
  95. package/dist/node_modules/date-fns/getWeekYear.cjs +0 -63
  96. package/dist/node_modules/date-fns/getWeekYear.js +0 -63
  97. package/dist/node_modules/date-fns/getWeeksInMonth.cjs +0 -38
  98. package/dist/node_modules/date-fns/getWeeksInMonth.js +0 -38
  99. package/dist/node_modules/date-fns/isAfter.cjs +0 -29
  100. package/dist/node_modules/date-fns/isAfter.js +0 -29
  101. package/dist/node_modules/date-fns/isBefore.cjs +0 -29
  102. package/dist/node_modules/date-fns/isBefore.js +0 -29
  103. package/dist/node_modules/date-fns/isDate.cjs +0 -38
  104. package/dist/node_modules/date-fns/isDate.js +0 -38
  105. package/dist/node_modules/date-fns/isSameDay.cjs +0 -39
  106. package/dist/node_modules/date-fns/isSameDay.js +0 -39
  107. package/dist/node_modules/date-fns/isSameMonth.cjs +0 -34
  108. package/dist/node_modules/date-fns/isSameMonth.js +0 -34
  109. package/dist/node_modules/date-fns/isSameYear.cjs +0 -29
  110. package/dist/node_modules/date-fns/isSameYear.js +0 -29
  111. package/dist/node_modules/date-fns/isValid.cjs +0 -43
  112. package/dist/node_modules/date-fns/isValid.js +0 -43
  113. package/dist/node_modules/date-fns/lastDayOfMonth.cjs +0 -31
  114. package/dist/node_modules/date-fns/lastDayOfMonth.js +0 -31
  115. package/dist/node_modules/date-fns/locale/_lib/buildFormatLongFn.cjs +0 -9
  116. package/dist/node_modules/date-fns/locale/_lib/buildFormatLongFn.js +0 -9
  117. package/dist/node_modules/date-fns/locale/_lib/buildLocalizeFn.cjs +0 -51
  118. package/dist/node_modules/date-fns/locale/_lib/buildLocalizeFn.js +0 -51
  119. package/dist/node_modules/date-fns/locale/_lib/buildMatchFn.cjs +0 -28
  120. package/dist/node_modules/date-fns/locale/_lib/buildMatchFn.js +0 -28
  121. package/dist/node_modules/date-fns/locale/_lib/buildMatchPatternFn.cjs +0 -19
  122. package/dist/node_modules/date-fns/locale/_lib/buildMatchPatternFn.js +0 -19
  123. package/dist/node_modules/date-fns/locale/en-US/_lib/formatDistance.cjs +0 -76
  124. package/dist/node_modules/date-fns/locale/en-US/_lib/formatDistance.js +0 -76
  125. package/dist/node_modules/date-fns/locale/en-US/_lib/formatLong.cjs +0 -32
  126. package/dist/node_modules/date-fns/locale/en-US/_lib/formatLong.js +0 -32
  127. package/dist/node_modules/date-fns/locale/en-US/_lib/formatRelative.cjs +0 -12
  128. package/dist/node_modules/date-fns/locale/en-US/_lib/formatRelative.js +0 -12
  129. package/dist/node_modules/date-fns/locale/en-US/_lib/localize.cjs +0 -211
  130. package/dist/node_modules/date-fns/locale/en-US/_lib/localize.js +0 -211
  131. package/dist/node_modules/date-fns/locale/en-US/_lib/match.cjs +0 -123
  132. package/dist/node_modules/date-fns/locale/en-US/_lib/match.js +0 -124
  133. package/dist/node_modules/date-fns/locale/en-US.cjs +0 -28
  134. package/dist/node_modules/date-fns/locale/en-US.js +0 -28
  135. package/dist/node_modules/date-fns/max.cjs +0 -36
  136. package/dist/node_modules/date-fns/max.js +0 -36
  137. package/dist/node_modules/date-fns/min.cjs +0 -36
  138. package/dist/node_modules/date-fns/min.js +0 -36
  139. package/dist/node_modules/date-fns/setMonth.cjs +0 -37
  140. package/dist/node_modules/date-fns/setMonth.js +0 -37
  141. package/dist/node_modules/date-fns/setYear.cjs +0 -31
  142. package/dist/node_modules/date-fns/setYear.js +0 -31
  143. package/dist/node_modules/date-fns/startOfDay.cjs +0 -29
  144. package/dist/node_modules/date-fns/startOfDay.js +0 -29
  145. package/dist/node_modules/date-fns/startOfISOWeek.cjs +0 -29
  146. package/dist/node_modules/date-fns/startOfISOWeek.js +0 -29
  147. package/dist/node_modules/date-fns/startOfISOWeekYear.cjs +0 -36
  148. package/dist/node_modules/date-fns/startOfISOWeekYear.js +0 -36
  149. package/dist/node_modules/date-fns/startOfMonth.cjs +0 -30
  150. package/dist/node_modules/date-fns/startOfMonth.js +0 -30
  151. package/dist/node_modules/date-fns/startOfWeek.cjs +0 -44
  152. package/dist/node_modules/date-fns/startOfWeek.js +0 -44
  153. package/dist/node_modules/date-fns/startOfWeekYear.cjs +0 -55
  154. package/dist/node_modules/date-fns/startOfWeekYear.js +0 -55
  155. package/dist/node_modules/date-fns/startOfYear.cjs +0 -32
  156. package/dist/node_modules/date-fns/startOfYear.js +0 -32
  157. package/dist/node_modules/date-fns/subDays.cjs +0 -27
  158. package/dist/node_modules/date-fns/subDays.js +0 -27
  159. package/dist/node_modules/date-fns/toDate.cjs +0 -41
  160. package/dist/node_modules/date-fns/toDate.js +0 -41
  161. package/dist/node_modules/react-day-picker/dist/index.esm.cjs +0 -2094
  162. package/dist/node_modules/react-day-picker/dist/index.esm.js +0 -2092
  163. package/skills/redis-ui-components/references/DatePicker.md +0 -52
@@ -1,2094 +0,0 @@
1
- require("../../../_virtual/_rolldown/runtime.cjs");
2
- const require_addDays = require("../../date-fns/addDays.cjs");
3
- const require_addMonths = require("../../date-fns/addMonths.cjs");
4
- const require_startOfWeek = require("../../date-fns/startOfWeek.cjs");
5
- const require_startOfISOWeek = require("../../date-fns/startOfISOWeek.cjs");
6
- const require_startOfDay = require("../../date-fns/startOfDay.cjs");
7
- const require_differenceInCalendarDays = require("../../date-fns/differenceInCalendarDays.cjs");
8
- const require_addWeeks = require("../../date-fns/addWeeks.cjs");
9
- const require_addYears = require("../../date-fns/addYears.cjs");
10
- const require_max = require("../../date-fns/max.cjs");
11
- const require_min = require("../../date-fns/min.cjs");
12
- const require_isSameDay = require("../../date-fns/isSameDay.cjs");
13
- const require_isDate = require("../../date-fns/isDate.cjs");
14
- const require_differenceInCalendarMonths = require("../../date-fns/differenceInCalendarMonths.cjs");
15
- const require_endOfMonth = require("../../date-fns/endOfMonth.cjs");
16
- const require_startOfMonth = require("../../date-fns/startOfMonth.cjs");
17
- const require_startOfYear = require("../../date-fns/startOfYear.cjs");
18
- const require_endOfWeek = require("../../date-fns/endOfWeek.cjs");
19
- const require_endOfISOWeek = require("../../date-fns/endOfISOWeek.cjs");
20
- const require_en_US = require("../../date-fns/locale/en-US.cjs");
21
- const require_getISOWeek = require("../../date-fns/getISOWeek.cjs");
22
- const require_getWeek = require("../../date-fns/getWeek.cjs");
23
- const require_format = require("../../date-fns/format.cjs");
24
- const require_getUnixTime = require("../../date-fns/getUnixTime.cjs");
25
- const require_getWeeksInMonth = require("../../date-fns/getWeeksInMonth.cjs");
26
- const require_isAfter = require("../../date-fns/isAfter.cjs");
27
- const require_isBefore = require("../../date-fns/isBefore.cjs");
28
- const require_isSameMonth = require("../../date-fns/isSameMonth.cjs");
29
- const require_isSameYear = require("../../date-fns/isSameYear.cjs");
30
- const require_subDays = require("../../date-fns/subDays.cjs");
31
- const require_setMonth = require("../../date-fns/setMonth.cjs");
32
- const require_setYear = require("../../date-fns/setYear.cjs");
33
- let react_jsx_runtime = require("react/jsx-runtime");
34
- let react = require("react");
35
- //#region ../../node_modules/react-day-picker/dist/index.esm.js
36
- /******************************************************************************
37
- Copyright (c) Microsoft Corporation.
38
-
39
- Permission to use, copy, modify, and/or distribute this software for any
40
- purpose with or without fee is hereby granted.
41
-
42
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
43
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
44
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
45
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
46
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
47
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
48
- PERFORMANCE OF THIS SOFTWARE.
49
- ***************************************************************************** */
50
- var __assign = function() {
51
- __assign = Object.assign || function __assign(t) {
52
- for (var s, i = 1, n = arguments.length; i < n; i++) {
53
- s = arguments[i];
54
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
55
- }
56
- return t;
57
- };
58
- return __assign.apply(this, arguments);
59
- };
60
- function __rest(s, e) {
61
- var t = {};
62
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
63
- if (s != null && typeof Object.getOwnPropertySymbols === "function") {
64
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
65
- }
66
- return t;
67
- }
68
- function __spreadArray(to, from, pack) {
69
- if (pack || arguments.length === 2) {
70
- for (var i = 0, l = from.length, ar; i < l; i++) if (ar || !(i in from)) {
71
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
72
- ar[i] = from[i];
73
- }
74
- }
75
- return to.concat(ar || Array.prototype.slice.call(from));
76
- }
77
- /** Returns true when the props are of type {@link DayPickerMultipleProps}. */
78
- function isDayPickerMultiple(props) {
79
- return props.mode === "multiple";
80
- }
81
- /** Returns true when the props are of type {@link DayPickerRangeProps}. */
82
- function isDayPickerRange(props) {
83
- return props.mode === "range";
84
- }
85
- /** Returns true when the props are of type {@link DayPickerSingleProps}. */
86
- function isDayPickerSingle(props) {
87
- return props.mode === "single";
88
- }
89
- /**
90
- * The name of the default CSS classes.
91
- */
92
- var defaultClassNames = {
93
- root: "rdp",
94
- multiple_months: "rdp-multiple_months",
95
- with_weeknumber: "rdp-with_weeknumber",
96
- vhidden: "rdp-vhidden",
97
- button_reset: "rdp-button_reset",
98
- button: "rdp-button",
99
- caption: "rdp-caption",
100
- caption_start: "rdp-caption_start",
101
- caption_end: "rdp-caption_end",
102
- caption_between: "rdp-caption_between",
103
- caption_label: "rdp-caption_label",
104
- caption_dropdowns: "rdp-caption_dropdowns",
105
- dropdown: "rdp-dropdown",
106
- dropdown_month: "rdp-dropdown_month",
107
- dropdown_year: "rdp-dropdown_year",
108
- dropdown_icon: "rdp-dropdown_icon",
109
- months: "rdp-months",
110
- month: "rdp-month",
111
- table: "rdp-table",
112
- tbody: "rdp-tbody",
113
- tfoot: "rdp-tfoot",
114
- head: "rdp-head",
115
- head_row: "rdp-head_row",
116
- head_cell: "rdp-head_cell",
117
- nav: "rdp-nav",
118
- nav_button: "rdp-nav_button",
119
- nav_button_previous: "rdp-nav_button_previous",
120
- nav_button_next: "rdp-nav_button_next",
121
- nav_icon: "rdp-nav_icon",
122
- row: "rdp-row",
123
- weeknumber: "rdp-weeknumber",
124
- cell: "rdp-cell",
125
- day: "rdp-day",
126
- day_today: "rdp-day_today",
127
- day_outside: "rdp-day_outside",
128
- day_selected: "rdp-day_selected",
129
- day_disabled: "rdp-day_disabled",
130
- day_hidden: "rdp-day_hidden",
131
- day_range_start: "rdp-day_range_start",
132
- day_range_end: "rdp-day_range_end",
133
- day_range_middle: "rdp-day_range_middle"
134
- };
135
- /**
136
- * The default formatter for the caption.
137
- */
138
- function formatCaption(month, options) {
139
- return require_format.default(month, "LLLL y", options);
140
- }
141
- /**
142
- * The default formatter for the Day button.
143
- */
144
- function formatDay(day, options) {
145
- return require_format.default(day, "d", options);
146
- }
147
- /**
148
- * The default formatter for the Month caption.
149
- */
150
- function formatMonthCaption(month, options) {
151
- return require_format.default(month, "LLLL", options);
152
- }
153
- /**
154
- * The default formatter for the week number.
155
- */
156
- function formatWeekNumber(weekNumber) {
157
- return "".concat(weekNumber);
158
- }
159
- /**
160
- * The default formatter for the name of the weekday.
161
- */
162
- function formatWeekdayName(weekday, options) {
163
- return require_format.default(weekday, "cccccc", options);
164
- }
165
- /**
166
- * The default formatter for the Year caption.
167
- */
168
- function formatYearCaption(year, options) {
169
- return require_format.default(year, "yyyy", options);
170
- }
171
- var formatters = /* @__PURE__ */ Object.freeze({
172
- __proto__: null,
173
- formatCaption,
174
- formatDay,
175
- formatMonthCaption,
176
- formatWeekNumber,
177
- formatWeekdayName,
178
- formatYearCaption
179
- });
180
- /**
181
- * The default ARIA label for the day button.
182
- */
183
- var labelDay = function(day, activeModifiers, options) {
184
- return require_format.default(day, "do MMMM (EEEE)", options);
185
- };
186
- /**
187
- * The default ARIA label for the WeekNumber element.
188
- */
189
- var labelMonthDropdown = function() {
190
- return "Month: ";
191
- };
192
- /**
193
- * The default ARIA label for next month button in navigation
194
- */
195
- var labelNext = function() {
196
- return "Go to next month";
197
- };
198
- /**
199
- * The default ARIA label for previous month button in navigation
200
- */
201
- var labelPrevious = function() {
202
- return "Go to previous month";
203
- };
204
- /**
205
- * The default ARIA label for the Weekday element.
206
- */
207
- var labelWeekday = function(day, options) {
208
- return require_format.default(day, "cccc", options);
209
- };
210
- /**
211
- * The default ARIA label for the WeekNumber element.
212
- */
213
- var labelWeekNumber = function(n) {
214
- return "Week n. ".concat(n);
215
- };
216
- /**
217
- * The default ARIA label for the WeekNumber element.
218
- */
219
- var labelYearDropdown = function() {
220
- return "Year: ";
221
- };
222
- var labels = /* @__PURE__ */ Object.freeze({
223
- __proto__: null,
224
- labelDay,
225
- labelMonthDropdown,
226
- labelNext,
227
- labelPrevious,
228
- labelWeekNumber,
229
- labelWeekday,
230
- labelYearDropdown
231
- });
232
- /**
233
- * Returns the default values to use in the DayPickerContext, in case they are
234
- * not passed down with the DayPicker initial props.
235
- */
236
- function getDefaultContextValues() {
237
- return {
238
- captionLayout: "buttons",
239
- classNames: defaultClassNames,
240
- formatters,
241
- labels,
242
- locale: require_en_US.default,
243
- modifiersClassNames: {},
244
- modifiers: {},
245
- numberOfMonths: 1,
246
- styles: {},
247
- today: /* @__PURE__ */ new Date(),
248
- mode: "default"
249
- };
250
- }
251
- /** Return the `fromDate` and `toDate` prop values values parsing the DayPicker props. */
252
- function parseFromToProps(props) {
253
- var fromYear = props.fromYear, toYear = props.toYear, fromMonth = props.fromMonth, toMonth = props.toMonth;
254
- var fromDate = props.fromDate, toDate = props.toDate;
255
- if (fromMonth) fromDate = require_startOfMonth.default(fromMonth);
256
- else if (fromYear) fromDate = new Date(fromYear, 0, 1);
257
- if (toMonth) toDate = require_endOfMonth.default(toMonth);
258
- else if (toYear) toDate = new Date(toYear, 11, 31);
259
- return {
260
- fromDate: fromDate ? require_startOfDay.default(fromDate) : void 0,
261
- toDate: toDate ? require_startOfDay.default(toDate) : void 0
262
- };
263
- }
264
- /**
265
- * The DayPicker context shares the props passed to DayPicker within internal
266
- * and custom components. It is used to set the default values and perform
267
- * one-time calculations required to render the days.
268
- *
269
- * Access to this context from the {@link useDayPicker} hook.
270
- */
271
- var DayPickerContext = (0, react.createContext)(void 0);
272
- /**
273
- * The provider for the {@link DayPickerContext}, assigning the defaults from the
274
- * initial DayPicker props.
275
- */
276
- function DayPickerProvider(props) {
277
- var _a;
278
- var initialProps = props.initialProps;
279
- var defaultContextValues = getDefaultContextValues();
280
- var _b = parseFromToProps(initialProps), fromDate = _b.fromDate, toDate = _b.toDate;
281
- var captionLayout = (_a = initialProps.captionLayout) !== null && _a !== void 0 ? _a : defaultContextValues.captionLayout;
282
- if (captionLayout !== "buttons" && (!fromDate || !toDate)) captionLayout = "buttons";
283
- var onSelect;
284
- if (isDayPickerSingle(initialProps) || isDayPickerMultiple(initialProps) || isDayPickerRange(initialProps)) onSelect = initialProps.onSelect;
285
- var value = __assign(__assign(__assign({}, defaultContextValues), initialProps), {
286
- captionLayout,
287
- classNames: __assign(__assign({}, defaultContextValues.classNames), initialProps.classNames),
288
- components: __assign({}, initialProps.components),
289
- formatters: __assign(__assign({}, defaultContextValues.formatters), initialProps.formatters),
290
- fromDate,
291
- labels: __assign(__assign({}, defaultContextValues.labels), initialProps.labels),
292
- mode: initialProps.mode || defaultContextValues.mode,
293
- modifiers: __assign(__assign({}, defaultContextValues.modifiers), initialProps.modifiers),
294
- modifiersClassNames: __assign(__assign({}, defaultContextValues.modifiersClassNames), initialProps.modifiersClassNames),
295
- onSelect,
296
- styles: __assign(__assign({}, defaultContextValues.styles), initialProps.styles),
297
- toDate
298
- });
299
- return (0, react_jsx_runtime.jsx)(DayPickerContext.Provider, {
300
- value,
301
- children: props.children
302
- });
303
- }
304
- /**
305
- * Hook to access the {@link DayPickerContextValue}.
306
- *
307
- * Use the DayPicker context to access to the props passed to DayPicker inside
308
- * internal or custom components.
309
- */
310
- function useDayPicker() {
311
- var context = (0, react.useContext)(DayPickerContext);
312
- if (!context) throw new Error("useDayPicker must be used within a DayPickerProvider.");
313
- return context;
314
- }
315
- /** Render the caption for the displayed month. This component is used when `captionLayout="buttons"`. */
316
- function CaptionLabel(props) {
317
- var _a = useDayPicker(), locale = _a.locale, classNames = _a.classNames, styles = _a.styles, formatCaption = _a.formatters.formatCaption;
318
- return (0, react_jsx_runtime.jsx)("div", {
319
- className: classNames.caption_label,
320
- style: styles.caption_label,
321
- "aria-live": "polite",
322
- role: "presentation",
323
- id: props.id,
324
- children: formatCaption(props.displayMonth, { locale })
325
- });
326
- }
327
- /**
328
- * Render the icon in the styled drop-down.
329
- */
330
- function IconDropdown(props) {
331
- return (0, react_jsx_runtime.jsx)("svg", __assign({
332
- width: "8px",
333
- height: "8px",
334
- viewBox: "0 0 120 120",
335
- "data-testid": "iconDropdown"
336
- }, props, { children: (0, react_jsx_runtime.jsx)("path", {
337
- d: "M4.22182541,48.2218254 C8.44222828,44.0014225 15.2388494,43.9273804 19.5496459,47.9996989 L19.7781746,48.2218254 L60,88.443 L100.221825,48.2218254 C104.442228,44.0014225 111.238849,43.9273804 115.549646,47.9996989 L115.778175,48.2218254 C119.998577,52.4422283 120.07262,59.2388494 116.000301,63.5496459 L115.778175,63.7781746 L67.7781746,111.778175 C63.5577717,115.998577 56.7611506,116.07262 52.4503541,112.000301 L52.2218254,111.778175 L4.22182541,63.7781746 C-0.0739418023,59.4824074 -0.0739418023,52.5175926 4.22182541,48.2218254 Z",
338
- fill: "currentColor",
339
- fillRule: "nonzero"
340
- }) }));
341
- }
342
- /**
343
- * Render a styled select component – displaying a caption and a custom
344
- * drop-down icon.
345
- */
346
- function Dropdown(props) {
347
- var _a, _b;
348
- var onChange = props.onChange, value = props.value, children = props.children, caption = props.caption, className = props.className, style = props.style;
349
- var dayPicker = useDayPicker();
350
- var IconDropdownComponent = (_b = (_a = dayPicker.components) === null || _a === void 0 ? void 0 : _a.IconDropdown) !== null && _b !== void 0 ? _b : IconDropdown;
351
- return (0, react_jsx_runtime.jsxs)("div", {
352
- className,
353
- style,
354
- children: [
355
- (0, react_jsx_runtime.jsx)("span", {
356
- className: dayPicker.classNames.vhidden,
357
- children: props["aria-label"]
358
- }),
359
- (0, react_jsx_runtime.jsx)("select", {
360
- name: props.name,
361
- "aria-label": props["aria-label"],
362
- className: dayPicker.classNames.dropdown,
363
- style: dayPicker.styles.dropdown,
364
- value,
365
- onChange,
366
- children
367
- }),
368
- (0, react_jsx_runtime.jsxs)("div", {
369
- className: dayPicker.classNames.caption_label,
370
- style: dayPicker.styles.caption_label,
371
- "aria-hidden": "true",
372
- children: [caption, (0, react_jsx_runtime.jsx)(IconDropdownComponent, {
373
- className: dayPicker.classNames.dropdown_icon,
374
- style: dayPicker.styles.dropdown_icon
375
- })]
376
- })
377
- ]
378
- });
379
- }
380
- /** Render the dropdown to navigate between months. */
381
- function MonthsDropdown(props) {
382
- var _a;
383
- var _b = useDayPicker(), fromDate = _b.fromDate, toDate = _b.toDate, styles = _b.styles, locale = _b.locale, formatMonthCaption = _b.formatters.formatMonthCaption, classNames = _b.classNames, components = _b.components, labelMonthDropdown = _b.labels.labelMonthDropdown;
384
- if (!fromDate) return (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {});
385
- if (!toDate) return (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {});
386
- var dropdownMonths = [];
387
- if (require_isSameYear.default(fromDate, toDate)) {
388
- var date = require_startOfMonth.default(fromDate);
389
- for (var month = fromDate.getMonth(); month <= toDate.getMonth(); month++) dropdownMonths.push(require_setMonth.default(date, month));
390
- } else {
391
- var date = require_startOfMonth.default(/* @__PURE__ */ new Date());
392
- for (var month = 0; month <= 11; month++) dropdownMonths.push(require_setMonth.default(date, month));
393
- }
394
- var handleChange = function(e) {
395
- var selectedMonth = Number(e.target.value);
396
- var newMonth = require_setMonth.default(require_startOfMonth.default(props.displayMonth), selectedMonth);
397
- props.onChange(newMonth);
398
- };
399
- return (0, react_jsx_runtime.jsx)((_a = components === null || components === void 0 ? void 0 : components.Dropdown) !== null && _a !== void 0 ? _a : Dropdown, {
400
- name: "months",
401
- "aria-label": labelMonthDropdown(),
402
- className: classNames.dropdown_month,
403
- style: styles.dropdown_month,
404
- onChange: handleChange,
405
- value: props.displayMonth.getMonth(),
406
- caption: formatMonthCaption(props.displayMonth, { locale }),
407
- children: dropdownMonths.map(function(m) {
408
- return (0, react_jsx_runtime.jsx)("option", {
409
- value: m.getMonth(),
410
- children: formatMonthCaption(m, { locale })
411
- }, m.getMonth());
412
- })
413
- });
414
- }
415
- /**
416
- * Render a dropdown to change the year. Take in account the `nav.fromDate` and
417
- * `toDate` from context.
418
- */
419
- function YearsDropdown(props) {
420
- var _a;
421
- var displayMonth = props.displayMonth;
422
- var _b = useDayPicker(), fromDate = _b.fromDate, toDate = _b.toDate, locale = _b.locale, styles = _b.styles, classNames = _b.classNames, components = _b.components, formatYearCaption = _b.formatters.formatYearCaption, labelYearDropdown = _b.labels.labelYearDropdown;
423
- var years = [];
424
- if (!fromDate) return (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {});
425
- if (!toDate) return (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {});
426
- var fromYear = fromDate.getFullYear();
427
- var toYear = toDate.getFullYear();
428
- for (var year = fromYear; year <= toYear; year++) years.push(require_setYear.default(require_startOfYear.default(/* @__PURE__ */ new Date()), year));
429
- var handleChange = function(e) {
430
- var newMonth = require_setYear.default(require_startOfMonth.default(displayMonth), Number(e.target.value));
431
- props.onChange(newMonth);
432
- };
433
- return (0, react_jsx_runtime.jsx)((_a = components === null || components === void 0 ? void 0 : components.Dropdown) !== null && _a !== void 0 ? _a : Dropdown, {
434
- name: "years",
435
- "aria-label": labelYearDropdown(),
436
- className: classNames.dropdown_year,
437
- style: styles.dropdown_year,
438
- onChange: handleChange,
439
- value: displayMonth.getFullYear(),
440
- caption: formatYearCaption(displayMonth, { locale }),
441
- children: years.map(function(year) {
442
- return (0, react_jsx_runtime.jsx)("option", {
443
- value: year.getFullYear(),
444
- children: formatYearCaption(year, { locale })
445
- }, year.getFullYear());
446
- })
447
- });
448
- }
449
- /**
450
- * Helper hook for using controlled/uncontrolled values from a component props.
451
- *
452
- * When the value is not controlled, pass `undefined` as `controlledValue` and
453
- * use the returned setter to update it.
454
- *
455
- * When the value is controlled, pass the controlled value as second
456
- * argument, which will be always returned as `value`.
457
- */
458
- function useControlledValue(defaultValue, controlledValue) {
459
- var _a = (0, react.useState)(defaultValue), uncontrolledValue = _a[0], setValue = _a[1];
460
- return [controlledValue === void 0 ? uncontrolledValue : controlledValue, setValue];
461
- }
462
- /** Return the initial month according to the given options. */
463
- function getInitialMonth(context) {
464
- var month = context.month, defaultMonth = context.defaultMonth, today = context.today;
465
- var initialMonth = month || defaultMonth || today || /* @__PURE__ */ new Date();
466
- var toDate = context.toDate, fromDate = context.fromDate, _a = context.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
467
- if (toDate && require_differenceInCalendarMonths.default(toDate, initialMonth) < 0) initialMonth = require_addMonths.default(toDate, -1 * (numberOfMonths - 1));
468
- if (fromDate && require_differenceInCalendarMonths.default(initialMonth, fromDate) < 0) initialMonth = fromDate;
469
- return require_startOfMonth.default(initialMonth);
470
- }
471
- /** Controls the navigation state. */
472
- function useNavigationState() {
473
- var context = useDayPicker();
474
- var _a = useControlledValue(getInitialMonth(context), context.month), month = _a[0], setMonth = _a[1];
475
- var goToMonth = function(date) {
476
- var _a;
477
- if (context.disableNavigation) return;
478
- var month = require_startOfMonth.default(date);
479
- setMonth(month);
480
- (_a = context.onMonthChange) === null || _a === void 0 || _a.call(context, month);
481
- };
482
- return [month, goToMonth];
483
- }
484
- /**
485
- * Return the months to display in the component according to the number of
486
- * months and the from/to date.
487
- */
488
- function getDisplayMonths(month, _a) {
489
- var reverseMonths = _a.reverseMonths, numberOfMonths = _a.numberOfMonths;
490
- var start = require_startOfMonth.default(month);
491
- var monthsDiff = require_differenceInCalendarMonths.default(require_startOfMonth.default(require_addMonths.default(start, numberOfMonths)), start);
492
- var months = [];
493
- for (var i = 0; i < monthsDiff; i++) {
494
- var nextMonth = require_addMonths.default(start, i);
495
- months.push(nextMonth);
496
- }
497
- if (reverseMonths) months = months.reverse();
498
- return months;
499
- }
500
- /**
501
- * Returns the next month the user can navigate to according to the given
502
- * options.
503
- *
504
- * Please note that the next month is not always the next calendar month:
505
- *
506
- * - if after the `toDate` range, is undefined;
507
- * - if the navigation is paged, is the number of months displayed ahead.
508
- *
509
- */
510
- function getNextMonth(startingMonth, options) {
511
- if (options.disableNavigation) return;
512
- var toDate = options.toDate, pagedNavigation = options.pagedNavigation, _a = options.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
513
- var offset = pagedNavigation ? numberOfMonths : 1;
514
- var month = require_startOfMonth.default(startingMonth);
515
- if (!toDate) return require_addMonths.default(month, offset);
516
- if (require_differenceInCalendarMonths.default(toDate, startingMonth) < numberOfMonths) return;
517
- return require_addMonths.default(month, offset);
518
- }
519
- /**
520
- * Returns the next previous the user can navigate to, according to the given
521
- * options.
522
- *
523
- * Please note that the previous month is not always the previous calendar
524
- * month:
525
- *
526
- * - if before the `fromDate` date, is `undefined`;
527
- * - if the navigation is paged, is the number of months displayed before.
528
- *
529
- */
530
- function getPreviousMonth(startingMonth, options) {
531
- if (options.disableNavigation) return;
532
- var fromDate = options.fromDate, pagedNavigation = options.pagedNavigation, _a = options.numberOfMonths;
533
- var offset = pagedNavigation ? _a === void 0 ? 1 : _a : 1;
534
- var month = require_startOfMonth.default(startingMonth);
535
- if (!fromDate) return require_addMonths.default(month, -offset);
536
- if (require_differenceInCalendarMonths.default(month, fromDate) <= 0) return;
537
- return require_addMonths.default(month, -offset);
538
- }
539
- /**
540
- * The Navigation context shares details and methods to navigate the months in DayPicker.
541
- * Access this context from the {@link useNavigation} hook.
542
- */
543
- var NavigationContext = (0, react.createContext)(void 0);
544
- /** Provides the values for the {@link NavigationContext}. */
545
- function NavigationProvider(props) {
546
- var dayPicker = useDayPicker();
547
- var _a = useNavigationState(), currentMonth = _a[0], goToMonth = _a[1];
548
- var displayMonths = getDisplayMonths(currentMonth, dayPicker);
549
- var nextMonth = getNextMonth(currentMonth, dayPicker);
550
- var previousMonth = getPreviousMonth(currentMonth, dayPicker);
551
- var isDateDisplayed = function(date) {
552
- return displayMonths.some(function(displayMonth) {
553
- return require_isSameMonth.default(date, displayMonth);
554
- });
555
- };
556
- var goToDate = function(date, refDate) {
557
- if (isDateDisplayed(date)) return;
558
- if (refDate && require_isBefore.default(date, refDate)) goToMonth(require_addMonths.default(date, 1 + dayPicker.numberOfMonths * -1));
559
- else goToMonth(date);
560
- };
561
- var value = {
562
- currentMonth,
563
- displayMonths,
564
- goToMonth,
565
- goToDate,
566
- previousMonth,
567
- nextMonth,
568
- isDateDisplayed
569
- };
570
- return (0, react_jsx_runtime.jsx)(NavigationContext.Provider, {
571
- value,
572
- children: props.children
573
- });
574
- }
575
- /**
576
- * Hook to access the {@link NavigationContextValue}. Use this hook to navigate
577
- * between months or years in DayPicker.
578
- *
579
- * This hook is meant to be used inside internal or custom components.
580
- */
581
- function useNavigation() {
582
- var context = (0, react.useContext)(NavigationContext);
583
- if (!context) throw new Error("useNavigation must be used within a NavigationProvider");
584
- return context;
585
- }
586
- /**
587
- * Render a caption with the dropdowns to navigate between months and years.
588
- */
589
- function CaptionDropdowns(props) {
590
- var _a;
591
- var _b = useDayPicker(), classNames = _b.classNames, styles = _b.styles, components = _b.components;
592
- var goToMonth = useNavigation().goToMonth;
593
- var handleMonthChange = function(newMonth) {
594
- goToMonth(require_addMonths.default(newMonth, props.displayIndex ? -props.displayIndex : 0));
595
- };
596
- var captionLabel = (0, react_jsx_runtime.jsx)((_a = components === null || components === void 0 ? void 0 : components.CaptionLabel) !== null && _a !== void 0 ? _a : CaptionLabel, {
597
- id: props.id,
598
- displayMonth: props.displayMonth
599
- });
600
- return (0, react_jsx_runtime.jsxs)("div", {
601
- className: classNames.caption_dropdowns,
602
- style: styles.caption_dropdowns,
603
- children: [
604
- (0, react_jsx_runtime.jsx)("div", {
605
- className: classNames.vhidden,
606
- children: captionLabel
607
- }),
608
- (0, react_jsx_runtime.jsx)(MonthsDropdown, {
609
- onChange: handleMonthChange,
610
- displayMonth: props.displayMonth
611
- }),
612
- (0, react_jsx_runtime.jsx)(YearsDropdown, {
613
- onChange: handleMonthChange,
614
- displayMonth: props.displayMonth
615
- })
616
- ]
617
- });
618
- }
619
- /**
620
- * Render the "previous month" button in the navigation.
621
- */
622
- function IconLeft(props) {
623
- return (0, react_jsx_runtime.jsx)("svg", __assign({
624
- width: "16px",
625
- height: "16px",
626
- viewBox: "0 0 120 120"
627
- }, props, { children: (0, react_jsx_runtime.jsx)("path", {
628
- d: "M69.490332,3.34314575 C72.6145263,0.218951416 77.6798462,0.218951416 80.8040405,3.34314575 C83.8617626,6.40086786 83.9268205,11.3179931 80.9992143,14.4548388 L80.8040405,14.6568542 L35.461,60 L80.8040405,105.343146 C83.8617626,108.400868 83.9268205,113.317993 80.9992143,116.454839 L80.8040405,116.656854 C77.7463184,119.714576 72.8291931,119.779634 69.6923475,116.852028 L69.490332,116.656854 L18.490332,65.6568542 C15.4326099,62.5991321 15.367552,57.6820069 18.2951583,54.5451612 L18.490332,54.3431458 L69.490332,3.34314575 Z",
629
- fill: "currentColor",
630
- fillRule: "nonzero"
631
- }) }));
632
- }
633
- /**
634
- * Render the "next month" button in the navigation.
635
- */
636
- function IconRight(props) {
637
- return (0, react_jsx_runtime.jsx)("svg", __assign({
638
- width: "16px",
639
- height: "16px",
640
- viewBox: "0 0 120 120"
641
- }, props, { children: (0, react_jsx_runtime.jsx)("path", {
642
- d: "M49.8040405,3.34314575 C46.6798462,0.218951416 41.6145263,0.218951416 38.490332,3.34314575 C35.4326099,6.40086786 35.367552,11.3179931 38.2951583,14.4548388 L38.490332,14.6568542 L83.8333725,60 L38.490332,105.343146 C35.4326099,108.400868 35.367552,113.317993 38.2951583,116.454839 L38.490332,116.656854 C41.5480541,119.714576 46.4651794,119.779634 49.602025,116.852028 L49.8040405,116.656854 L100.804041,65.6568542 C103.861763,62.5991321 103.926821,57.6820069 100.999214,54.5451612 L100.804041,54.3431458 L49.8040405,3.34314575 Z",
643
- fill: "currentColor"
644
- }) }));
645
- }
646
- /** Render a button HTML element applying the reset class name. */
647
- var Button = (0, react.forwardRef)(function(props, ref) {
648
- var _a = useDayPicker(), classNames = _a.classNames, styles = _a.styles;
649
- var classNamesArr = [classNames.button_reset, classNames.button];
650
- if (props.className) classNamesArr.push(props.className);
651
- var className = classNamesArr.join(" ");
652
- var style = __assign(__assign({}, styles.button_reset), styles.button);
653
- if (props.style) Object.assign(style, props.style);
654
- return (0, react_jsx_runtime.jsx)("button", __assign({}, props, {
655
- ref,
656
- type: "button",
657
- className,
658
- style
659
- }));
660
- });
661
- /** A component rendering the navigation buttons or the drop-downs. */
662
- function Navigation(props) {
663
- var _a, _b;
664
- var _c = useDayPicker(), dir = _c.dir, locale = _c.locale, classNames = _c.classNames, styles = _c.styles, _d = _c.labels, labelPrevious = _d.labelPrevious, labelNext = _d.labelNext, components = _c.components;
665
- if (!props.nextMonth && !props.previousMonth) return (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {});
666
- var previousLabel = labelPrevious(props.previousMonth, { locale });
667
- var previousClassName = [classNames.nav_button, classNames.nav_button_previous].join(" ");
668
- var nextLabel = labelNext(props.nextMonth, { locale });
669
- var nextClassName = [classNames.nav_button, classNames.nav_button_next].join(" ");
670
- var IconRightComponent = (_a = components === null || components === void 0 ? void 0 : components.IconRight) !== null && _a !== void 0 ? _a : IconRight;
671
- var IconLeftComponent = (_b = components === null || components === void 0 ? void 0 : components.IconLeft) !== null && _b !== void 0 ? _b : IconLeft;
672
- return (0, react_jsx_runtime.jsxs)("div", {
673
- className: classNames.nav,
674
- style: styles.nav,
675
- children: [!props.hidePrevious && (0, react_jsx_runtime.jsx)(Button, {
676
- name: "previous-month",
677
- "aria-label": previousLabel,
678
- className: previousClassName,
679
- style: styles.nav_button_previous,
680
- disabled: !props.previousMonth,
681
- onClick: props.onPreviousClick,
682
- children: dir === "rtl" ? (0, react_jsx_runtime.jsx)(IconRightComponent, {
683
- className: classNames.nav_icon,
684
- style: styles.nav_icon
685
- }) : (0, react_jsx_runtime.jsx)(IconLeftComponent, {
686
- className: classNames.nav_icon,
687
- style: styles.nav_icon
688
- })
689
- }), !props.hideNext && (0, react_jsx_runtime.jsx)(Button, {
690
- name: "next-month",
691
- "aria-label": nextLabel,
692
- className: nextClassName,
693
- style: styles.nav_button_next,
694
- disabled: !props.nextMonth,
695
- onClick: props.onNextClick,
696
- children: dir === "rtl" ? (0, react_jsx_runtime.jsx)(IconLeftComponent, {
697
- className: classNames.nav_icon,
698
- style: styles.nav_icon
699
- }) : (0, react_jsx_runtime.jsx)(IconRightComponent, {
700
- className: classNames.nav_icon,
701
- style: styles.nav_icon
702
- })
703
- })]
704
- });
705
- }
706
- /**
707
- * Render a caption with a button-based navigation.
708
- */
709
- function CaptionNavigation(props) {
710
- var numberOfMonths = useDayPicker().numberOfMonths;
711
- var _a = useNavigation(), previousMonth = _a.previousMonth, nextMonth = _a.nextMonth, goToMonth = _a.goToMonth, displayMonths = _a.displayMonths;
712
- var displayIndex = displayMonths.findIndex(function(month) {
713
- return require_isSameMonth.default(props.displayMonth, month);
714
- });
715
- var isFirst = displayIndex === 0;
716
- var isLast = displayIndex === displayMonths.length - 1;
717
- var hideNext = numberOfMonths > 1 && (isFirst || !isLast);
718
- var hidePrevious = numberOfMonths > 1 && (isLast || !isFirst);
719
- var handlePreviousClick = function() {
720
- if (!previousMonth) return;
721
- goToMonth(previousMonth);
722
- };
723
- var handleNextClick = function() {
724
- if (!nextMonth) return;
725
- goToMonth(nextMonth);
726
- };
727
- return (0, react_jsx_runtime.jsx)(Navigation, {
728
- displayMonth: props.displayMonth,
729
- hideNext,
730
- hidePrevious,
731
- nextMonth,
732
- previousMonth,
733
- onPreviousClick: handlePreviousClick,
734
- onNextClick: handleNextClick
735
- });
736
- }
737
- /**
738
- * Render the caption of a month. The caption has a different layout when
739
- * setting the {@link DayPickerBase.captionLayout} prop.
740
- */
741
- function Caption(props) {
742
- var _a;
743
- var _b = useDayPicker(), classNames = _b.classNames, disableNavigation = _b.disableNavigation, styles = _b.styles, captionLayout = _b.captionLayout, components = _b.components;
744
- var CaptionLabelComponent = (_a = components === null || components === void 0 ? void 0 : components.CaptionLabel) !== null && _a !== void 0 ? _a : CaptionLabel;
745
- var caption;
746
- if (disableNavigation) caption = (0, react_jsx_runtime.jsx)(CaptionLabelComponent, {
747
- id: props.id,
748
- displayMonth: props.displayMonth
749
- });
750
- else if (captionLayout === "dropdown") caption = (0, react_jsx_runtime.jsx)(CaptionDropdowns, {
751
- displayMonth: props.displayMonth,
752
- id: props.id
753
- });
754
- else if (captionLayout === "dropdown-buttons") caption = (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [(0, react_jsx_runtime.jsx)(CaptionDropdowns, {
755
- displayMonth: props.displayMonth,
756
- displayIndex: props.displayIndex,
757
- id: props.id
758
- }), (0, react_jsx_runtime.jsx)(CaptionNavigation, {
759
- displayMonth: props.displayMonth,
760
- displayIndex: props.displayIndex,
761
- id: props.id
762
- })] });
763
- else caption = (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [(0, react_jsx_runtime.jsx)(CaptionLabelComponent, {
764
- id: props.id,
765
- displayMonth: props.displayMonth,
766
- displayIndex: props.displayIndex
767
- }), (0, react_jsx_runtime.jsx)(CaptionNavigation, {
768
- displayMonth: props.displayMonth,
769
- id: props.id
770
- })] });
771
- return (0, react_jsx_runtime.jsx)("div", {
772
- className: classNames.caption,
773
- style: styles.caption,
774
- children: caption
775
- });
776
- }
777
- /** Render the Footer component (empty as default).*/
778
- function Footer(props) {
779
- var _a = useDayPicker(), footer = _a.footer, styles = _a.styles, tfoot = _a.classNames.tfoot;
780
- if (!footer) return (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {});
781
- return (0, react_jsx_runtime.jsx)("tfoot", {
782
- className: tfoot,
783
- style: styles.tfoot,
784
- children: (0, react_jsx_runtime.jsx)("tr", { children: (0, react_jsx_runtime.jsx)("td", {
785
- colSpan: 8,
786
- children: footer
787
- }) })
788
- });
789
- }
790
- /**
791
- * Generate a series of 7 days, starting from the week, to use for formatting
792
- * the weekday names (Monday, Tuesday, etc.).
793
- */
794
- function getWeekdays(locale, weekStartsOn, ISOWeek) {
795
- var start = ISOWeek ? require_startOfISOWeek.default(/* @__PURE__ */ new Date()) : require_startOfWeek.default(/* @__PURE__ */ new Date(), {
796
- locale,
797
- weekStartsOn
798
- });
799
- var days = [];
800
- for (var i = 0; i < 7; i++) {
801
- var day = require_addDays.default(start, i);
802
- days.push(day);
803
- }
804
- return days;
805
- }
806
- /**
807
- * Render the HeadRow component - i.e. the table head row with the weekday names.
808
- */
809
- function HeadRow() {
810
- var _a = useDayPicker(), classNames = _a.classNames, styles = _a.styles, showWeekNumber = _a.showWeekNumber, locale = _a.locale, weekStartsOn = _a.weekStartsOn, ISOWeek = _a.ISOWeek, formatWeekdayName = _a.formatters.formatWeekdayName, labelWeekday = _a.labels.labelWeekday;
811
- var weekdays = getWeekdays(locale, weekStartsOn, ISOWeek);
812
- return (0, react_jsx_runtime.jsxs)("tr", {
813
- style: styles.head_row,
814
- className: classNames.head_row,
815
- children: [showWeekNumber && (0, react_jsx_runtime.jsx)("td", {
816
- style: styles.head_cell,
817
- className: classNames.head_cell
818
- }), weekdays.map(function(weekday, i) {
819
- return (0, react_jsx_runtime.jsx)("th", {
820
- scope: "col",
821
- className: classNames.head_cell,
822
- style: styles.head_cell,
823
- "aria-label": labelWeekday(weekday, { locale }),
824
- children: formatWeekdayName(weekday, { locale })
825
- }, i);
826
- })]
827
- });
828
- }
829
- /** Render the table head. */
830
- function Head() {
831
- var _a;
832
- var _b = useDayPicker(), classNames = _b.classNames, styles = _b.styles, components = _b.components;
833
- var HeadRowComponent = (_a = components === null || components === void 0 ? void 0 : components.HeadRow) !== null && _a !== void 0 ? _a : HeadRow;
834
- return (0, react_jsx_runtime.jsx)("thead", {
835
- style: styles.head,
836
- className: classNames.head,
837
- children: (0, react_jsx_runtime.jsx)(HeadRowComponent, {})
838
- });
839
- }
840
- /** Render the content of the day cell. */
841
- function DayContent(props) {
842
- var _a = useDayPicker(), locale = _a.locale, formatDay = _a.formatters.formatDay;
843
- return (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: formatDay(props.date, { locale }) });
844
- }
845
- /**
846
- * The SelectMultiple context shares details about the selected days when in
847
- * multiple selection mode.
848
- *
849
- * Access this context from the {@link useSelectMultiple} hook.
850
- */
851
- var SelectMultipleContext = (0, react.createContext)(void 0);
852
- /** Provides the values for the {@link SelectMultipleContext}. */
853
- function SelectMultipleProvider(props) {
854
- if (!isDayPickerMultiple(props.initialProps)) return (0, react_jsx_runtime.jsx)(SelectMultipleContext.Provider, {
855
- value: {
856
- selected: void 0,
857
- modifiers: { disabled: [] }
858
- },
859
- children: props.children
860
- });
861
- return (0, react_jsx_runtime.jsx)(SelectMultipleProviderInternal, {
862
- initialProps: props.initialProps,
863
- children: props.children
864
- });
865
- }
866
- function SelectMultipleProviderInternal(_a) {
867
- var initialProps = _a.initialProps, children = _a.children;
868
- var selected = initialProps.selected, min = initialProps.min, max = initialProps.max;
869
- var onDayClick = function(day, activeModifiers, e) {
870
- var _a, _b;
871
- (_a = initialProps.onDayClick) === null || _a === void 0 || _a.call(initialProps, day, activeModifiers, e);
872
- if (Boolean(activeModifiers.selected && min && (selected === null || selected === void 0 ? void 0 : selected.length) === min)) return;
873
- if (Boolean(!activeModifiers.selected && max && (selected === null || selected === void 0 ? void 0 : selected.length) === max)) return;
874
- var selectedDays = selected ? __spreadArray([], selected, true) : [];
875
- if (activeModifiers.selected) {
876
- var index = selectedDays.findIndex(function(selectedDay) {
877
- return require_isSameDay.default(day, selectedDay);
878
- });
879
- selectedDays.splice(index, 1);
880
- } else selectedDays.push(day);
881
- (_b = initialProps.onSelect) === null || _b === void 0 || _b.call(initialProps, selectedDays, day, activeModifiers, e);
882
- };
883
- var modifiers = { disabled: [] };
884
- if (selected) modifiers.disabled.push(function(day) {
885
- var isMaxSelected = max && selected.length > max - 1;
886
- var isSelected = selected.some(function(selectedDay) {
887
- return require_isSameDay.default(selectedDay, day);
888
- });
889
- return Boolean(isMaxSelected && !isSelected);
890
- });
891
- var contextValue = {
892
- selected,
893
- onDayClick,
894
- modifiers
895
- };
896
- return (0, react_jsx_runtime.jsx)(SelectMultipleContext.Provider, {
897
- value: contextValue,
898
- children
899
- });
900
- }
901
- /**
902
- * Hook to access the {@link SelectMultipleContextValue}.
903
- *
904
- * This hook is meant to be used inside internal or custom components.
905
- */
906
- function useSelectMultiple() {
907
- var context = (0, react.useContext)(SelectMultipleContext);
908
- if (!context) throw new Error("useSelectMultiple must be used within a SelectMultipleProvider");
909
- return context;
910
- }
911
- /**
912
- * Add a day to an existing range.
913
- *
914
- * The returned range takes in account the `undefined` values and if the added
915
- * day is already present in the range.
916
- */
917
- function addToRange(day, range) {
918
- var _a = range || {}, from = _a.from, to = _a.to;
919
- if (from && to) {
920
- if (require_isSameDay.default(to, day) && require_isSameDay.default(from, day)) return;
921
- if (require_isSameDay.default(to, day)) return {
922
- from: to,
923
- to: void 0
924
- };
925
- if (require_isSameDay.default(from, day)) return;
926
- if (require_isAfter.default(from, day)) return {
927
- from: day,
928
- to
929
- };
930
- return {
931
- from,
932
- to: day
933
- };
934
- }
935
- if (to) {
936
- if (require_isAfter.default(day, to)) return {
937
- from: to,
938
- to: day
939
- };
940
- return {
941
- from: day,
942
- to
943
- };
944
- }
945
- if (from) {
946
- if (require_isBefore.default(day, from)) return {
947
- from: day,
948
- to: from
949
- };
950
- return {
951
- from,
952
- to: day
953
- };
954
- }
955
- return {
956
- from: day,
957
- to: void 0
958
- };
959
- }
960
- /**
961
- * The SelectRange context shares details about the selected days when in
962
- * range selection mode.
963
- *
964
- * Access this context from the {@link useSelectRange} hook.
965
- */
966
- var SelectRangeContext = (0, react.createContext)(void 0);
967
- /** Provides the values for the {@link SelectRangeProvider}. */
968
- function SelectRangeProvider(props) {
969
- if (!isDayPickerRange(props.initialProps)) return (0, react_jsx_runtime.jsx)(SelectRangeContext.Provider, {
970
- value: {
971
- selected: void 0,
972
- modifiers: {
973
- range_start: [],
974
- range_end: [],
975
- range_middle: [],
976
- disabled: []
977
- }
978
- },
979
- children: props.children
980
- });
981
- return (0, react_jsx_runtime.jsx)(SelectRangeProviderInternal, {
982
- initialProps: props.initialProps,
983
- children: props.children
984
- });
985
- }
986
- function SelectRangeProviderInternal(_a) {
987
- var initialProps = _a.initialProps, children = _a.children;
988
- var selected = initialProps.selected;
989
- var _b = selected || {}, selectedFrom = _b.from, selectedTo = _b.to;
990
- var min = initialProps.min;
991
- var max = initialProps.max;
992
- var onDayClick = function(day, activeModifiers, e) {
993
- var _a, _b;
994
- (_a = initialProps.onDayClick) === null || _a === void 0 || _a.call(initialProps, day, activeModifiers, e);
995
- var newRange = addToRange(day, selected);
996
- (_b = initialProps.onSelect) === null || _b === void 0 || _b.call(initialProps, newRange, day, activeModifiers, e);
997
- };
998
- var modifiers = {
999
- range_start: [],
1000
- range_end: [],
1001
- range_middle: [],
1002
- disabled: []
1003
- };
1004
- if (selectedFrom) {
1005
- modifiers.range_start = [selectedFrom];
1006
- if (!selectedTo) modifiers.range_end = [selectedFrom];
1007
- else {
1008
- modifiers.range_end = [selectedTo];
1009
- if (!require_isSameDay.default(selectedFrom, selectedTo)) modifiers.range_middle = [{
1010
- after: selectedFrom,
1011
- before: selectedTo
1012
- }];
1013
- }
1014
- } else if (selectedTo) {
1015
- modifiers.range_start = [selectedTo];
1016
- modifiers.range_end = [selectedTo];
1017
- }
1018
- if (min) {
1019
- if (selectedFrom && !selectedTo) modifiers.disabled.push({
1020
- after: require_subDays.default(selectedFrom, min - 1),
1021
- before: require_addDays.default(selectedFrom, min - 1)
1022
- });
1023
- if (selectedFrom && selectedTo) modifiers.disabled.push({
1024
- after: selectedFrom,
1025
- before: require_addDays.default(selectedFrom, min - 1)
1026
- });
1027
- if (!selectedFrom && selectedTo) modifiers.disabled.push({
1028
- after: require_subDays.default(selectedTo, min - 1),
1029
- before: require_addDays.default(selectedTo, min - 1)
1030
- });
1031
- }
1032
- if (max) {
1033
- if (selectedFrom && !selectedTo) {
1034
- modifiers.disabled.push({ before: require_addDays.default(selectedFrom, -max + 1) });
1035
- modifiers.disabled.push({ after: require_addDays.default(selectedFrom, max - 1) });
1036
- }
1037
- if (selectedFrom && selectedTo) {
1038
- var offset = max - (require_differenceInCalendarDays.default(selectedTo, selectedFrom) + 1);
1039
- modifiers.disabled.push({ before: require_subDays.default(selectedFrom, offset) });
1040
- modifiers.disabled.push({ after: require_addDays.default(selectedTo, offset) });
1041
- }
1042
- if (!selectedFrom && selectedTo) {
1043
- modifiers.disabled.push({ before: require_addDays.default(selectedTo, -max + 1) });
1044
- modifiers.disabled.push({ after: require_addDays.default(selectedTo, max - 1) });
1045
- }
1046
- }
1047
- return (0, react_jsx_runtime.jsx)(SelectRangeContext.Provider, {
1048
- value: {
1049
- selected,
1050
- onDayClick,
1051
- modifiers
1052
- },
1053
- children
1054
- });
1055
- }
1056
- /**
1057
- * Hook to access the {@link SelectRangeContextValue}.
1058
- *
1059
- * This hook is meant to be used inside internal or custom components.
1060
- */
1061
- function useSelectRange() {
1062
- var context = (0, react.useContext)(SelectRangeContext);
1063
- if (!context) throw new Error("useSelectRange must be used within a SelectRangeProvider");
1064
- return context;
1065
- }
1066
- /** Normalize to array a matcher input. */
1067
- function matcherToArray(matcher) {
1068
- if (Array.isArray(matcher)) return __spreadArray([], matcher, true);
1069
- else if (matcher !== void 0) return [matcher];
1070
- else return [];
1071
- }
1072
- /** Create CustomModifiers from dayModifiers */
1073
- function getCustomModifiers(dayModifiers) {
1074
- var customModifiers = {};
1075
- Object.entries(dayModifiers).forEach(function(_a) {
1076
- var modifier = _a[0], matcher = _a[1];
1077
- customModifiers[modifier] = matcherToArray(matcher);
1078
- });
1079
- return customModifiers;
1080
- }
1081
- /** The name of the modifiers that are used internally by DayPicker. */
1082
- var InternalModifier;
1083
- (function(InternalModifier) {
1084
- InternalModifier["Outside"] = "outside";
1085
- /** Name of the modifier applied to the disabled days, using the `disabled` prop. */
1086
- InternalModifier["Disabled"] = "disabled";
1087
- /** Name of the modifier applied to the selected days using the `selected` prop). */
1088
- InternalModifier["Selected"] = "selected";
1089
- /** Name of the modifier applied to the hidden days using the `hidden` prop). */
1090
- InternalModifier["Hidden"] = "hidden";
1091
- /** Name of the modifier applied to the day specified using the `today` prop). */
1092
- InternalModifier["Today"] = "today";
1093
- /** The modifier applied to the day starting a selected range, when in range selection mode. */
1094
- InternalModifier["RangeStart"] = "range_start";
1095
- /** The modifier applied to the day ending a selected range, when in range selection mode. */
1096
- InternalModifier["RangeEnd"] = "range_end";
1097
- /** The modifier applied to the days between the start and the end of a selected range, when in range selection mode. */
1098
- InternalModifier["RangeMiddle"] = "range_middle";
1099
- })(InternalModifier || (InternalModifier = {}));
1100
- var Selected = InternalModifier.Selected, Disabled = InternalModifier.Disabled, Hidden = InternalModifier.Hidden, Today = InternalModifier.Today, RangeEnd = InternalModifier.RangeEnd, RangeMiddle = InternalModifier.RangeMiddle, RangeStart = InternalModifier.RangeStart, Outside = InternalModifier.Outside;
1101
- /** Return the {@link InternalModifiers} from the DayPicker and select contexts. */
1102
- function getInternalModifiers(dayPicker, selectMultiple, selectRange) {
1103
- var _a;
1104
- var internalModifiers = (_a = {}, _a[Selected] = matcherToArray(dayPicker.selected), _a[Disabled] = matcherToArray(dayPicker.disabled), _a[Hidden] = matcherToArray(dayPicker.hidden), _a[Today] = [dayPicker.today], _a[RangeEnd] = [], _a[RangeMiddle] = [], _a[RangeStart] = [], _a[Outside] = [], _a);
1105
- if (dayPicker.fromDate) internalModifiers[Disabled].push({ before: dayPicker.fromDate });
1106
- if (dayPicker.toDate) internalModifiers[Disabled].push({ after: dayPicker.toDate });
1107
- if (isDayPickerMultiple(dayPicker)) internalModifiers[Disabled] = internalModifiers[Disabled].concat(selectMultiple.modifiers[Disabled]);
1108
- else if (isDayPickerRange(dayPicker)) {
1109
- internalModifiers[Disabled] = internalModifiers[Disabled].concat(selectRange.modifiers[Disabled]);
1110
- internalModifiers[RangeStart] = selectRange.modifiers[RangeStart];
1111
- internalModifiers[RangeMiddle] = selectRange.modifiers[RangeMiddle];
1112
- internalModifiers[RangeEnd] = selectRange.modifiers[RangeEnd];
1113
- }
1114
- return internalModifiers;
1115
- }
1116
- /** The Modifiers context store the modifiers used in DayPicker. To access the value of this context, use {@link useModifiers}. */
1117
- var ModifiersContext = (0, react.createContext)(void 0);
1118
- /** Provide the value for the {@link ModifiersContext}. */
1119
- function ModifiersProvider(props) {
1120
- var dayPicker = useDayPicker();
1121
- var internalModifiers = getInternalModifiers(dayPicker, useSelectMultiple(), useSelectRange());
1122
- var customModifiers = getCustomModifiers(dayPicker.modifiers);
1123
- var modifiers = __assign(__assign({}, internalModifiers), customModifiers);
1124
- return (0, react_jsx_runtime.jsx)(ModifiersContext.Provider, {
1125
- value: modifiers,
1126
- children: props.children
1127
- });
1128
- }
1129
- /**
1130
- * Return the modifiers used by DayPicker.
1131
- *
1132
- * This hook is meant to be used inside internal or custom components.
1133
- * Requires to be wrapped into {@link ModifiersProvider}.
1134
- *
1135
- */
1136
- function useModifiers() {
1137
- var context = (0, react.useContext)(ModifiersContext);
1138
- if (!context) throw new Error("useModifiers must be used within a ModifiersProvider");
1139
- return context;
1140
- }
1141
- /** Returns true if `matcher` is of type {@link DateInterval}. */
1142
- function isDateInterval(matcher) {
1143
- return Boolean(matcher && typeof matcher === "object" && "before" in matcher && "after" in matcher);
1144
- }
1145
- /** Returns true if `value` is a {@link DateRange} type. */
1146
- function isDateRange(value) {
1147
- return Boolean(value && typeof value === "object" && "from" in value);
1148
- }
1149
- /** Returns true if `value` is of type {@link DateAfter}. */
1150
- function isDateAfterType(value) {
1151
- return Boolean(value && typeof value === "object" && "after" in value);
1152
- }
1153
- /** Returns true if `value` is of type {@link DateBefore}. */
1154
- function isDateBeforeType(value) {
1155
- return Boolean(value && typeof value === "object" && "before" in value);
1156
- }
1157
- /** Returns true if `value` is a {@link DayOfWeek} type. */
1158
- function isDayOfWeekType(value) {
1159
- return Boolean(value && typeof value === "object" && "dayOfWeek" in value);
1160
- }
1161
- /** Return `true` whether `date` is inside `range`. */
1162
- function isDateInRange(date, range) {
1163
- var _a;
1164
- var from = range.from, to = range.to;
1165
- if (from && to) {
1166
- if (require_differenceInCalendarDays.default(to, from) < 0) _a = [to, from], from = _a[0], to = _a[1];
1167
- return require_differenceInCalendarDays.default(date, from) >= 0 && require_differenceInCalendarDays.default(to, date) >= 0;
1168
- }
1169
- if (to) return require_isSameDay.default(to, date);
1170
- if (from) return require_isSameDay.default(from, date);
1171
- return false;
1172
- }
1173
- /** Returns true if `value` is a Date type. */
1174
- function isDateType(value) {
1175
- return require_isDate.default(value);
1176
- }
1177
- /** Returns true if `value` is an array of valid dates. */
1178
- function isArrayOfDates(value) {
1179
- return Array.isArray(value) && value.every(require_isDate.default);
1180
- }
1181
- /**
1182
- * Returns whether a day matches against at least one of the given Matchers.
1183
- *
1184
- * ```
1185
- * const day = new Date(2022, 5, 19);
1186
- * const matcher1: DateRange = {
1187
- * from: new Date(2021, 12, 21),
1188
- * to: new Date(2021, 12, 30)
1189
- * }
1190
- * const matcher2: DateRange = {
1191
- * from: new Date(2022, 5, 1),
1192
- * to: new Date(2022, 5, 23)
1193
- * }
1194
- *
1195
- * const isMatch(day, [matcher1, matcher2]); // true, since day is in the matcher1 range.
1196
- * ```
1197
- * */
1198
- function isMatch(day, matchers) {
1199
- return matchers.some(function(matcher) {
1200
- if (typeof matcher === "boolean") return matcher;
1201
- if (isDateType(matcher)) return require_isSameDay.default(day, matcher);
1202
- if (isArrayOfDates(matcher)) return matcher.includes(day);
1203
- if (isDateRange(matcher)) return isDateInRange(day, matcher);
1204
- if (isDayOfWeekType(matcher)) return matcher.dayOfWeek.includes(day.getDay());
1205
- if (isDateInterval(matcher)) {
1206
- var diffBefore = require_differenceInCalendarDays.default(matcher.before, day);
1207
- var diffAfter = require_differenceInCalendarDays.default(matcher.after, day);
1208
- var isDayBefore = diffBefore > 0;
1209
- var isDayAfter = diffAfter < 0;
1210
- if (require_isAfter.default(matcher.before, matcher.after)) return isDayAfter && isDayBefore;
1211
- else return isDayBefore || isDayAfter;
1212
- }
1213
- if (isDateAfterType(matcher)) return require_differenceInCalendarDays.default(day, matcher.after) > 0;
1214
- if (isDateBeforeType(matcher)) return require_differenceInCalendarDays.default(matcher.before, day) > 0;
1215
- if (typeof matcher === "function") return matcher(day);
1216
- return false;
1217
- });
1218
- }
1219
- /** Return the active modifiers for the given day. */
1220
- function getActiveModifiers(day, modifiers, displayMonth) {
1221
- var matchedModifiers = Object.keys(modifiers).reduce(function(result, key) {
1222
- var modifier = modifiers[key];
1223
- if (isMatch(day, modifier)) result.push(key);
1224
- return result;
1225
- }, []);
1226
- var activeModifiers = {};
1227
- matchedModifiers.forEach(function(modifier) {
1228
- return activeModifiers[modifier] = true;
1229
- });
1230
- if (displayMonth && !require_isSameMonth.default(day, displayMonth)) activeModifiers.outside = true;
1231
- return activeModifiers;
1232
- }
1233
- /**
1234
- * Returns the day that should be the target of the focus when DayPicker is
1235
- * rendered the first time.
1236
- *
1237
- * TODO: this function doesn't consider if the day is outside the month. We
1238
- * implemented this check in `useDayRender` but it should probably go here. See
1239
- * https://github.com/gpbl/react-day-picker/pull/1576
1240
- */
1241
- function getInitialFocusTarget(displayMonths, modifiers) {
1242
- var firstDayInMonth = require_startOfMonth.default(displayMonths[0]);
1243
- var lastDayInMonth = require_endOfMonth.default(displayMonths[displayMonths.length - 1]);
1244
- var firstFocusableDay;
1245
- var today;
1246
- var date = firstDayInMonth;
1247
- while (date <= lastDayInMonth) {
1248
- var activeModifiers = getActiveModifiers(date, modifiers);
1249
- if (!(!activeModifiers.disabled && !activeModifiers.hidden)) {
1250
- date = require_addDays.default(date, 1);
1251
- continue;
1252
- }
1253
- if (activeModifiers.selected) return date;
1254
- if (activeModifiers.today && !today) today = date;
1255
- if (!firstFocusableDay) firstFocusableDay = date;
1256
- date = require_addDays.default(date, 1);
1257
- }
1258
- if (today) return today;
1259
- else return firstFocusableDay;
1260
- }
1261
- var MAX_RETRY = 365;
1262
- /** Return the next date to be focused. */
1263
- function getNextFocus(focusedDay, options) {
1264
- var moveBy = options.moveBy, direction = options.direction, context = options.context, modifiers = options.modifiers, _a = options.retry, retry = _a === void 0 ? {
1265
- count: 0,
1266
- lastFocused: focusedDay
1267
- } : _a;
1268
- var weekStartsOn = context.weekStartsOn, fromDate = context.fromDate, toDate = context.toDate, locale = context.locale;
1269
- var newFocusedDay = {
1270
- day: require_addDays.default,
1271
- week: require_addWeeks.default,
1272
- month: require_addMonths.default,
1273
- year: require_addYears.default,
1274
- startOfWeek: function(date) {
1275
- return context.ISOWeek ? require_startOfISOWeek.default(date) : require_startOfWeek.default(date, {
1276
- locale,
1277
- weekStartsOn
1278
- });
1279
- },
1280
- endOfWeek: function(date) {
1281
- return context.ISOWeek ? require_endOfISOWeek.default(date) : require_endOfWeek.default(date, {
1282
- locale,
1283
- weekStartsOn
1284
- });
1285
- }
1286
- }[moveBy](focusedDay, direction === "after" ? 1 : -1);
1287
- if (direction === "before" && fromDate) newFocusedDay = require_max.default([fromDate, newFocusedDay]);
1288
- else if (direction === "after" && toDate) newFocusedDay = require_min.default([toDate, newFocusedDay]);
1289
- var isFocusable = true;
1290
- if (modifiers) {
1291
- var activeModifiers = getActiveModifiers(newFocusedDay, modifiers);
1292
- isFocusable = !activeModifiers.disabled && !activeModifiers.hidden;
1293
- }
1294
- if (isFocusable) return newFocusedDay;
1295
- else {
1296
- if (retry.count > MAX_RETRY) return retry.lastFocused;
1297
- return getNextFocus(newFocusedDay, {
1298
- moveBy,
1299
- direction,
1300
- context,
1301
- modifiers,
1302
- retry: __assign(__assign({}, retry), { count: retry.count + 1 })
1303
- });
1304
- }
1305
- }
1306
- /**
1307
- * The Focus context shares details about the focused day for the keyboard
1308
- *
1309
- * Access this context from the {@link useFocusContext} hook.
1310
- */
1311
- var FocusContext = (0, react.createContext)(void 0);
1312
- /** The provider for the {@link FocusContext}. */
1313
- function FocusProvider(props) {
1314
- var navigation = useNavigation();
1315
- var modifiers = useModifiers();
1316
- var _a = (0, react.useState)(), focusedDay = _a[0], setFocusedDay = _a[1];
1317
- var _b = (0, react.useState)(), lastFocused = _b[0], setLastFocused = _b[1];
1318
- var initialFocusTarget = getInitialFocusTarget(navigation.displayMonths, modifiers);
1319
- var focusTarget = (focusedDay !== null && focusedDay !== void 0 ? focusedDay : lastFocused && navigation.isDateDisplayed(lastFocused)) ? lastFocused : initialFocusTarget;
1320
- var blur = function() {
1321
- setLastFocused(focusedDay);
1322
- setFocusedDay(void 0);
1323
- };
1324
- var focus = function(date) {
1325
- setFocusedDay(date);
1326
- };
1327
- var context = useDayPicker();
1328
- var moveFocus = function(moveBy, direction) {
1329
- if (!focusedDay) return;
1330
- var nextFocused = getNextFocus(focusedDay, {
1331
- moveBy,
1332
- direction,
1333
- context,
1334
- modifiers
1335
- });
1336
- if (require_isSameDay.default(focusedDay, nextFocused)) return void 0;
1337
- navigation.goToDate(nextFocused, focusedDay);
1338
- focus(nextFocused);
1339
- };
1340
- var value = {
1341
- focusedDay,
1342
- focusTarget,
1343
- blur,
1344
- focus,
1345
- focusDayAfter: function() {
1346
- return moveFocus("day", "after");
1347
- },
1348
- focusDayBefore: function() {
1349
- return moveFocus("day", "before");
1350
- },
1351
- focusWeekAfter: function() {
1352
- return moveFocus("week", "after");
1353
- },
1354
- focusWeekBefore: function() {
1355
- return moveFocus("week", "before");
1356
- },
1357
- focusMonthBefore: function() {
1358
- return moveFocus("month", "before");
1359
- },
1360
- focusMonthAfter: function() {
1361
- return moveFocus("month", "after");
1362
- },
1363
- focusYearBefore: function() {
1364
- return moveFocus("year", "before");
1365
- },
1366
- focusYearAfter: function() {
1367
- return moveFocus("year", "after");
1368
- },
1369
- focusStartOfWeek: function() {
1370
- return moveFocus("startOfWeek", "before");
1371
- },
1372
- focusEndOfWeek: function() {
1373
- return moveFocus("endOfWeek", "after");
1374
- }
1375
- };
1376
- return (0, react_jsx_runtime.jsx)(FocusContext.Provider, {
1377
- value,
1378
- children: props.children
1379
- });
1380
- }
1381
- /**
1382
- * Hook to access the {@link FocusContextValue}. Use this hook to handle the
1383
- * focus state of the elements.
1384
- *
1385
- * This hook is meant to be used inside internal or custom components.
1386
- */
1387
- function useFocusContext() {
1388
- var context = (0, react.useContext)(FocusContext);
1389
- if (!context) throw new Error("useFocusContext must be used within a FocusProvider");
1390
- return context;
1391
- }
1392
- /**
1393
- * Return the active modifiers for the specified day.
1394
- *
1395
- * This hook is meant to be used inside internal or custom components.
1396
- *
1397
- * @param day
1398
- * @param displayMonth
1399
- */
1400
- function useActiveModifiers(day, displayMonth) {
1401
- return getActiveModifiers(day, useModifiers(), displayMonth);
1402
- }
1403
- /**
1404
- * The SelectSingle context shares details about the selected days when in
1405
- * single selection mode.
1406
- *
1407
- * Access this context from the {@link useSelectSingle} hook.
1408
- */
1409
- var SelectSingleContext = (0, react.createContext)(void 0);
1410
- /** Provides the values for the {@link SelectSingleProvider}. */
1411
- function SelectSingleProvider(props) {
1412
- if (!isDayPickerSingle(props.initialProps)) return (0, react_jsx_runtime.jsx)(SelectSingleContext.Provider, {
1413
- value: { selected: void 0 },
1414
- children: props.children
1415
- });
1416
- return (0, react_jsx_runtime.jsx)(SelectSingleProviderInternal, {
1417
- initialProps: props.initialProps,
1418
- children: props.children
1419
- });
1420
- }
1421
- function SelectSingleProviderInternal(_a) {
1422
- var initialProps = _a.initialProps, children = _a.children;
1423
- var onDayClick = function(day, activeModifiers, e) {
1424
- var _a, _b, _c;
1425
- (_a = initialProps.onDayClick) === null || _a === void 0 || _a.call(initialProps, day, activeModifiers, e);
1426
- if (activeModifiers.selected && !initialProps.required) {
1427
- (_b = initialProps.onSelect) === null || _b === void 0 || _b.call(initialProps, void 0, day, activeModifiers, e);
1428
- return;
1429
- }
1430
- (_c = initialProps.onSelect) === null || _c === void 0 || _c.call(initialProps, day, day, activeModifiers, e);
1431
- };
1432
- var contextValue = {
1433
- selected: initialProps.selected,
1434
- onDayClick
1435
- };
1436
- return (0, react_jsx_runtime.jsx)(SelectSingleContext.Provider, {
1437
- value: contextValue,
1438
- children
1439
- });
1440
- }
1441
- /**
1442
- * Hook to access the {@link SelectSingleContextValue}.
1443
- *
1444
- * This hook is meant to be used inside internal or custom components.
1445
- */
1446
- function useSelectSingle() {
1447
- var context = (0, react.useContext)(SelectSingleContext);
1448
- if (!context) throw new Error("useSelectSingle must be used within a SelectSingleProvider");
1449
- return context;
1450
- }
1451
- /**
1452
- * This hook returns details about the content to render in the day cell.
1453
- *
1454
- *
1455
- * When a day cell is rendered in the table, DayPicker can either:
1456
- *
1457
- * - render nothing: when the day is outside the month or has matched the
1458
- * "hidden" modifier.
1459
- * - render a button when `onDayClick` or a selection mode is set.
1460
- * - render a non-interactive element: when no selection mode is set, the day
1461
- * cell shouldn’t respond to any interaction. DayPicker should render a `div`
1462
- * or a `span`.
1463
- *
1464
- * ### Usage
1465
- *
1466
- * Use this hook to customize the behavior of the {@link Day} component. Create a
1467
- * new `Day` component using this hook and pass it to the `components` prop.
1468
- * The source of {@link Day} can be a good starting point.
1469
- *
1470
- */
1471
- function useDayEventHandlers(date, activeModifiers) {
1472
- var dayPicker = useDayPicker();
1473
- var single = useSelectSingle();
1474
- var multiple = useSelectMultiple();
1475
- var range = useSelectRange();
1476
- var _a = useFocusContext(), focusDayAfter = _a.focusDayAfter, focusDayBefore = _a.focusDayBefore, focusWeekAfter = _a.focusWeekAfter, focusWeekBefore = _a.focusWeekBefore, blur = _a.blur, focus = _a.focus, focusMonthBefore = _a.focusMonthBefore, focusMonthAfter = _a.focusMonthAfter, focusYearBefore = _a.focusYearBefore, focusYearAfter = _a.focusYearAfter, focusStartOfWeek = _a.focusStartOfWeek, focusEndOfWeek = _a.focusEndOfWeek;
1477
- var onClick = function(e) {
1478
- var _a, _b, _c, _d;
1479
- if (isDayPickerSingle(dayPicker)) (_a = single.onDayClick) === null || _a === void 0 || _a.call(single, date, activeModifiers, e);
1480
- else if (isDayPickerMultiple(dayPicker)) (_b = multiple.onDayClick) === null || _b === void 0 || _b.call(multiple, date, activeModifiers, e);
1481
- else if (isDayPickerRange(dayPicker)) (_c = range.onDayClick) === null || _c === void 0 || _c.call(range, date, activeModifiers, e);
1482
- else (_d = dayPicker.onDayClick) === null || _d === void 0 || _d.call(dayPicker, date, activeModifiers, e);
1483
- };
1484
- var onFocus = function(e) {
1485
- var _a;
1486
- focus(date);
1487
- (_a = dayPicker.onDayFocus) === null || _a === void 0 || _a.call(dayPicker, date, activeModifiers, e);
1488
- };
1489
- var onBlur = function(e) {
1490
- var _a;
1491
- blur();
1492
- (_a = dayPicker.onDayBlur) === null || _a === void 0 || _a.call(dayPicker, date, activeModifiers, e);
1493
- };
1494
- var onMouseEnter = function(e) {
1495
- var _a;
1496
- (_a = dayPicker.onDayMouseEnter) === null || _a === void 0 || _a.call(dayPicker, date, activeModifiers, e);
1497
- };
1498
- var onMouseLeave = function(e) {
1499
- var _a;
1500
- (_a = dayPicker.onDayMouseLeave) === null || _a === void 0 || _a.call(dayPicker, date, activeModifiers, e);
1501
- };
1502
- var onPointerEnter = function(e) {
1503
- var _a;
1504
- (_a = dayPicker.onDayPointerEnter) === null || _a === void 0 || _a.call(dayPicker, date, activeModifiers, e);
1505
- };
1506
- var onPointerLeave = function(e) {
1507
- var _a;
1508
- (_a = dayPicker.onDayPointerLeave) === null || _a === void 0 || _a.call(dayPicker, date, activeModifiers, e);
1509
- };
1510
- var onTouchCancel = function(e) {
1511
- var _a;
1512
- (_a = dayPicker.onDayTouchCancel) === null || _a === void 0 || _a.call(dayPicker, date, activeModifiers, e);
1513
- };
1514
- var onTouchEnd = function(e) {
1515
- var _a;
1516
- (_a = dayPicker.onDayTouchEnd) === null || _a === void 0 || _a.call(dayPicker, date, activeModifiers, e);
1517
- };
1518
- var onTouchMove = function(e) {
1519
- var _a;
1520
- (_a = dayPicker.onDayTouchMove) === null || _a === void 0 || _a.call(dayPicker, date, activeModifiers, e);
1521
- };
1522
- var onTouchStart = function(e) {
1523
- var _a;
1524
- (_a = dayPicker.onDayTouchStart) === null || _a === void 0 || _a.call(dayPicker, date, activeModifiers, e);
1525
- };
1526
- var onKeyUp = function(e) {
1527
- var _a;
1528
- (_a = dayPicker.onDayKeyUp) === null || _a === void 0 || _a.call(dayPicker, date, activeModifiers, e);
1529
- };
1530
- var onKeyDown = function(e) {
1531
- var _a;
1532
- switch (e.key) {
1533
- case "ArrowLeft":
1534
- e.preventDefault();
1535
- e.stopPropagation();
1536
- dayPicker.dir === "rtl" ? focusDayAfter() : focusDayBefore();
1537
- break;
1538
- case "ArrowRight":
1539
- e.preventDefault();
1540
- e.stopPropagation();
1541
- dayPicker.dir === "rtl" ? focusDayBefore() : focusDayAfter();
1542
- break;
1543
- case "ArrowDown":
1544
- e.preventDefault();
1545
- e.stopPropagation();
1546
- focusWeekAfter();
1547
- break;
1548
- case "ArrowUp":
1549
- e.preventDefault();
1550
- e.stopPropagation();
1551
- focusWeekBefore();
1552
- break;
1553
- case "PageUp":
1554
- e.preventDefault();
1555
- e.stopPropagation();
1556
- e.shiftKey ? focusYearBefore() : focusMonthBefore();
1557
- break;
1558
- case "PageDown":
1559
- e.preventDefault();
1560
- e.stopPropagation();
1561
- e.shiftKey ? focusYearAfter() : focusMonthAfter();
1562
- break;
1563
- case "Home":
1564
- e.preventDefault();
1565
- e.stopPropagation();
1566
- focusStartOfWeek();
1567
- break;
1568
- case "End":
1569
- e.preventDefault();
1570
- e.stopPropagation();
1571
- focusEndOfWeek();
1572
- break;
1573
- }
1574
- (_a = dayPicker.onDayKeyDown) === null || _a === void 0 || _a.call(dayPicker, date, activeModifiers, e);
1575
- };
1576
- return {
1577
- onClick,
1578
- onFocus,
1579
- onBlur,
1580
- onKeyDown,
1581
- onKeyUp,
1582
- onMouseEnter,
1583
- onMouseLeave,
1584
- onPointerEnter,
1585
- onPointerLeave,
1586
- onTouchCancel,
1587
- onTouchEnd,
1588
- onTouchMove,
1589
- onTouchStart
1590
- };
1591
- }
1592
- /**
1593
- * Return the current selected days when DayPicker is in selection mode. Days
1594
- * selected by the custom selection mode are not returned.
1595
- *
1596
- * This hook is meant to be used inside internal or custom components.
1597
- *
1598
- */
1599
- function useSelectedDays() {
1600
- var dayPicker = useDayPicker();
1601
- var single = useSelectSingle();
1602
- var multiple = useSelectMultiple();
1603
- var range = useSelectRange();
1604
- return isDayPickerSingle(dayPicker) ? single.selected : isDayPickerMultiple(dayPicker) ? multiple.selected : isDayPickerRange(dayPicker) ? range.selected : void 0;
1605
- }
1606
- function isInternalModifier(modifier) {
1607
- return Object.values(InternalModifier).includes(modifier);
1608
- }
1609
- /**
1610
- * Return the class names for the Day element, according to the given active
1611
- * modifiers.
1612
- *
1613
- * Custom class names are set via `modifiersClassNames` or `classNames`,
1614
- * where the first have the precedence.
1615
- */
1616
- function getDayClassNames(dayPicker, activeModifiers) {
1617
- var classNames = [dayPicker.classNames.day];
1618
- Object.keys(activeModifiers).forEach(function(modifier) {
1619
- var customClassName = dayPicker.modifiersClassNames[modifier];
1620
- if (customClassName) classNames.push(customClassName);
1621
- else if (isInternalModifier(modifier)) {
1622
- var internalClassName = dayPicker.classNames["day_".concat(modifier)];
1623
- if (internalClassName) classNames.push(internalClassName);
1624
- }
1625
- });
1626
- return classNames;
1627
- }
1628
- /** Return the style for the Day element, according to the given active modifiers. */
1629
- function getDayStyle(dayPicker, activeModifiers) {
1630
- var style = __assign({}, dayPicker.styles.day);
1631
- Object.keys(activeModifiers).forEach(function(modifier) {
1632
- var _a;
1633
- style = __assign(__assign({}, style), (_a = dayPicker.modifiersStyles) === null || _a === void 0 ? void 0 : _a[modifier]);
1634
- });
1635
- return style;
1636
- }
1637
- /**
1638
- * Return props and data used to render the {@link Day} component.
1639
- *
1640
- * Use this hook when creating a component to replace the built-in `Day`
1641
- * component.
1642
- */
1643
- function useDayRender(day, displayMonth, buttonRef) {
1644
- var _a;
1645
- var _b, _c;
1646
- var dayPicker = useDayPicker();
1647
- var focusContext = useFocusContext();
1648
- var activeModifiers = useActiveModifiers(day, displayMonth);
1649
- var eventHandlers = useDayEventHandlers(day, activeModifiers);
1650
- var selectedDays = useSelectedDays();
1651
- var isButton = Boolean(dayPicker.onDayClick || dayPicker.mode !== "default");
1652
- (0, react.useEffect)(function() {
1653
- var _a;
1654
- if (activeModifiers.outside) return;
1655
- if (!focusContext.focusedDay) return;
1656
- if (!isButton) return;
1657
- if (require_isSameDay.default(focusContext.focusedDay, day)) (_a = buttonRef.current) === null || _a === void 0 || _a.focus();
1658
- }, [
1659
- focusContext.focusedDay,
1660
- day,
1661
- buttonRef,
1662
- isButton,
1663
- activeModifiers.outside
1664
- ]);
1665
- var className = getDayClassNames(dayPicker, activeModifiers).join(" ");
1666
- var style = getDayStyle(dayPicker, activeModifiers);
1667
- var isHidden = Boolean(activeModifiers.outside && !dayPicker.showOutsideDays || activeModifiers.hidden);
1668
- var divProps = {
1669
- style,
1670
- className,
1671
- children: (0, react_jsx_runtime.jsx)((_c = (_b = dayPicker.components) === null || _b === void 0 ? void 0 : _b.DayContent) !== null && _c !== void 0 ? _c : DayContent, {
1672
- date: day,
1673
- displayMonth,
1674
- activeModifiers
1675
- }),
1676
- role: "gridcell"
1677
- };
1678
- var isFocusTarget = focusContext.focusTarget && require_isSameDay.default(focusContext.focusTarget, day) && !activeModifiers.outside;
1679
- var isFocused = focusContext.focusedDay && require_isSameDay.default(focusContext.focusedDay, day);
1680
- return {
1681
- isButton,
1682
- isHidden,
1683
- activeModifiers,
1684
- selectedDays,
1685
- buttonProps: __assign(__assign(__assign({}, divProps), (_a = {
1686
- disabled: activeModifiers.disabled,
1687
- role: "gridcell"
1688
- }, _a["aria-selected"] = activeModifiers.selected, _a.tabIndex = isFocused || isFocusTarget ? 0 : -1, _a)), eventHandlers),
1689
- divProps
1690
- };
1691
- }
1692
- /**
1693
- * The content of a day cell – as a button or span element according to its
1694
- * modifiers.
1695
- */
1696
- function Day(props) {
1697
- var buttonRef = (0, react.useRef)(null);
1698
- var dayRender = useDayRender(props.date, props.displayMonth, buttonRef);
1699
- if (dayRender.isHidden) return (0, react_jsx_runtime.jsx)("div", { role: "gridcell" });
1700
- if (!dayRender.isButton) return (0, react_jsx_runtime.jsx)("div", __assign({}, dayRender.divProps));
1701
- return (0, react_jsx_runtime.jsx)(Button, __assign({
1702
- name: "day",
1703
- ref: buttonRef
1704
- }, dayRender.buttonProps));
1705
- }
1706
- /**
1707
- * Render the week number element. If `onWeekNumberClick` is passed to DayPicker, it
1708
- * renders a button, otherwise a span element.
1709
- */
1710
- function WeekNumber(props) {
1711
- var weekNumber = props.number, dates = props.dates;
1712
- var _a = useDayPicker(), onWeekNumberClick = _a.onWeekNumberClick, styles = _a.styles, classNames = _a.classNames, locale = _a.locale, labelWeekNumber = _a.labels.labelWeekNumber, formatWeekNumber = _a.formatters.formatWeekNumber;
1713
- var content = formatWeekNumber(Number(weekNumber), { locale });
1714
- if (!onWeekNumberClick) return (0, react_jsx_runtime.jsx)("span", {
1715
- className: classNames.weeknumber,
1716
- style: styles.weeknumber,
1717
- children: content
1718
- });
1719
- var label = labelWeekNumber(Number(weekNumber), { locale });
1720
- var handleClick = function(e) {
1721
- onWeekNumberClick(weekNumber, dates, e);
1722
- };
1723
- return (0, react_jsx_runtime.jsx)(Button, {
1724
- name: "week-number",
1725
- "aria-label": label,
1726
- className: classNames.weeknumber,
1727
- style: styles.weeknumber,
1728
- onClick: handleClick,
1729
- children: content
1730
- });
1731
- }
1732
- /** Render a row in the calendar, with the days and the week number. */
1733
- function Row(props) {
1734
- var _a, _b;
1735
- var _c = useDayPicker(), styles = _c.styles, classNames = _c.classNames, showWeekNumber = _c.showWeekNumber, components = _c.components;
1736
- var DayComponent = (_a = components === null || components === void 0 ? void 0 : components.Day) !== null && _a !== void 0 ? _a : Day;
1737
- var WeeknumberComponent = (_b = components === null || components === void 0 ? void 0 : components.WeekNumber) !== null && _b !== void 0 ? _b : WeekNumber;
1738
- var weekNumberCell;
1739
- if (showWeekNumber) weekNumberCell = (0, react_jsx_runtime.jsx)("td", {
1740
- className: classNames.cell,
1741
- style: styles.cell,
1742
- children: (0, react_jsx_runtime.jsx)(WeeknumberComponent, {
1743
- number: props.weekNumber,
1744
- dates: props.dates
1745
- })
1746
- });
1747
- return (0, react_jsx_runtime.jsxs)("tr", {
1748
- className: classNames.row,
1749
- style: styles.row,
1750
- children: [weekNumberCell, props.dates.map(function(date) {
1751
- return (0, react_jsx_runtime.jsx)("td", {
1752
- className: classNames.cell,
1753
- style: styles.cell,
1754
- role: "presentation",
1755
- children: (0, react_jsx_runtime.jsx)(DayComponent, {
1756
- displayMonth: props.displayMonth,
1757
- date
1758
- })
1759
- }, require_getUnixTime.default(date));
1760
- })]
1761
- });
1762
- }
1763
- /** Return the weeks between two dates. */
1764
- function daysToMonthWeeks(fromDate, toDate, options) {
1765
- var toWeek = (options === null || options === void 0 ? void 0 : options.ISOWeek) ? require_endOfISOWeek.default(toDate) : require_endOfWeek.default(toDate, options);
1766
- var fromWeek = (options === null || options === void 0 ? void 0 : options.ISOWeek) ? require_startOfISOWeek.default(fromDate) : require_startOfWeek.default(fromDate, options);
1767
- var nOfDays = require_differenceInCalendarDays.default(toWeek, fromWeek);
1768
- var days = [];
1769
- for (var i = 0; i <= nOfDays; i++) days.push(require_addDays.default(fromWeek, i));
1770
- return days.reduce(function(result, date) {
1771
- var weekNumber = (options === null || options === void 0 ? void 0 : options.ISOWeek) ? require_getISOWeek.default(date) : require_getWeek.default(date, options);
1772
- var existingWeek = result.find(function(value) {
1773
- return value.weekNumber === weekNumber;
1774
- });
1775
- if (existingWeek) {
1776
- existingWeek.dates.push(date);
1777
- return result;
1778
- }
1779
- result.push({
1780
- weekNumber,
1781
- dates: [date]
1782
- });
1783
- return result;
1784
- }, []);
1785
- }
1786
- /**
1787
- * Return the weeks belonging to the given month, adding the "outside days" to
1788
- * the first and last week.
1789
- */
1790
- function getMonthWeeks(month, options) {
1791
- var weeksInMonth = daysToMonthWeeks(require_startOfMonth.default(month), require_endOfMonth.default(month), options);
1792
- if (options === null || options === void 0 ? void 0 : options.useFixedWeeks) {
1793
- var nrOfMonthWeeks = require_getWeeksInMonth.default(month, options);
1794
- if (nrOfMonthWeeks < 6) {
1795
- var lastWeek = weeksInMonth[weeksInMonth.length - 1];
1796
- var lastDate = lastWeek.dates[lastWeek.dates.length - 1];
1797
- var toDate = require_addWeeks.default(lastDate, 6 - nrOfMonthWeeks);
1798
- var extraWeeks = daysToMonthWeeks(require_addWeeks.default(lastDate, 1), toDate, options);
1799
- weeksInMonth.push.apply(weeksInMonth, extraWeeks);
1800
- }
1801
- }
1802
- return weeksInMonth;
1803
- }
1804
- /** Render the table with the calendar. */
1805
- function Table(props) {
1806
- var _a, _b, _c;
1807
- var _d = useDayPicker(), locale = _d.locale, classNames = _d.classNames, styles = _d.styles, hideHead = _d.hideHead, fixedWeeks = _d.fixedWeeks, components = _d.components, weekStartsOn = _d.weekStartsOn, firstWeekContainsDate = _d.firstWeekContainsDate, ISOWeek = _d.ISOWeek;
1808
- var weeks = getMonthWeeks(props.displayMonth, {
1809
- useFixedWeeks: Boolean(fixedWeeks),
1810
- ISOWeek,
1811
- locale,
1812
- weekStartsOn,
1813
- firstWeekContainsDate
1814
- });
1815
- var HeadComponent = (_a = components === null || components === void 0 ? void 0 : components.Head) !== null && _a !== void 0 ? _a : Head;
1816
- var RowComponent = (_b = components === null || components === void 0 ? void 0 : components.Row) !== null && _b !== void 0 ? _b : Row;
1817
- var FooterComponent = (_c = components === null || components === void 0 ? void 0 : components.Footer) !== null && _c !== void 0 ? _c : Footer;
1818
- return (0, react_jsx_runtime.jsxs)("table", {
1819
- id: props.id,
1820
- className: classNames.table,
1821
- style: styles.table,
1822
- role: "grid",
1823
- "aria-labelledby": props["aria-labelledby"],
1824
- children: [
1825
- !hideHead && (0, react_jsx_runtime.jsx)(HeadComponent, {}),
1826
- (0, react_jsx_runtime.jsx)("tbody", {
1827
- className: classNames.tbody,
1828
- style: styles.tbody,
1829
- children: weeks.map(function(week) {
1830
- return (0, react_jsx_runtime.jsx)(RowComponent, {
1831
- displayMonth: props.displayMonth,
1832
- dates: week.dates,
1833
- weekNumber: week.weekNumber
1834
- }, week.weekNumber);
1835
- })
1836
- }),
1837
- (0, react_jsx_runtime.jsx)(FooterComponent, { displayMonth: props.displayMonth })
1838
- ]
1839
- });
1840
- }
1841
- function canUseDOM() {
1842
- return !!(typeof window !== "undefined" && window.document && window.document.createElement);
1843
- }
1844
- /**
1845
- * React currently throws a warning when using useLayoutEffect on the server. To
1846
- * get around it, we can conditionally useEffect on the server (no-op) and
1847
- * useLayoutEffect in the browser. We occasionally need useLayoutEffect to
1848
- * ensure we don't get a render flash for certain operations, but we may also
1849
- * need affected components to render on the server. One example is when setting
1850
- * a component's descendants to retrieve their index values.
1851
- *
1852
- * Important to note that using this hook as an escape hatch will break the
1853
- * eslint dependency warnings unless you rename the import to `useLayoutEffect`.
1854
- * Use sparingly only when the effect won't effect the rendered HTML to avoid
1855
- * any server/client mismatch.
1856
- *
1857
- * If a useLayoutEffect is needed and the result would create a mismatch, it's
1858
- * likely that the component in question shouldn't be rendered on the server at
1859
- * all, so a better approach would be to lazily render those in a parent
1860
- * component after client-side hydration.
1861
- *
1862
- * https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
1863
- * https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js
1864
- *
1865
- * @param effect
1866
- * @param deps
1867
- */
1868
- var useIsomorphicLayoutEffect = canUseDOM() ? react.useLayoutEffect : react.useEffect;
1869
- var serverHandoffComplete = false;
1870
- var id = 0;
1871
- function genId() {
1872
- return "react-day-picker-".concat(++id);
1873
- }
1874
- function useId(providedId) {
1875
- var _a;
1876
- var _b = (0, react.useState)(providedId !== null && providedId !== void 0 ? providedId : serverHandoffComplete ? genId() : null), id = _b[0], setId = _b[1];
1877
- useIsomorphicLayoutEffect(function() {
1878
- if (id === null) setId(genId());
1879
- }, []);
1880
- (0, react.useEffect)(function() {
1881
- if (serverHandoffComplete === false) serverHandoffComplete = true;
1882
- }, []);
1883
- return (_a = providedId !== null && providedId !== void 0 ? providedId : id) !== null && _a !== void 0 ? _a : void 0;
1884
- }
1885
- /** Render a month. */
1886
- function Month(props) {
1887
- var _a;
1888
- var _b;
1889
- var dayPicker = useDayPicker();
1890
- var dir = dayPicker.dir, classNames = dayPicker.classNames, styles = dayPicker.styles, components = dayPicker.components;
1891
- var displayMonths = useNavigation().displayMonths;
1892
- var captionId = useId(dayPicker.id ? "".concat(dayPicker.id, "-").concat(props.displayIndex) : void 0);
1893
- var tableId = dayPicker.id ? "".concat(dayPicker.id, "-grid-").concat(props.displayIndex) : void 0;
1894
- var className = [classNames.month];
1895
- var style = styles.month;
1896
- var isStart = props.displayIndex === 0;
1897
- var isEnd = props.displayIndex === displayMonths.length - 1;
1898
- var isCenter = !isStart && !isEnd;
1899
- if (dir === "rtl") _a = [isStart, isEnd], isEnd = _a[0], isStart = _a[1];
1900
- if (isStart) {
1901
- className.push(classNames.caption_start);
1902
- style = __assign(__assign({}, style), styles.caption_start);
1903
- }
1904
- if (isEnd) {
1905
- className.push(classNames.caption_end);
1906
- style = __assign(__assign({}, style), styles.caption_end);
1907
- }
1908
- if (isCenter) {
1909
- className.push(classNames.caption_between);
1910
- style = __assign(__assign({}, style), styles.caption_between);
1911
- }
1912
- var CaptionComponent = (_b = components === null || components === void 0 ? void 0 : components.Caption) !== null && _b !== void 0 ? _b : Caption;
1913
- return (0, react_jsx_runtime.jsxs)("div", {
1914
- className: className.join(" "),
1915
- style,
1916
- children: [(0, react_jsx_runtime.jsx)(CaptionComponent, {
1917
- id: captionId,
1918
- displayMonth: props.displayMonth,
1919
- displayIndex: props.displayIndex
1920
- }), (0, react_jsx_runtime.jsx)(Table, {
1921
- id: tableId,
1922
- "aria-labelledby": captionId,
1923
- displayMonth: props.displayMonth
1924
- })]
1925
- }, props.displayIndex);
1926
- }
1927
- /**
1928
- * Render the wrapper for the month grids.
1929
- */
1930
- function Months(props) {
1931
- var _a = useDayPicker(), classNames = _a.classNames, styles = _a.styles;
1932
- return (0, react_jsx_runtime.jsx)("div", {
1933
- className: classNames.months,
1934
- style: styles.months,
1935
- children: props.children
1936
- });
1937
- }
1938
- /** Render the container with the months according to the number of months to display. */
1939
- function Root(_a) {
1940
- var _b, _c;
1941
- var initialProps = _a.initialProps;
1942
- var dayPicker = useDayPicker();
1943
- var focusContext = useFocusContext();
1944
- var navigation = useNavigation();
1945
- var _d = (0, react.useState)(false), hasInitialFocus = _d[0], setHasInitialFocus = _d[1];
1946
- (0, react.useEffect)(function() {
1947
- if (!dayPicker.initialFocus) return;
1948
- if (!focusContext.focusTarget) return;
1949
- if (hasInitialFocus) return;
1950
- focusContext.focus(focusContext.focusTarget);
1951
- setHasInitialFocus(true);
1952
- }, [
1953
- dayPicker.initialFocus,
1954
- hasInitialFocus,
1955
- focusContext.focus,
1956
- focusContext.focusTarget,
1957
- focusContext
1958
- ]);
1959
- var classNames = [dayPicker.classNames.root, dayPicker.className];
1960
- if (dayPicker.numberOfMonths > 1) classNames.push(dayPicker.classNames.multiple_months);
1961
- if (dayPicker.showWeekNumber) classNames.push(dayPicker.classNames.with_weeknumber);
1962
- var style = __assign(__assign({}, dayPicker.styles.root), dayPicker.style);
1963
- var dataAttributes = Object.keys(initialProps).filter(function(key) {
1964
- return key.startsWith("data-");
1965
- }).reduce(function(attrs, key) {
1966
- var _a;
1967
- return __assign(__assign({}, attrs), (_a = {}, _a[key] = initialProps[key], _a));
1968
- }, {});
1969
- var MonthsComponent = (_c = (_b = initialProps.components) === null || _b === void 0 ? void 0 : _b.Months) !== null && _c !== void 0 ? _c : Months;
1970
- return (0, react_jsx_runtime.jsx)("div", __assign({
1971
- className: classNames.join(" "),
1972
- style,
1973
- dir: dayPicker.dir,
1974
- id: dayPicker.id,
1975
- nonce: initialProps.nonce,
1976
- title: initialProps.title,
1977
- lang: initialProps.lang
1978
- }, dataAttributes, { children: (0, react_jsx_runtime.jsx)(MonthsComponent, { children: navigation.displayMonths.map(function(month, i) {
1979
- return (0, react_jsx_runtime.jsx)(Month, {
1980
- displayIndex: i,
1981
- displayMonth: month
1982
- }, i);
1983
- }) }) }));
1984
- }
1985
- /** Provide the value for all the context providers. */
1986
- function RootProvider(props) {
1987
- var children = props.children, initialProps = __rest(props, ["children"]);
1988
- return (0, react_jsx_runtime.jsx)(DayPickerProvider, {
1989
- initialProps,
1990
- children: (0, react_jsx_runtime.jsx)(NavigationProvider, { children: (0, react_jsx_runtime.jsx)(SelectSingleProvider, {
1991
- initialProps,
1992
- children: (0, react_jsx_runtime.jsx)(SelectMultipleProvider, {
1993
- initialProps,
1994
- children: (0, react_jsx_runtime.jsx)(SelectRangeProvider, {
1995
- initialProps,
1996
- children: (0, react_jsx_runtime.jsx)(ModifiersProvider, { children: (0, react_jsx_runtime.jsx)(FocusProvider, { children }) })
1997
- })
1998
- })
1999
- }) })
2000
- });
2001
- }
2002
- /**
2003
- * DayPicker render a date picker component to let users pick dates from a
2004
- * calendar. See http://react-day-picker.js.org for updated documentation and
2005
- * examples.
2006
- *
2007
- * ### Customization
2008
- *
2009
- * DayPicker offers different customization props. For example,
2010
- *
2011
- * - show multiple months using `numberOfMonths`
2012
- * - display a dropdown to navigate the months via `captionLayout`
2013
- * - display the week numbers with `showWeekNumbers`
2014
- * - disable or hide days with `disabled` or `hidden`
2015
- *
2016
- * ### Controlling the months
2017
- *
2018
- * Change the initially displayed month using the `defaultMonth` prop. The
2019
- * displayed months are controlled by DayPicker and stored in its internal
2020
- * state. To control the months yourself, use `month` instead of `defaultMonth`
2021
- * and use the `onMonthChange` event to set it.
2022
- *
2023
- * To limit the months the user can navigate to, use
2024
- * `fromDate`/`fromMonth`/`fromYear` or `toDate`/`toMonth`/`toYear`.
2025
- *
2026
- * ### Selection modes
2027
- *
2028
- * DayPicker supports different selection mode that can be toggled using the
2029
- * `mode` prop:
2030
- *
2031
- * - `mode="single"`: only one day can be selected. Use `required` to make the
2032
- * selection required. Use the `onSelect` event handler to get the selected
2033
- * days.
2034
- * - `mode="multiple"`: users can select one or more days. Limit the amount of
2035
- * days that can be selected with the `min` or the `max` props.
2036
- * - `mode="range"`: users can select a range of days. Limit the amount of days
2037
- * in the range with the `min` or the `max` props.
2038
- * - `mode="default"` (default): the built-in selections are disabled. Implement
2039
- * your own selection mode with `onDayClick`.
2040
- *
2041
- * The selection modes should cover the most common use cases. In case you
2042
- * need a more refined way of selecting days, use `mode="default"`. Use the
2043
- * `selected` props and add the day event handlers to add/remove days from the
2044
- * selection.
2045
- *
2046
- * ### Modifiers
2047
- *
2048
- * A _modifier_ represents different styles or states for the days displayed in
2049
- * the calendar (like "selected" or "disabled"). Define custom modifiers using
2050
- * the `modifiers` prop.
2051
- *
2052
- * ### Formatters and custom component
2053
- *
2054
- * You can customize how the content is displayed in the date picker by using
2055
- * either the formatters or replacing the internal components.
2056
- *
2057
- * For the most common cases you want to use the `formatters` prop to change how
2058
- * the content is formatted in the calendar. Use the `components` prop to
2059
- * replace the internal components, like the navigation icons.
2060
- *
2061
- * ### Styling
2062
- *
2063
- * DayPicker comes with a default, basic style in `react-day-picker/style` – use
2064
- * it as template for your own style.
2065
- *
2066
- * If you are using CSS modules, pass the imported styles object the
2067
- * `classNames` props.
2068
- *
2069
- * You can also style the elements via inline styles using the `styles` prop.
2070
- *
2071
- * ### Form fields
2072
- *
2073
- * If you need to bind the date picker to a form field, you can use the
2074
- * `useInput` hooks for a basic behavior. See the `useInput` source as an
2075
- * example to bind the date picker with form fields.
2076
- *
2077
- * ### Localization
2078
- *
2079
- * To localize DayPicker, import the locale from `date-fns` package and use the
2080
- * `locale` prop.
2081
- *
2082
- * For example, to use Spanish locale:
2083
- *
2084
- * ```
2085
- * import { es } from 'date-fns/locale';
2086
- * <DayPicker locale={es} />
2087
- * ```
2088
- */
2089
- function DayPicker(props) {
2090
- return (0, react_jsx_runtime.jsx)(RootProvider, __assign({}, props, { children: (0, react_jsx_runtime.jsx)(Root, { initialProps: props }) }));
2091
- }
2092
- //#endregion
2093
- exports.DayPicker = DayPicker;
2094
- exports.useNavigation = useNavigation;