@uxf/datepicker 15.2.1 → 16.1.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/README.md +1 -1
- package/hooks/use-day.d.ts +2 -2
- package/hooks/use-day.js +92 -91
- package/hooks/use-day.test.js +16 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -284,7 +284,7 @@ export const DateRangePickerDay: FC<{ day: string; date: Date }> = ({ day, date
|
|
|
284
284
|
| onDateFocus | `(date: Date) => void` | yes | | |
|
|
285
285
|
| onDateHover | `(date: Date) => void` | yes | | |
|
|
286
286
|
| onDateSelect | `(date: Date) => void` | yes | | |
|
|
287
|
-
| unavailableDates | `Date[]` | |
|
|
287
|
+
| unavailableDates | `Date[]` | | `[]` | @deprecated |
|
|
288
288
|
| datesConfig | `DatesConfig[]` | | | |
|
|
289
289
|
|
|
290
290
|
**UseDayReturnType**
|
package/hooks/use-day.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ export interface UseDayProps {
|
|
|
14
14
|
onDateHover: (date: Date) => void;
|
|
15
15
|
onDateSelect: (date: Date) => void;
|
|
16
16
|
preventScroll?: boolean;
|
|
17
|
-
/** @deprecated */
|
|
18
|
-
unavailableDates
|
|
17
|
+
/** @deprecated Pass the dates in `datesConfig` with `isDisabled: true`. */
|
|
18
|
+
unavailableDates?: Date[];
|
|
19
19
|
}
|
|
20
20
|
export interface UseDayReturnType {
|
|
21
21
|
flags: Flag[];
|
package/hooks/use-day.js
CHANGED
|
@@ -9,92 +9,93 @@ const get_date_invervals_1 = require("../utils/get-date-invervals");
|
|
|
9
9
|
function useDay(t0) {
|
|
10
10
|
var _a;
|
|
11
11
|
const $ = (0, compiler_runtime_1.c)(49);
|
|
12
|
-
const { date, datesConfig, dayRef, focusedDate, isDateBlocked, isDateFocused, isDateHovered, isDateInsideRange, isDateSelected, onDateFocus, onDateHover, onDateSelect, preventScroll, unavailableDates } = t0;
|
|
12
|
+
const { date, datesConfig, dayRef, focusedDate, isDateBlocked, isDateFocused, isDateHovered, isDateInsideRange, isDateSelected, onDateFocus, onDateHover, onDateSelect, preventScroll, unavailableDates: t1 } = t0;
|
|
13
|
+
const unavailableDates = t1 === undefined ? empty_array_1.EMPTY_ARRAY : t1;
|
|
13
14
|
const disabledDatesFromConfig = (_a = datesConfig === null || datesConfig === void 0 ? void 0 : datesConfig.filter(_temp).flatMap(_temp2)) !== null && _a !== void 0 ? _a : empty_array_1.EMPTY_ARRAY;
|
|
14
15
|
const disabledDates = [...unavailableDates, ...disabledDatesFromConfig].filter(_temp3);
|
|
15
|
-
let
|
|
16
|
+
let t2;
|
|
16
17
|
if ($[0] !== date || $[1] !== onDateSelect) {
|
|
17
|
-
|
|
18
|
+
t2 = () => onDateSelect(date);
|
|
18
19
|
$[0] = date;
|
|
19
20
|
$[1] = onDateSelect;
|
|
20
|
-
$[2] =
|
|
21
|
+
$[2] = t2;
|
|
21
22
|
}
|
|
22
23
|
else {
|
|
23
|
-
|
|
24
|
+
t2 = $[2];
|
|
24
25
|
}
|
|
25
|
-
const onClick =
|
|
26
|
-
let
|
|
26
|
+
const onClick = t2;
|
|
27
|
+
let t3;
|
|
27
28
|
if ($[3] !== date || $[4] !== onDateHover) {
|
|
28
|
-
|
|
29
|
+
t3 = () => onDateHover(date);
|
|
29
30
|
$[3] = date;
|
|
30
31
|
$[4] = onDateHover;
|
|
31
|
-
$[5] =
|
|
32
|
+
$[5] = t3;
|
|
32
33
|
}
|
|
33
34
|
else {
|
|
34
|
-
|
|
35
|
+
t3 = $[5];
|
|
35
36
|
}
|
|
36
|
-
const onMouseEnter =
|
|
37
|
-
let
|
|
37
|
+
const onMouseEnter = t3;
|
|
38
|
+
let t4;
|
|
38
39
|
if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
|
|
39
|
-
|
|
40
|
-
$[6] =
|
|
40
|
+
t4 = (0, date_string_1.todayDateString)();
|
|
41
|
+
$[6] = t4;
|
|
41
42
|
}
|
|
42
43
|
else {
|
|
43
|
-
|
|
44
|
+
t4 = $[6];
|
|
44
45
|
}
|
|
45
|
-
let
|
|
46
|
+
let t5;
|
|
46
47
|
if ($[7] !== date) {
|
|
47
|
-
|
|
48
|
+
t5 = (0, date_string_1.toDateString)(date);
|
|
48
49
|
$[7] = date;
|
|
49
|
-
$[8] =
|
|
50
|
+
$[8] = t5;
|
|
50
51
|
}
|
|
51
52
|
else {
|
|
52
|
-
|
|
53
|
+
t5 = $[8];
|
|
53
54
|
}
|
|
54
|
-
const isToday =
|
|
55
|
-
let t5;
|
|
55
|
+
const isToday = t4 === t5;
|
|
56
56
|
let t6;
|
|
57
|
+
let t7;
|
|
57
58
|
if ($[9] !== date || $[10] !== dayRef || $[11] !== isDateFocused || $[12] !== preventScroll) {
|
|
58
|
-
|
|
59
|
+
t6 = () => {
|
|
59
60
|
if (dayRef && dayRef.current && isDateFocused(date)) {
|
|
60
61
|
dayRef.current.focus({
|
|
61
62
|
preventScroll
|
|
62
63
|
});
|
|
63
64
|
}
|
|
64
65
|
};
|
|
65
|
-
|
|
66
|
+
t7 = [dayRef, date, isDateFocused, preventScroll];
|
|
66
67
|
$[9] = date;
|
|
67
68
|
$[10] = dayRef;
|
|
68
69
|
$[11] = isDateFocused;
|
|
69
70
|
$[12] = preventScroll;
|
|
70
|
-
$[13] =
|
|
71
|
-
$[14] =
|
|
71
|
+
$[13] = t6;
|
|
72
|
+
$[14] = t7;
|
|
72
73
|
}
|
|
73
74
|
else {
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
t6 = $[13];
|
|
76
|
+
t7 = $[14];
|
|
76
77
|
}
|
|
77
|
-
(0, react_1.useEffect)(
|
|
78
|
-
let
|
|
78
|
+
(0, react_1.useEffect)(t6, t7);
|
|
79
|
+
let t8;
|
|
79
80
|
if ($[15] !== date || $[16] !== onDateFocus) {
|
|
80
|
-
|
|
81
|
+
t8 = e => {
|
|
81
82
|
if (["ArrowRight", "ArrowLeft", "ArrowUp", "ArrowDown"].includes(e.key)) {
|
|
82
83
|
e.preventDefault();
|
|
83
|
-
|
|
84
|
+
bb48: switch (e.key) {
|
|
84
85
|
case "ArrowRight":
|
|
85
86
|
{
|
|
86
87
|
onDateFocus((0, date_string_1.fromDateString)((0, date_string_1.addDays)((0, date_string_1.toDateString)(date), 1)));
|
|
87
|
-
break
|
|
88
|
+
break bb48;
|
|
88
89
|
}
|
|
89
90
|
case "ArrowLeft":
|
|
90
91
|
{
|
|
91
92
|
onDateFocus((0, date_string_1.fromDateString)((0, date_string_1.addDays)((0, date_string_1.toDateString)(date), -1)));
|
|
92
|
-
break
|
|
93
|
+
break bb48;
|
|
93
94
|
}
|
|
94
95
|
case "ArrowUp":
|
|
95
96
|
{
|
|
96
97
|
onDateFocus((0, date_string_1.fromDateString)((0, date_string_1.addDays)((0, date_string_1.toDateString)(date), -7)));
|
|
97
|
-
break
|
|
98
|
+
break bb48;
|
|
98
99
|
}
|
|
99
100
|
case "ArrowDown":
|
|
100
101
|
{
|
|
@@ -105,29 +106,29 @@ function useDay(t0) {
|
|
|
105
106
|
};
|
|
106
107
|
$[15] = date;
|
|
107
108
|
$[16] = onDateFocus;
|
|
108
|
-
$[17] =
|
|
109
|
+
$[17] = t8;
|
|
109
110
|
}
|
|
110
111
|
else {
|
|
111
|
-
|
|
112
|
+
t8 = $[17];
|
|
112
113
|
}
|
|
113
|
-
const onKeyDown =
|
|
114
|
+
const onKeyDown = t8;
|
|
114
115
|
const dateIntervals = (0, get_date_invervals_1.getDateIntervals)(disabledDates);
|
|
115
|
-
let
|
|
116
|
+
let t9;
|
|
116
117
|
if ($[18] !== date) {
|
|
117
|
-
|
|
118
|
+
t9 = (0, date_string_1.toDateString)(date);
|
|
118
119
|
$[18] = date;
|
|
119
|
-
$[19] =
|
|
120
|
+
$[19] = t9;
|
|
120
121
|
}
|
|
121
122
|
else {
|
|
122
|
-
|
|
123
|
+
t9 = $[19];
|
|
123
124
|
}
|
|
124
|
-
const dateStr =
|
|
125
|
+
const dateStr = t9;
|
|
125
126
|
const _isFirstUnavailableDate = () => dateIntervals.some(interval => (0, date_string_1.toDateString)(interval.start) === dateStr);
|
|
126
127
|
const _isLastUnavailableDate = () => dateIntervals.some(interval_0 => (0, date_string_1.toDateString)(interval_0.end) === dateStr);
|
|
127
|
-
let
|
|
128
|
+
let t10;
|
|
128
129
|
if ($[20] !== dateStr || $[21] !== datesConfig) {
|
|
129
130
|
const applicableDatesConfigs = datesConfig === null || datesConfig === void 0 ? void 0 : datesConfig.filter(config_1 => config_1.dates.some(configDay => (0, date_string_1.toDateString)(configDay) === dateStr));
|
|
130
|
-
|
|
131
|
+
t10 = applicableDatesConfigs === null || applicableDatesConfigs === void 0 ? void 0 : applicableDatesConfigs.reduce((acc, curr) => {
|
|
131
132
|
if (!curr.flag) {
|
|
132
133
|
return acc;
|
|
133
134
|
}
|
|
@@ -141,95 +142,95 @@ function useDay(t0) {
|
|
|
141
142
|
}, []);
|
|
142
143
|
$[20] = dateStr;
|
|
143
144
|
$[21] = datesConfig;
|
|
144
|
-
$[22] =
|
|
145
|
+
$[22] = t10;
|
|
145
146
|
}
|
|
146
147
|
else {
|
|
147
|
-
|
|
148
|
+
t10 = $[22];
|
|
148
149
|
}
|
|
149
|
-
const flags =
|
|
150
|
-
let
|
|
150
|
+
const flags = t10;
|
|
151
|
+
let t11;
|
|
151
152
|
if ($[23] !== date || $[24] !== isDateHovered) {
|
|
152
|
-
|
|
153
|
+
t11 = isDateHovered(date);
|
|
153
154
|
$[23] = date;
|
|
154
155
|
$[24] = isDateHovered;
|
|
155
|
-
$[25] =
|
|
156
|
+
$[25] = t11;
|
|
156
157
|
}
|
|
157
158
|
else {
|
|
158
|
-
|
|
159
|
+
t11 = $[25];
|
|
159
160
|
}
|
|
160
|
-
const isHovered =
|
|
161
|
-
let
|
|
161
|
+
const isHovered = t11;
|
|
162
|
+
let t12;
|
|
162
163
|
if ($[26] !== date || $[27] !== isDateBlocked || $[28] !== isHovered) {
|
|
163
|
-
|
|
164
|
+
t12 = isDateBlocked(date) && !isHovered;
|
|
164
165
|
$[26] = date;
|
|
165
166
|
$[27] = isDateBlocked;
|
|
166
167
|
$[28] = isHovered;
|
|
167
|
-
$[29] =
|
|
168
|
+
$[29] = t12;
|
|
168
169
|
}
|
|
169
170
|
else {
|
|
170
|
-
|
|
171
|
+
t12 = $[29];
|
|
171
172
|
}
|
|
172
|
-
const isDisabled =
|
|
173
|
-
const
|
|
174
|
-
const
|
|
175
|
-
let
|
|
173
|
+
const isDisabled = t12;
|
|
174
|
+
const t13 = flags !== null && flags !== void 0 ? flags : empty_array_1.EMPTY_ARRAY;
|
|
175
|
+
const t14 = _isFirstUnavailableDate();
|
|
176
|
+
let t15;
|
|
176
177
|
if ($[30] !== date || $[31] !== isDateInsideRange) {
|
|
177
|
-
|
|
178
|
+
t15 = isDateInsideRange ? isDateInsideRange(date) : false;
|
|
178
179
|
$[30] = date;
|
|
179
180
|
$[31] = isDateInsideRange;
|
|
180
|
-
$[32] =
|
|
181
|
+
$[32] = t15;
|
|
181
182
|
}
|
|
182
183
|
else {
|
|
183
|
-
|
|
184
|
+
t15 = $[32];
|
|
184
185
|
}
|
|
185
|
-
const
|
|
186
|
-
let
|
|
186
|
+
const t16 = _isLastUnavailableDate();
|
|
187
|
+
let t17;
|
|
187
188
|
if ($[33] !== date || $[34] !== isDateSelected) {
|
|
188
|
-
|
|
189
|
+
t17 = isDateSelected(date);
|
|
189
190
|
$[33] = date;
|
|
190
191
|
$[34] = isDateSelected;
|
|
191
|
-
$[35] =
|
|
192
|
+
$[35] = t17;
|
|
192
193
|
}
|
|
193
194
|
else {
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
const
|
|
197
|
-
const
|
|
198
|
-
let
|
|
199
|
-
if ($[36] !== isDisabled || $[37] !== isHovered || $[38] !== isToday || $[39] !== onKeyDown || $[40] !== onMouseEnter || $[41] !==
|
|
200
|
-
|
|
201
|
-
flags:
|
|
195
|
+
t17 = $[35];
|
|
196
|
+
}
|
|
197
|
+
const t18 = !isDisabled ? onClick : undefined;
|
|
198
|
+
const t19 = focusedDate === null || isDateFocused(date) ? 0 : -1;
|
|
199
|
+
let t20;
|
|
200
|
+
if ($[36] !== isDisabled || $[37] !== isHovered || $[38] !== isToday || $[39] !== onKeyDown || $[40] !== onMouseEnter || $[41] !== t13 || $[42] !== t14 || $[43] !== t15 || $[44] !== t16 || $[45] !== t17 || $[46] !== t18 || $[47] !== t19) {
|
|
201
|
+
t20 = {
|
|
202
|
+
flags: t13,
|
|
202
203
|
disabledDate: isDisabled,
|
|
203
|
-
isFirstDisabled:
|
|
204
|
+
isFirstDisabled: t14,
|
|
204
205
|
isHovered,
|
|
205
|
-
isInsideRange:
|
|
206
|
-
isLastDisabled:
|
|
207
|
-
isSelected:
|
|
206
|
+
isInsideRange: t15,
|
|
207
|
+
isLastDisabled: t16,
|
|
208
|
+
isSelected: t17,
|
|
208
209
|
isToday,
|
|
209
210
|
isWithinHoverRange: isHovered,
|
|
210
|
-
onClick:
|
|
211
|
+
onClick: t18,
|
|
211
212
|
onKeyDown,
|
|
212
213
|
onMouseEnter,
|
|
213
|
-
tabIndex:
|
|
214
|
+
tabIndex: t19
|
|
214
215
|
};
|
|
215
216
|
$[36] = isDisabled;
|
|
216
217
|
$[37] = isHovered;
|
|
217
218
|
$[38] = isToday;
|
|
218
219
|
$[39] = onKeyDown;
|
|
219
220
|
$[40] = onMouseEnter;
|
|
220
|
-
$[41] =
|
|
221
|
-
$[42] =
|
|
222
|
-
$[43] =
|
|
223
|
-
$[44] =
|
|
224
|
-
$[45] =
|
|
225
|
-
$[46] =
|
|
226
|
-
$[47] =
|
|
227
|
-
$[48] =
|
|
221
|
+
$[41] = t13;
|
|
222
|
+
$[42] = t14;
|
|
223
|
+
$[43] = t15;
|
|
224
|
+
$[44] = t16;
|
|
225
|
+
$[45] = t17;
|
|
226
|
+
$[46] = t18;
|
|
227
|
+
$[47] = t19;
|
|
228
|
+
$[48] = t20;
|
|
228
229
|
}
|
|
229
230
|
else {
|
|
230
|
-
|
|
231
|
+
t20 = $[48];
|
|
231
232
|
}
|
|
232
|
-
return
|
|
233
|
+
return t20;
|
|
233
234
|
}
|
|
234
235
|
function _temp3(day, index, self) {
|
|
235
236
|
return index === self.findIndex(d => d.getTime() === day.getTime());
|
package/hooks/use-day.test.js
CHANGED
|
@@ -34,6 +34,22 @@ test("useDay", () => {
|
|
|
34
34
|
expect(result.current.isInsideRange).toBe(false);
|
|
35
35
|
expect(result.current.isWithinHoverRange).toBe(false);
|
|
36
36
|
});
|
|
37
|
+
test("useDay takes disabled dates from datesConfig alone", () => {
|
|
38
|
+
const { result } = (0, react_1.renderHook)(() => (0, use_day_1.useDay)({
|
|
39
|
+
date: new Date("2021-09-05"),
|
|
40
|
+
datesConfig: [{ dates: [new Date("2021-09-05")], isDisabled: true }],
|
|
41
|
+
focusedDate: null,
|
|
42
|
+
isDateBlocked: () => false,
|
|
43
|
+
isDateFocused: () => false,
|
|
44
|
+
isDateHovered: () => false,
|
|
45
|
+
isDateSelected: () => false,
|
|
46
|
+
onDateFocus: () => undefined,
|
|
47
|
+
onDateHover: () => undefined,
|
|
48
|
+
onDateSelect: () => undefined,
|
|
49
|
+
}));
|
|
50
|
+
expect(result.current.isFirstDisabled).toBe(true);
|
|
51
|
+
expect(result.current.isLastDisabled).toBe(true);
|
|
52
|
+
});
|
|
37
53
|
test("useDay with unavailableDates", () => {
|
|
38
54
|
const { result } = (0, react_1.renderHook)(() => (0, use_day_1.useDay)({
|
|
39
55
|
date: new Date("2021-09-05"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/datepicker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "16.1.0",
|
|
4
4
|
"description": "A set of React hooks to create an awesome datepicker.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@uxf/core": "15.2.1",
|
|
23
|
-
"@uxf/core-react": "
|
|
23
|
+
"@uxf/core-react": "16.1.0",
|
|
24
24
|
"dayjs": "^1.11.23",
|
|
25
25
|
"next": ">=16.4.3",
|
|
26
26
|
"react": "^19.3.0",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@types/react": "19.3.0",
|
|
36
36
|
"@types/react-dom": "19.3.0",
|
|
37
37
|
"@uxf/core": "15.2.1",
|
|
38
|
-
"@uxf/core-react": "
|
|
38
|
+
"@uxf/core-react": "16.1.0",
|
|
39
39
|
"dayjs": "^1.11.23",
|
|
40
40
|
"react": "19.3.1",
|
|
41
41
|
"react-dom": "19.3.1"
|