react-day-picker 8.3.5 → 8.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.esm.js +2 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +203 -240
- package/dist/index.js.map +1 -1
- package/dist/react-day-picker.min.js +1 -1
- package/package.json +22 -20
- package/src/contexts/Navigation/NavigationContext.test.ts +1 -1
- package/src/contexts/Navigation/useNavigationState.test.ts +2 -2
- package/src/hooks/useDayRender/useDayRender.test.tsx +14 -0
- package/src/hooks/useDayRender/useDayRender.tsx +4 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var React = require('react');
|
|
6
4
|
var enUS = require('date-fns/locale/en-US');
|
|
7
5
|
var format = require('date-fns/format');
|
|
@@ -37,10 +35,7 @@ var getISOWeek = require('date-fns/getISOWeek');
|
|
|
37
35
|
var getWeek = require('date-fns/getWeek');
|
|
38
36
|
var parse = require('date-fns/parse');
|
|
39
37
|
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
function _interopNamespace(e) {
|
|
43
|
-
if (e && e.__esModule) return e;
|
|
38
|
+
function _interopNamespaceDefault(e) {
|
|
44
39
|
var n = Object.create(null);
|
|
45
40
|
if (e) {
|
|
46
41
|
Object.keys(e).forEach(function (k) {
|
|
@@ -53,44 +48,11 @@ function _interopNamespace(e) {
|
|
|
53
48
|
}
|
|
54
49
|
});
|
|
55
50
|
}
|
|
56
|
-
n
|
|
51
|
+
n.default = e;
|
|
57
52
|
return Object.freeze(n);
|
|
58
53
|
}
|
|
59
54
|
|
|
60
|
-
var
|
|
61
|
-
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
62
|
-
var enUS__default = /*#__PURE__*/_interopDefaultLegacy(enUS);
|
|
63
|
-
var format__default = /*#__PURE__*/_interopDefaultLegacy(format);
|
|
64
|
-
var endOfMonth__default = /*#__PURE__*/_interopDefaultLegacy(endOfMonth);
|
|
65
|
-
var startOfDay__default = /*#__PURE__*/_interopDefaultLegacy(startOfDay);
|
|
66
|
-
var startOfMonth__default = /*#__PURE__*/_interopDefaultLegacy(startOfMonth);
|
|
67
|
-
var isSameYear__default = /*#__PURE__*/_interopDefaultLegacy(isSameYear);
|
|
68
|
-
var setMonth__default = /*#__PURE__*/_interopDefaultLegacy(setMonth);
|
|
69
|
-
var setYear__default = /*#__PURE__*/_interopDefaultLegacy(setYear);
|
|
70
|
-
var startOfYear__default = /*#__PURE__*/_interopDefaultLegacy(startOfYear);
|
|
71
|
-
var addMonths__default = /*#__PURE__*/_interopDefaultLegacy(addMonths);
|
|
72
|
-
var isBefore__default = /*#__PURE__*/_interopDefaultLegacy(isBefore);
|
|
73
|
-
var isSameMonth__default = /*#__PURE__*/_interopDefaultLegacy(isSameMonth);
|
|
74
|
-
var differenceInCalendarMonths__default = /*#__PURE__*/_interopDefaultLegacy(differenceInCalendarMonths);
|
|
75
|
-
var addDays__default = /*#__PURE__*/_interopDefaultLegacy(addDays);
|
|
76
|
-
var startOfISOWeek__default = /*#__PURE__*/_interopDefaultLegacy(startOfISOWeek);
|
|
77
|
-
var startOfWeek__default = /*#__PURE__*/_interopDefaultLegacy(startOfWeek);
|
|
78
|
-
var getUnixTime__default = /*#__PURE__*/_interopDefaultLegacy(getUnixTime);
|
|
79
|
-
var isSameDay__default = /*#__PURE__*/_interopDefaultLegacy(isSameDay);
|
|
80
|
-
var differenceInCalendarDays__default = /*#__PURE__*/_interopDefaultLegacy(differenceInCalendarDays);
|
|
81
|
-
var subDays__default = /*#__PURE__*/_interopDefaultLegacy(subDays);
|
|
82
|
-
var isAfter__default = /*#__PURE__*/_interopDefaultLegacy(isAfter);
|
|
83
|
-
var isDate__default = /*#__PURE__*/_interopDefaultLegacy(isDate);
|
|
84
|
-
var addWeeks__default = /*#__PURE__*/_interopDefaultLegacy(addWeeks);
|
|
85
|
-
var addYears__default = /*#__PURE__*/_interopDefaultLegacy(addYears);
|
|
86
|
-
var endOfISOWeek__default = /*#__PURE__*/_interopDefaultLegacy(endOfISOWeek);
|
|
87
|
-
var endOfWeek__default = /*#__PURE__*/_interopDefaultLegacy(endOfWeek);
|
|
88
|
-
var max__default = /*#__PURE__*/_interopDefaultLegacy(max);
|
|
89
|
-
var min__default = /*#__PURE__*/_interopDefaultLegacy(min);
|
|
90
|
-
var getWeeksInMonth__default = /*#__PURE__*/_interopDefaultLegacy(getWeeksInMonth);
|
|
91
|
-
var getISOWeek__default = /*#__PURE__*/_interopDefaultLegacy(getISOWeek);
|
|
92
|
-
var getWeek__default = /*#__PURE__*/_interopDefaultLegacy(getWeek);
|
|
93
|
-
var parse__default = /*#__PURE__*/_interopDefaultLegacy(parse);
|
|
55
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
94
56
|
|
|
95
57
|
/******************************************************************************
|
|
96
58
|
Copyright (c) Microsoft Corporation.
|
|
@@ -206,21 +168,21 @@ var defaultClassNames = {
|
|
|
206
168
|
* The default formatter for the caption.
|
|
207
169
|
*/
|
|
208
170
|
function formatCaption(month, options) {
|
|
209
|
-
return
|
|
171
|
+
return format(month, 'LLLL y', options);
|
|
210
172
|
}
|
|
211
173
|
|
|
212
174
|
/**
|
|
213
175
|
* The default formatter for the Day button.
|
|
214
176
|
*/
|
|
215
177
|
function formatDay(day, options) {
|
|
216
|
-
return
|
|
178
|
+
return format(day, 'd', options);
|
|
217
179
|
}
|
|
218
180
|
|
|
219
181
|
/**
|
|
220
182
|
* The default formatter for the Month caption.
|
|
221
183
|
*/
|
|
222
184
|
function formatMonthCaption(month, options) {
|
|
223
|
-
return
|
|
185
|
+
return format(month, 'LLLL', options);
|
|
224
186
|
}
|
|
225
187
|
|
|
226
188
|
/**
|
|
@@ -234,14 +196,14 @@ function formatWeekNumber(weekNumber) {
|
|
|
234
196
|
* The default formatter for the name of the weekday.
|
|
235
197
|
*/
|
|
236
198
|
function formatWeekdayName(weekday, options) {
|
|
237
|
-
return
|
|
199
|
+
return format(weekday, 'cccccc', options);
|
|
238
200
|
}
|
|
239
201
|
|
|
240
202
|
/**
|
|
241
203
|
* The default formatter for the Year caption.
|
|
242
204
|
*/
|
|
243
205
|
function formatYearCaption(year, options) {
|
|
244
|
-
return
|
|
206
|
+
return format(year, 'yyyy', options);
|
|
245
207
|
}
|
|
246
208
|
|
|
247
209
|
var formatters = /*#__PURE__*/Object.freeze({
|
|
@@ -258,7 +220,7 @@ var formatters = /*#__PURE__*/Object.freeze({
|
|
|
258
220
|
* The default ARIA label for the day button.
|
|
259
221
|
*/
|
|
260
222
|
var labelDay = function (day, activeModifiers, options) {
|
|
261
|
-
return
|
|
223
|
+
return format(day, 'do MMMM (EEEE)', options);
|
|
262
224
|
};
|
|
263
225
|
|
|
264
226
|
/**
|
|
@@ -286,7 +248,7 @@ var labelPrevious = function () {
|
|
|
286
248
|
* The default ARIA label for the Weekday element.
|
|
287
249
|
*/
|
|
288
250
|
var labelWeekday = function (day, options) {
|
|
289
|
-
return
|
|
251
|
+
return format(day, 'cccc', options);
|
|
290
252
|
};
|
|
291
253
|
|
|
292
254
|
/**
|
|
@@ -321,7 +283,7 @@ var labels = /*#__PURE__*/Object.freeze({
|
|
|
321
283
|
function getDefaultContextValues() {
|
|
322
284
|
var captionLayout = 'buttons';
|
|
323
285
|
var classNames = defaultClassNames;
|
|
324
|
-
var locale =
|
|
286
|
+
var locale = enUS;
|
|
325
287
|
var modifiersClassNames = {};
|
|
326
288
|
var modifiers = {};
|
|
327
289
|
var numberOfMonths = 1;
|
|
@@ -347,20 +309,20 @@ function parseFromToProps(props) {
|
|
|
347
309
|
var fromYear = props.fromYear, toYear = props.toYear, fromMonth = props.fromMonth, toMonth = props.toMonth;
|
|
348
310
|
var fromDate = props.fromDate, toDate = props.toDate;
|
|
349
311
|
if (fromMonth) {
|
|
350
|
-
fromDate =
|
|
312
|
+
fromDate = startOfMonth(fromMonth);
|
|
351
313
|
}
|
|
352
314
|
else if (fromYear) {
|
|
353
315
|
fromDate = new Date(fromYear, 0, 1);
|
|
354
316
|
}
|
|
355
317
|
if (toMonth) {
|
|
356
|
-
toDate =
|
|
318
|
+
toDate = endOfMonth(toMonth);
|
|
357
319
|
}
|
|
358
320
|
else if (toYear) {
|
|
359
321
|
toDate = new Date(toYear, 11, 31);
|
|
360
322
|
}
|
|
361
323
|
return {
|
|
362
|
-
fromDate: fromDate ?
|
|
363
|
-
toDate: toDate ?
|
|
324
|
+
fromDate: fromDate ? startOfDay(fromDate) : undefined,
|
|
325
|
+
toDate: toDate ? startOfDay(toDate) : undefined
|
|
364
326
|
};
|
|
365
327
|
}
|
|
366
328
|
|
|
@@ -393,7 +355,7 @@ function DayPickerProvider(props) {
|
|
|
393
355
|
onSelect = initialProps.onSelect;
|
|
394
356
|
}
|
|
395
357
|
var value = __assign(__assign(__assign({}, defaultContextValues), initialProps), { captionLayout: captionLayout, classNames: __assign(__assign({}, defaultContextValues.classNames), initialProps.classNames), components: __assign({}, initialProps.components), formatters: __assign(__assign({}, defaultContextValues.formatters), initialProps.formatters), fromDate: fromDate, labels: __assign(__assign({}, defaultContextValues.labels), initialProps.labels), mode: initialProps.mode || defaultContextValues.mode, modifiers: __assign(__assign({}, defaultContextValues.modifiers), initialProps.modifiers), modifiersClassNames: __assign(__assign({}, defaultContextValues.modifiersClassNames), initialProps.modifiersClassNames), onSelect: onSelect, styles: __assign(__assign({}, defaultContextValues.styles), initialProps.styles), toDate: toDate });
|
|
396
|
-
return (
|
|
358
|
+
return (React.createElement(DayPickerContext.Provider, { value: value }, props.children));
|
|
397
359
|
}
|
|
398
360
|
/**
|
|
399
361
|
* Hook to access the {@link DayPickerContextValue}.
|
|
@@ -412,15 +374,15 @@ function useDayPicker() {
|
|
|
412
374
|
/** Render the caption for the displayed month. This component is used when `captionLayout="buttons"`. */
|
|
413
375
|
function CaptionLabel(props) {
|
|
414
376
|
var _a = useDayPicker(), locale = _a.locale, classNames = _a.classNames, styles = _a.styles, formatCaption = _a.formatters.formatCaption;
|
|
415
|
-
return (
|
|
377
|
+
return (React.createElement("h2", { className: classNames.caption_label, style: styles.caption_label, "aria-live": "polite", "aria-atomic": "true", id: props.id }, formatCaption(props.displayMonth, { locale: locale })));
|
|
416
378
|
}
|
|
417
379
|
|
|
418
380
|
/**
|
|
419
381
|
* Render the icon in the styled drop-down.
|
|
420
382
|
*/
|
|
421
383
|
function IconDropdown(props) {
|
|
422
|
-
return (
|
|
423
|
-
|
|
384
|
+
return (React.createElement("svg", __assign({ width: "8px", height: "8px", viewBox: "0 0 120 120", "data-testid": "iconDropdown" }, props),
|
|
385
|
+
React.createElement("path", { 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", fill: "currentColor", fillRule: "nonzero" })));
|
|
424
386
|
}
|
|
425
387
|
|
|
426
388
|
/**
|
|
@@ -432,12 +394,12 @@ function Dropdown(props) {
|
|
|
432
394
|
var onChange = props.onChange, value = props.value, children = props.children, caption = props.caption, className = props.className, style = props.style;
|
|
433
395
|
var dayPicker = useDayPicker();
|
|
434
396
|
var IconDropdownComponent = (_b = (_a = dayPicker.components) === null || _a === void 0 ? void 0 : _a.IconDropdown) !== null && _b !== void 0 ? _b : IconDropdown;
|
|
435
|
-
return (
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
397
|
+
return (React.createElement("div", { className: className, style: style },
|
|
398
|
+
React.createElement("span", { className: dayPicker.classNames.vhidden }, props['aria-label']),
|
|
399
|
+
React.createElement("select", { name: props.name, "aria-label": props['aria-label'], className: dayPicker.classNames.dropdown, style: dayPicker.styles.dropdown, value: value, onChange: onChange }, children),
|
|
400
|
+
React.createElement("div", { className: dayPicker.classNames.caption_label, style: dayPicker.styles.caption_label, "aria-hidden": "true" },
|
|
439
401
|
caption,
|
|
440
|
-
|
|
402
|
+
React.createElement(IconDropdownComponent, { className: dayPicker.classNames.dropdown_icon, style: dayPicker.styles.dropdown_icon }))));
|
|
441
403
|
}
|
|
442
404
|
|
|
443
405
|
/** Render the dropdown to navigate between months. */
|
|
@@ -446,31 +408,31 @@ function MonthsDropdown(props) {
|
|
|
446
408
|
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;
|
|
447
409
|
// Dropdown should appear only when both from/toDate is set
|
|
448
410
|
if (!fromDate)
|
|
449
|
-
return
|
|
411
|
+
return React.createElement(React.Fragment, null);
|
|
450
412
|
if (!toDate)
|
|
451
|
-
return
|
|
413
|
+
return React.createElement(React.Fragment, null);
|
|
452
414
|
var dropdownMonths = [];
|
|
453
|
-
if (
|
|
415
|
+
if (isSameYear(fromDate, toDate)) {
|
|
454
416
|
// only display the months included in the range
|
|
455
|
-
var date =
|
|
417
|
+
var date = startOfMonth(fromDate);
|
|
456
418
|
for (var month = fromDate.getMonth(); month <= toDate.getMonth(); month++) {
|
|
457
|
-
dropdownMonths.push(
|
|
419
|
+
dropdownMonths.push(setMonth(date, month));
|
|
458
420
|
}
|
|
459
421
|
}
|
|
460
422
|
else {
|
|
461
423
|
// display all the 12 months
|
|
462
|
-
var date =
|
|
424
|
+
var date = startOfMonth(new Date()); // Any date should be OK, as we just need the year
|
|
463
425
|
for (var month = 0; month <= 11; month++) {
|
|
464
|
-
dropdownMonths.push(
|
|
426
|
+
dropdownMonths.push(setMonth(date, month));
|
|
465
427
|
}
|
|
466
428
|
}
|
|
467
429
|
var handleChange = function (e) {
|
|
468
430
|
var selectedMonth = Number(e.target.value);
|
|
469
|
-
var newMonth =
|
|
431
|
+
var newMonth = setMonth(startOfMonth(props.displayMonth), selectedMonth);
|
|
470
432
|
props.onChange(newMonth);
|
|
471
433
|
};
|
|
472
434
|
var DropdownComponent = (_a = components === null || components === void 0 ? void 0 : components.Dropdown) !== null && _a !== void 0 ? _a : Dropdown;
|
|
473
|
-
return (
|
|
435
|
+
return (React.createElement(DropdownComponent, { name: "months", "aria-label": labelMonthDropdown(), className: classNames.dropdown_month, style: styles.dropdown_month, onChange: handleChange, value: props.displayMonth.getMonth(), caption: formatMonthCaption(props.displayMonth, { locale: locale }) }, dropdownMonths.map(function (m) { return (React.createElement("option", { key: m.getMonth(), value: m.getMonth() }, formatMonthCaption(m, { locale: locale }))); })));
|
|
474
436
|
}
|
|
475
437
|
|
|
476
438
|
/**
|
|
@@ -484,20 +446,20 @@ function YearsDropdown(props) {
|
|
|
484
446
|
var years = [];
|
|
485
447
|
// Dropdown should appear only when both from/toDate is set
|
|
486
448
|
if (!fromDate)
|
|
487
|
-
return
|
|
449
|
+
return React.createElement(React.Fragment, null);
|
|
488
450
|
if (!toDate)
|
|
489
|
-
return
|
|
451
|
+
return React.createElement(React.Fragment, null);
|
|
490
452
|
var fromYear = fromDate.getFullYear();
|
|
491
453
|
var toYear = toDate.getFullYear();
|
|
492
454
|
for (var year = fromYear; year <= toYear; year++) {
|
|
493
|
-
years.push(
|
|
455
|
+
years.push(setYear(startOfYear(new Date()), year));
|
|
494
456
|
}
|
|
495
457
|
var handleChange = function (e) {
|
|
496
|
-
var newMonth =
|
|
458
|
+
var newMonth = setYear(startOfMonth(displayMonth), Number(e.target.value));
|
|
497
459
|
props.onChange(newMonth);
|
|
498
460
|
};
|
|
499
461
|
var DropdownComponent = (_a = components === null || components === void 0 ? void 0 : components.Dropdown) !== null && _a !== void 0 ? _a : Dropdown;
|
|
500
|
-
return (
|
|
462
|
+
return (React.createElement(DropdownComponent, { name: "years", "aria-label": labelYearDropdown(), className: classNames.dropdown_year, style: styles.dropdown_year, onChange: handleChange, value: displayMonth.getFullYear(), caption: formatYearCaption(displayMonth, { locale: locale }) }, years.map(function (year) { return (React.createElement("option", { key: year.getFullYear(), value: year.getFullYear() }, formatYearCaption(year, { locale: locale }))); })));
|
|
501
463
|
}
|
|
502
464
|
|
|
503
465
|
/**
|
|
@@ -521,15 +483,15 @@ function getInitialMonth(context) {
|
|
|
521
483
|
var initialMonth = month || defaultMonth || today || new Date();
|
|
522
484
|
var toDate = context.toDate, fromDate = context.fromDate, _a = context.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
|
|
523
485
|
// Fix the initialMonth if is after the to-date
|
|
524
|
-
if (toDate &&
|
|
486
|
+
if (toDate && differenceInCalendarMonths(toDate, initialMonth) < 0) {
|
|
525
487
|
var offset = -1 * (numberOfMonths - 1);
|
|
526
|
-
initialMonth =
|
|
488
|
+
initialMonth = addMonths(toDate, offset);
|
|
527
489
|
}
|
|
528
490
|
// Fix the initialMonth if is before the from-date
|
|
529
|
-
if (fromDate &&
|
|
491
|
+
if (fromDate && differenceInCalendarMonths(initialMonth, fromDate) < 0) {
|
|
530
492
|
initialMonth = fromDate;
|
|
531
493
|
}
|
|
532
|
-
return
|
|
494
|
+
return startOfMonth(initialMonth);
|
|
533
495
|
}
|
|
534
496
|
|
|
535
497
|
/** Controls the navigation state. */
|
|
@@ -541,7 +503,7 @@ function useNavigationState() {
|
|
|
541
503
|
var _a;
|
|
542
504
|
if (context.disableNavigation)
|
|
543
505
|
return;
|
|
544
|
-
var month =
|
|
506
|
+
var month = startOfMonth(date);
|
|
545
507
|
setMonth(month);
|
|
546
508
|
(_a = context.onMonthChange) === null || _a === void 0 ? void 0 : _a.call(context, month);
|
|
547
509
|
};
|
|
@@ -554,12 +516,12 @@ function useNavigationState() {
|
|
|
554
516
|
*/
|
|
555
517
|
function getDisplayMonths(month, _a) {
|
|
556
518
|
var reverseMonths = _a.reverseMonths, numberOfMonths = _a.numberOfMonths;
|
|
557
|
-
var start =
|
|
558
|
-
var end =
|
|
559
|
-
var monthsDiff =
|
|
519
|
+
var start = startOfMonth(month);
|
|
520
|
+
var end = startOfMonth(addMonths(start, numberOfMonths));
|
|
521
|
+
var monthsDiff = differenceInCalendarMonths(end, start);
|
|
560
522
|
var months = [];
|
|
561
523
|
for (var i = 0; i < monthsDiff; i++) {
|
|
562
|
-
var nextMonth =
|
|
524
|
+
var nextMonth = addMonths(start, i);
|
|
563
525
|
months.push(nextMonth);
|
|
564
526
|
}
|
|
565
527
|
if (reverseMonths)
|
|
@@ -583,16 +545,16 @@ function getNextMonth(startingMonth, options) {
|
|
|
583
545
|
}
|
|
584
546
|
var toDate = options.toDate, pagedNavigation = options.pagedNavigation, _a = options.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
|
|
585
547
|
var offset = pagedNavigation ? numberOfMonths : 1;
|
|
586
|
-
var month =
|
|
548
|
+
var month = startOfMonth(startingMonth);
|
|
587
549
|
if (!toDate) {
|
|
588
|
-
return
|
|
550
|
+
return addMonths(month, offset);
|
|
589
551
|
}
|
|
590
|
-
var monthsDiff =
|
|
552
|
+
var monthsDiff = differenceInCalendarMonths(toDate, startingMonth);
|
|
591
553
|
if (monthsDiff < numberOfMonths) {
|
|
592
554
|
return undefined;
|
|
593
555
|
}
|
|
594
556
|
// Jump forward as the number of months when paged navigation
|
|
595
|
-
return
|
|
557
|
+
return addMonths(month, offset);
|
|
596
558
|
}
|
|
597
559
|
|
|
598
560
|
/**
|
|
@@ -612,16 +574,16 @@ function getPreviousMonth(startingMonth, options) {
|
|
|
612
574
|
}
|
|
613
575
|
var fromDate = options.fromDate, pagedNavigation = options.pagedNavigation, _a = options.numberOfMonths, numberOfMonths = _a === void 0 ? 1 : _a;
|
|
614
576
|
var offset = pagedNavigation ? numberOfMonths : 1;
|
|
615
|
-
var month =
|
|
577
|
+
var month = startOfMonth(startingMonth);
|
|
616
578
|
if (!fromDate) {
|
|
617
|
-
return
|
|
579
|
+
return addMonths(month, -offset);
|
|
618
580
|
}
|
|
619
|
-
var monthsDiff =
|
|
581
|
+
var monthsDiff = differenceInCalendarMonths(month, fromDate);
|
|
620
582
|
if (monthsDiff <= 0) {
|
|
621
583
|
return undefined;
|
|
622
584
|
}
|
|
623
585
|
// Jump back as the number of months when paged navigation
|
|
624
|
-
return
|
|
586
|
+
return addMonths(month, -offset);
|
|
625
587
|
}
|
|
626
588
|
|
|
627
589
|
/**
|
|
@@ -638,15 +600,15 @@ function NavigationProvider(props) {
|
|
|
638
600
|
var previousMonth = getPreviousMonth(currentMonth, dayPicker);
|
|
639
601
|
var isDateDisplayed = function (date) {
|
|
640
602
|
return displayMonths.some(function (displayMonth) {
|
|
641
|
-
return
|
|
603
|
+
return isSameMonth(date, displayMonth);
|
|
642
604
|
});
|
|
643
605
|
};
|
|
644
606
|
var goToDate = function (date, refDate) {
|
|
645
607
|
if (isDateDisplayed(date)) {
|
|
646
608
|
return;
|
|
647
609
|
}
|
|
648
|
-
if (refDate &&
|
|
649
|
-
goToMonth(
|
|
610
|
+
if (refDate && isBefore(date, refDate)) {
|
|
611
|
+
goToMonth(addMonths(date, 1 + dayPicker.numberOfMonths * -1));
|
|
650
612
|
}
|
|
651
613
|
else {
|
|
652
614
|
goToMonth(date);
|
|
@@ -661,7 +623,7 @@ function NavigationProvider(props) {
|
|
|
661
623
|
nextMonth: nextMonth,
|
|
662
624
|
isDateDisplayed: isDateDisplayed
|
|
663
625
|
};
|
|
664
|
-
return (
|
|
626
|
+
return (React.createElement(NavigationContext.Provider, { value: value }, props.children));
|
|
665
627
|
}
|
|
666
628
|
/**
|
|
667
629
|
* Hook to access the {@link NavigationContextValue}. Use this hook to navigate
|
|
@@ -688,27 +650,27 @@ function CaptionDropdowns(props) {
|
|
|
688
650
|
goToMonth(newMonth);
|
|
689
651
|
};
|
|
690
652
|
var CaptionLabelComponent = (_a = components === null || components === void 0 ? void 0 : components.CaptionLabel) !== null && _a !== void 0 ? _a : CaptionLabel;
|
|
691
|
-
var captionLabel = (
|
|
692
|
-
return (
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
653
|
+
var captionLabel = (React.createElement(CaptionLabelComponent, { id: props.id, displayMonth: props.displayMonth }));
|
|
654
|
+
return (React.createElement("div", { className: classNames.caption_dropdowns, style: styles.caption_dropdowns },
|
|
655
|
+
React.createElement("div", { className: classNames.vhidden }, captionLabel),
|
|
656
|
+
React.createElement(MonthsDropdown, { onChange: handleMonthChange, displayMonth: props.displayMonth }),
|
|
657
|
+
React.createElement(YearsDropdown, { onChange: handleMonthChange, displayMonth: props.displayMonth })));
|
|
696
658
|
}
|
|
697
659
|
|
|
698
660
|
/**
|
|
699
661
|
* Render the "previous month" button in the navigation.
|
|
700
662
|
*/
|
|
701
663
|
function IconLeft(props) {
|
|
702
|
-
return (
|
|
703
|
-
|
|
664
|
+
return (React.createElement("svg", __assign({ width: "16px", height: "16px", viewBox: "0 0 120 120" }, props),
|
|
665
|
+
React.createElement("path", { 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", fill: "currentColor", fillRule: "nonzero" })));
|
|
704
666
|
}
|
|
705
667
|
|
|
706
668
|
/**
|
|
707
669
|
* Render the "next month" button in the navigation.
|
|
708
670
|
*/
|
|
709
671
|
function IconRight(props) {
|
|
710
|
-
return (
|
|
711
|
-
|
|
672
|
+
return (React.createElement("svg", __assign({ width: "16px", height: "16px", viewBox: "0 0 120 120" }, props),
|
|
673
|
+
React.createElement("path", { 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", fill: "currentColor" })));
|
|
712
674
|
}
|
|
713
675
|
|
|
714
676
|
/**
|
|
@@ -725,7 +687,7 @@ var Button = React.forwardRef(function (props, ref) {
|
|
|
725
687
|
if (props.style) {
|
|
726
688
|
Object.assign(style, props.style);
|
|
727
689
|
}
|
|
728
|
-
return (
|
|
690
|
+
return (React.createElement("button", __assign({}, props, { ref: ref, type: "button", className: className, style: style })));
|
|
729
691
|
});
|
|
730
692
|
|
|
731
693
|
/** A component rendering the navigation buttons or the drop-downs. */
|
|
@@ -733,7 +695,7 @@ function Navigation(props) {
|
|
|
733
695
|
var _a, _b;
|
|
734
696
|
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;
|
|
735
697
|
if (!props.nextMonth && !props.previousMonth) {
|
|
736
|
-
return
|
|
698
|
+
return React.createElement(React.Fragment, null);
|
|
737
699
|
}
|
|
738
700
|
var previousLabel = labelPrevious(props.previousMonth, { locale: locale });
|
|
739
701
|
var previousClassName = [
|
|
@@ -747,9 +709,9 @@ function Navigation(props) {
|
|
|
747
709
|
].join(' ');
|
|
748
710
|
var IconRightComponent = (_a = components === null || components === void 0 ? void 0 : components.IconRight) !== null && _a !== void 0 ? _a : IconRight;
|
|
749
711
|
var IconLeftComponent = (_b = components === null || components === void 0 ? void 0 : components.IconLeft) !== null && _b !== void 0 ? _b : IconLeft;
|
|
750
|
-
return (
|
|
751
|
-
!props.hidePrevious && (
|
|
752
|
-
!props.hideNext && (
|
|
712
|
+
return (React.createElement("div", { className: classNames.nav, style: styles.nav },
|
|
713
|
+
!props.hidePrevious && (React.createElement(Button, { name: "previous-month", "aria-label": previousLabel, className: previousClassName, style: styles.nav_button_previous, disabled: !props.previousMonth, onClick: props.onPreviousClick }, dir === 'rtl' ? (React.createElement(IconRightComponent, { className: classNames.nav_icon, style: styles.nav_icon })) : (React.createElement(IconLeftComponent, { className: classNames.nav_icon, style: styles.nav_icon })))),
|
|
714
|
+
!props.hideNext && (React.createElement(Button, { name: "next-month", "aria-label": nextLabel, className: nextClassName, style: styles.nav_button_next, disabled: !props.nextMonth, onClick: props.onNextClick }, dir === 'rtl' ? (React.createElement(IconLeftComponent, { className: classNames.nav_icon, style: styles.nav_icon })) : (React.createElement(IconRightComponent, { className: classNames.nav_icon, style: styles.nav_icon }))))));
|
|
753
715
|
}
|
|
754
716
|
|
|
755
717
|
/**
|
|
@@ -761,7 +723,7 @@ function CaptionNavigation(props) {
|
|
|
761
723
|
var _c = useDayPicker(), numberOfMonths = _c.numberOfMonths, dir = _c.dir, components = _c.components;
|
|
762
724
|
var _d = useNavigation(), previousMonth = _d.previousMonth, nextMonth = _d.nextMonth, goToMonth = _d.goToMonth, displayMonths = _d.displayMonths;
|
|
763
725
|
var displayIndex = displayMonths.findIndex(function (month) {
|
|
764
|
-
return
|
|
726
|
+
return isSameMonth(props.displayMonth, month);
|
|
765
727
|
});
|
|
766
728
|
var isFirst = displayIndex === 0;
|
|
767
729
|
var isLast = displayIndex === displayMonths.length - 1;
|
|
@@ -781,10 +743,10 @@ function CaptionNavigation(props) {
|
|
|
781
743
|
goToMonth(nextMonth);
|
|
782
744
|
};
|
|
783
745
|
var CaptionLabelComponent = (_b = components === null || components === void 0 ? void 0 : components.CaptionLabel) !== null && _b !== void 0 ? _b : CaptionLabel;
|
|
784
|
-
var captionLabel = (
|
|
785
|
-
return (
|
|
746
|
+
var captionLabel = (React.createElement(CaptionLabelComponent, { id: props.id, displayMonth: props.displayMonth }));
|
|
747
|
+
return (React.createElement(React.Fragment, null,
|
|
786
748
|
captionLabel,
|
|
787
|
-
|
|
749
|
+
React.createElement(Navigation, { displayMonth: props.displayMonth, hideNext: hideNext, hidePrevious: hidePrevious, nextMonth: nextMonth, previousMonth: previousMonth, onPreviousClick: handlePreviousClick, onNextClick: handleNextClick })));
|
|
788
750
|
}
|
|
789
751
|
|
|
790
752
|
/**
|
|
@@ -797,25 +759,25 @@ function Caption(props) {
|
|
|
797
759
|
var CaptionLabelComponent = (_a = components === null || components === void 0 ? void 0 : components.CaptionLabel) !== null && _a !== void 0 ? _a : CaptionLabel;
|
|
798
760
|
var caption;
|
|
799
761
|
if (disableNavigation) {
|
|
800
|
-
caption = (
|
|
762
|
+
caption = (React.createElement(CaptionLabelComponent, { id: props.id, displayMonth: props.displayMonth }));
|
|
801
763
|
}
|
|
802
764
|
else if (captionLayout === 'dropdown') {
|
|
803
|
-
caption = (
|
|
765
|
+
caption = (React.createElement(CaptionDropdowns, { displayMonth: props.displayMonth, id: props.id }));
|
|
804
766
|
}
|
|
805
767
|
else {
|
|
806
|
-
caption = (
|
|
768
|
+
caption = (React.createElement(CaptionNavigation, { displayMonth: props.displayMonth, id: props.id }));
|
|
807
769
|
}
|
|
808
|
-
return (
|
|
770
|
+
return (React.createElement("div", { className: classNames.caption, style: styles.caption }, caption));
|
|
809
771
|
}
|
|
810
772
|
|
|
811
773
|
/** Render the Footer component (empty as default).*/
|
|
812
774
|
function Footer() {
|
|
813
775
|
var _a = useDayPicker(), footer = _a.footer, styles = _a.styles, tfoot = _a.classNames.tfoot;
|
|
814
776
|
if (!footer)
|
|
815
|
-
return
|
|
816
|
-
return (
|
|
817
|
-
|
|
818
|
-
|
|
777
|
+
return React.createElement(React.Fragment, null);
|
|
778
|
+
return (React.createElement("tfoot", { className: tfoot, style: styles.tfoot },
|
|
779
|
+
React.createElement("tr", null,
|
|
780
|
+
React.createElement("td", { colSpan: 8 }, footer))));
|
|
819
781
|
}
|
|
820
782
|
|
|
821
783
|
/**
|
|
@@ -828,11 +790,11 @@ weekStartsOn,
|
|
|
828
790
|
/** Use ISOWeek instead of locale/ */
|
|
829
791
|
ISOWeek) {
|
|
830
792
|
var start = ISOWeek
|
|
831
|
-
?
|
|
832
|
-
:
|
|
793
|
+
? startOfISOWeek(new Date())
|
|
794
|
+
: startOfWeek(new Date(), { locale: locale, weekStartsOn: weekStartsOn });
|
|
833
795
|
var days = [];
|
|
834
796
|
for (var i = 0; i < 7; i++) {
|
|
835
|
-
var day =
|
|
797
|
+
var day = addDays(start, i);
|
|
836
798
|
days.push(day);
|
|
837
799
|
}
|
|
838
800
|
return days;
|
|
@@ -844,11 +806,11 @@ ISOWeek) {
|
|
|
844
806
|
function HeadRow() {
|
|
845
807
|
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;
|
|
846
808
|
var weekdays = getWeekdays(locale, weekStartsOn, ISOWeek);
|
|
847
|
-
return (
|
|
848
|
-
showWeekNumber && (
|
|
849
|
-
weekdays.map(function (weekday, i) { return (
|
|
850
|
-
|
|
851
|
-
|
|
809
|
+
return (React.createElement("tr", { style: styles.head_row, className: classNames.head_row },
|
|
810
|
+
showWeekNumber && (React.createElement("th", { scope: "col", style: styles.head_cell, className: classNames.head_cell })),
|
|
811
|
+
weekdays.map(function (weekday, i) { return (React.createElement("th", { key: i, scope: "col", className: classNames.head_cell, style: styles.head_cell },
|
|
812
|
+
React.createElement("span", { "aria-hidden": true }, formatWeekdayName(weekday, { locale: locale })),
|
|
813
|
+
React.createElement("span", { className: classNames.vhidden }, labelWeekday(weekday, { locale: locale })))); })));
|
|
852
814
|
}
|
|
853
815
|
|
|
854
816
|
/** Render the table head. */
|
|
@@ -856,14 +818,14 @@ function Head() {
|
|
|
856
818
|
var _a;
|
|
857
819
|
var _b = useDayPicker(), classNames = _b.classNames, styles = _b.styles, components = _b.components;
|
|
858
820
|
var HeadRowComponent = (_a = components === null || components === void 0 ? void 0 : components.HeadRow) !== null && _a !== void 0 ? _a : HeadRow;
|
|
859
|
-
return (
|
|
860
|
-
|
|
821
|
+
return (React.createElement("thead", { style: styles.head, className: classNames.head },
|
|
822
|
+
React.createElement(HeadRowComponent, null)));
|
|
861
823
|
}
|
|
862
824
|
|
|
863
825
|
/** Render the content of the day cell. */
|
|
864
826
|
function DayContent(props) {
|
|
865
827
|
var _a = useDayPicker(), locale = _a.locale, formatDay = _a.formatters.formatDay;
|
|
866
|
-
return
|
|
828
|
+
return React.createElement(React.Fragment, null, formatDay(props.date, { locale: locale }));
|
|
867
829
|
}
|
|
868
830
|
|
|
869
831
|
/**
|
|
@@ -882,9 +844,9 @@ function SelectMultipleProvider(props) {
|
|
|
882
844
|
disabled: []
|
|
883
845
|
}
|
|
884
846
|
};
|
|
885
|
-
return (
|
|
847
|
+
return (React.createElement(SelectMultipleContext.Provider, { value: emptyContextValue }, props.children));
|
|
886
848
|
}
|
|
887
|
-
return (
|
|
849
|
+
return (React.createElement(SelectMultipleProviderInternal, { initialProps: props.initialProps, children: props.children }));
|
|
888
850
|
}
|
|
889
851
|
function SelectMultipleProviderInternal(_a) {
|
|
890
852
|
var initialProps = _a.initialProps, children = _a.children;
|
|
@@ -903,7 +865,7 @@ function SelectMultipleProviderInternal(_a) {
|
|
|
903
865
|
var selectedDays = selected ? __spreadArray([], selected, true) : [];
|
|
904
866
|
if (activeModifiers.selected) {
|
|
905
867
|
var index = selectedDays.findIndex(function (selectedDay) {
|
|
906
|
-
return
|
|
868
|
+
return isSameDay(day, selectedDay);
|
|
907
869
|
});
|
|
908
870
|
selectedDays.splice(index, 1);
|
|
909
871
|
}
|
|
@@ -919,7 +881,7 @@ function SelectMultipleProviderInternal(_a) {
|
|
|
919
881
|
modifiers.disabled.push(function (day) {
|
|
920
882
|
var isMaxSelected = max && selected.length > max - 1;
|
|
921
883
|
var isSelected = selected.some(function (selectedDay) {
|
|
922
|
-
return
|
|
884
|
+
return isSameDay(selectedDay, day);
|
|
923
885
|
});
|
|
924
886
|
return Boolean(isMaxSelected && !isSelected);
|
|
925
887
|
});
|
|
@@ -929,7 +891,7 @@ function SelectMultipleProviderInternal(_a) {
|
|
|
929
891
|
onDayClick: onDayClick,
|
|
930
892
|
modifiers: modifiers
|
|
931
893
|
};
|
|
932
|
-
return (
|
|
894
|
+
return (React.createElement(SelectMultipleContext.Provider, { value: contextValue }, children));
|
|
933
895
|
}
|
|
934
896
|
/**
|
|
935
897
|
* Hook to access the {@link SelectMultipleContextValue}.
|
|
@@ -955,25 +917,25 @@ function addToRange(day, range) {
|
|
|
955
917
|
if (!from) {
|
|
956
918
|
return { from: day, to: undefined };
|
|
957
919
|
}
|
|
958
|
-
if (!to &&
|
|
920
|
+
if (!to && isSameDay(from, day)) {
|
|
959
921
|
return { from: from, to: day };
|
|
960
922
|
}
|
|
961
|
-
if (!to &&
|
|
923
|
+
if (!to && isBefore(day, from)) {
|
|
962
924
|
return { from: day, to: from };
|
|
963
925
|
}
|
|
964
926
|
if (!to) {
|
|
965
927
|
return { from: from, to: day };
|
|
966
928
|
}
|
|
967
|
-
if (
|
|
929
|
+
if (isSameDay(to, day) && isSameDay(from, day)) {
|
|
968
930
|
return undefined;
|
|
969
931
|
}
|
|
970
|
-
if (
|
|
932
|
+
if (isSameDay(to, day)) {
|
|
971
933
|
return { from: to, to: undefined };
|
|
972
934
|
}
|
|
973
|
-
if (
|
|
935
|
+
if (isSameDay(from, day)) {
|
|
974
936
|
return undefined;
|
|
975
937
|
}
|
|
976
|
-
if (
|
|
938
|
+
if (isAfter(from, day)) {
|
|
977
939
|
return { from: day, to: to };
|
|
978
940
|
}
|
|
979
941
|
return { from: from, to: day };
|
|
@@ -998,9 +960,9 @@ function SelectRangeProvider(props) {
|
|
|
998
960
|
disabled: []
|
|
999
961
|
}
|
|
1000
962
|
};
|
|
1001
|
-
return (
|
|
963
|
+
return (React.createElement(SelectRangeContext.Provider, { value: emptyContextValue }, props.children));
|
|
1002
964
|
}
|
|
1003
|
-
return (
|
|
965
|
+
return (React.createElement(SelectRangeProviderInternal, { initialProps: props.initialProps, children: props.children }));
|
|
1004
966
|
}
|
|
1005
967
|
function SelectRangeProviderInternal(_a) {
|
|
1006
968
|
var initialProps = _a.initialProps, children = _a.children;
|
|
@@ -1040,38 +1002,38 @@ function SelectRangeProviderInternal(_a) {
|
|
|
1040
1002
|
if (min) {
|
|
1041
1003
|
if (selectedFrom && !selectedTo) {
|
|
1042
1004
|
modifiers.disabled.push({
|
|
1043
|
-
after:
|
|
1044
|
-
before:
|
|
1005
|
+
after: subDays(selectedFrom, min - 1),
|
|
1006
|
+
before: addDays(selectedFrom, min - 1)
|
|
1045
1007
|
});
|
|
1046
1008
|
}
|
|
1047
1009
|
if (selectedFrom && selectedTo) {
|
|
1048
1010
|
modifiers.disabled.push({
|
|
1049
1011
|
after: selectedFrom,
|
|
1050
|
-
before:
|
|
1012
|
+
before: addDays(selectedFrom, min - 1)
|
|
1051
1013
|
});
|
|
1052
1014
|
}
|
|
1053
1015
|
}
|
|
1054
1016
|
if (max) {
|
|
1055
1017
|
if (selectedFrom && !selectedTo) {
|
|
1056
1018
|
modifiers.disabled.push({
|
|
1057
|
-
before:
|
|
1019
|
+
before: addDays(selectedFrom, -max + 1)
|
|
1058
1020
|
});
|
|
1059
1021
|
modifiers.disabled.push({
|
|
1060
|
-
after:
|
|
1022
|
+
after: addDays(selectedFrom, max - 1)
|
|
1061
1023
|
});
|
|
1062
1024
|
}
|
|
1063
1025
|
if (selectedFrom && selectedTo) {
|
|
1064
|
-
var selectedCount =
|
|
1026
|
+
var selectedCount = differenceInCalendarDays(selectedTo, selectedFrom) + 1;
|
|
1065
1027
|
var offset = max - selectedCount;
|
|
1066
1028
|
modifiers.disabled.push({
|
|
1067
|
-
before:
|
|
1029
|
+
before: subDays(selectedFrom, offset)
|
|
1068
1030
|
});
|
|
1069
1031
|
modifiers.disabled.push({
|
|
1070
|
-
after:
|
|
1032
|
+
after: addDays(selectedTo, offset)
|
|
1071
1033
|
});
|
|
1072
1034
|
}
|
|
1073
1035
|
}
|
|
1074
|
-
return (
|
|
1036
|
+
return (React.createElement(SelectRangeContext.Provider, { value: { selected: selected, onDayClick: onDayClick, modifiers: modifiers } }, children));
|
|
1075
1037
|
}
|
|
1076
1038
|
/**
|
|
1077
1039
|
* Hook to access the {@link SelectRangeContextValue}.
|
|
@@ -1171,7 +1133,7 @@ function ModifiersProvider(props) {
|
|
|
1171
1133
|
var internalModifiers = getInternalModifiers(dayPicker, selectMultiple, selectRange);
|
|
1172
1134
|
var customModifiers = getCustomModifiers(dayPicker.modifiers);
|
|
1173
1135
|
var modifiers = __assign(__assign({}, internalModifiers), customModifiers);
|
|
1174
|
-
return (
|
|
1136
|
+
return (React.createElement(ModifiersContext.Provider, { value: modifiers }, props.children));
|
|
1175
1137
|
}
|
|
1176
1138
|
/**
|
|
1177
1139
|
* Return the modifiers used by DayPicker.
|
|
@@ -1219,28 +1181,28 @@ function isDateInRange(date, range) {
|
|
|
1219
1181
|
if (!from) {
|
|
1220
1182
|
return false;
|
|
1221
1183
|
}
|
|
1222
|
-
if (!to &&
|
|
1184
|
+
if (!to && isSameDay(from, date)) {
|
|
1223
1185
|
return true;
|
|
1224
1186
|
}
|
|
1225
1187
|
if (!to) {
|
|
1226
1188
|
return false;
|
|
1227
1189
|
}
|
|
1228
|
-
var isRangeInverted =
|
|
1190
|
+
var isRangeInverted = differenceInCalendarDays(to, from) < 0;
|
|
1229
1191
|
if (isRangeInverted) {
|
|
1230
1192
|
_a = [to, from], from = _a[0], to = _a[1];
|
|
1231
1193
|
}
|
|
1232
|
-
var isInRange =
|
|
1233
|
-
|
|
1194
|
+
var isInRange = differenceInCalendarDays(date, from) >= 0 &&
|
|
1195
|
+
differenceInCalendarDays(to, date) >= 0;
|
|
1234
1196
|
return isInRange;
|
|
1235
1197
|
}
|
|
1236
1198
|
|
|
1237
1199
|
/** Returns true if `value` is a Date type. */
|
|
1238
1200
|
function isDateType(value) {
|
|
1239
|
-
return
|
|
1201
|
+
return isDate(value);
|
|
1240
1202
|
}
|
|
1241
1203
|
/** Returns true if `value` is an array of valid dates. */
|
|
1242
1204
|
function isArrayOfDates(value) {
|
|
1243
|
-
return Array.isArray(value) && value.every(
|
|
1205
|
+
return Array.isArray(value) && value.every(isDate);
|
|
1244
1206
|
}
|
|
1245
1207
|
/**
|
|
1246
1208
|
* Returns whether a day matches against at least one of the given Matchers.
|
|
@@ -1265,7 +1227,7 @@ function isMatch(day, matchers) {
|
|
|
1265
1227
|
return matcher;
|
|
1266
1228
|
}
|
|
1267
1229
|
if (isDateType(matcher)) {
|
|
1268
|
-
return
|
|
1230
|
+
return isSameDay(day, matcher);
|
|
1269
1231
|
}
|
|
1270
1232
|
if (isArrayOfDates(matcher)) {
|
|
1271
1233
|
return matcher.includes(day);
|
|
@@ -1277,8 +1239,8 @@ function isMatch(day, matchers) {
|
|
|
1277
1239
|
return matcher.dayOfWeek.includes(day.getDay());
|
|
1278
1240
|
}
|
|
1279
1241
|
if (isDateInterval(matcher)) {
|
|
1280
|
-
var diffBefore =
|
|
1281
|
-
var diffAfter =
|
|
1242
|
+
var diffBefore = differenceInCalendarDays(matcher.before, day);
|
|
1243
|
+
var diffAfter = differenceInCalendarDays(matcher.after, day);
|
|
1282
1244
|
var isDayBefore = diffBefore > 0;
|
|
1283
1245
|
var isDayAfter = diffAfter < 0;
|
|
1284
1246
|
var isClosedInterval = dateFns.isAfter(matcher.before, matcher.after);
|
|
@@ -1290,10 +1252,10 @@ function isMatch(day, matchers) {
|
|
|
1290
1252
|
}
|
|
1291
1253
|
}
|
|
1292
1254
|
if (isDateAfterType(matcher)) {
|
|
1293
|
-
return
|
|
1255
|
+
return differenceInCalendarDays(day, matcher.after) > 0;
|
|
1294
1256
|
}
|
|
1295
1257
|
if (isDateBeforeType(matcher)) {
|
|
1296
|
-
return
|
|
1258
|
+
return differenceInCalendarDays(matcher.before, day) > 0;
|
|
1297
1259
|
}
|
|
1298
1260
|
if (typeof matcher === 'function') {
|
|
1299
1261
|
return matcher(day);
|
|
@@ -1317,7 +1279,7 @@ displayMonth) {
|
|
|
1317
1279
|
}, []);
|
|
1318
1280
|
var activeModifiers = {};
|
|
1319
1281
|
matchedModifiers.forEach(function (modifier) { return (activeModifiers[modifier] = true); });
|
|
1320
|
-
if (displayMonth && !
|
|
1282
|
+
if (displayMonth && !isSameMonth(day, displayMonth)) {
|
|
1321
1283
|
activeModifiers.outside = true;
|
|
1322
1284
|
}
|
|
1323
1285
|
return activeModifiers;
|
|
@@ -1332,8 +1294,8 @@ displayMonth) {
|
|
|
1332
1294
|
* https://github.com/gpbl/react-day-picker/pull/1576
|
|
1333
1295
|
*/
|
|
1334
1296
|
function getInitialFocusTarget(displayMonths, modifiers) {
|
|
1335
|
-
var firstDayInMonth =
|
|
1336
|
-
var lastDayInMonth =
|
|
1297
|
+
var firstDayInMonth = startOfMonth(displayMonths[0]);
|
|
1298
|
+
var lastDayInMonth = endOfMonth(displayMonths[displayMonths.length - 1]);
|
|
1337
1299
|
// TODO: cleanup code
|
|
1338
1300
|
var firstFocusableDay;
|
|
1339
1301
|
var today;
|
|
@@ -1342,7 +1304,7 @@ function getInitialFocusTarget(displayMonths, modifiers) {
|
|
|
1342
1304
|
var activeModifiers = getActiveModifiers(date, modifiers);
|
|
1343
1305
|
var isFocusable = !activeModifiers.disabled && !activeModifiers.hidden;
|
|
1344
1306
|
if (!isFocusable) {
|
|
1345
|
-
date =
|
|
1307
|
+
date = addDays(date, 1);
|
|
1346
1308
|
continue;
|
|
1347
1309
|
}
|
|
1348
1310
|
if (activeModifiers.selected) {
|
|
@@ -1354,7 +1316,7 @@ function getInitialFocusTarget(displayMonths, modifiers) {
|
|
|
1354
1316
|
if (!firstFocusableDay) {
|
|
1355
1317
|
firstFocusableDay = date;
|
|
1356
1318
|
}
|
|
1357
|
-
date =
|
|
1319
|
+
date = addDays(date, 1);
|
|
1358
1320
|
}
|
|
1359
1321
|
if (today) {
|
|
1360
1322
|
return today;
|
|
@@ -1370,27 +1332,27 @@ function getNextFocus(focusedDay, options) {
|
|
|
1370
1332
|
var moveBy = options.moveBy, direction = options.direction, context = options.context, modifiers = options.modifiers, _a = options.retry, retry = _a === void 0 ? { count: 0, lastFocused: focusedDay } : _a;
|
|
1371
1333
|
var weekStartsOn = context.weekStartsOn, fromDate = context.fromDate, toDate = context.toDate, locale = context.locale;
|
|
1372
1334
|
var moveFns = {
|
|
1373
|
-
day:
|
|
1374
|
-
week:
|
|
1375
|
-
month:
|
|
1376
|
-
year:
|
|
1335
|
+
day: addDays,
|
|
1336
|
+
week: addWeeks,
|
|
1337
|
+
month: addMonths,
|
|
1338
|
+
year: addYears,
|
|
1377
1339
|
startOfWeek: function (date) {
|
|
1378
1340
|
return context.ISOWeek
|
|
1379
|
-
?
|
|
1380
|
-
:
|
|
1341
|
+
? startOfISOWeek(date)
|
|
1342
|
+
: startOfWeek(date, { locale: locale, weekStartsOn: weekStartsOn });
|
|
1381
1343
|
},
|
|
1382
1344
|
endOfWeek: function (date) {
|
|
1383
1345
|
return context.ISOWeek
|
|
1384
|
-
?
|
|
1385
|
-
:
|
|
1346
|
+
? endOfISOWeek(date)
|
|
1347
|
+
: endOfWeek(date, { locale: locale, weekStartsOn: weekStartsOn });
|
|
1386
1348
|
}
|
|
1387
1349
|
};
|
|
1388
1350
|
var newFocusedDay = moveFns[moveBy](focusedDay, direction === 'after' ? 1 : -1);
|
|
1389
1351
|
if (direction === 'before' && fromDate) {
|
|
1390
|
-
newFocusedDay =
|
|
1352
|
+
newFocusedDay = max([fromDate, newFocusedDay]);
|
|
1391
1353
|
}
|
|
1392
1354
|
else if (direction === 'after' && toDate) {
|
|
1393
|
-
newFocusedDay =
|
|
1355
|
+
newFocusedDay = min([toDate, newFocusedDay]);
|
|
1394
1356
|
}
|
|
1395
1357
|
var isFocusable = true;
|
|
1396
1358
|
if (modifiers) {
|
|
@@ -1448,7 +1410,7 @@ function FocusProvider(props) {
|
|
|
1448
1410
|
context: context,
|
|
1449
1411
|
modifiers: modifiers
|
|
1450
1412
|
});
|
|
1451
|
-
if (
|
|
1413
|
+
if (isSameDay(focusedDay, nextFocused))
|
|
1452
1414
|
return undefined;
|
|
1453
1415
|
navigation.goToDate(nextFocused, focusedDay);
|
|
1454
1416
|
focus(nextFocused);
|
|
@@ -1469,7 +1431,7 @@ function FocusProvider(props) {
|
|
|
1469
1431
|
focusStartOfWeek: function () { return moveFocus('startOfWeek', 'before'); },
|
|
1470
1432
|
focusEndOfWeek: function () { return moveFocus('endOfWeek', 'after'); }
|
|
1471
1433
|
};
|
|
1472
|
-
return (
|
|
1434
|
+
return (React.createElement(FocusContext.Provider, { value: value }, props.children));
|
|
1473
1435
|
}
|
|
1474
1436
|
/**
|
|
1475
1437
|
* Hook to access the {@link FocusContextValue}. Use this hook to handle the
|
|
@@ -1517,9 +1479,9 @@ function SelectSingleProvider(props) {
|
|
|
1517
1479
|
var emptyContextValue = {
|
|
1518
1480
|
selected: undefined
|
|
1519
1481
|
};
|
|
1520
|
-
return (
|
|
1482
|
+
return (React.createElement(SelectSingleContext.Provider, { value: emptyContextValue }, props.children));
|
|
1521
1483
|
}
|
|
1522
|
-
return (
|
|
1484
|
+
return (React.createElement(SelectSingleProviderInternal, { initialProps: props.initialProps, children: props.children }));
|
|
1523
1485
|
}
|
|
1524
1486
|
function SelectSingleProviderInternal(_a) {
|
|
1525
1487
|
var initialProps = _a.initialProps, children = _a.children;
|
|
@@ -1536,7 +1498,7 @@ function SelectSingleProviderInternal(_a) {
|
|
|
1536
1498
|
selected: initialProps.selected,
|
|
1537
1499
|
onDayClick: onDayClick
|
|
1538
1500
|
};
|
|
1539
|
-
return (
|
|
1501
|
+
return (React.createElement(SelectSingleContext.Provider, { value: contextValue }, children));
|
|
1540
1502
|
}
|
|
1541
1503
|
/**
|
|
1542
1504
|
* Hook to access the {@link SelectSingleContextValue}.
|
|
@@ -1781,7 +1743,7 @@ buttonRef) {
|
|
|
1781
1743
|
return;
|
|
1782
1744
|
if (!isButton)
|
|
1783
1745
|
return;
|
|
1784
|
-
if (
|
|
1746
|
+
if (isSameDay(focusContext.focusedDay, day)) {
|
|
1785
1747
|
(_a = buttonRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
1786
1748
|
}
|
|
1787
1749
|
}, [
|
|
@@ -1799,7 +1761,7 @@ buttonRef) {
|
|
|
1799
1761
|
var isHidden = Boolean((activeModifiers.outside && !dayPicker.showOutsideDays) ||
|
|
1800
1762
|
activeModifiers.hidden);
|
|
1801
1763
|
var DayContentComponent = (_c = (_b = dayPicker.components) === null || _b === void 0 ? void 0 : _b.DayContent) !== null && _c !== void 0 ? _c : DayContent;
|
|
1802
|
-
var children = (
|
|
1764
|
+
var children = (React.createElement(DayContentComponent, { date: day, displayMonth: displayMonth, activeModifiers: activeModifiers }));
|
|
1803
1765
|
var divProps = {
|
|
1804
1766
|
style: style,
|
|
1805
1767
|
className: className,
|
|
@@ -1807,9 +1769,10 @@ buttonRef) {
|
|
|
1807
1769
|
'aria-label': ariaLabel
|
|
1808
1770
|
};
|
|
1809
1771
|
var isFocusTarget = focusContext.focusTarget &&
|
|
1810
|
-
|
|
1772
|
+
isSameDay(focusContext.focusTarget, day) &&
|
|
1811
1773
|
!activeModifiers.outside;
|
|
1812
|
-
var
|
|
1774
|
+
var isFocused = focusContext.focusedDay && isSameDay(focusContext.focusedDay, day);
|
|
1775
|
+
var buttonProps = __assign(__assign(__assign({}, divProps), (_a = { disabled: activeModifiers.disabled }, _a['aria-pressed'] = activeModifiers.selected, _a['aria-label'] = ariaLabel, _a.tabIndex = isFocused || isFocusTarget ? 0 : -1, _a)), eventHandlers);
|
|
1813
1776
|
var dayRender = {
|
|
1814
1777
|
isButton: isButton,
|
|
1815
1778
|
isHidden: isHidden,
|
|
@@ -1829,12 +1792,12 @@ function Day(props) {
|
|
|
1829
1792
|
var buttonRef = React.useRef(null);
|
|
1830
1793
|
var dayRender = useDayRender(props.date, props.displayMonth, buttonRef);
|
|
1831
1794
|
if (dayRender.isHidden) {
|
|
1832
|
-
return
|
|
1795
|
+
return React.createElement(React.Fragment, null);
|
|
1833
1796
|
}
|
|
1834
1797
|
if (!dayRender.isButton) {
|
|
1835
|
-
return
|
|
1798
|
+
return React.createElement("div", __assign({}, dayRender.divProps));
|
|
1836
1799
|
}
|
|
1837
|
-
return
|
|
1800
|
+
return React.createElement(Button, __assign({ name: "day", ref: buttonRef }, dayRender.buttonProps));
|
|
1838
1801
|
}
|
|
1839
1802
|
|
|
1840
1803
|
/**
|
|
@@ -1846,13 +1809,13 @@ function WeekNumber(props) {
|
|
|
1846
1809
|
var _a = useDayPicker(), onWeekNumberClick = _a.onWeekNumberClick, styles = _a.styles, classNames = _a.classNames, locale = _a.locale, labelWeekNumber = _a.labels.labelWeekNumber, formatWeekNumber = _a.formatters.formatWeekNumber;
|
|
1847
1810
|
var content = formatWeekNumber(Number(weekNumber), { locale: locale });
|
|
1848
1811
|
if (!onWeekNumberClick) {
|
|
1849
|
-
return (
|
|
1812
|
+
return (React.createElement("span", { className: classNames.weeknumber, style: styles.weeknumber }, content));
|
|
1850
1813
|
}
|
|
1851
1814
|
var label = labelWeekNumber(Number(weekNumber), { locale: locale });
|
|
1852
1815
|
var handleClick = function (e) {
|
|
1853
1816
|
onWeekNumberClick(weekNumber, dates, e);
|
|
1854
1817
|
};
|
|
1855
|
-
return (
|
|
1818
|
+
return (React.createElement(Button, { name: "week-number", "aria-label": label, className: classNames.weeknumber, style: styles.weeknumber, onClick: handleClick }, content));
|
|
1856
1819
|
}
|
|
1857
1820
|
|
|
1858
1821
|
/** Render a row in the calendar, with the days and the week number. */
|
|
@@ -1863,32 +1826,32 @@ function Row(props) {
|
|
|
1863
1826
|
var WeeknumberComponent = (_b = components === null || components === void 0 ? void 0 : components.WeekNumber) !== null && _b !== void 0 ? _b : WeekNumber;
|
|
1864
1827
|
var weekNumberCell;
|
|
1865
1828
|
if (showWeekNumber) {
|
|
1866
|
-
weekNumberCell = (
|
|
1867
|
-
|
|
1829
|
+
weekNumberCell = (React.createElement("td", { className: classNames.cell, style: styles.cell },
|
|
1830
|
+
React.createElement(WeeknumberComponent, { number: props.weekNumber, dates: props.dates })));
|
|
1868
1831
|
}
|
|
1869
|
-
return (
|
|
1832
|
+
return (React.createElement("tr", { className: classNames.row, style: styles.row },
|
|
1870
1833
|
weekNumberCell,
|
|
1871
|
-
props.dates.map(function (date) { return (
|
|
1872
|
-
|
|
1834
|
+
props.dates.map(function (date) { return (React.createElement("td", { className: classNames.cell, style: styles.cell, key: getUnixTime(date) },
|
|
1835
|
+
React.createElement(DayComponent, { displayMonth: props.displayMonth, date: date }))); })));
|
|
1873
1836
|
}
|
|
1874
1837
|
|
|
1875
1838
|
/** Return the weeks between two dates. */
|
|
1876
1839
|
function daysToMonthWeeks(fromDate, toDate, options) {
|
|
1877
1840
|
var toWeek = (options === null || options === void 0 ? void 0 : options.ISOWeek)
|
|
1878
|
-
?
|
|
1879
|
-
:
|
|
1841
|
+
? endOfISOWeek(toDate)
|
|
1842
|
+
: endOfWeek(toDate, options);
|
|
1880
1843
|
var fromWeek = (options === null || options === void 0 ? void 0 : options.ISOWeek)
|
|
1881
|
-
?
|
|
1882
|
-
:
|
|
1883
|
-
var nOfDays =
|
|
1844
|
+
? startOfISOWeek(fromDate)
|
|
1845
|
+
: startOfWeek(fromDate, options);
|
|
1846
|
+
var nOfDays = differenceInCalendarDays(toWeek, fromWeek);
|
|
1884
1847
|
var days = [];
|
|
1885
1848
|
for (var i = 0; i <= nOfDays; i++) {
|
|
1886
|
-
days.push(
|
|
1849
|
+
days.push(addDays(fromWeek, i));
|
|
1887
1850
|
}
|
|
1888
1851
|
var weeksInMonth = days.reduce(function (result, date) {
|
|
1889
1852
|
var weekNumber = (options === null || options === void 0 ? void 0 : options.ISOWeek)
|
|
1890
|
-
?
|
|
1891
|
-
:
|
|
1853
|
+
? getISOWeek(date)
|
|
1854
|
+
: getWeek(date, options);
|
|
1892
1855
|
var existingWeek = result.find(function (value) { return value.weekNumber === weekNumber; });
|
|
1893
1856
|
if (existingWeek) {
|
|
1894
1857
|
existingWeek.dates.push(date);
|
|
@@ -1908,15 +1871,15 @@ function daysToMonthWeeks(fromDate, toDate, options) {
|
|
|
1908
1871
|
* the first and last week.
|
|
1909
1872
|
*/
|
|
1910
1873
|
function getMonthWeeks(month, options) {
|
|
1911
|
-
var weeksInMonth = daysToMonthWeeks(
|
|
1874
|
+
var weeksInMonth = daysToMonthWeeks(startOfMonth(month), endOfMonth(month), options);
|
|
1912
1875
|
if (options === null || options === void 0 ? void 0 : options.useFixedWeeks) {
|
|
1913
1876
|
// Add extra weeks to the month, up to 6 weeks
|
|
1914
|
-
var nrOfMonthWeeks =
|
|
1877
|
+
var nrOfMonthWeeks = getWeeksInMonth(month, options);
|
|
1915
1878
|
if (nrOfMonthWeeks < 6) {
|
|
1916
1879
|
var lastWeek = weeksInMonth[weeksInMonth.length - 1];
|
|
1917
1880
|
var lastDate = lastWeek.dates[lastWeek.dates.length - 1];
|
|
1918
|
-
var toDate =
|
|
1919
|
-
var extraWeeks = daysToMonthWeeks(
|
|
1881
|
+
var toDate = addWeeks(lastDate, 6 - nrOfMonthWeeks);
|
|
1882
|
+
var extraWeeks = daysToMonthWeeks(addWeeks(lastDate, 1), toDate, options);
|
|
1920
1883
|
weeksInMonth.push.apply(weeksInMonth, extraWeeks);
|
|
1921
1884
|
}
|
|
1922
1885
|
}
|
|
@@ -1937,10 +1900,10 @@ function Table(props) {
|
|
|
1937
1900
|
var HeadComponent = (_a = components === null || components === void 0 ? void 0 : components.Head) !== null && _a !== void 0 ? _a : Head;
|
|
1938
1901
|
var RowComponent = (_b = components === null || components === void 0 ? void 0 : components.Row) !== null && _b !== void 0 ? _b : Row;
|
|
1939
1902
|
var FooterComponent = (_c = components === null || components === void 0 ? void 0 : components.Footer) !== null && _c !== void 0 ? _c : Footer;
|
|
1940
|
-
return (
|
|
1941
|
-
!hideHead &&
|
|
1942
|
-
|
|
1943
|
-
|
|
1903
|
+
return (React.createElement("table", { className: classNames.table, style: styles.table, role: "grid", "aria-labelledby": props['aria-labelledby'] },
|
|
1904
|
+
!hideHead && React.createElement(HeadComponent, null),
|
|
1905
|
+
React.createElement("tbody", { className: classNames.tbody, style: styles.tbody }, weeks.map(function (week) { return (React.createElement(RowComponent, { displayMonth: props.displayMonth, key: week.weekNumber, dates: week.dates, weekNumber: week.weekNumber })); })),
|
|
1906
|
+
React.createElement(FooterComponent, null)));
|
|
1944
1907
|
}
|
|
1945
1908
|
|
|
1946
1909
|
/*
|
|
@@ -2049,9 +2012,9 @@ function Month(props) {
|
|
|
2049
2012
|
style = __assign(__assign({}, style), styles.caption_between);
|
|
2050
2013
|
}
|
|
2051
2014
|
var CaptionComponent = (_b = components === null || components === void 0 ? void 0 : components.Caption) !== null && _b !== void 0 ? _b : Caption;
|
|
2052
|
-
return (
|
|
2053
|
-
|
|
2054
|
-
|
|
2015
|
+
return (React.createElement("div", { key: props.displayIndex, className: className.join(' '), style: style },
|
|
2016
|
+
React.createElement(CaptionComponent, { id: captionId, displayMonth: props.displayMonth }),
|
|
2017
|
+
React.createElement(Table, { "aria-labelledby": captionId, displayMonth: props.displayMonth })));
|
|
2055
2018
|
}
|
|
2056
2019
|
|
|
2057
2020
|
/** Render the container with the months according to the number of months to display. */
|
|
@@ -2086,20 +2049,20 @@ function Root() {
|
|
|
2086
2049
|
classNames.push(dayPicker.classNames.with_weeknumber);
|
|
2087
2050
|
}
|
|
2088
2051
|
var style = __assign(__assign({}, dayPicker.styles.root), dayPicker.style);
|
|
2089
|
-
return (
|
|
2090
|
-
|
|
2052
|
+
return (React.createElement("div", { className: classNames.join(' '), style: style, dir: dayPicker.dir },
|
|
2053
|
+
React.createElement("div", { className: dayPicker.classNames.months, style: dayPicker.styles.months }, navigation.displayMonths.map(function (month, i) { return (React.createElement(Month, { key: i, displayIndex: i, displayMonth: month })); }))));
|
|
2091
2054
|
}
|
|
2092
2055
|
|
|
2093
2056
|
/** Provide the value for all the context providers. */
|
|
2094
2057
|
function RootProvider(props) {
|
|
2095
2058
|
var children = props.children, initialProps = __rest(props, ["children"]);
|
|
2096
|
-
return (
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2059
|
+
return (React.createElement(DayPickerProvider, { initialProps: initialProps },
|
|
2060
|
+
React.createElement(NavigationProvider, null,
|
|
2061
|
+
React.createElement(SelectSingleProvider, { initialProps: initialProps },
|
|
2062
|
+
React.createElement(SelectMultipleProvider, { initialProps: initialProps },
|
|
2063
|
+
React.createElement(SelectRangeProvider, { initialProps: initialProps },
|
|
2064
|
+
React.createElement(ModifiersProvider, null,
|
|
2065
|
+
React.createElement(FocusProvider, null, children))))))));
|
|
2103
2066
|
}
|
|
2104
2067
|
|
|
2105
2068
|
/**
|
|
@@ -2190,8 +2153,8 @@ function RootProvider(props) {
|
|
|
2190
2153
|
* ```
|
|
2191
2154
|
*/
|
|
2192
2155
|
function DayPicker(props) {
|
|
2193
|
-
return (
|
|
2194
|
-
|
|
2156
|
+
return (React.createElement(RootProvider, __assign({}, props),
|
|
2157
|
+
React.createElement(Root, null)));
|
|
2195
2158
|
}
|
|
2196
2159
|
|
|
2197
2160
|
/** @private */
|
|
@@ -2202,15 +2165,15 @@ function isValidDate(day) {
|
|
|
2202
2165
|
/** Return props and setters for binding an input field to DayPicker. */
|
|
2203
2166
|
function useInput(options) {
|
|
2204
2167
|
if (options === void 0) { options = {}; }
|
|
2205
|
-
var _a = options.locale, locale = _a === void 0 ?
|
|
2168
|
+
var _a = options.locale, locale = _a === void 0 ? enUS : _a, required = options.required, _b = options.format, format$1 = _b === void 0 ? 'PP' : _b, defaultSelected = options.defaultSelected, _c = options.today, today = _c === void 0 ? new Date() : _c;
|
|
2206
2169
|
var _d = parseFromToProps(options), fromDate = _d.fromDate, toDate = _d.toDate;
|
|
2207
2170
|
// Shortcut to the DateFns functions
|
|
2208
|
-
var parseValue = function (value) { return
|
|
2171
|
+
var parseValue = function (value) { return parse(value, format$1, today, { locale: locale }); };
|
|
2209
2172
|
// Initialize states
|
|
2210
2173
|
var _e = React.useState(defaultSelected !== null && defaultSelected !== void 0 ? defaultSelected : today), month = _e[0], setMonth = _e[1];
|
|
2211
2174
|
var _f = React.useState(defaultSelected), selectedDay = _f[0], setSelectedDay = _f[1];
|
|
2212
2175
|
var defaultInputValue = defaultSelected
|
|
2213
|
-
?
|
|
2176
|
+
? format(defaultSelected, format$1, { locale: locale })
|
|
2214
2177
|
: '';
|
|
2215
2178
|
var _g = React.useState(defaultInputValue), inputValue = _g[0], setInputValue = _g[1];
|
|
2216
2179
|
var reset = function () {
|
|
@@ -2221,7 +2184,7 @@ function useInput(options) {
|
|
|
2221
2184
|
var setSelected = function (date) {
|
|
2222
2185
|
setSelectedDay(date);
|
|
2223
2186
|
setMonth(date !== null && date !== void 0 ? date : today);
|
|
2224
|
-
setInputValue(date ?
|
|
2187
|
+
setInputValue(date ? format(date, format$1, { locale: locale }) : '');
|
|
2225
2188
|
};
|
|
2226
2189
|
var handleDayClick = function (day, _a) {
|
|
2227
2190
|
var selected = _a.selected;
|
|
@@ -2231,7 +2194,7 @@ function useInput(options) {
|
|
|
2231
2194
|
return;
|
|
2232
2195
|
}
|
|
2233
2196
|
setSelectedDay(day);
|
|
2234
|
-
setInputValue(day ?
|
|
2197
|
+
setInputValue(day ? format(day, format$1, { locale: locale }) : '');
|
|
2235
2198
|
};
|
|
2236
2199
|
var handleMonthChange = function (month) {
|
|
2237
2200
|
setMonth(month);
|
|
@@ -2242,8 +2205,8 @@ function useInput(options) {
|
|
|
2242
2205
|
var handleChange = function (e) {
|
|
2243
2206
|
setInputValue(e.target.value);
|
|
2244
2207
|
var day = parseValue(e.target.value);
|
|
2245
|
-
var isBefore = fromDate &&
|
|
2246
|
-
var isAfter = toDate &&
|
|
2208
|
+
var isBefore = fromDate && differenceInCalendarDays(fromDate, day) > 0;
|
|
2209
|
+
var isAfter = toDate && differenceInCalendarDays(day, toDate) > 0;
|
|
2247
2210
|
if (!isValidDate(day) || isBefore || isAfter) {
|
|
2248
2211
|
setSelectedDay(undefined);
|
|
2249
2212
|
return;
|
|
@@ -2286,7 +2249,7 @@ function useInput(options) {
|
|
|
2286
2249
|
onChange: handleChange,
|
|
2287
2250
|
onFocus: handleFocus,
|
|
2288
2251
|
value: inputValue,
|
|
2289
|
-
placeholder:
|
|
2252
|
+
placeholder: format(new Date(), format$1, { locale: locale })
|
|
2290
2253
|
};
|
|
2291
2254
|
return { dayPickerProps: dayPickerProps, inputProps: inputProps, reset: reset, setSelected: setSelected };
|
|
2292
2255
|
}
|