react-day-picker 8.7.0 → 8.7.1
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/index.d.ts +3 -7
- package/dist/index.esm.js +7 -12
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +7 -12
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +4 -4
- package/src/DayPicker.tsx +1 -1
- package/src/components/Root/Root.test.tsx +1 -17
- package/src/components/Root/Root.tsx +22 -16
- package/src/types/DayPickerBase.ts +1 -8
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { DayPickerProps } from 'DayPicker';
|
|
2
4
|
|
|
3
5
|
import { Month } from 'components/Month';
|
|
4
6
|
import { useDayPicker } from 'contexts/DayPicker';
|
|
5
7
|
import { useFocusContext } from 'contexts/Focus';
|
|
6
8
|
import { useNavigation } from 'contexts/Navigation';
|
|
7
|
-
|
|
9
|
+
|
|
10
|
+
function isDataAttributes(attrs: DayPickerProps): attrs is {
|
|
11
|
+
[key: string]: string | boolean | number | undefined;
|
|
12
|
+
} {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface RootProps {
|
|
17
|
+
initialProps: DayPickerProps;
|
|
18
|
+
}
|
|
8
19
|
|
|
9
20
|
/** Render the container with the months according to the number of months to display. */
|
|
10
|
-
export function Root(): JSX.Element {
|
|
21
|
+
export function Root({ initialProps }: RootProps): JSX.Element {
|
|
11
22
|
const dayPicker = useDayPicker();
|
|
12
23
|
const focusContext = useFocusContext();
|
|
13
24
|
const navigation = useNavigation();
|
|
@@ -44,19 +55,15 @@ export function Root(): JSX.Element {
|
|
|
44
55
|
...dayPicker.style
|
|
45
56
|
};
|
|
46
57
|
|
|
47
|
-
const dataAttributes =
|
|
58
|
+
const dataAttributes = Object.keys(initialProps)
|
|
48
59
|
.filter((key) => key.startsWith('data-'))
|
|
49
|
-
.reduce(
|
|
50
|
-
(
|
|
51
|
-
{
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
.reduce(
|
|
57
|
-
(attrs, key) => ({ ...attrs, [key]: dayPicker[key] }),
|
|
58
|
-
{} as AriaAttributes
|
|
59
|
-
);
|
|
60
|
+
.reduce((attrs, key) => {
|
|
61
|
+
if (!isDataAttributes(initialProps)) return attrs;
|
|
62
|
+
return {
|
|
63
|
+
...attrs,
|
|
64
|
+
[key]: initialProps[key]
|
|
65
|
+
};
|
|
66
|
+
}, {});
|
|
60
67
|
|
|
61
68
|
return (
|
|
62
69
|
<div
|
|
@@ -65,7 +72,6 @@ export function Root(): JSX.Element {
|
|
|
65
72
|
dir={dayPicker.dir}
|
|
66
73
|
id={dayPicker.id}
|
|
67
74
|
{...dataAttributes}
|
|
68
|
-
{...ariaAttributes}
|
|
69
75
|
>
|
|
70
76
|
<div
|
|
71
77
|
className={dayPicker.classNames.months}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { Locale } from 'date-fns';
|
|
2
2
|
|
|
3
|
-
import { AriaAttributes } from 'react';
|
|
4
|
-
|
|
5
3
|
import { CaptionLayout, CaptionProps } from 'components/Caption';
|
|
6
4
|
import { CaptionLabelProps } from 'components/CaptionLabel';
|
|
7
5
|
import { DayProps } from 'components/Day';
|
|
@@ -31,11 +29,6 @@ import {
|
|
|
31
29
|
} from './Modifiers';
|
|
32
30
|
import { ClassNames, StyledComponent, Styles } from './Styles';
|
|
33
31
|
|
|
34
|
-
/** A type with all the attributes starting with data- */
|
|
35
|
-
export type DataAttributes = {
|
|
36
|
-
[key: `data-${string}`]: string | boolean | number | undefined;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
32
|
/**
|
|
40
33
|
* Selection modes supported by DayPicker.
|
|
41
34
|
*
|
|
@@ -50,7 +43,7 @@ export type DaySelectionMode = 'single' | 'multiple' | 'range' | 'default';
|
|
|
50
43
|
/**
|
|
51
44
|
* The base props for the {@link DayPicker} component and the {@link DayPickerContext}.
|
|
52
45
|
*/
|
|
53
|
-
export interface DayPickerBase
|
|
46
|
+
export interface DayPickerBase {
|
|
54
47
|
/**
|
|
55
48
|
* The CSS class to add to the container element. To change the name of the
|
|
56
49
|
* class instead, use `classNames.root`.
|