react-day-picker 8.0.3 → 8.0.4
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/package.json +13 -11
- package/src/DayPicker.tsx +113 -0
- package/src/components/Button/Button.test.tsx +47 -0
- package/src/components/Button/Button.tsx +36 -0
- package/src/components/Button/index.ts +1 -0
- package/src/components/Caption/Caption.test.tsx +86 -0
- package/src/components/Caption/Caption.tsx +54 -0
- package/src/components/Caption/index.ts +1 -0
- package/src/components/CaptionDropdowns/CaptionDropdowns.test.tsx +123 -0
- package/src/components/CaptionDropdowns/CaptionDropdowns.tsx +43 -0
- package/src/components/CaptionDropdowns/index.ts +1 -0
- package/src/components/CaptionLabel/CaptionLabel.test.tsx +29 -0
- package/src/components/CaptionLabel/CaptionLabel.tsx +32 -0
- package/src/components/CaptionLabel/index.ts +1 -0
- package/src/components/CaptionNavigation/CaptionNavigation.test.tsx +172 -0
- package/src/components/CaptionNavigation/CaptionNavigation.tsx +63 -0
- package/src/components/CaptionNavigation/index.ts +1 -0
- package/src/components/Day/Day.test.tsx +84 -0
- package/src/components/Day/Day.tsx +30 -0
- package/src/components/Day/index.ts +1 -0
- package/src/components/DayContent/DayContent.test.tsx +51 -0
- package/src/components/DayContent/DayContent.tsx +36 -0
- package/src/components/DayContent/index.ts +1 -0
- package/src/components/Dropdown/Dropdown.test.tsx +73 -0
- package/src/components/Dropdown/Dropdown.tsx +56 -0
- package/src/components/Dropdown/index.ts +1 -0
- package/src/components/Footer/Footer.test.tsx +29 -0
- package/src/components/Footer/Footer.tsx +20 -0
- package/src/components/Footer/index.ts +1 -0
- package/src/components/Head/Head.test.tsx +117 -0
- package/src/components/Head/Head.tsx +51 -0
- package/src/components/Head/index.ts +1 -0
- package/src/components/Head/utils/getWeekdays.test.ts +36 -0
- package/src/components/Head/utils/getWeekdays.ts +22 -0
- package/src/components/Head/utils/index.ts +1 -0
- package/src/components/IconDropdown/IconDropdown.test.tsx +20 -0
- package/src/components/IconDropdown/IconDropdown.tsx +24 -0
- package/src/components/IconDropdown/index.ts +1 -0
- package/src/components/IconLeft/IconLeft.test.tsx +20 -0
- package/src/components/IconLeft/IconLeft.tsx +18 -0
- package/src/components/IconLeft/index.ts +1 -0
- package/src/components/IconRight/IconRight.test.tsx +20 -0
- package/src/components/IconRight/IconRight.tsx +17 -0
- package/src/components/IconRight/index.ts +1 -0
- package/src/components/Month/Month.test.tsx +216 -0
- package/src/components/Month/Month.tsx +53 -0
- package/src/components/Month/index.ts +1 -0
- package/src/components/MonthsDropdown/MonthsDropdown.test.tsx +99 -0
- package/src/components/MonthsDropdown/MonthsDropdown.tsx +75 -0
- package/src/components/MonthsDropdown/index.ts +1 -0
- package/src/components/Navigation/Navigation.test.tsx +129 -0
- package/src/components/Navigation/Navigation.tsx +102 -0
- package/src/components/Navigation/index.ts +1 -0
- package/src/components/Root/Root.test.tsx +123 -0
- package/src/components/Root/Root.tsx +58 -0
- package/src/components/Root/index.ts +1 -0
- package/src/components/Row/Row.test.tsx +69 -0
- package/src/components/Row/Row.tsx +51 -0
- package/src/components/Row/index.ts +1 -0
- package/src/components/Table/Table.test.tsx +42 -0
- package/src/components/Table/Table.tsx +60 -0
- package/src/components/Table/__snapshots__/Table.test.tsx.snap +1453 -0
- package/src/components/Table/index.ts +1 -0
- package/src/components/Table/utils/daysToMonthWeeks.ts +47 -0
- package/src/components/Table/utils/getMonthWeeks.test.ts +68 -0
- package/src/components/Table/utils/getMonthWeeks.ts +55 -0
- package/src/components/WeekNumber/WeekNumber.test.tsx +46 -0
- package/src/components/WeekNumber/WeekNumber.tsx +58 -0
- package/src/components/WeekNumber/__snapshots__/WeekNumber.test.tsx.snap +11 -0
- package/src/components/WeekNumber/index.ts +1 -0
- package/src/components/YearsDropdown/YearsDropdown.test.tsx +98 -0
- package/src/components/YearsDropdown/YearsDropdown.tsx +76 -0
- package/src/components/YearsDropdown/index.ts +1 -0
- package/src/contexts/DayPicker/DayPickerContext.tsx +156 -0
- package/src/contexts/DayPicker/defaultClassNames.ts +58 -0
- package/src/contexts/DayPicker/defaultContextValue.ts +37 -0
- package/src/contexts/DayPicker/formatters/formatCaption.test.ts +15 -0
- package/src/contexts/DayPicker/formatters/formatCaption.ts +12 -0
- package/src/contexts/DayPicker/formatters/formatDay.test.ts +7 -0
- package/src/contexts/DayPicker/formatters/formatDay.ts +9 -0
- package/src/contexts/DayPicker/formatters/formatMonthCaption.test.ts +15 -0
- package/src/contexts/DayPicker/formatters/formatMonthCaption.ts +12 -0
- package/src/contexts/DayPicker/formatters/formatWeekNumber.test.ts +5 -0
- package/src/contexts/DayPicker/formatters/formatWeekNumber.ts +6 -0
- package/src/contexts/DayPicker/formatters/formatWeekdayName.test.ts +15 -0
- package/src/contexts/DayPicker/formatters/formatWeekdayName.ts +12 -0
- package/src/contexts/DayPicker/formatters/formatYearCaption.test.ts +7 -0
- package/src/contexts/DayPicker/formatters/formatYearCaption.ts +11 -0
- package/src/contexts/DayPicker/formatters/index.ts +6 -0
- package/src/contexts/DayPicker/index.ts +2 -0
- package/src/contexts/DayPicker/labels/index.ts +7 -0
- package/src/contexts/DayPicker/labels/labelDay.test.ts +7 -0
- package/src/contexts/DayPicker/labels/labelDay.ts +10 -0
- package/src/contexts/DayPicker/labels/labelMonthDropdown.test.ts +5 -0
- package/src/contexts/DayPicker/labels/labelMonthDropdown.ts +6 -0
- package/src/contexts/DayPicker/labels/labelNext.test.ts +5 -0
- package/src/contexts/DayPicker/labels/labelNext.ts +8 -0
- package/src/contexts/DayPicker/labels/labelPrevious.test.ts +5 -0
- package/src/contexts/DayPicker/labels/labelPrevious.ts +8 -0
- package/src/contexts/DayPicker/labels/labelWeekNumber.test.ts +5 -0
- package/src/contexts/DayPicker/labels/labelWeekNumber.ts +8 -0
- package/src/contexts/DayPicker/labels/labelWeekday.test.ts +15 -0
- package/src/contexts/DayPicker/labels/labelWeekday.ts +10 -0
- package/src/contexts/DayPicker/labels/labelYearDropdown.test.ts +5 -0
- package/src/contexts/DayPicker/labels/labelYearDropdown.ts +6 -0
- package/src/contexts/DayPicker/useDayPicker.test.ts +297 -0
- package/src/contexts/DayPicker/useDayPicker.ts +17 -0
- package/src/contexts/DayPicker/utils/index.ts +1 -0
- package/src/contexts/DayPicker/utils/parseFromToProps.test.ts +47 -0
- package/src/contexts/DayPicker/utils/parseFromToProps.ts +32 -0
- package/src/contexts/Focus/FocusContext.tsx +174 -0
- package/src/contexts/Focus/index.ts +2 -0
- package/src/contexts/Focus/useFocusContext.test.ts +183 -0
- package/src/contexts/Focus/useFocusContext.ts +12 -0
- package/src/contexts/Focus/utils/getInitialFocusTarget.test.tsx +12 -0
- package/src/contexts/Focus/utils/getInitialFocusTarget.tsx +44 -0
- package/src/contexts/Modifiers/ModifiersContext.tsx +44 -0
- package/src/contexts/Modifiers/index.ts +2 -0
- package/src/contexts/Modifiers/useModifiers.test.ts +46 -0
- package/src/contexts/Modifiers/useModifiers.ts +17 -0
- package/src/contexts/Modifiers/utils/getActiveModifiers.test.ts +53 -0
- package/src/contexts/Modifiers/utils/getActiveModifiers.ts +33 -0
- package/src/contexts/Modifiers/utils/getCustomModifiers.test.ts +14 -0
- package/src/contexts/Modifiers/utils/getCustomModifiers.ts +14 -0
- package/src/contexts/Modifiers/utils/getInternalModifiers.test.ts +146 -0
- package/src/contexts/Modifiers/utils/getInternalModifiers.ts +58 -0
- package/src/contexts/Modifiers/utils/isDateInRange.test.ts +28 -0
- package/src/contexts/Modifiers/utils/isDateInRange.ts +27 -0
- package/src/contexts/Modifiers/utils/isMatch.test.ts +92 -0
- package/src/contexts/Modifiers/utils/isMatch.ts +76 -0
- package/src/contexts/Modifiers/utils/matcherToArray.test.ts +22 -0
- package/src/contexts/Modifiers/utils/matcherToArray.ts +14 -0
- package/src/contexts/Navigation/NavigationContext.tsx +84 -0
- package/src/contexts/Navigation/index.ts +2 -0
- package/src/contexts/Navigation/useNavigation.test.ts +126 -0
- package/src/contexts/Navigation/useNavigation.ts +12 -0
- package/src/contexts/Navigation/useNavigationState.test.ts +36 -0
- package/src/contexts/Navigation/useNavigationState.ts +25 -0
- package/src/contexts/Navigation/utils/getDisplayMonths.ts +31 -0
- package/src/contexts/Navigation/utils/getInitialMonth.test.ts +56 -0
- package/src/contexts/Navigation/utils/getInitialMonth.ts +24 -0
- package/src/contexts/Navigation/utils/getNextMonth.test.ts +75 -0
- package/src/contexts/Navigation/utils/getNextMonth.ts +45 -0
- package/src/contexts/Navigation/utils/getPreviousMonth.test.ts +55 -0
- package/src/contexts/Navigation/utils/getPreviousMonth.ts +44 -0
- package/src/contexts/RootProvider.tsx +37 -0
- package/src/contexts/SelectMultiple/SelectMultipleContext.tsx +135 -0
- package/src/contexts/SelectMultiple/index.ts +2 -0
- package/src/contexts/SelectMultiple/useSelectMultiple.test.ts +191 -0
- package/src/contexts/SelectMultiple/useSelectMultiple.ts +17 -0
- package/src/contexts/SelectRange/SelectRangeContext.tsx +158 -0
- package/src/contexts/SelectRange/index.ts +2 -0
- package/src/contexts/SelectRange/useSelectRange.test.ts +282 -0
- package/src/contexts/SelectRange/useSelectRange.ts +15 -0
- package/src/contexts/SelectRange/utils/addToRange.test.ts +119 -0
- package/src/contexts/SelectRange/utils/addToRange.ts +43 -0
- package/src/contexts/SelectSingle/SelectSingleContext.tsx +80 -0
- package/src/contexts/SelectSingle/index.ts +2 -0
- package/src/contexts/SelectSingle/useSelectSingle.test.ts +81 -0
- package/src/contexts/SelectSingle/useSelectSingle.ts +17 -0
- package/src/hooks/useActiveModifiers/index.ts +1 -0
- package/src/hooks/useActiveModifiers/useActiveModifiers.test.tsx +36 -0
- package/src/hooks/useActiveModifiers/useActiveModifiers.tsx +18 -0
- package/src/hooks/useControlledValue/index.ts +1 -0
- package/src/hooks/useControlledValue/useControlledValue.test.ts +68 -0
- package/src/hooks/useControlledValue/useControlledValue.ts +24 -0
- package/src/hooks/useDayEventHandlers/index.ts +1 -0
- package/src/hooks/useDayEventHandlers/useDayEventHandlers.test.tsx +213 -0
- package/src/hooks/useDayEventHandlers/useDayEventHandlers.tsx +195 -0
- package/src/hooks/useDayRender/index.ts +1 -0
- package/src/hooks/useDayRender/useDayRender.test.tsx +304 -0
- package/src/hooks/useDayRender/useDayRender.tsx +123 -0
- package/src/hooks/useDayRender/utils/getDayClassNames.test.ts +63 -0
- package/src/hooks/useDayRender/utils/getDayClassNames.ts +32 -0
- package/src/hooks/useDayRender/utils/getDayStyle.ts +19 -0
- package/src/hooks/useInput/index.ts +1 -0
- package/src/hooks/useInput/useInput.ts +175 -0
- package/src/hooks/useInput/utils/isValidDate.tsx +4 -0
- package/src/hooks/useSelectedDays/index.ts +1 -0
- package/src/hooks/useSelectedDays/useSelectedDays.test.ts +72 -0
- package/src/hooks/useSelectedDays/useSelectedDays.ts +32 -0
- package/src/index.ts +43 -0
- package/src/style.css +310 -0
- package/src/style.css.d.ts +38 -0
- package/src/types/DayPickerBase.ts +267 -0
- package/src/types/DayPickerDefault.ts +15 -0
- package/src/types/DayPickerMultiple.ts +26 -0
- package/src/types/DayPickerRange.ts +27 -0
- package/src/types/DayPickerSingle.ts +24 -0
- package/src/types/EventHandlers.ts +87 -0
- package/src/types/Formatters.ts +29 -0
- package/src/types/Labels.ts +36 -0
- package/src/types/Matchers.ts +106 -0
- package/src/types/Modifiers.ts +62 -0
- package/src/types/Styles.ts +108 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import enUS from 'date-fns/locale/en-US';
|
|
2
|
+
|
|
3
|
+
import { CaptionLayout } from 'components/Caption';
|
|
4
|
+
import { DayPickerContextValue } from 'contexts/DayPicker';
|
|
5
|
+
|
|
6
|
+
import { defaultClassNames } from './defaultClassNames';
|
|
7
|
+
import * as formatters from './formatters';
|
|
8
|
+
import * as labels from './labels';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Returns the default values to use in the DayPickerContext, in case they are
|
|
12
|
+
* not passed down with the DayPicker initial props.
|
|
13
|
+
*/
|
|
14
|
+
export function getDefaultContextValue(): DayPickerContextValue {
|
|
15
|
+
const captionLayout: CaptionLayout = 'buttons';
|
|
16
|
+
const classNames = defaultClassNames;
|
|
17
|
+
const locale = enUS;
|
|
18
|
+
const modifiersClassNames = {};
|
|
19
|
+
const modifiers = {};
|
|
20
|
+
const numberOfMonths = 1;
|
|
21
|
+
const styles = {};
|
|
22
|
+
const today = new Date();
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
captionLayout,
|
|
26
|
+
classNames,
|
|
27
|
+
formatters,
|
|
28
|
+
labels,
|
|
29
|
+
locale,
|
|
30
|
+
modifiersClassNames,
|
|
31
|
+
modifiers,
|
|
32
|
+
numberOfMonths,
|
|
33
|
+
styles,
|
|
34
|
+
today,
|
|
35
|
+
mode: 'default'
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import es from 'date-fns/locale/es';
|
|
2
|
+
|
|
3
|
+
import { formatCaption } from './formatCaption';
|
|
4
|
+
|
|
5
|
+
const date = new Date(2022, 10, 21);
|
|
6
|
+
|
|
7
|
+
test('should return the formatted caption', () => {
|
|
8
|
+
expect(formatCaption(date)).toEqual('November 2022');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe('when a locale is passed in', () => {
|
|
12
|
+
test('should format using the locale', () => {
|
|
13
|
+
expect(formatCaption(date, { locale: es })).toEqual('noviembre 2022');
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Locale } from 'date-fns';
|
|
2
|
+
import format from 'date-fns/format';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The default formatter for the caption.
|
|
6
|
+
*/
|
|
7
|
+
export function formatCaption(
|
|
8
|
+
month: Date,
|
|
9
|
+
options?: { locale?: Locale }
|
|
10
|
+
): string {
|
|
11
|
+
return format(month, 'LLLL y', options);
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import es from 'date-fns/locale/es';
|
|
2
|
+
|
|
3
|
+
import { formatMonthCaption } from './formatMonthCaption';
|
|
4
|
+
|
|
5
|
+
const date = new Date(2022, 10, 21);
|
|
6
|
+
|
|
7
|
+
test('should return the formatted month caption', () => {
|
|
8
|
+
expect(formatMonthCaption(date)).toEqual('November');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe('when a locale is passed in', () => {
|
|
12
|
+
test('should format using the locale', () => {
|
|
13
|
+
expect(formatMonthCaption(date, { locale: es })).toEqual('noviembre');
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Locale } from 'date-fns';
|
|
2
|
+
import format from 'date-fns/format';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The default formatter for the Month caption.
|
|
6
|
+
*/
|
|
7
|
+
export function formatMonthCaption(
|
|
8
|
+
month: Date,
|
|
9
|
+
options?: { locale?: Locale }
|
|
10
|
+
): string {
|
|
11
|
+
return format(month, 'LLLL', options);
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import es from 'date-fns/locale/es';
|
|
2
|
+
|
|
3
|
+
import { formatWeekdayName } from './formatWeekdayName';
|
|
4
|
+
|
|
5
|
+
const date = new Date(2022, 10, 21);
|
|
6
|
+
|
|
7
|
+
test('should return the formatted weekday name', () => {
|
|
8
|
+
expect(formatWeekdayName(date)).toEqual('Mo');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe('when a locale is passed in', () => {
|
|
12
|
+
test('should format using the locale', () => {
|
|
13
|
+
expect(formatWeekdayName(date, { locale: es })).toEqual('lu');
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Locale } from 'date-fns';
|
|
2
|
+
import format from 'date-fns/format';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The default formatter for the name of the weekday.
|
|
6
|
+
*/
|
|
7
|
+
export function formatWeekdayName(
|
|
8
|
+
weekday: Date,
|
|
9
|
+
options?: { locale?: Locale }
|
|
10
|
+
): string {
|
|
11
|
+
return format(weekday, 'cccccc', options);
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import format from 'date-fns/format';
|
|
2
|
+
|
|
3
|
+
import { DayLabel } from 'types/Labels';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The default ARIA label for the day button.
|
|
7
|
+
*/
|
|
8
|
+
export const labelDay: DayLabel = (day, activeModifiers, options): string => {
|
|
9
|
+
return format(day, 'do MMMM (EEEE)', options);
|
|
10
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import es from 'date-fns/locale/es';
|
|
2
|
+
|
|
3
|
+
import { labelWeekday } from './labelWeekday';
|
|
4
|
+
|
|
5
|
+
const weekDay = new Date(2022, 10, 21);
|
|
6
|
+
|
|
7
|
+
test('should return the formatted weekday name', () => {
|
|
8
|
+
expect(labelWeekday(weekDay)).toEqual('Monday');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe('when a locale is passed in', () => {
|
|
12
|
+
test('should format using the locale', () => {
|
|
13
|
+
expect(labelWeekday(weekDay, { locale: es })).toEqual('lunes');
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import format from 'date-fns/format';
|
|
2
|
+
|
|
3
|
+
import { WeekdayLabel } from 'types/Labels';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The default ARIA label for the Weekday element.
|
|
7
|
+
*/
|
|
8
|
+
export const labelWeekday: WeekdayLabel = (day, options): string => {
|
|
9
|
+
return format(day, 'cccc', options);
|
|
10
|
+
};
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { RenderResult } from '@testing-library/react-hooks';
|
|
2
|
+
import es from 'date-fns/locale/es';
|
|
3
|
+
import { DayPickerProps } from 'DayPicker';
|
|
4
|
+
|
|
5
|
+
import { customRenderHook } from 'test/render';
|
|
6
|
+
import { freezeBeforeAll } from 'test/utils';
|
|
7
|
+
|
|
8
|
+
import { CaptionLayout } from 'components/Caption';
|
|
9
|
+
import { DayPickerContextValue, useDayPicker } from 'contexts/DayPicker';
|
|
10
|
+
import { getDefaultContextValue } from 'contexts/DayPicker/defaultContextValue';
|
|
11
|
+
import { CustomComponents } from 'types/DayPickerBase';
|
|
12
|
+
import { Formatters } from 'types/Formatters';
|
|
13
|
+
import { Labels } from 'types/Labels';
|
|
14
|
+
import { DayModifiers, ModifiersClassNames } from 'types/Modifiers';
|
|
15
|
+
import { ClassNames, Styles } from 'types/Styles';
|
|
16
|
+
|
|
17
|
+
const today = new Date(2022, 5, 13);
|
|
18
|
+
const defaults = getDefaultContextValue();
|
|
19
|
+
|
|
20
|
+
freezeBeforeAll(today);
|
|
21
|
+
|
|
22
|
+
let renderResult: RenderResult<DayPickerContextValue>;
|
|
23
|
+
function setup(dayPickerProps?: DayPickerProps) {
|
|
24
|
+
const { result } = customRenderHook(() => useDayPicker(), dayPickerProps);
|
|
25
|
+
renderResult = result;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('when passing rendered without props', () => {
|
|
29
|
+
type PropName =
|
|
30
|
+
| 'captionLayout'
|
|
31
|
+
| 'classNames'
|
|
32
|
+
| 'formatters'
|
|
33
|
+
| 'labels'
|
|
34
|
+
| 'locale'
|
|
35
|
+
| 'modifiersClassNames'
|
|
36
|
+
| 'modifiers'
|
|
37
|
+
| 'numberOfMonths'
|
|
38
|
+
| 'styles'
|
|
39
|
+
| 'today';
|
|
40
|
+
|
|
41
|
+
const testPropNames: PropName[] = [
|
|
42
|
+
'captionLayout',
|
|
43
|
+
'classNames',
|
|
44
|
+
'formatters',
|
|
45
|
+
'labels',
|
|
46
|
+
'locale',
|
|
47
|
+
'modifiersClassNames',
|
|
48
|
+
'modifiers',
|
|
49
|
+
'numberOfMonths',
|
|
50
|
+
'styles'
|
|
51
|
+
// 'today' SKIPPED: this test doesn't pass
|
|
52
|
+
];
|
|
53
|
+
beforeAll(() => {
|
|
54
|
+
setup();
|
|
55
|
+
});
|
|
56
|
+
test.each(testPropNames)('should use the %s default value', (propName) => {
|
|
57
|
+
expect(renderResult.current[propName]).toEqual(defaults[propName]);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('when passing "locale" from props', () => {
|
|
62
|
+
const locale = es;
|
|
63
|
+
const dayPickerProps: DayPickerProps = { locale };
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
setup(dayPickerProps);
|
|
66
|
+
});
|
|
67
|
+
test('should override the default locale', () => {
|
|
68
|
+
expect(renderResult.current.locale).not.toBe(defaults.locale);
|
|
69
|
+
});
|
|
70
|
+
test('should return the custom locale', () => {
|
|
71
|
+
expect(renderResult.current.locale).toBe(locale);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('when passing "numberOfMonths" from props', () => {
|
|
76
|
+
const numberOfMonths = 4;
|
|
77
|
+
const dayPickerProps: DayPickerProps = { numberOfMonths };
|
|
78
|
+
beforeEach(() => {
|
|
79
|
+
setup(dayPickerProps);
|
|
80
|
+
});
|
|
81
|
+
test('should override the default numberOfMonths', () => {
|
|
82
|
+
expect(renderResult.current.numberOfMonths).not.toBe(
|
|
83
|
+
defaults.numberOfMonths
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
test('should return the custom numberOfMonths', () => {
|
|
87
|
+
expect(renderResult.current.numberOfMonths).toBe(4);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('when passing "today" from props', () => {
|
|
92
|
+
const today = new Date(2010, 9, 11);
|
|
93
|
+
const dayPickerProps: DayPickerProps = { today };
|
|
94
|
+
beforeEach(() => {
|
|
95
|
+
setup(dayPickerProps);
|
|
96
|
+
});
|
|
97
|
+
test('should override the default "today"', () => {
|
|
98
|
+
expect(renderResult.current.today).not.toBe(defaults.today);
|
|
99
|
+
});
|
|
100
|
+
test('should return the custom "today"', () => {
|
|
101
|
+
expect(renderResult.current.today).toBe(today);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('when passing "captionLayout" from props', () => {
|
|
106
|
+
const captionLayout: CaptionLayout = 'dropdown';
|
|
107
|
+
const fromYear = 2000;
|
|
108
|
+
const toYear = 2010;
|
|
109
|
+
const dayPickerProps: DayPickerProps = { captionLayout, fromYear, toYear };
|
|
110
|
+
beforeEach(() => {
|
|
111
|
+
setup(dayPickerProps);
|
|
112
|
+
});
|
|
113
|
+
test('should override the default "captionLayout"', () => {
|
|
114
|
+
expect(renderResult.current.captionLayout).not.toBe(defaults.captionLayout);
|
|
115
|
+
});
|
|
116
|
+
test('should return the custom "captionLayout"', () => {
|
|
117
|
+
expect(renderResult.current.captionLayout).toBe(captionLayout);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe('when "fromDate" and "toDate" are undefined', () => {
|
|
122
|
+
const fromDate = undefined;
|
|
123
|
+
const toDate = undefined;
|
|
124
|
+
|
|
125
|
+
describe('when using "dropdown" as "captionLayout"', () => {
|
|
126
|
+
const captionLayout: CaptionLayout = 'dropdown';
|
|
127
|
+
beforeEach(() => {
|
|
128
|
+
setup({ fromDate, toDate, captionLayout });
|
|
129
|
+
});
|
|
130
|
+
test('should return "buttons" as "captionLayout"', () => {
|
|
131
|
+
expect(renderResult.current.captionLayout).toBe('buttons');
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('when "fromDate" is undefined, but not "toDate"', () => {
|
|
137
|
+
const fromDate = undefined;
|
|
138
|
+
const toDate = new Date();
|
|
139
|
+
|
|
140
|
+
describe('when using "dropdown" as "captionLayout"', () => {
|
|
141
|
+
const captionLayout: CaptionLayout = 'dropdown';
|
|
142
|
+
beforeEach(() => {
|
|
143
|
+
setup({ fromDate, toDate, captionLayout });
|
|
144
|
+
});
|
|
145
|
+
test('should return "buttons" as "captionLayout"', () => {
|
|
146
|
+
expect(renderResult.current.captionLayout).toBe('buttons');
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe('when "toDate" is undefined, but not "fromDate"', () => {
|
|
152
|
+
const fromDate = new Date();
|
|
153
|
+
const toDate = undefined;
|
|
154
|
+
|
|
155
|
+
describe('when using "dropdown" as "captionLayout"', () => {
|
|
156
|
+
const captionLayout: CaptionLayout = 'dropdown';
|
|
157
|
+
beforeEach(() => {
|
|
158
|
+
setup({ fromDate, toDate, captionLayout });
|
|
159
|
+
});
|
|
160
|
+
test('should return "buttons" as "captionLayout"', () => {
|
|
161
|
+
expect(renderResult.current.captionLayout).toBe('buttons');
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('when using "dropdown" as "captionLayout"', () => {
|
|
167
|
+
const captionLayout: CaptionLayout = 'dropdown';
|
|
168
|
+
const fromYear = 2000;
|
|
169
|
+
const toYear = 2010;
|
|
170
|
+
const dayPickerProps: DayPickerProps = { captionLayout, fromYear, toYear };
|
|
171
|
+
beforeEach(() => {
|
|
172
|
+
setup(dayPickerProps);
|
|
173
|
+
});
|
|
174
|
+
test('should override the default "captionLayout"', () => {
|
|
175
|
+
expect(renderResult.current.captionLayout).not.toBe(defaults.captionLayout);
|
|
176
|
+
});
|
|
177
|
+
test('should return the custom "captionLayout"', () => {
|
|
178
|
+
expect(renderResult.current.captionLayout).toBe(captionLayout);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe('when passing "modifiers" from props', () => {
|
|
183
|
+
const modifiers: DayModifiers = { foo: new Date() };
|
|
184
|
+
const dayPickerProps: DayPickerProps = { modifiers };
|
|
185
|
+
beforeEach(() => {
|
|
186
|
+
setup(dayPickerProps);
|
|
187
|
+
});
|
|
188
|
+
test('should override the default "modifiers"', () => {
|
|
189
|
+
expect(renderResult.current.modifiers).not.toBe(defaults.modifiers);
|
|
190
|
+
});
|
|
191
|
+
test('should return the custom "modifiers"', () => {
|
|
192
|
+
expect(renderResult.current.modifiers).toStrictEqual(modifiers);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe('when passing "modifiersClassNames" from props', () => {
|
|
197
|
+
const modifiersClassNames: ModifiersClassNames = { foo: 'bar' };
|
|
198
|
+
const dayPickerProps: DayPickerProps = { modifiersClassNames };
|
|
199
|
+
beforeEach(() => {
|
|
200
|
+
setup(dayPickerProps);
|
|
201
|
+
});
|
|
202
|
+
test('should override the default "modifiersClassNames"', () => {
|
|
203
|
+
expect(renderResult.current.modifiersClassNames).not.toBe(
|
|
204
|
+
defaults.modifiersClassNames
|
|
205
|
+
);
|
|
206
|
+
});
|
|
207
|
+
test('should return the custom "modifiersClassNames"', () => {
|
|
208
|
+
expect(renderResult.current.modifiersClassNames).toStrictEqual(
|
|
209
|
+
modifiersClassNames
|
|
210
|
+
);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
describe('when passing "styles" from props', () => {
|
|
215
|
+
const styles: Styles = { caption: { color: 'red ' } };
|
|
216
|
+
const dayPickerProps: DayPickerProps = { styles };
|
|
217
|
+
beforeEach(() => {
|
|
218
|
+
setup(dayPickerProps);
|
|
219
|
+
});
|
|
220
|
+
test('should override the default "styles"', () => {
|
|
221
|
+
expect(renderResult.current.styles).not.toBe(defaults.styles);
|
|
222
|
+
});
|
|
223
|
+
test('should include the custom "styles"', () => {
|
|
224
|
+
expect(renderResult.current.styles).toStrictEqual({
|
|
225
|
+
...defaults.styles,
|
|
226
|
+
...styles
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
describe('when passing "classNames" from props', () => {
|
|
232
|
+
const classNames: ClassNames = { caption: 'foo' };
|
|
233
|
+
const dayPickerProps: DayPickerProps = { classNames };
|
|
234
|
+
beforeEach(() => {
|
|
235
|
+
setup(dayPickerProps);
|
|
236
|
+
});
|
|
237
|
+
test('should override the default "classNames"', () => {
|
|
238
|
+
expect(renderResult.current.classNames).not.toBe(defaults.classNames);
|
|
239
|
+
});
|
|
240
|
+
test('should include the custom "classNames"', () => {
|
|
241
|
+
expect(renderResult.current.classNames).toStrictEqual({
|
|
242
|
+
...defaults.classNames,
|
|
243
|
+
...classNames
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
describe('when passing "formatters" from props', () => {
|
|
249
|
+
const formatters: Partial<Formatters> = { formatCaption: jest.fn() };
|
|
250
|
+
const dayPickerProps: DayPickerProps = { formatters };
|
|
251
|
+
beforeEach(() => {
|
|
252
|
+
setup(dayPickerProps);
|
|
253
|
+
});
|
|
254
|
+
test('should override the default "formatters"', () => {
|
|
255
|
+
expect(renderResult.current.formatters).not.toBe(defaults.formatters);
|
|
256
|
+
});
|
|
257
|
+
test('should include the custom "formatters"', () => {
|
|
258
|
+
expect(renderResult.current.formatters).toStrictEqual({
|
|
259
|
+
...defaults.formatters,
|
|
260
|
+
...formatters
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
describe('when passing "labels" from props', () => {
|
|
266
|
+
const labels: Partial<Labels> = { labelDay: jest.fn() };
|
|
267
|
+
const dayPickerProps: DayPickerProps = { labels };
|
|
268
|
+
beforeEach(() => {
|
|
269
|
+
setup(dayPickerProps);
|
|
270
|
+
});
|
|
271
|
+
test('should override the default "labels"', () => {
|
|
272
|
+
expect(renderResult.current.labels).not.toBe(defaults.labels);
|
|
273
|
+
});
|
|
274
|
+
test('should include the custom "labels"', () => {
|
|
275
|
+
expect(renderResult.current.labels).toStrictEqual({
|
|
276
|
+
...defaults.labels,
|
|
277
|
+
...labels
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
describe('when passing "components" from props', () => {
|
|
283
|
+
const components: CustomComponents = { Day: jest.fn() };
|
|
284
|
+
const dayPickerProps: DayPickerProps = { components };
|
|
285
|
+
beforeEach(() => {
|
|
286
|
+
setup(dayPickerProps);
|
|
287
|
+
});
|
|
288
|
+
test('should override the default "components"', () => {
|
|
289
|
+
expect(renderResult.current.components).not.toBe(defaults.components);
|
|
290
|
+
});
|
|
291
|
+
test('should include the custom "components"', () => {
|
|
292
|
+
expect(renderResult.current.components).toStrictEqual({
|
|
293
|
+
...defaults.components,
|
|
294
|
+
...components
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
import { DayPickerContext, DayPickerContextValue } from './DayPickerContext';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hook to access the [[DayPickerContext]].
|
|
7
|
+
*
|
|
8
|
+
* To use this hook make sure to wrap the components with a one
|
|
9
|
+
* [[DayPickerProvider]].
|
|
10
|
+
*/
|
|
11
|
+
export function useDayPicker(): DayPickerContextValue {
|
|
12
|
+
const context = useContext(DayPickerContext);
|
|
13
|
+
if (!context) {
|
|
14
|
+
throw new Error(`useDayPicker must be used within a DayPickerProvider.`);
|
|
15
|
+
}
|
|
16
|
+
return context;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './parseFromToProps';
|