react-day-picker 9.2.0 → 9.3.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/cjs/DayPicker.js +1 -0
- package/dist/cjs/DayPicker.js.map +1 -1
- package/dist/cjs/selection/useRange.js +5 -12
- package/dist/cjs/selection/useRange.js.map +1 -1
- package/dist/cjs/types/props.d.ts +7 -0
- package/dist/cjs/useDayPicker.d.ts +8 -1
- package/dist/cjs/useDayPicker.js +1 -1
- package/dist/cjs/useDayPicker.js.map +1 -1
- package/dist/cjs/utils/dateMatchModifiers.d.ts +7 -7
- package/dist/cjs/utils/dateMatchModifiers.js +7 -7
- package/dist/cjs/utils/index.d.ts +3 -0
- package/dist/cjs/utils/index.js +3 -0
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/rangeContainsDayOfWeek.d.ts +19 -0
- package/dist/cjs/utils/rangeContainsDayOfWeek.js +33 -0
- package/dist/cjs/utils/rangeContainsDayOfWeek.js.map +1 -0
- package/dist/cjs/utils/rangeContainsModifiers.d.ts +25 -0
- package/dist/cjs/utils/rangeContainsModifiers.js +84 -0
- package/dist/cjs/utils/rangeContainsModifiers.js.map +1 -0
- package/dist/cjs/utils/rangeOverlaps.d.ts +13 -0
- package/dist/cjs/utils/rangeOverlaps.js +18 -0
- package/dist/cjs/utils/rangeOverlaps.js.map +1 -0
- package/dist/esm/DayPicker.js +1 -0
- package/dist/esm/DayPicker.js.map +1 -1
- package/dist/esm/selection/useRange.js +6 -13
- package/dist/esm/selection/useRange.js.map +1 -1
- package/dist/esm/types/props.d.ts +7 -0
- package/dist/esm/useDayPicker.d.ts +8 -1
- package/dist/esm/useDayPicker.js +1 -1
- package/dist/esm/useDayPicker.js.map +1 -1
- package/dist/esm/utils/dateMatchModifiers.d.ts +7 -7
- package/dist/esm/utils/dateMatchModifiers.js +7 -7
- package/dist/esm/utils/index.d.ts +3 -0
- package/dist/esm/utils/index.js +3 -0
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/rangeContainsDayOfWeek.d.ts +19 -0
- package/dist/esm/utils/rangeContainsDayOfWeek.js +30 -0
- package/dist/esm/utils/rangeContainsDayOfWeek.js.map +1 -0
- package/dist/esm/utils/rangeContainsModifiers.d.ts +25 -0
- package/dist/esm/utils/rangeContainsModifiers.js +81 -0
- package/dist/esm/utils/rangeContainsModifiers.js.map +1 -0
- package/dist/esm/utils/rangeOverlaps.d.ts +13 -0
- package/dist/esm/utils/rangeOverlaps.js +15 -0
- package/dist/esm/utils/rangeOverlaps.js.map +1 -0
- package/examples/ItalianLabels.tsx +1 -1
- package/examples/Range.test.tsx +8 -0
- package/examples/Range.tsx +13 -8
- package/examples/RangeLong.tsx +1 -3
- package/examples/RangeLongExcludeDisabled.tsx +22 -0
- package/examples/__snapshots__/Range.test.tsx.snap +1253 -1239
- package/examples/index.ts +2 -0
- package/package.json +7 -1
- package/src/DayPicker.tsx +1 -0
- package/src/selection/useRange.tsx +12 -15
- package/src/style.css +10 -14
- package/src/style.module.css +12 -16
- package/src/types/props.ts +7 -0
- package/src/useDayPicker.test.tsx +134 -0
- package/src/useDayPicker.ts +8 -1
- package/src/utils/dateMatchModifiers.ts +7 -7
- package/src/utils/index.ts +3 -0
- package/src/utils/rangeContainsDayOfWeek.test.ts +48 -0
- package/src/utils/rangeContainsDayOfWeek.ts +35 -0
- package/src/utils/rangeContainsModifiers.test.ts +230 -0
- package/src/utils/rangeContainsModifiers.ts +125 -0
- package/src/utils/rangeOverlaps.test.ts +60 -0
- package/src/utils/rangeOverlaps.ts +22 -0
- package/website/docs/docs/styling.mdx +36 -43
- package/website/docs/docs/translation.mdx +1 -1
- package/website/docs/guides/custom-components.mdx +16 -15
- package/website/docs/upgrading.mdx +1 -1
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { defaultDateLib } from "../classes/DateLib";
|
|
2
|
+
import { DayOfWeek } from "../types";
|
|
3
|
+
|
|
4
|
+
import { rangeContainsModifiers } from "./rangeContainsModifiers";
|
|
5
|
+
|
|
6
|
+
const sunday = new Date(2024, 8, 1); // day of the week 0
|
|
7
|
+
const monday = new Date(2024, 8, 2); // day of the week 1
|
|
8
|
+
const tuesday = new Date(2024, 8, 3); // day of the week 1
|
|
9
|
+
const wednesday = new Date(2024, 8, 4); // day of the week 1
|
|
10
|
+
const thursday = new Date(2024, 8, 5); // day of the week 1
|
|
11
|
+
const friday = new Date(2024, 8, 6); // day of the week 5
|
|
12
|
+
const saturday = new Date(2024, 8, 7); // day of the week 6
|
|
13
|
+
const nextWeekSunday = new Date(2024, 8, 8); // day of the week 0
|
|
14
|
+
|
|
15
|
+
const testRange = { from: monday, to: saturday };
|
|
16
|
+
|
|
17
|
+
describe("when the matcher is a boolean", () => {
|
|
18
|
+
const matcher = true;
|
|
19
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
20
|
+
test("should return the boolean", () => {
|
|
21
|
+
expect(result).toBe(matcher);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe("when matching a single date", () => {
|
|
26
|
+
test("should return true when matching a date in the range", () => {
|
|
27
|
+
const matcher = thursday;
|
|
28
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
29
|
+
expect(result).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
test('should return true when matching the "from" date', () => {
|
|
32
|
+
const matcher = monday;
|
|
33
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
34
|
+
expect(result).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
test('should return true when matching the "to" date', () => {
|
|
37
|
+
const matcher = saturday;
|
|
38
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
39
|
+
expect(result).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
test('should return false on the edge of the "from" date', () => {
|
|
42
|
+
const matcher = sunday;
|
|
43
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
44
|
+
expect(result).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
test('should return false on the edge of the "to" date', () => {
|
|
47
|
+
const matcher = nextWeekSunday;
|
|
48
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
49
|
+
expect(result).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe("when matching an array of dates", () => {
|
|
54
|
+
test("should return true", () => {
|
|
55
|
+
const matcher = [sunday, wednesday, nextWeekSunday];
|
|
56
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
57
|
+
expect(result).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
test("should return false", () => {
|
|
60
|
+
const matcher = [sunday, nextWeekSunday];
|
|
61
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
62
|
+
expect(result).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe("when matching date range", () => {
|
|
67
|
+
test('should return true when matching the "from" date', () => {
|
|
68
|
+
const matcher = { from: sunday, to: monday };
|
|
69
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
70
|
+
expect(result).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
test('should return true when matching the "to" date', () => {
|
|
73
|
+
const matcher = { from: saturday, to: nextWeekSunday };
|
|
74
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
75
|
+
expect(result).toBe(true);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("should return true when date range contains matcher", () => {
|
|
79
|
+
const matcher = { from: tuesday, to: thursday };
|
|
80
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
81
|
+
expect(result).toBe(true);
|
|
82
|
+
});
|
|
83
|
+
test("should return true when matcher contains date range", () => {
|
|
84
|
+
const matcher = { from: sunday, to: nextWeekSunday };
|
|
85
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
86
|
+
expect(result).toBe(true);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('should return false on the edge of the "from" date', () => {
|
|
90
|
+
const matcher = { from: new Date(2000, 1, 1), to: sunday };
|
|
91
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
92
|
+
expect(result).toBe(false);
|
|
93
|
+
});
|
|
94
|
+
test('should return false on the edge of the "to" date', () => {
|
|
95
|
+
const matcher = { from: nextWeekSunday, to: new Date(2077, 1, 1) };
|
|
96
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
97
|
+
expect(result).toBe(false);
|
|
98
|
+
});
|
|
99
|
+
test("should return false if matcher is an incomplete date range", () => {
|
|
100
|
+
const matcher = { from: monday };
|
|
101
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
102
|
+
expect(result).toBe(false);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe("when matching the day of week", () => {
|
|
107
|
+
test("should return true", () => {
|
|
108
|
+
const matcher: DayOfWeek = {
|
|
109
|
+
dayOfWeek: [monday.getDay()]
|
|
110
|
+
};
|
|
111
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
112
|
+
expect(result).toBe(true);
|
|
113
|
+
});
|
|
114
|
+
test("should return false", () => {
|
|
115
|
+
const matcher: DayOfWeek = {
|
|
116
|
+
dayOfWeek: [sunday.getDay()]
|
|
117
|
+
};
|
|
118
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
119
|
+
expect(result).toBe(false);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe("when matching date interval (closed)", () => {
|
|
124
|
+
test('should return true when matching the "from" date', () => {
|
|
125
|
+
const matcher = { after: sunday, before: tuesday };
|
|
126
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
127
|
+
expect(result).toBe(true);
|
|
128
|
+
});
|
|
129
|
+
test('should return true when matching the "to" date', () => {
|
|
130
|
+
const matcher = { after: friday, before: nextWeekSunday };
|
|
131
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
132
|
+
expect(result).toBe(true);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("should return true when date range contains matcher", () => {
|
|
136
|
+
const matcher = { after: tuesday, before: thursday };
|
|
137
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
138
|
+
expect(result).toBe(true);
|
|
139
|
+
});
|
|
140
|
+
test("should return true when matcher contains date range", () => {
|
|
141
|
+
const matcher = { after: sunday, before: nextWeekSunday };
|
|
142
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
143
|
+
expect(result).toBe(true);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('should return false on the edge of the "from" date', () => {
|
|
147
|
+
const matcher = { after: new Date(2000, 1, 1), before: monday };
|
|
148
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
149
|
+
expect(result).toBe(false);
|
|
150
|
+
});
|
|
151
|
+
test('should return false on the edge of the "to" date', () => {
|
|
152
|
+
const matcher = { after: saturday, before: new Date(2077, 1, 1) };
|
|
153
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
154
|
+
expect(result).toBe(false);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe("when matching date interval (open)", () => {
|
|
159
|
+
test('should return true when matching the "from" date', () => {
|
|
160
|
+
const matcher = { before: tuesday, after: saturday };
|
|
161
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
162
|
+
expect(result).toBe(true);
|
|
163
|
+
});
|
|
164
|
+
test('should return true when matching the "to" date', () => {
|
|
165
|
+
const matcher = { before: monday, after: friday };
|
|
166
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
167
|
+
expect(result).toBe(true);
|
|
168
|
+
});
|
|
169
|
+
test("should return false when date range is not part of the matcher", () => {
|
|
170
|
+
const matcher = { before: monday, after: saturday };
|
|
171
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
172
|
+
expect(result).toBe(false);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
describe("when matching the date after", () => {
|
|
177
|
+
test('should return true when matching the "from" date', () => {
|
|
178
|
+
const matcher = { after: sunday };
|
|
179
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
180
|
+
expect(result).toBe(true);
|
|
181
|
+
});
|
|
182
|
+
test('should return true when matching the "to" date', () => {
|
|
183
|
+
const matcher = { after: friday };
|
|
184
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
185
|
+
expect(result).toBe(true);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test("should return false", () => {
|
|
189
|
+
const matcher = { after: saturday };
|
|
190
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
191
|
+
expect(result).toBe(false);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
describe("when matching the date before", () => {
|
|
196
|
+
test('should return true when matching the "from" date', () => {
|
|
197
|
+
const matcher = { before: tuesday };
|
|
198
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
199
|
+
expect(result).toBe(true);
|
|
200
|
+
});
|
|
201
|
+
test('should return true when matching the "to" date', () => {
|
|
202
|
+
const matcher = { before: nextWeekSunday };
|
|
203
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
204
|
+
expect(result).toBe(true);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test("should return false", () => {
|
|
208
|
+
const matcher = { before: monday };
|
|
209
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
210
|
+
expect(result).toBe(false);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
describe("when the matcher is a function", () => {
|
|
215
|
+
test('should return true when matching the "from" date', () => {
|
|
216
|
+
const matcher = (date: Date) => date.getTime() === monday.getTime();
|
|
217
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
218
|
+
expect(result).toBe(true);
|
|
219
|
+
});
|
|
220
|
+
test('should return true when matching the "to" date', () => {
|
|
221
|
+
const matcher = (date: Date) => date.getTime() === saturday.getTime();
|
|
222
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
223
|
+
expect(result).toBe(true);
|
|
224
|
+
});
|
|
225
|
+
test("should return false", () => {
|
|
226
|
+
const matcher = (date: Date) => date.getTime() === nextWeekSunday.getTime();
|
|
227
|
+
const result = rangeContainsModifiers(testRange, [matcher], defaultDateLib);
|
|
228
|
+
expect(result).toBe(false);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { defaultDateLib, type DateLib } from "../classes/DateLib.js";
|
|
2
|
+
import type { Matcher } from "../types/index.js";
|
|
3
|
+
|
|
4
|
+
import { dateMatchModifiers } from "./dateMatchModifiers.js";
|
|
5
|
+
import { rangeContainsDayOfWeek } from "./rangeContainsDayOfWeek.js";
|
|
6
|
+
import { rangeIncludesDate } from "./rangeIncludesDate.js";
|
|
7
|
+
import { rangeOverlaps } from "./rangeOverlaps.js";
|
|
8
|
+
import {
|
|
9
|
+
isDateAfterType,
|
|
10
|
+
isDateBeforeType,
|
|
11
|
+
isDateInterval,
|
|
12
|
+
isDateRange,
|
|
13
|
+
isDatesArray,
|
|
14
|
+
isDayOfWeekType
|
|
15
|
+
} from "./typeguards.js";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns whether a range contains dates that match the given modifiers.
|
|
19
|
+
*
|
|
20
|
+
* ```tsx
|
|
21
|
+
* const range: DateRange = {
|
|
22
|
+
* from: new Date(2021, 12, 21),
|
|
23
|
+
* to: new Date(2021, 12, 30)
|
|
24
|
+
* };
|
|
25
|
+
* const matcher1: Date = new Date(2021, 12, 21);
|
|
26
|
+
* const matcher2: DateRange = {
|
|
27
|
+
* from: new Date(2022, 5, 1),
|
|
28
|
+
* to: new Date(2022, 5, 23)
|
|
29
|
+
* };
|
|
30
|
+
* rangeContainsModifiers(range, [matcher1, matcher2]); // true, since matcher1 is in the date.
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @since 9.2.2
|
|
34
|
+
* @group Utilities
|
|
35
|
+
*/
|
|
36
|
+
export function rangeContainsModifiers(
|
|
37
|
+
range: { from: Date; to: Date },
|
|
38
|
+
modifiers: Matcher | Matcher[],
|
|
39
|
+
dateLib: DateLib = defaultDateLib
|
|
40
|
+
): boolean {
|
|
41
|
+
const matchers = Array.isArray(modifiers) ? modifiers : [modifiers];
|
|
42
|
+
|
|
43
|
+
// Defer function matchers evaluation as they are the least performant.
|
|
44
|
+
const nonFunctionMatchers = matchers.filter(
|
|
45
|
+
(matcher) => typeof matcher !== "function"
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const nonFunctionMatchersResult = nonFunctionMatchers.some((matcher) => {
|
|
49
|
+
if (typeof matcher === "boolean") return matcher;
|
|
50
|
+
|
|
51
|
+
if (dateLib.isDate(matcher)) {
|
|
52
|
+
return rangeIncludesDate(range, matcher, false, dateLib);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (isDatesArray(matcher, dateLib)) {
|
|
56
|
+
return matcher.some((date) =>
|
|
57
|
+
rangeIncludesDate(range, date, false, dateLib)
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (isDateRange(matcher)) {
|
|
62
|
+
if (matcher.from && matcher.to) {
|
|
63
|
+
return rangeOverlaps(
|
|
64
|
+
range,
|
|
65
|
+
{ from: matcher.from, to: matcher.to },
|
|
66
|
+
dateLib
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (isDayOfWeekType(matcher)) {
|
|
73
|
+
return rangeContainsDayOfWeek(range, matcher.dayOfWeek, dateLib);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (isDateInterval(matcher)) {
|
|
77
|
+
const isClosedInterval = dateLib.isAfter(matcher.before, matcher.after);
|
|
78
|
+
if (isClosedInterval) {
|
|
79
|
+
return rangeOverlaps(
|
|
80
|
+
range,
|
|
81
|
+
{
|
|
82
|
+
from: dateLib.addDays(matcher.after, 1),
|
|
83
|
+
to: dateLib.addDays(matcher.before, -1)
|
|
84
|
+
},
|
|
85
|
+
dateLib
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
return (
|
|
89
|
+
dateMatchModifiers(range.from, matcher, dateLib) ||
|
|
90
|
+
dateMatchModifiers(range.to, matcher, dateLib)
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (isDateAfterType(matcher) || isDateBeforeType(matcher)) {
|
|
95
|
+
return (
|
|
96
|
+
dateMatchModifiers(range.from, matcher, dateLib) ||
|
|
97
|
+
dateMatchModifiers(range.to, matcher, dateLib)
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return false;
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
if (nonFunctionMatchersResult) {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const functionMatchers = matchers.filter(
|
|
109
|
+
(matcher) => typeof matcher === "function"
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
if (functionMatchers.length) {
|
|
113
|
+
let date = range.from;
|
|
114
|
+
const totalDays = dateLib.differenceInCalendarDays(range.to, range.from);
|
|
115
|
+
|
|
116
|
+
for (let i = 0; i <= totalDays; i++) {
|
|
117
|
+
if (functionMatchers.some((matcher) => matcher(date))) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
date = dateLib.addDays(date, 1);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { defaultDateLib } from "../classes/DateLib";
|
|
2
|
+
|
|
3
|
+
import { rangeOverlaps } from "./rangeOverlaps";
|
|
4
|
+
|
|
5
|
+
const sunday = new Date(2024, 8, 1);
|
|
6
|
+
const monday = new Date(2024, 8, 2);
|
|
7
|
+
const tuesday = new Date(2024, 8, 3);
|
|
8
|
+
const thursday = new Date(2024, 8, 5);
|
|
9
|
+
const saturday = new Date(2024, 8, 7);
|
|
10
|
+
const nextWeekSunday = new Date(2024, 8, 8);
|
|
11
|
+
|
|
12
|
+
const leftRange = { from: monday, to: saturday };
|
|
13
|
+
|
|
14
|
+
test('should return true when matching the "from" date', () => {
|
|
15
|
+
const rightRange = { from: sunday, to: monday };
|
|
16
|
+
const result = rangeOverlaps(leftRange, rightRange, defaultDateLib);
|
|
17
|
+
expect(result).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('should return true when matching the "to" date', () => {
|
|
21
|
+
const rightRange = { from: saturday, to: nextWeekSunday };
|
|
22
|
+
const result = rangeOverlaps(leftRange, rightRange, defaultDateLib);
|
|
23
|
+
expect(result).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("should return true when left date range contains right date range", () => {
|
|
27
|
+
const rightRange = { from: tuesday, to: thursday };
|
|
28
|
+
const result = rangeOverlaps(leftRange, rightRange, defaultDateLib);
|
|
29
|
+
expect(result).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("should return true when right date range contains left date range", () => {
|
|
33
|
+
const rightRange = { from: sunday, to: nextWeekSunday };
|
|
34
|
+
const result = rangeOverlaps(leftRange, rightRange, defaultDateLib);
|
|
35
|
+
expect(result).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("should return true when a date range is inverted", () => {
|
|
39
|
+
const rightRange = { to: sunday, from: nextWeekSunday };
|
|
40
|
+
const result = rangeOverlaps(leftRange, rightRange, defaultDateLib);
|
|
41
|
+
expect(result).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('should return false on the edge of the "from" date', () => {
|
|
45
|
+
const rightRange = { from: new Date(2000, 1, 1), to: sunday };
|
|
46
|
+
const result = rangeOverlaps(leftRange, rightRange, defaultDateLib);
|
|
47
|
+
expect(result).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('should return false on the edge of the "to" date', () => {
|
|
51
|
+
const rightRange = { from: nextWeekSunday, to: new Date(2077, 1, 1) };
|
|
52
|
+
const result = rangeOverlaps(leftRange, rightRange, defaultDateLib);
|
|
53
|
+
expect(result).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("should return false when a date range is inverted", () => {
|
|
57
|
+
const rightRange = { to: nextWeekSunday, from: new Date(2077, 1, 1) };
|
|
58
|
+
const result = rangeOverlaps(leftRange, rightRange, defaultDateLib);
|
|
59
|
+
expect(result).toBe(false);
|
|
60
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defaultDateLib } from "../classes/index.js";
|
|
2
|
+
|
|
3
|
+
import { rangeIncludesDate } from "./rangeIncludesDate.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Determines whether a given range overlaps with another range.
|
|
7
|
+
*
|
|
8
|
+
* @since 9.2.2
|
|
9
|
+
* @group Utilities
|
|
10
|
+
*/
|
|
11
|
+
export function rangeOverlaps(
|
|
12
|
+
rangeLeft: { from: Date; to: Date },
|
|
13
|
+
rangeRight: { from: Date; to: Date },
|
|
14
|
+
dateLib = defaultDateLib
|
|
15
|
+
): boolean {
|
|
16
|
+
return (
|
|
17
|
+
rangeIncludesDate(rangeLeft, rangeRight.from, false, dateLib) ||
|
|
18
|
+
rangeIncludesDate(rangeLeft, rangeRight.to, false, dateLib) ||
|
|
19
|
+
rangeIncludesDate(rangeRight, rangeLeft.from, false, dateLib) ||
|
|
20
|
+
rangeIncludesDate(rangeRight, rangeLeft.to, false, dateLib)
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -52,49 +52,42 @@ Define the CSS variables in your app's CSS file, after importing the DayPicker C
|
|
|
52
52
|
|
|
53
53
|
The following table lists the CSS variables used by DayPicker within the `.rdp-root` class:
|
|
54
54
|
|
|
55
|
-
| CSS Variable | Description
|
|
56
|
-
| ----------------------------------------- |
|
|
57
|
-
| `--rdp-accent-color` | The accent color used for selected days and UI elements.
|
|
58
|
-
| `--rdp-accent-background-color` | The accent background color used for selected days and UI elements.
|
|
59
|
-
| `--rdp-
|
|
60
|
-
| `--rdp-day-
|
|
61
|
-
| `--rdp-
|
|
62
|
-
| `--rdp-
|
|
63
|
-
| `--rdp-
|
|
64
|
-
| `--rdp-day_button-
|
|
65
|
-
| `--rdp-day_button-
|
|
66
|
-
| `--rdp-
|
|
67
|
-
| `--rdp-
|
|
68
|
-
| `--rdp-
|
|
69
|
-
| `--rdp-
|
|
70
|
-
| `--rdp-
|
|
71
|
-
| `--rdp-
|
|
72
|
-
| `--rdp-
|
|
73
|
-
| `--rdp-
|
|
74
|
-
| `--rdp-
|
|
75
|
-
| `--rdp-
|
|
76
|
-
| `--rdp-
|
|
77
|
-
| `--rdp-
|
|
78
|
-
| `--rdp-
|
|
79
|
-
| `--rdp-
|
|
80
|
-
| `--rdp-
|
|
81
|
-
| `--rdp-
|
|
82
|
-
| `--rdp-
|
|
83
|
-
| `--rdp-
|
|
84
|
-
| `--rdp-
|
|
85
|
-
| `--rdp-
|
|
86
|
-
| `--rdp-
|
|
87
|
-
| `--
|
|
88
|
-
| `--rdp-
|
|
89
|
-
| `--rdp-
|
|
90
|
-
| `--rdp-
|
|
91
|
-
| `--rdp-week_number-font` | The font of the week number cells. |
|
|
92
|
-
| `--rdp-week_number-height` | The height of the week number cells. |
|
|
93
|
-
| `--rdd-week_number-width` | The width of the week number cells. |
|
|
94
|
-
| `--rdp-weekday-font` | The font of the weekday. |
|
|
95
|
-
| `--rdp-weekday-opacity` | The opacity of the weekday. |
|
|
96
|
-
| `--rdp-weekday-padding` | The padding of the weekday. |
|
|
97
|
-
| `--rdp-weekday-text-align` | The text alignment of the weekday cells. |
|
|
55
|
+
| CSS Variable | Description |
|
|
56
|
+
| ----------------------------------------- | -------------------------------------------------------------------- |
|
|
57
|
+
| `--rdp-accent-color` | The accent color used for selected days and UI elements. |
|
|
58
|
+
| `--rdp-accent-background-color` | The accent background color used for selected days and UI elements. |
|
|
59
|
+
| `--rdp-day-height` | The height of the day cells. |
|
|
60
|
+
| `--rdp-day-width` | The width of the day cells. |
|
|
61
|
+
| `--rdp-chevron-disabled-opacity` | The opacity of the chevron when its container is disabled. |
|
|
62
|
+
| `--rdp-day_button-border-radius` | The border radius of the day cells. |
|
|
63
|
+
| `--rdp-day_button-border` | The border of the day cells. |
|
|
64
|
+
| `--rdp-day_button-height` | The height of the day cells. |
|
|
65
|
+
| `--rdp-day_button-width` | The width of the day cells. |
|
|
66
|
+
| `--rdp-selected-border` | The border of the selected days. |
|
|
67
|
+
| `--rdp-disabled-opacity` | The opacity of the disabled days. |
|
|
68
|
+
| `--rdp-outside-opacity` | The opacity of the days outside the current month. |
|
|
69
|
+
| `--rdp-today-color` | The color of today's date. |
|
|
70
|
+
| `--rdp-dropdown-gap` | The gap between the dropdowns used in the month captions. |
|
|
71
|
+
| `--rdp-months-gap` | The gap between the months in the multi-month view. |
|
|
72
|
+
| `--rdp-nav_button-disabled-opacity` | The opacity of the disabled navigation buttons. |
|
|
73
|
+
| `--rdp-nav_button-height` | The height of the navigation buttons. |
|
|
74
|
+
| `--rdp-nav_button-width` | The width of the navigation buttons. |
|
|
75
|
+
| `--rdp-nav-height` | The height of the navigation bar. |
|
|
76
|
+
| `--rdp-range_middle-background-color` | The color of the background for days in the middle of a range. |
|
|
77
|
+
| `--rdp-range_middle-foreground-color` | The color of the text for days in the middle of a range. |
|
|
78
|
+
| `--rdp-range_start-color` | The color of the range text at the start of the range. |
|
|
79
|
+
| `--rdp-range_start-background` | Used for the background of the start of the selected range. |
|
|
80
|
+
| `--rdp-range_start-date-background-color` | The background color of the date at the start of the selected range. |
|
|
81
|
+
| `--rdp-range_end-background` | Used for the background of the end of the selected range. |
|
|
82
|
+
| `--rdp-range_end-color` | The color of the range text at the end of the range. |
|
|
83
|
+
| `--rdp-range_end-date-background-color` | The background color of the date at the end of the selected range. |
|
|
84
|
+
| `--rdp-week_number-border-radius` | The border radius of the week number. |
|
|
85
|
+
| `--rdp-week_number-border` | The border of the week number. |
|
|
86
|
+
| `--rdp-week_number-height` | The height of the week number cells. |
|
|
87
|
+
| `--rdd-week_number-width` | The width of the week number cells. |
|
|
88
|
+
| `--rdp-weekday-opacity` | The opacity of the weekday. |
|
|
89
|
+
| `--rdp-weekday-padding` | The padding of the weekday. |
|
|
90
|
+
| `--rdp-weekday-text-align` | The text alignment of the weekday cells. |
|
|
98
91
|
|
|
99
92
|
### Light/Dark Appearance
|
|
100
93
|
|
|
@@ -38,7 +38,7 @@ function ItalianLabels() {
|
|
|
38
38
|
locale={it}
|
|
39
39
|
labels={{
|
|
40
40
|
labelDayButton: (date, { today, selected }) => {
|
|
41
|
-
let label = format(date, "PPPP");
|
|
41
|
+
let label = format(date, "PPPP", { locale: it });
|
|
42
42
|
if (today) label = `Oggi, ${label}`;
|
|
43
43
|
if (selected) label = `${label}, selezionato`;
|
|
44
44
|
return label;
|
|
@@ -130,18 +130,19 @@ import { useDayPicker } from "react-day-picker";
|
|
|
130
130
|
|
|
131
131
|
The DayPicker context provides the current state of the calendar, including the selected days, modifiers, and navigation state.
|
|
132
132
|
|
|
133
|
-
| Name
|
|
134
|
-
|
|
|
135
|
-
| `classNames`
|
|
136
|
-
| `components`
|
|
137
|
-
| `formatters`
|
|
138
|
-
| `getModifiers`
|
|
139
|
-
| `goToMonth`
|
|
140
|
-
| `isSelected`
|
|
141
|
-
| `labels`
|
|
142
|
-
| `months`
|
|
143
|
-
| `nextMonth`
|
|
144
|
-
| `previousMonth`
|
|
145
|
-
| `select`
|
|
146
|
-
| `selected`
|
|
147
|
-
| `styles`
|
|
133
|
+
| Name | Type | Description |
|
|
134
|
+
| ---------------- | ----------------------------------------------------------------------------- | ---------------------------------------------- |
|
|
135
|
+
| `classNames` | [`ClassNames`](../api/type-aliases/ClassNames.md) | The class names for the UI elements. |
|
|
136
|
+
| `components` | [`CustomComponents`](../api/type-aliases/CustomComponents.md) | The components used internally by DayPicker. |
|
|
137
|
+
| `formatters` | [`Formatters`](../api/type-aliases/Formatters.md) | The formatters used to format the UI elements. |
|
|
138
|
+
| `getModifiers` | (`day`) => [`Modifiers`](../api/type-aliases/Modifiers.md) | Returns the modifiers for the given day. |
|
|
139
|
+
| `goToMonth` | (`month`) => `void` | Navigate to the specified month. |
|
|
140
|
+
| `isSelected` | (`date`) => `boolean` \| `undefined` | Whether the given date is selected. |
|
|
141
|
+
| `labels` | [`Labels`](../api/type-aliases/Labels.md) | The labels used in the user interface. |
|
|
142
|
+
| `months` | [`CalendarMonth`](../api/classes/CalendarMonth.md)[] | The months displayed in the calendar. |
|
|
143
|
+
| `nextMonth` | `Date` \| `undefined` | The next month to display. |
|
|
144
|
+
| `previousMonth` | `Date` \| `undefined` | The previous month to display. |
|
|
145
|
+
| `select` | [`SelectHandler`](../api/type-aliases/SelectHandler.md)\<`T`\> \| `undefined` | Set a selection. |
|
|
146
|
+
| `selected` | [`SelectedValue`](../api/type-aliases/SelectedValue.md)\<`T`\> \| `undefined` | The selected date(s). |
|
|
147
|
+
| `styles` | `Partial`\<[`Styles`](../api/type-aliases/Styles.md)\> \| `undefined` | The styles for the UI elements. |
|
|
148
|
+
| `dayPickerProps` | [`DayPickerProps`](../api/type-aliases/DayPickerProps.md) | The props passed to the DayPicker component. |
|
|
@@ -195,7 +195,7 @@ In case you are using the `components` prop, you may need to update your code, a
|
|
|
195
195
|
<DayPicker
|
|
196
196
|
components={{
|
|
197
197
|
- IconLeft: MyLeftIcon,
|
|
198
|
-
+ Chevron: (props) {
|
|
198
|
+
+ Chevron: (props) => {
|
|
199
199
|
+ if (props.orientation === "left") {
|
|
200
200
|
+ return <MyLeftIcon {...props} />;
|
|
201
201
|
+ }
|