react-day-picker 9.3.2 → 9.4.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 +2 -1
- package/dist/cjs/DayPicker.js +3 -2
- package/dist/cjs/DayPicker.js.map +1 -1
- package/dist/cjs/classes/DateLib.d.ts +16 -0
- package/dist/cjs/classes/DateLib.js +24 -0
- package/dist/cjs/classes/DateLib.js.map +1 -1
- package/dist/cjs/helpers/endOfBroadcastWeek.d.ts +7 -0
- package/dist/cjs/helpers/endOfBroadcastWeek.js +17 -0
- package/dist/cjs/helpers/endOfBroadcastWeek.js.map +1 -0
- package/dist/cjs/helpers/getBroadcastWeeksInMonth.d.ts +7 -0
- package/dist/cjs/helpers/getBroadcastWeeksInMonth.js +23 -0
- package/dist/cjs/helpers/getBroadcastWeeksInMonth.js.map +1 -0
- package/dist/cjs/helpers/getDataAttributes.js +2 -1
- package/dist/cjs/helpers/getDataAttributes.js.map +1 -1
- package/dist/cjs/helpers/getDates.d.ts +1 -3
- package/dist/cjs/helpers/getDates.js +14 -12
- package/dist/cjs/helpers/getDates.js.map +1 -1
- package/dist/cjs/helpers/getFocusableDate.d.ts +1 -1
- package/dist/cjs/helpers/getFocusableDate.js +12 -4
- package/dist/cjs/helpers/getFocusableDate.js.map +1 -1
- package/dist/cjs/helpers/getMonths.d.ts +1 -1
- package/dist/cjs/helpers/getMonths.js +14 -10
- package/dist/cjs/helpers/getMonths.js.map +1 -1
- package/dist/cjs/helpers/getWeekdays.d.ts +3 -1
- package/dist/cjs/helpers/getWeekdays.js +8 -4
- package/dist/cjs/helpers/getWeekdays.js.map +1 -1
- package/dist/cjs/helpers/startOfBroadcastWeek.d.ts +7 -0
- package/dist/cjs/helpers/startOfBroadcastWeek.js +22 -0
- package/dist/cjs/helpers/startOfBroadcastWeek.js.map +1 -0
- package/dist/cjs/types/props.d.ts +12 -0
- package/dist/cjs/useCalendar.d.ts +1 -1
- package/dist/cjs/useCalendar.js.map +1 -1
- package/dist/cjs/useGetModifiers.js +4 -2
- package/dist/cjs/useGetModifiers.js.map +1 -1
- package/dist/esm/DayPicker.js +3 -2
- package/dist/esm/DayPicker.js.map +1 -1
- package/dist/esm/classes/DateLib.d.ts +16 -0
- package/dist/esm/classes/DateLib.js +24 -0
- package/dist/esm/classes/DateLib.js.map +1 -1
- package/dist/esm/helpers/endOfBroadcastWeek.d.ts +7 -0
- package/dist/esm/helpers/endOfBroadcastWeek.js +14 -0
- package/dist/esm/helpers/endOfBroadcastWeek.js.map +1 -0
- package/dist/esm/helpers/getBroadcastWeeksInMonth.d.ts +7 -0
- package/dist/esm/helpers/getBroadcastWeeksInMonth.js +20 -0
- package/dist/esm/helpers/getBroadcastWeeksInMonth.js.map +1 -0
- package/dist/esm/helpers/getDataAttributes.js +2 -1
- package/dist/esm/helpers/getDataAttributes.js.map +1 -1
- package/dist/esm/helpers/getDates.d.ts +1 -3
- package/dist/esm/helpers/getDates.js +14 -11
- package/dist/esm/helpers/getDates.js.map +1 -1
- package/dist/esm/helpers/getFocusableDate.d.ts +1 -1
- package/dist/esm/helpers/getFocusableDate.js +12 -4
- package/dist/esm/helpers/getFocusableDate.js.map +1 -1
- package/dist/esm/helpers/getMonths.d.ts +1 -1
- package/dist/esm/helpers/getMonths.js +14 -10
- package/dist/esm/helpers/getMonths.js.map +1 -1
- package/dist/esm/helpers/getWeekdays.d.ts +3 -1
- package/dist/esm/helpers/getWeekdays.js +8 -4
- package/dist/esm/helpers/getWeekdays.js.map +1 -1
- package/dist/esm/helpers/startOfBroadcastWeek.d.ts +7 -0
- package/dist/esm/helpers/startOfBroadcastWeek.js +19 -0
- package/dist/esm/helpers/startOfBroadcastWeek.js.map +1 -0
- package/dist/esm/types/props.d.ts +12 -0
- package/dist/esm/useCalendar.d.ts +1 -1
- package/dist/esm/useCalendar.js.map +1 -1
- package/dist/esm/useGetModifiers.js +4 -2
- package/dist/esm/useGetModifiers.js.map +1 -1
- package/examples/BroadcastCalendar.tsx +7 -0
- package/examples/index.ts +1 -0
- package/package.json +1 -1
- package/src/DayPicker.tsx +3 -2
- package/src/classes/DateLib.ts +28 -0
- package/src/helpers/broadcastCalendar.test.ts +43 -0
- package/src/helpers/endOfBroadcastWeek.test.ts +25 -0
- package/src/helpers/endOfBroadcastWeek.ts +16 -0
- package/src/helpers/getBroadcastWeeksInMonth.test.ts +23 -0
- package/src/helpers/getBroadcastWeeksInMonth.ts +31 -0
- package/src/helpers/getDataAttributes.tsx +2 -1
- package/src/helpers/getDates.ts +21 -17
- package/src/helpers/getFocusableDate.ts +19 -8
- package/src/helpers/getMonths.ts +25 -17
- package/src/helpers/getWeekdays.ts +9 -4
- package/src/helpers/startOfBroadcastWeek.test.ts +24 -0
- package/src/helpers/startOfBroadcastWeek.ts +19 -0
- package/src/style.css +13 -4
- package/src/style.module.css +13 -4
- package/src/types/props.ts +12 -0
- package/src/useCalendar.ts +1 -0
- package/src/useGetModifiers.tsx +11 -2
- package/website/docs/docs/localization.mdx +23 -7
- package/website/docs/docs/styling.mdx +4 -4
- package/website/docs/intro.mdx +2 -1
|
@@ -203,6 +203,8 @@ export interface PropsBase {
|
|
|
203
203
|
/**
|
|
204
204
|
* Show the outside days (days falling in the next or the previous month).
|
|
205
205
|
*
|
|
206
|
+
* **Note:** when {@link broadcastCalendar} is set, this prop defaults to true.
|
|
207
|
+
*
|
|
206
208
|
* @see https://daypicker.dev/docs/customization#outside-days
|
|
207
209
|
*/
|
|
208
210
|
showOutsideDays?: boolean;
|
|
@@ -216,6 +218,16 @@ export interface PropsBase {
|
|
|
216
218
|
* @see https://daypicker.dev/docs/customization#showweeknumber
|
|
217
219
|
*/
|
|
218
220
|
showWeekNumber?: boolean;
|
|
221
|
+
/**
|
|
222
|
+
* Display the weeks in the month following the broadcast calendar. Setting
|
|
223
|
+
* this prop will ignore {@link weekStartsOn} (always Monday) and
|
|
224
|
+
* {@link showOutsideDays} will default to true.
|
|
225
|
+
*
|
|
226
|
+
* @since 9.4.0
|
|
227
|
+
* @see https://daypicker.dev/docs/localization#broadcast-calendar
|
|
228
|
+
* @see https://en.wikipedia.org/wiki/Broadcast_calendar
|
|
229
|
+
*/
|
|
230
|
+
broadcastCalendar?: boolean;
|
|
219
231
|
/**
|
|
220
232
|
* Use ISO week dates instead of the locale setting. Setting this prop will
|
|
221
233
|
* ignore `weekStartsOn` and `firstWeekContainsDate`.
|
|
@@ -44,4 +44,4 @@ export interface Calendar {
|
|
|
44
44
|
goToDay: (day: CalendarDay) => void;
|
|
45
45
|
}
|
|
46
46
|
/** @private */
|
|
47
|
-
export declare function useCalendar(props: Pick<DayPickerProps, "captionLayout" | "endMonth" | "startMonth" | "today" | "fixedWeeks" | "ISOWeek" | "numberOfMonths" | "disableNavigation" | "onMonthChange" | "month" | "defaultMonth" | "timeZone" | "fromMonth" | "fromYear" | "toMonth" | "toYear">, dateLib: DateLib): Calendar;
|
|
47
|
+
export declare function useCalendar(props: Pick<DayPickerProps, "captionLayout" | "endMonth" | "startMonth" | "today" | "fixedWeeks" | "ISOWeek" | "numberOfMonths" | "disableNavigation" | "onMonthChange" | "month" | "defaultMonth" | "timeZone" | "broadcastCalendar" | "fromMonth" | "fromYear" | "toMonth" | "toYear">, dateLib: DateLib): Calendar;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCalendar.js","sourceRoot":"","sources":["../../src/useCalendar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAQlC,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC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disabled, hidden, modifiers, showOutsideDays, today } = props;
|
|
12
|
+
const { disabled, hidden, modifiers, showOutsideDays, broadcastCalendar, today } = props;
|
|
13
13
|
const { isSameDay, isSameMonth, startOfMonth, isBefore, endOfMonth, isAfter } = dateLib;
|
|
14
14
|
const startMonth = props.startMonth && startOfMonth(props.startMonth);
|
|
15
15
|
const endMonth = props.endMonth && endOfMonth(props.endMonth);
|
|
@@ -30,7 +30,9 @@ export function useGetModifiers(days, props, dateLib) {
|
|
|
30
30
|
const isHidden = Boolean(hidden && dateMatchModifiers(date, hidden, dateLib)) ||
|
|
31
31
|
isBeforeStartMonth ||
|
|
32
32
|
isAfterEndMonth ||
|
|
33
|
-
|
|
33
|
+
// Broadcast calendar will show outside days as default
|
|
34
|
+
(!broadcastCalendar && !showOutsideDays && isOutside) ||
|
|
35
|
+
(broadcastCalendar && showOutsideDays === false && isOutside);
|
|
34
36
|
const isToday = isSameDay(date, today ??
|
|
35
37
|
(props.timeZone
|
|
36
38
|
? TZDate.tz(props.timeZone)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetModifiers.js","sourceRoot":"","sources":["../../src/useGetModifiers.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAC7B,IAAmB,EACnB,KAAqB,EACrB,OAAgB;IAEhB,MAAM,
|
|
1
|
+
{"version":3,"file":"useGetModifiers.js","sourceRoot":"","sources":["../../src/useGetModifiers.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAE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AAG,QAAQ;YACX,yDAAyD;YACzD,GAAG,eAAe;SACnB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
package/examples/index.ts
CHANGED
package/package.json
CHANGED
package/src/DayPicker.tsx
CHANGED
|
@@ -49,7 +49,7 @@ export function DayPicker(props: DayPickerProps) {
|
|
|
49
49
|
const dateLib = new DateLib(
|
|
50
50
|
{
|
|
51
51
|
locale,
|
|
52
|
-
weekStartsOn: props.weekStartsOn,
|
|
52
|
+
weekStartsOn: props.broadcastCalendar ? 1 : props.weekStartsOn,
|
|
53
53
|
firstWeekContainsDate: props.firstWeekContainsDate,
|
|
54
54
|
useAdditionalWeekYearTokens: props.useAdditionalWeekYearTokens,
|
|
55
55
|
useAdditionalDayOfYearTokens: props.useAdditionalDayOfYearTokens
|
|
@@ -75,7 +75,8 @@ export function DayPicker(props: DayPickerProps) {
|
|
|
75
75
|
props.locale,
|
|
76
76
|
props.useAdditionalDayOfYearTokens,
|
|
77
77
|
props.useAdditionalWeekYearTokens,
|
|
78
|
-
props.weekStartsOn
|
|
78
|
+
props.weekStartsOn,
|
|
79
|
+
props.broadcastCalendar
|
|
79
80
|
]);
|
|
80
81
|
|
|
81
82
|
const {
|
package/src/classes/DateLib.ts
CHANGED
|
@@ -35,6 +35,10 @@ import {
|
|
|
35
35
|
import type { Locale } from "date-fns/locale";
|
|
36
36
|
import { enUS } from "date-fns/locale";
|
|
37
37
|
|
|
38
|
+
import { endOfBroadcastWeek } from "../helpers/endOfBroadcastWeek.js";
|
|
39
|
+
import { startOfBroadcastWeek } from "../helpers/startOfBroadcastWeek.js";
|
|
40
|
+
import type { PropsBase } from "../types/props.js";
|
|
41
|
+
|
|
38
42
|
export type { Locale } from "date-fns/locale";
|
|
39
43
|
export type { Month as DateFnsMonth } from "date-fns";
|
|
40
44
|
|
|
@@ -180,6 +184,18 @@ export class DateLib {
|
|
|
180
184
|
: differenceInCalendarMonths(dateLeft, dateRight);
|
|
181
185
|
};
|
|
182
186
|
|
|
187
|
+
/**
|
|
188
|
+
* Returns the end of the broadcast week for the given date.
|
|
189
|
+
*
|
|
190
|
+
* @param date The original date.
|
|
191
|
+
* @returns The end of the broadcast week.
|
|
192
|
+
*/
|
|
193
|
+
endOfBroadcastWeek: typeof endOfBroadcastWeek = (date: Date) => {
|
|
194
|
+
return this.overrides?.endOfBroadcastWeek
|
|
195
|
+
? this.overrides.endOfBroadcastWeek(date, this)
|
|
196
|
+
: endOfBroadcastWeek(date, this);
|
|
197
|
+
};
|
|
198
|
+
|
|
183
199
|
/**
|
|
184
200
|
* Returns the end of the ISO week for the given date.
|
|
185
201
|
*
|
|
@@ -396,6 +412,18 @@ export class DateLib {
|
|
|
396
412
|
: setYear(date, year);
|
|
397
413
|
};
|
|
398
414
|
|
|
415
|
+
/**
|
|
416
|
+
* Returns the start of the broadcast week for the given date.
|
|
417
|
+
*
|
|
418
|
+
* @param date The original date.
|
|
419
|
+
* @returns The start of the broadcast week.
|
|
420
|
+
*/
|
|
421
|
+
startOfBroadcastWeek: typeof startOfBroadcastWeek = (date: Date) => {
|
|
422
|
+
return this.overrides?.startOfBroadcastWeek
|
|
423
|
+
? this.overrides.startOfBroadcastWeek(date, this)
|
|
424
|
+
: startOfBroadcastWeek(date, this);
|
|
425
|
+
};
|
|
426
|
+
|
|
399
427
|
/**
|
|
400
428
|
* Returns the start of the day for the given date.
|
|
401
429
|
*
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { defaultDateLib } from "react-day-picker/classes";
|
|
2
|
+
|
|
3
|
+
import { endOfBroadcastWeek } from "./endOfBroadcastWeek";
|
|
4
|
+
import { getBroadcastWeeksInMonth } from "./getBroadcastWeeksInMonth";
|
|
5
|
+
import { startOfBroadcastWeek } from "./startOfBroadcastWeek";
|
|
6
|
+
|
|
7
|
+
describe("broadcastCalendar", () => {
|
|
8
|
+
test("getBroadcastWeeksInMonth should return correct number of weeks", () => {
|
|
9
|
+
// Test for a month with 5 weeks
|
|
10
|
+
expect(getBroadcastWeeksInMonth(new Date(2023, 0, 1), defaultDateLib)).toBe(
|
|
11
|
+
5
|
|
12
|
+
); // January 2023
|
|
13
|
+
// Test for a month with 4 weeks
|
|
14
|
+
expect(getBroadcastWeeksInMonth(new Date(2023, 1, 1), defaultDateLib)).toBe(
|
|
15
|
+
4
|
|
16
|
+
); // February 2023
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("startOfBroadcastWeek should return correct start date", () => {
|
|
20
|
+
// Test for a month starting on a Monday
|
|
21
|
+
expect(startOfBroadcastWeek(new Date(2023, 0, 1), defaultDateLib)).toEqual(
|
|
22
|
+
new Date(2022, 11, 26)
|
|
23
|
+
); // December 26 2022
|
|
24
|
+
// Test for a month starting on a Wednesday
|
|
25
|
+
expect(startOfBroadcastWeek(new Date(2020, 0, 1), defaultDateLib)).toEqual(
|
|
26
|
+
new Date(2019, 11, 30)
|
|
27
|
+
); // December 30 2019
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("endOfBroadcastWeek should return correct end date", () => {
|
|
31
|
+
const startDate = startOfBroadcastWeek(
|
|
32
|
+
new Date(2023, 0, 1),
|
|
33
|
+
defaultDateLib
|
|
34
|
+
);
|
|
35
|
+
expect(endOfBroadcastWeek(new Date(2023, 0, 1), defaultDateLib)).toEqual(
|
|
36
|
+
new Date(
|
|
37
|
+
startDate.getFullYear(),
|
|
38
|
+
startDate.getMonth(),
|
|
39
|
+
startDate.getDate() + 34
|
|
40
|
+
)
|
|
41
|
+
); // January 2023
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defaultDateLib } from "react-day-picker/classes";
|
|
2
|
+
|
|
3
|
+
import { endOfBroadcastWeek } from "./endOfBroadcastWeek";
|
|
4
|
+
|
|
5
|
+
const testCases = [
|
|
6
|
+
[new Date(2023, 0, 1), new Date(2023, 0, 29)], // January
|
|
7
|
+
[new Date(2023, 1, 1), new Date(2023, 1, 26)], // February
|
|
8
|
+
[new Date(2023, 2, 1), new Date(2023, 2, 26)], // March
|
|
9
|
+
[new Date(2023, 3, 1), new Date(2023, 3, 30)], // April
|
|
10
|
+
[new Date(2023, 4, 1), new Date(2023, 4, 28)], // May
|
|
11
|
+
[new Date(2023, 5, 1), new Date(2023, 5, 25)], // June
|
|
12
|
+
[new Date(2023, 6, 1), new Date(2023, 6, 30)], // July
|
|
13
|
+
[new Date(2023, 7, 1), new Date(2023, 7, 27)], // August
|
|
14
|
+
[new Date(2023, 8, 1), new Date(2023, 8, 24)], // September
|
|
15
|
+
[new Date(2023, 9, 1), new Date(2023, 9, 29)], // October
|
|
16
|
+
[new Date(2023, 10, 1), new Date(2023, 10, 26)], // November
|
|
17
|
+
[new Date(2023, 11, 1), new Date(2023, 11, 31)] // December
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
describe("endOfBroadcastWeek", () => {
|
|
21
|
+
test.each(testCases)("%s should return %s", (date, expected) => {
|
|
22
|
+
const result = endOfBroadcastWeek(date, defaultDateLib);
|
|
23
|
+
expect(result).toEqual(expected);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DateLib } from "../classes/index.js";
|
|
2
|
+
|
|
3
|
+
import { getBroadcastWeeksInMonth } from "./getBroadcastWeeksInMonth.js";
|
|
4
|
+
import { startOfBroadcastWeek } from "./startOfBroadcastWeek.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Return the end date of the week in the broadcast calendar.
|
|
8
|
+
*
|
|
9
|
+
* @since 9.4.0
|
|
10
|
+
*/
|
|
11
|
+
export function endOfBroadcastWeek(date: Date, dateLib: DateLib): Date {
|
|
12
|
+
const startDate = startOfBroadcastWeek(date, dateLib);
|
|
13
|
+
const numberOfWeeks = getBroadcastWeeksInMonth(date, dateLib);
|
|
14
|
+
const endDate = dateLib.addDays(startDate, numberOfWeeks * 7 - 1);
|
|
15
|
+
return endDate;
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { defaultDateLib } from "../classes/index.js";
|
|
2
|
+
|
|
3
|
+
import { getBroadcastWeeksInMonth } from "./getBroadcastWeeksInMonth";
|
|
4
|
+
|
|
5
|
+
describe("getBroadcastWeeksInMonth", () => {
|
|
6
|
+
test.each`
|
|
7
|
+
month | expectedWeeks
|
|
8
|
+
${new Date(2023, 0, 1)} | ${5}
|
|
9
|
+
${new Date(2023, 1, 1)} | ${4}
|
|
10
|
+
${new Date(2023, 2, 1)} | ${4}
|
|
11
|
+
${new Date(2023, 3, 1)} | ${5}
|
|
12
|
+
${new Date(2023, 4, 1)} | ${4}
|
|
13
|
+
${new Date(2023, 5, 1)} | ${4}
|
|
14
|
+
${new Date(2023, 6, 1)} | ${5}
|
|
15
|
+
${new Date(2023, 7, 1)} | ${4}
|
|
16
|
+
${new Date(2023, 8, 1)} | ${4}
|
|
17
|
+
${new Date(2023, 9, 1)} | ${5}
|
|
18
|
+
${new Date(2023, 10, 1)} | ${4}
|
|
19
|
+
${new Date(2023, 11, 1)} | ${5}
|
|
20
|
+
`("returns $expectedWeeks weeks for $month", ({ month, expectedWeeks }) => {
|
|
21
|
+
expect(getBroadcastWeeksInMonth(month, defaultDateLib)).toBe(expectedWeeks);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { DateLib } from "../classes/index.js";
|
|
2
|
+
|
|
3
|
+
const FIVE_WEEKS = 5;
|
|
4
|
+
const FOUR_WEEKS = 4;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Return the number of weeks to display in the broadcast calendar.
|
|
8
|
+
*
|
|
9
|
+
* @since 9.4.0
|
|
10
|
+
*/
|
|
11
|
+
export function getBroadcastWeeksInMonth(month: Date, dateLib: DateLib): 4 | 5 {
|
|
12
|
+
// Get the first day of the month
|
|
13
|
+
const firstDayOfMonth = dateLib.startOfMonth(month);
|
|
14
|
+
|
|
15
|
+
// Get the day of the week for the first day of the month (1-7, where 1 is Monday)
|
|
16
|
+
const firstDayOfWeek =
|
|
17
|
+
firstDayOfMonth.getDay() > 0 ? firstDayOfMonth.getDay() : 7;
|
|
18
|
+
|
|
19
|
+
const broadcastStartDate = dateLib.addDays(month, -firstDayOfWeek + 1);
|
|
20
|
+
|
|
21
|
+
const lastDateOfLastWeek = dateLib.addDays(
|
|
22
|
+
broadcastStartDate,
|
|
23
|
+
FIVE_WEEKS * 7 - 1
|
|
24
|
+
);
|
|
25
|
+
const numberOfWeeks =
|
|
26
|
+
month.getMonth() === lastDateOfLastWeek.getMonth()
|
|
27
|
+
? FIVE_WEEKS
|
|
28
|
+
: FOUR_WEEKS;
|
|
29
|
+
|
|
30
|
+
return numberOfWeeks;
|
|
31
|
+
}
|
|
@@ -9,7 +9,8 @@ export function getDataAttributes(
|
|
|
9
9
|
"data-required": "required" in props ? props.required : undefined,
|
|
10
10
|
"data-multiple-months":
|
|
11
11
|
(props.numberOfMonths && props.numberOfMonths > 1) || undefined,
|
|
12
|
-
"data-week-numbers": props.showWeekNumber || undefined
|
|
12
|
+
"data-week-numbers": props.showWeekNumber || undefined,
|
|
13
|
+
"data-broadcast-calendar": props.broadcastCalendar || undefined
|
|
13
14
|
};
|
|
14
15
|
Object.entries(props).forEach(([key, val]) => {
|
|
15
16
|
if (key.startsWith("data-")) {
|
package/src/helpers/getDates.ts
CHANGED
|
@@ -1,39 +1,42 @@
|
|
|
1
1
|
import { type DateLib } from "../classes/DateLib.js";
|
|
2
2
|
import { type DayPickerProps } from "../types/props.js";
|
|
3
3
|
|
|
4
|
-
/** The number of days in a month when having 6 weeks. */
|
|
5
|
-
export const NrOfDaysWithFixedWeeks = 42;
|
|
6
|
-
|
|
7
4
|
/** Return all the dates to display in the calendar. */
|
|
8
5
|
export function getDates(
|
|
9
6
|
displayMonths: Date[],
|
|
10
7
|
maxDate: Date | undefined,
|
|
11
|
-
props: Pick<DayPickerProps, "ISOWeek" | "fixedWeeks">,
|
|
8
|
+
props: Pick<DayPickerProps, "ISOWeek" | "fixedWeeks" | "broadcastCalendar">,
|
|
12
9
|
dateLib: DateLib
|
|
13
10
|
): Date[] {
|
|
14
11
|
const firstMonth = displayMonths[0];
|
|
15
12
|
const lastMonth = displayMonths[displayMonths.length - 1];
|
|
16
13
|
|
|
17
|
-
const { ISOWeek, fixedWeeks } = props ?? {};
|
|
14
|
+
const { ISOWeek, fixedWeeks, broadcastCalendar } = props ?? {};
|
|
18
15
|
const {
|
|
19
|
-
startOfWeek,
|
|
20
|
-
endOfWeek,
|
|
21
|
-
startOfISOWeek,
|
|
22
|
-
endOfISOWeek,
|
|
23
16
|
addDays,
|
|
24
17
|
differenceInCalendarDays,
|
|
25
18
|
differenceInCalendarMonths,
|
|
19
|
+
endOfBroadcastWeek,
|
|
20
|
+
endOfISOWeek,
|
|
21
|
+
endOfMonth,
|
|
22
|
+
endOfWeek,
|
|
26
23
|
isAfter,
|
|
27
|
-
|
|
24
|
+
startOfBroadcastWeek,
|
|
25
|
+
startOfISOWeek,
|
|
26
|
+
startOfWeek
|
|
28
27
|
} = dateLib;
|
|
29
28
|
|
|
30
|
-
const startWeekFirstDate =
|
|
31
|
-
?
|
|
32
|
-
:
|
|
29
|
+
const startWeekFirstDate = broadcastCalendar
|
|
30
|
+
? startOfBroadcastWeek(firstMonth, dateLib)
|
|
31
|
+
: ISOWeek
|
|
32
|
+
? startOfISOWeek(firstMonth)
|
|
33
|
+
: startOfWeek(firstMonth);
|
|
33
34
|
|
|
34
|
-
const endWeekLastDate =
|
|
35
|
-
?
|
|
36
|
-
:
|
|
35
|
+
const endWeekLastDate = broadcastCalendar
|
|
36
|
+
? endOfBroadcastWeek(lastMonth, dateLib)
|
|
37
|
+
: ISOWeek
|
|
38
|
+
? endOfISOWeek(endOfMonth(lastMonth))
|
|
39
|
+
: endOfWeek(endOfMonth(lastMonth));
|
|
37
40
|
|
|
38
41
|
const nOfDays = differenceInCalendarDays(endWeekLastDate, startWeekFirstDate);
|
|
39
42
|
const nOfMonths = differenceInCalendarMonths(lastMonth, firstMonth) + 1;
|
|
@@ -48,7 +51,8 @@ export function getDates(
|
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
// If fixed weeks is enabled, add the extra dates to the array
|
|
51
|
-
const
|
|
54
|
+
const nrOfDaysWithFixedWeeks = broadcastCalendar ? 35 : 42;
|
|
55
|
+
const extraDates = nrOfDaysWithFixedWeeks * nOfMonths;
|
|
52
56
|
if (fixedWeeks && dates.length < extraDates) {
|
|
53
57
|
const daysToAdd = extraDates - dates.length;
|
|
54
58
|
for (let i = 0; i < daysToAdd; i++) {
|
|
@@ -12,21 +12,23 @@ export function getFocusableDate(
|
|
|
12
12
|
refDate: Date,
|
|
13
13
|
navStart: Date | undefined,
|
|
14
14
|
navEnd: Date | undefined,
|
|
15
|
-
props: Pick<DayPickerProps, "ISOWeek">,
|
|
15
|
+
props: Pick<DayPickerProps, "ISOWeek" | "broadcastCalendar">,
|
|
16
16
|
dateLib: DateLib
|
|
17
17
|
): Date {
|
|
18
|
-
const { ISOWeek } = props;
|
|
18
|
+
const { ISOWeek, broadcastCalendar } = props;
|
|
19
19
|
const {
|
|
20
20
|
addDays,
|
|
21
21
|
addMonths,
|
|
22
|
-
addYears,
|
|
23
22
|
addWeeks,
|
|
24
|
-
|
|
23
|
+
addYears,
|
|
24
|
+
endOfBroadcastWeek,
|
|
25
25
|
endOfISOWeek,
|
|
26
|
-
startOfWeek,
|
|
27
26
|
endOfWeek,
|
|
28
27
|
max,
|
|
29
|
-
min
|
|
28
|
+
min,
|
|
29
|
+
startOfBroadcastWeek,
|
|
30
|
+
startOfISOWeek,
|
|
31
|
+
startOfWeek
|
|
30
32
|
} = dateLib;
|
|
31
33
|
const moveFns = {
|
|
32
34
|
day: addDays,
|
|
@@ -34,8 +36,17 @@ export function getFocusableDate(
|
|
|
34
36
|
month: addMonths,
|
|
35
37
|
year: addYears,
|
|
36
38
|
startOfWeek: (date: Date) =>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
broadcastCalendar
|
|
40
|
+
? startOfBroadcastWeek(date, dateLib)
|
|
41
|
+
: ISOWeek
|
|
42
|
+
? startOfISOWeek(date)
|
|
43
|
+
: startOfWeek(date),
|
|
44
|
+
endOfWeek: (date: Date) =>
|
|
45
|
+
broadcastCalendar
|
|
46
|
+
? endOfBroadcastWeek(date, dateLib)
|
|
47
|
+
: ISOWeek
|
|
48
|
+
? endOfISOWeek(date)
|
|
49
|
+
: endOfWeek(date)
|
|
39
50
|
};
|
|
40
51
|
|
|
41
52
|
let focusableDate = moveFns[moveBy](refDate, moveDir === "after" ? 1 : -1);
|
package/src/helpers/getMonths.ts
CHANGED
|
@@ -2,8 +2,6 @@ import type { DateLib } from "../classes/DateLib.js";
|
|
|
2
2
|
import { CalendarWeek, CalendarDay, CalendarMonth } from "../classes/index.js";
|
|
3
3
|
import type { DayPickerProps } from "../types/index.js";
|
|
4
4
|
|
|
5
|
-
import { NrOfDaysWithFixedWeeks } from "./getDates.js";
|
|
6
|
-
|
|
7
5
|
/** Return the months to display in the calendar. */
|
|
8
6
|
export function getMonths(
|
|
9
7
|
/** The months (as dates) to display in the calendar. */
|
|
@@ -11,37 +9,48 @@ export function getMonths(
|
|
|
11
9
|
/** The dates to display in the calendar. */
|
|
12
10
|
dates: Date[],
|
|
13
11
|
/** Options from the props context. */
|
|
14
|
-
props: Pick<
|
|
12
|
+
props: Pick<
|
|
13
|
+
DayPickerProps,
|
|
14
|
+
"broadcastCalendar" | "fixedWeeks" | "ISOWeek" | "reverseMonths"
|
|
15
|
+
>,
|
|
15
16
|
dateLib: DateLib
|
|
16
17
|
): CalendarMonth[] {
|
|
17
18
|
const {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
startOfISOWeek,
|
|
19
|
+
addDays,
|
|
20
|
+
endOfBroadcastWeek,
|
|
21
21
|
endOfISOWeek,
|
|
22
22
|
endOfMonth,
|
|
23
|
-
|
|
23
|
+
endOfWeek,
|
|
24
|
+
getISOWeek,
|
|
24
25
|
getWeek,
|
|
25
|
-
|
|
26
|
+
startOfBroadcastWeek,
|
|
27
|
+
startOfISOWeek,
|
|
28
|
+
startOfWeek
|
|
26
29
|
} = dateLib;
|
|
27
30
|
const dayPickerMonths = displayMonths.reduce<CalendarMonth[]>(
|
|
28
31
|
(months, month) => {
|
|
29
|
-
const firstDateOfFirstWeek = props.
|
|
30
|
-
?
|
|
31
|
-
:
|
|
32
|
+
const firstDateOfFirstWeek = props.broadcastCalendar
|
|
33
|
+
? startOfBroadcastWeek(month, dateLib)
|
|
34
|
+
: props.ISOWeek
|
|
35
|
+
? startOfISOWeek(month)
|
|
36
|
+
: startOfWeek(month);
|
|
32
37
|
|
|
33
|
-
const lastDateOfLastWeek = props.
|
|
34
|
-
?
|
|
35
|
-
:
|
|
38
|
+
const lastDateOfLastWeek = props.broadcastCalendar
|
|
39
|
+
? endOfBroadcastWeek(month, dateLib)
|
|
40
|
+
: props.ISOWeek
|
|
41
|
+
? endOfISOWeek(endOfMonth(month))
|
|
42
|
+
: endOfWeek(endOfMonth(month));
|
|
36
43
|
|
|
37
44
|
/** The dates to display in the month. */
|
|
38
45
|
const monthDates = dates.filter((date) => {
|
|
39
46
|
return date >= firstDateOfFirstWeek && date <= lastDateOfLastWeek;
|
|
40
47
|
});
|
|
41
48
|
|
|
42
|
-
|
|
49
|
+
const nrOfDaysWithFixedWeeks = props.broadcastCalendar ? 35 : 42;
|
|
50
|
+
|
|
51
|
+
if (props.fixedWeeks && monthDates.length < nrOfDaysWithFixedWeeks) {
|
|
43
52
|
const extraDates = dates.filter((date) => {
|
|
44
|
-
const daysToAdd =
|
|
53
|
+
const daysToAdd = nrOfDaysWithFixedWeeks - monthDates.length;
|
|
45
54
|
return (
|
|
46
55
|
date > lastDateOfLastWeek &&
|
|
47
56
|
date <= addDays(lastDateOfLastWeek, daysToAdd)
|
|
@@ -67,7 +76,6 @@ export function getMonths(
|
|
|
67
76
|
);
|
|
68
77
|
|
|
69
78
|
const dayPickerMonth = new CalendarMonth(month, weeks);
|
|
70
|
-
|
|
71
79
|
months.push(dayPickerMonth);
|
|
72
80
|
return months;
|
|
73
81
|
},
|
|
@@ -11,16 +11,21 @@ export function getWeekdays(
|
|
|
11
11
|
dateLib: DateLib,
|
|
12
12
|
/** Use ISOWeek instead of locale/ */
|
|
13
13
|
ISOWeek?: boolean | undefined,
|
|
14
|
-
timeZone?: string | undefined
|
|
14
|
+
timeZone?: string | undefined,
|
|
15
|
+
/** @since 9.4.0 */
|
|
16
|
+
broadcastCalendar?: boolean | undefined
|
|
15
17
|
): Date[] {
|
|
16
18
|
const date = timeZone
|
|
17
19
|
? TZDate.tz(timeZone)
|
|
18
20
|
: dateLib.Date
|
|
19
21
|
? new dateLib.Date()
|
|
20
22
|
: new Date();
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
|
|
24
|
+
const start = broadcastCalendar
|
|
25
|
+
? dateLib.startOfBroadcastWeek(date, dateLib)
|
|
26
|
+
: ISOWeek
|
|
27
|
+
? dateLib.startOfISOWeek(date)
|
|
28
|
+
: dateLib.startOfWeek(date);
|
|
24
29
|
|
|
25
30
|
const days: Date[] = [];
|
|
26
31
|
for (let i = 0; i < 7; i++) {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defaultDateLib } from "../classes";
|
|
2
|
+
|
|
3
|
+
import { startOfBroadcastWeek } from "./startOfBroadcastWeek";
|
|
4
|
+
|
|
5
|
+
describe("startOfBroadcastWeek", () => {
|
|
6
|
+
test.each([
|
|
7
|
+
[new Date(2023, 0, 1), new Date(2022, 11, 26)], // January, Sunday
|
|
8
|
+
[new Date(2023, 1, 1), new Date(2023, 0, 30)], // February, Wednesday
|
|
9
|
+
[new Date(2023, 2, 1), new Date(2023, 1, 27)], // March, Wednesday
|
|
10
|
+
[new Date(2023, 3, 1), new Date(2023, 2, 27)], // April, Saturday
|
|
11
|
+
[new Date(2023, 4, 1), new Date(2023, 4, 1)], // May, Monday
|
|
12
|
+
[new Date(2023, 5, 1), new Date(2023, 4, 29)], // June, Thursday
|
|
13
|
+
[new Date(2023, 6, 1), new Date(2023, 5, 26)], // July, Saturday
|
|
14
|
+
[new Date(2023, 7, 1), new Date(2023, 6, 31)], // August, Tuesday
|
|
15
|
+
[new Date(2023, 8, 1), new Date(2023, 7, 28)], // September, Friday
|
|
16
|
+
[new Date(2023, 9, 1), new Date(2023, 8, 25)], // October, Sunday
|
|
17
|
+
[new Date(2023, 10, 1), new Date(2023, 9, 30)], // November, Wednesday
|
|
18
|
+
[new Date(2023, 11, 1), new Date(2023, 10, 27)] // December, Friday
|
|
19
|
+
])("startOfBroadcastWeek(%s) should return %s", (inputDate, expectedDate) => {
|
|
20
|
+
expect(startOfBroadcastWeek(inputDate, defaultDateLib)).toEqual(
|
|
21
|
+
expectedDate
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DateLib } from "../classes/index.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Return the start date of the week in the broadcast calendar.
|
|
5
|
+
*
|
|
6
|
+
* @since 9.4.0
|
|
7
|
+
*/
|
|
8
|
+
export function startOfBroadcastWeek(date: Date, dateLib: DateLib): Date {
|
|
9
|
+
const firstOfMonth = dateLib.startOfMonth(date);
|
|
10
|
+
const dayOfWeek = firstOfMonth.getDay();
|
|
11
|
+
|
|
12
|
+
if (dayOfWeek === 1) {
|
|
13
|
+
return firstOfMonth;
|
|
14
|
+
} else if (dayOfWeek === 0) {
|
|
15
|
+
return dateLib.addDays(firstOfMonth, -1 * 6);
|
|
16
|
+
} else {
|
|
17
|
+
return dateLib.addDays(firstOfMonth, -1 * (dayOfWeek - 1));
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/style.css
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
--rdp-accent-color: blue; /* The accent color used for selected days and UI elements. */
|
|
5
5
|
--rdp-accent-background-color: #f0f0ff; /* The accent background color used for selected days and UI elements. */
|
|
6
6
|
|
|
7
|
-
--rdp-day-height:
|
|
8
|
-
--rdp-day-width:
|
|
7
|
+
--rdp-day-height: 44px; /* The height of the day cells. */
|
|
8
|
+
--rdp-day-width: 44px; /* The width of the day cells. */
|
|
9
9
|
|
|
10
10
|
--rdp-day_button-border-radius: 100%; /* The border radius of the day cells. */
|
|
11
11
|
--rdp-day_button-border: 2px solid transparent; /* The border of the day cells. */
|
|
12
|
-
--rdp-day_button-height:
|
|
13
|
-
--rdp-day_button-width:
|
|
12
|
+
--rdp-day_button-height: 42px; /* The height of the day cells. */
|
|
13
|
+
--rdp-day_button-width: 42px; /* The width of the day cells. */
|
|
14
14
|
|
|
15
15
|
--rdp-selected-border: 2px solid var(--rdp-accent-color); /* The border of the selected days. */
|
|
16
16
|
--rdp-disabled-opacity: 0.5; /* The opacity of the disabled days. */
|
|
@@ -57,6 +57,10 @@
|
|
|
57
57
|
--rdp-gradient-direction: -90deg;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
.rdp-root[data-broadcast-calendar="true"] {
|
|
61
|
+
--rdp-outside-opacity: unset;
|
|
62
|
+
}
|
|
63
|
+
|
|
60
64
|
/* Root of the component. */
|
|
61
65
|
.rdp-root {
|
|
62
66
|
position: relative; /* Required to position the navigation toolbar. */
|
|
@@ -105,6 +109,11 @@
|
|
|
105
109
|
border: 0;
|
|
106
110
|
}
|
|
107
111
|
|
|
112
|
+
.rdp-dropdown:focus-visible ~ .rdp-caption_label {
|
|
113
|
+
outline: 5px auto Highlight;
|
|
114
|
+
outline: 5px auto -webkit-focus-ring-color;
|
|
115
|
+
}
|
|
116
|
+
|
|
108
117
|
.rdp-button_next,
|
|
109
118
|
.rdp-button_previous {
|
|
110
119
|
border: none;
|