react-day-picker 9.0.7 → 9.0.9
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 +8 -3
- package/dist/cjs/DayPicker.js.map +1 -1
- package/dist/cjs/components/Chevron.d.ts +1 -0
- package/dist/cjs/helpers/getFormatters.d.ts +5 -5
- package/dist/cjs/types/shared.d.ts +11 -9
- package/dist/cjs/useCalendar.js +3 -28
- package/dist/cjs/useCalendar.js.map +1 -1
- package/dist/cjs/useDayPicker.d.ts +11 -1
- package/dist/cjs/useDayPicker.js.map +1 -1
- package/dist/cjs/useGetModifiers.js +16 -16
- package/dist/cjs/useGetModifiers.js.map +1 -1
- package/dist/cjs/utils/dateMatchModifiers.d.ts +8 -3
- package/dist/cjs/utils/dateMatchModifiers.js +10 -3
- package/dist/cjs/utils/dateMatchModifiers.js.map +1 -1
- package/dist/cjs/utils/typeguards.d.ts +5 -1
- package/dist/cjs/utils/typeguards.js +5 -1
- package/dist/cjs/utils/typeguards.js.map +1 -1
- package/dist/esm/DayPicker.js +8 -3
- package/dist/esm/DayPicker.js.map +1 -1
- package/dist/esm/components/Chevron.d.ts +1 -0
- package/dist/esm/helpers/getFormatters.d.ts +5 -5
- package/dist/esm/types/shared.d.ts +11 -9
- package/dist/esm/useCalendar.js +3 -28
- package/dist/esm/useCalendar.js.map +1 -1
- package/dist/esm/useDayPicker.d.ts +11 -1
- package/dist/esm/useDayPicker.js.map +1 -1
- package/dist/esm/useGetModifiers.js +16 -16
- package/dist/esm/useGetModifiers.js.map +1 -1
- package/dist/esm/utils/dateMatchModifiers.d.ts +8 -3
- package/dist/esm/utils/dateMatchModifiers.js +9 -3
- package/dist/esm/utils/dateMatchModifiers.js.map +1 -1
- package/dist/esm/utils/typeguards.d.ts +5 -1
- package/dist/esm/utils/typeguards.js +5 -1
- package/dist/esm/utils/typeguards.js.map +1 -1
- package/examples/TestCase2389.test.tsx +41 -0
- package/examples/TestCase2389.tsx +18 -0
- package/examples/index.ts +1 -0
- package/package.json +9 -9
- package/src/DayPicker.test.tsx +1 -15
- package/src/DayPicker.tsx +8 -1
- package/src/components/Chevron.tsx +2 -0
- package/src/style.css +13 -18
- package/src/style.module.css +13 -18
- package/src/types/shared.ts +11 -8
- package/src/useCalendar.ts +7 -43
- package/src/useDayPicker.ts +18 -1
- package/src/useGetModifiers.tsx +16 -16
- package/src/utils/dateMatchModifiers.ts +10 -3
- package/src/utils/typeguards.ts +5 -1
- package/website/docs/docs/styling.mdx +1 -1
- package/website/docs/guides/input-fields.mdx +1 -1
- package/website/docs/upgrading.mdx +1 -1
package/src/types/shared.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
formatMonthDropdown,
|
|
11
11
|
formatWeekdayName,
|
|
12
12
|
formatWeekNumber,
|
|
13
|
+
formatWeekNumberHeader,
|
|
13
14
|
formatYearCaption,
|
|
14
15
|
formatYearDropdown
|
|
15
16
|
} from "../formatters/index.js";
|
|
@@ -98,20 +99,22 @@ export type DateLib = typeof dateLib;
|
|
|
98
99
|
export type Formatters = {
|
|
99
100
|
/** Format the caption of a month grid. */
|
|
100
101
|
formatCaption: typeof formatCaption;
|
|
101
|
-
/** @deprecated Use {@link Formatters.formatCaption} instead. */
|
|
102
|
-
formatMonthCaption: typeof formatMonthCaption;
|
|
103
|
-
/** Format the label in the month dropdown. */
|
|
104
|
-
formatMonthDropdown: typeof formatMonthDropdown;
|
|
105
|
-
/** @deprecated Use {@link Formatters.formatYearDropdown} instead. */
|
|
106
|
-
formatYearCaption: typeof formatYearCaption;
|
|
107
|
-
/** Format the label in the year dropdown. */
|
|
108
|
-
formatYearDropdown: typeof formatYearDropdown;
|
|
109
102
|
/** Format the day in the day cell. */
|
|
110
103
|
formatDay: typeof formatDay;
|
|
104
|
+
/** Format the label in the month dropdown. */
|
|
105
|
+
formatMonthDropdown: typeof formatMonthDropdown;
|
|
106
|
+
/** @deprecated Use {@link Formatters.formatCaption} instead. */
|
|
107
|
+
formatMonthCaption: typeof formatMonthCaption;
|
|
111
108
|
/** Format the week number. */
|
|
112
109
|
formatWeekNumber: typeof formatWeekNumber;
|
|
110
|
+
/** Format the header of the week number column. */
|
|
111
|
+
formatWeekNumberHeader: typeof formatWeekNumberHeader;
|
|
113
112
|
/** Format the week day name in the header. */
|
|
114
113
|
formatWeekdayName: typeof formatWeekdayName;
|
|
114
|
+
/** Format the label in the year dropdown. */
|
|
115
|
+
formatYearDropdown: typeof formatYearDropdown;
|
|
116
|
+
/** @deprecated Use {@link Formatters.formatYearDropdown} instead. */
|
|
117
|
+
formatYearCaption: typeof formatYearCaption;
|
|
115
118
|
};
|
|
116
119
|
|
|
117
120
|
/** Map of functions to translate ARIA labels for the relative elements. */
|
package/src/useCalendar.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
|
|
3
1
|
import type {
|
|
4
2
|
CalendarWeek,
|
|
5
3
|
CalendarDay,
|
|
@@ -14,6 +12,7 @@ import { getNavMonths } from "./helpers/getNavMonth.js";
|
|
|
14
12
|
import { getNextMonth } from "./helpers/getNextMonth.js";
|
|
15
13
|
import { getPreviousMonth } from "./helpers/getPreviousMonth.js";
|
|
16
14
|
import { getWeeks } from "./helpers/getWeeks.js";
|
|
15
|
+
import { useControlledValue } from "./helpers/useControlledValue.js";
|
|
17
16
|
import type { DayPickerProps } from "./types/props.js";
|
|
18
17
|
import type { DateLib } from "./types/shared.js";
|
|
19
18
|
|
|
@@ -88,51 +87,16 @@ export function useCalendar(
|
|
|
88
87
|
>,
|
|
89
88
|
dateLib: DateLib
|
|
90
89
|
): Calendar {
|
|
91
|
-
const {
|
|
92
|
-
fromYear,
|
|
93
|
-
toYear,
|
|
94
|
-
startMonth,
|
|
95
|
-
endMonth,
|
|
96
|
-
today,
|
|
97
|
-
numberOfMonths,
|
|
98
|
-
month,
|
|
99
|
-
defaultMonth
|
|
100
|
-
} = props;
|
|
101
90
|
const [navStart, navEnd] = getNavMonths(props, dateLib);
|
|
102
91
|
|
|
103
92
|
const { startOfMonth, endOfMonth } = dateLib;
|
|
104
93
|
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const initialDisplayMonth = getInitialMonth(
|
|
112
|
-
{
|
|
113
|
-
fromYear,
|
|
114
|
-
toYear,
|
|
115
|
-
startMonth,
|
|
116
|
-
endMonth,
|
|
117
|
-
month,
|
|
118
|
-
defaultMonth,
|
|
119
|
-
today,
|
|
120
|
-
numberOfMonths
|
|
121
|
-
},
|
|
122
|
-
dateLib
|
|
123
|
-
);
|
|
124
|
-
setFirstMonth(initialDisplayMonth);
|
|
125
|
-
}, [
|
|
126
|
-
dateLib,
|
|
127
|
-
defaultMonth,
|
|
128
|
-
endMonth,
|
|
129
|
-
fromYear,
|
|
130
|
-
month,
|
|
131
|
-
numberOfMonths,
|
|
132
|
-
startMonth,
|
|
133
|
-
toYear,
|
|
134
|
-
today
|
|
135
|
-
]);
|
|
94
|
+
const initialMonth = getInitialMonth(props, dateLib);
|
|
95
|
+
|
|
96
|
+
const [firstMonth, setFirstMonth] = useControlledValue(
|
|
97
|
+
initialMonth,
|
|
98
|
+
props.month ? startOfMonth(props.month) : undefined
|
|
99
|
+
);
|
|
136
100
|
|
|
137
101
|
/** The months displayed in the calendar. */
|
|
138
102
|
const displayMonths = getDisplayMonths(firstMonth, navEnd, props, dateLib);
|
package/src/useDayPicker.ts
CHANGED
|
@@ -4,7 +4,14 @@ import { CalendarDay } from "./classes/CalendarDay.js";
|
|
|
4
4
|
import { CalendarMonth } from "./classes/CalendarMonth.js";
|
|
5
5
|
import type { DayPickerProps } from "./types/props.js";
|
|
6
6
|
import type { SelectedValue, SelectHandler } from "./types/selection.js";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
ClassNames,
|
|
9
|
+
CustomComponents,
|
|
10
|
+
Formatters,
|
|
11
|
+
Labels,
|
|
12
|
+
Modifiers,
|
|
13
|
+
Styles
|
|
14
|
+
} from "./types/shared.js";
|
|
8
15
|
|
|
9
16
|
/** @private */
|
|
10
17
|
export const dayPickerContext = createContext<
|
|
@@ -28,6 +35,16 @@ export type DayPickerContext<T extends DayPickerProps> = {
|
|
|
28
35
|
select: SelectHandler<T> | undefined;
|
|
29
36
|
/** Whether the given date is selected. */
|
|
30
37
|
isSelected: ((date: Date) => boolean) | undefined;
|
|
38
|
+
/** The components used internally by DayP. */
|
|
39
|
+
components: CustomComponents;
|
|
40
|
+
/** The class names for the UI elements. */
|
|
41
|
+
classNames: ClassNames;
|
|
42
|
+
/** The styles for the UI elements. */
|
|
43
|
+
styles: Partial<Styles> | undefined;
|
|
44
|
+
/** The labels used in the UI. */
|
|
45
|
+
labels: Labels;
|
|
46
|
+
/** The formatters used to format the UI elements. */
|
|
47
|
+
formatters: Formatters;
|
|
31
48
|
};
|
|
32
49
|
|
|
33
50
|
/**
|
package/src/useGetModifiers.tsx
CHANGED
|
@@ -17,7 +17,7 @@ export function useGetModifiers(
|
|
|
17
17
|
|
|
18
18
|
const { isSameDay, isSameMonth, Date } = dateLib;
|
|
19
19
|
|
|
20
|
-
const
|
|
20
|
+
const internalModifiersMap: Record<DayFlag, CalendarDay[]> = {
|
|
21
21
|
[DayFlag.focused]: [],
|
|
22
22
|
[DayFlag.outside]: [],
|
|
23
23
|
[DayFlag.disabled]: [],
|
|
@@ -25,9 +25,9 @@ export function useGetModifiers(
|
|
|
25
25
|
[DayFlag.today]: []
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
const
|
|
28
|
+
const customModifiersMap: Record<string, CalendarDay[]> = {};
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const selectionModifiersMap: Record<SelectionState, CalendarDay[]> = {
|
|
31
31
|
[SelectionState.range_end]: [],
|
|
32
32
|
[SelectionState.range_middle]: [],
|
|
33
33
|
[SelectionState.range_start]: [],
|
|
@@ -49,10 +49,10 @@ export function useGetModifiers(
|
|
|
49
49
|
|
|
50
50
|
const isToday = isSameDay(date, today ?? new Date());
|
|
51
51
|
|
|
52
|
-
if (isOutside)
|
|
53
|
-
if (isDisabled)
|
|
54
|
-
if (isHidden)
|
|
55
|
-
if (isToday)
|
|
52
|
+
if (isOutside) internalModifiersMap.outside.push(day);
|
|
53
|
+
if (isDisabled) internalModifiersMap.disabled.push(day);
|
|
54
|
+
if (isHidden) internalModifiersMap.hidden.push(day);
|
|
55
|
+
if (isToday) internalModifiersMap.today.push(day);
|
|
56
56
|
|
|
57
57
|
// Add custom modifiers
|
|
58
58
|
if (modifiers) {
|
|
@@ -62,10 +62,10 @@ export function useGetModifiers(
|
|
|
62
62
|
? dateMatchModifiers(date, modifierValue, dateLib)
|
|
63
63
|
: false;
|
|
64
64
|
if (!isMatch) return;
|
|
65
|
-
if (
|
|
66
|
-
|
|
65
|
+
if (customModifiersMap[name]) {
|
|
66
|
+
customModifiersMap[name].push(day);
|
|
67
67
|
} else {
|
|
68
|
-
|
|
68
|
+
customModifiersMap[name] = [day];
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
}
|
|
@@ -89,16 +89,16 @@ export function useGetModifiers(
|
|
|
89
89
|
const customModifiers: Modifiers = {};
|
|
90
90
|
|
|
91
91
|
// Find the modifiers for the given day
|
|
92
|
-
for (const name in
|
|
93
|
-
const days =
|
|
92
|
+
for (const name in internalModifiersMap) {
|
|
93
|
+
const days = internalModifiersMap[name as DayFlag];
|
|
94
94
|
dayFlags[name as DayFlag] = days.some((d) => d === day);
|
|
95
95
|
}
|
|
96
|
-
for (const name in
|
|
97
|
-
const days =
|
|
96
|
+
for (const name in selectionModifiersMap) {
|
|
97
|
+
const days = selectionModifiersMap[name as SelectionState];
|
|
98
98
|
selectionStates[name as SelectionState] = days.some((d) => d === day);
|
|
99
99
|
}
|
|
100
|
-
for (const name in
|
|
101
|
-
customModifiers[name] =
|
|
100
|
+
for (const name in customModifiersMap) {
|
|
101
|
+
customModifiers[name] = customModifiersMap[name].some((d) => d === day);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
return {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { dateLib as defaultDateLib } from "../lib/dateLib.js";
|
|
1
2
|
import type { DateLib, Matcher } from "../types/index.js";
|
|
2
3
|
|
|
3
4
|
import { rangeIncludesDate } from "./rangeIncludesDate.js";
|
|
@@ -15,7 +16,7 @@ import {
|
|
|
15
16
|
* {@link Matcher}.
|
|
16
17
|
*
|
|
17
18
|
* ```tsx
|
|
18
|
-
* const
|
|
19
|
+
* const date = new Date(2022, 5, 19);
|
|
19
20
|
* const matcher1: DateRange = {
|
|
20
21
|
* from: new Date(2021, 12, 21),
|
|
21
22
|
* to: new Date(2021, 12, 30)
|
|
@@ -24,7 +25,7 @@ import {
|
|
|
24
25
|
* from: new Date(2022, 5, 1),
|
|
25
26
|
* to: new Date(2022, 5, 23)
|
|
26
27
|
* }
|
|
27
|
-
* const
|
|
28
|
+
* const dateMatchModifiers(date, [matcher1, matcher2]); // true, since day is in the matcher1 range.
|
|
28
29
|
* ```
|
|
29
30
|
*
|
|
30
31
|
* @group Utilities
|
|
@@ -32,7 +33,7 @@ import {
|
|
|
32
33
|
export function dateMatchModifiers(
|
|
33
34
|
date: Date,
|
|
34
35
|
matchers: Matcher | Matcher[],
|
|
35
|
-
dateLib: DateLib
|
|
36
|
+
dateLib: DateLib = defaultDateLib
|
|
36
37
|
): boolean {
|
|
37
38
|
const matchersArr = !Array.isArray(matchers) ? [matchers] : matchers;
|
|
38
39
|
const { isSameDay, differenceInCalendarDays, isAfter } = dateLib;
|
|
@@ -79,3 +80,9 @@ export function dateMatchModifiers(
|
|
|
79
80
|
return false;
|
|
80
81
|
});
|
|
81
82
|
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @private
|
|
86
|
+
* @deprecated Use {@link dateMatchModifiers} instead.
|
|
87
|
+
*/
|
|
88
|
+
export const isMatch = dateMatchModifiers;
|
package/src/utils/typeguards.ts
CHANGED
|
@@ -57,7 +57,11 @@ export function isDayOfWeekType(value: unknown): value is DayOfWeek {
|
|
|
57
57
|
return Boolean(value && typeof value === "object" && "dayOfWeek" in value);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Returns true if `value` is an array of valid dates.
|
|
62
|
+
*
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
61
65
|
export function isDatesArray(
|
|
62
66
|
value: unknown,
|
|
63
67
|
dateLib: DateLib
|
|
@@ -79,7 +79,7 @@ The following table lists the CSS variables used by DayPicker inside the `.rdp-r
|
|
|
79
79
|
| `--rdp-nav-height` | The height of the navigation bar. |
|
|
80
80
|
| `--rdp-range_middle-background-color` | The color of the background for days in the middle of a range. |
|
|
81
81
|
| `--rdp-range_middle-font` | The font for days in the middle of a range. |
|
|
82
|
-
| `--
|
|
82
|
+
| `--rdp-range_middle-foreground-color` | The color of the text for days in the middle of a range. |
|
|
83
83
|
| `--rdp-range_start-color` | The color of the range text at the start of the range. |
|
|
84
84
|
| `--rdp-range_start-background` | Used for the background of the start of the selected range. |
|
|
85
85
|
| `--rdp-range_start-date-background-color` | The background color of the date at the start of the selected range. |
|
|
@@ -16,7 +16,7 @@ Browsers offer [native date pickers](https://developer.mozilla.org/en-US/docs/We
|
|
|
16
16
|
|
|
17
17
|
### Input with Inline Calendar
|
|
18
18
|
|
|
19
|
-
See also the [full source code](https://github.com/gpbl/react-day-picker/blob/main/
|
|
19
|
+
See also the [full source code](https://github.com/gpbl/react-day-picker/blob/main/examples/Input.tsx) and [the unit tests](https://github.com/gpbl/react-day-picker/blob/main/examples/Input.test.tsx) for this example.
|
|
20
20
|
|
|
21
21
|
<BrowserWindow>
|
|
22
22
|
<Examples.Input />
|
|
@@ -259,7 +259,7 @@ If you are using TypeScript, some typings have been deprecated in favor of clari
|
|
|
259
259
|
+ import type { PropsBase } from 'react-day-picker';
|
|
260
260
|
```
|
|
261
261
|
|
|
262
|
-
See also the source of [types
|
|
262
|
+
See also the source of [types/deprecated.ts](https://github.com/gpbl/react-day-picker/blob/next/src/types/deprecated.ts).
|
|
263
263
|
|
|
264
264
|
<details>
|
|
265
265
|
<summary>**List of Deprecated Types**</summary>
|