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