react-day-picker 8.0.0-beta.33 → 8.0.0-beta.35
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/CHANGELOG.md +8 -0
- package/build/components/Button/Button.js +1 -0
- package/build/components/Button/Button.js.map +1 -1
- package/build/components/Caption/Caption.js +3 -2
- package/build/components/Caption/Caption.js.map +1 -1
- package/build/components/CaptionLabel/CaptionLabel.js +1 -0
- package/build/components/CaptionLabel/CaptionLabel.js.map +1 -1
- package/build/components/Day/hooks/useDay.d.ts +3 -3
- package/build/components/Day/hooks/useDay.js +5 -5
- package/build/components/Day/hooks/useDay.js.map +1 -1
- package/build/components/Day/hooks/useDayFocus.js +22 -8
- package/build/components/Day/hooks/useDayFocus.js.map +1 -1
- package/build/components/DayContent/DayContent.js +1 -0
- package/build/components/DayContent/DayContent.js.map +1 -1
- package/build/components/Dropdown/Dropdown.js +1 -0
- package/build/components/Dropdown/Dropdown.js.map +1 -1
- package/build/components/Footer/Footer.js +1 -0
- package/build/components/Footer/Footer.js.map +1 -1
- package/build/components/Head/Head.js +1 -0
- package/build/components/Head/Head.js.map +1 -1
- package/build/components/MonthsDropdown/MonthsDropdown.js +1 -0
- package/build/components/MonthsDropdown/MonthsDropdown.js.map +1 -1
- package/build/components/Navigation/Navigation.js +1 -0
- package/build/components/Navigation/Navigation.js.map +1 -1
- package/build/components/Root/Root.js +1 -0
- package/build/components/Root/Root.js.map +1 -1
- package/build/components/Row/Row.js +1 -0
- package/build/components/Row/Row.js.map +1 -1
- package/build/components/Table/Table.js +1 -0
- package/build/components/Table/Table.js.map +1 -1
- package/build/components/WeekNumber/WeekNumber.js +1 -0
- package/build/components/WeekNumber/WeekNumber.js.map +1 -1
- package/build/components/YearsDropdown/YearsDropdown.js +1 -0
- package/build/components/YearsDropdown/YearsDropdown.js.map +1 -1
- package/build/components/index.d.ts +0 -5
- package/build/contexts/DayPicker/DayPickerProvider.js +4 -4
- package/build/contexts/DayPicker/DayPickerProvider.js.map +1 -1
- package/build/contexts/DayPicker/index.d.ts +1 -0
- package/build/contexts/DayPicker/utils/parseModifierProps.d.ts +1 -2
- package/build/contexts/DayPicker/utils/parseModifierProps.js +1 -2
- package/build/contexts/DayPicker/utils/parseModifierProps.js.map +1 -1
- package/build/contexts/Focus/FocusContext.d.ts +6 -0
- package/build/contexts/Focus/FocusContext.js +55 -6
- package/build/contexts/Focus/FocusContext.js.map +1 -1
- package/build/contexts/Navigation/NavigationContext.js +1 -0
- package/build/contexts/Navigation/NavigationContext.js.map +1 -1
- package/build/contexts/Navigation/useNavigationState.js +1 -0
- package/build/contexts/Navigation/useNavigationState.js.map +1 -1
- package/build/contexts/RootProvider.js.map +1 -1
- package/build/contexts/SelectMultiple/SelectMultipleContext.d.ts +1 -1
- package/build/contexts/SelectMultiple/SelectMultipleContext.js +2 -2
- package/build/contexts/SelectMultiple/SelectMultipleContext.js.map +1 -1
- package/build/contexts/SelectRange/SelectRangeContext.d.ts +1 -1
- package/build/contexts/SelectRange/SelectRangeContext.js +2 -2
- package/build/contexts/SelectRange/SelectRangeContext.js.map +1 -1
- package/build/contexts/SelectSingle/SelectSingleContext.d.ts +1 -1
- package/build/contexts/SelectSingle/SelectSingleContext.js +2 -2
- package/build/contexts/SelectSingle/SelectSingleContext.js.map +1 -1
- package/build/contexts/index.d.ts +1 -1
- package/build/hooks/index.d.ts +0 -1
- package/build/hooks/useInput/useInput.d.ts +1 -1
- package/build/hooks/useInput/useInput.js.map +1 -1
- package/build/hooks/useModifiers/useModifiers.js +4 -3
- package/build/hooks/useModifiers/useModifiers.js.map +1 -1
- package/build/hooks/useModifiers/utils/getModifierStatus.js.map +1 -1
- package/build/hooks/useModifiers/utils/isMatch.js.map +1 -1
- package/build/main.js +2 -7
- package/build/main.js.map +1 -1
- package/build/packages/react-day-picker/src/DayPicker.d.ts +89 -0
- package/build/packages/react-day-picker/src/components/Button/Button.d.ts +7 -0
- package/build/packages/react-day-picker/src/components/Button/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/components/Caption/Caption.d.ts +18 -0
- package/build/packages/react-day-picker/src/components/Caption/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/components/CaptionLabel/CaptionLabel.d.ts +8 -0
- package/build/packages/react-day-picker/src/components/CaptionLabel/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/components/Day/Day.d.ts +13 -0
- package/build/packages/react-day-picker/src/components/Day/hooks/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/components/Day/hooks/useDay.d.ts +58 -0
- package/build/packages/react-day-picker/src/components/Day/hooks/useDayFocus.d.ts +8 -0
- package/build/packages/react-day-picker/src/components/Day/index.d.ts +2 -0
- package/build/packages/react-day-picker/src/components/DayContent/DayContent.d.ts +15 -0
- package/build/packages/react-day-picker/src/components/DayContent/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/components/Dropdown/Dropdown.d.ts +16 -0
- package/build/packages/react-day-picker/src/components/Dropdown/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/components/Footer/Footer.d.ts +3 -0
- package/build/packages/react-day-picker/src/components/Footer/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/components/Head/Head.d.ts +5 -0
- package/build/packages/react-day-picker/src/components/Head/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/components/Head/utils/getWeekdays.d.ts +6 -0
- package/build/packages/react-day-picker/src/components/Head/utils/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/components/IconDropdown/IconDropdown.d.ts +6 -0
- package/build/packages/react-day-picker/src/components/IconDropdown/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/components/IconLeft/IconLeft.d.ts +6 -0
- package/build/packages/react-day-picker/src/components/IconLeft/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/components/IconRight/IconRight.d.ts +6 -0
- package/build/packages/react-day-picker/src/components/IconRight/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/components/MonthsDropdown/MonthsDropdown.d.ts +12 -0
- package/build/packages/react-day-picker/src/components/MonthsDropdown/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/components/Navigation/Navigation.d.ts +20 -0
- package/build/packages/react-day-picker/src/components/Navigation/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/components/Root/Root.d.ts +6 -0
- package/build/packages/react-day-picker/src/components/Root/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/components/Row/Row.d.ts +16 -0
- package/build/packages/react-day-picker/src/components/Row/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/components/Table/Table.d.ts +12 -0
- package/build/packages/react-day-picker/src/components/Table/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/components/Table/utils/getOutsideEndDays.d.ts +3 -0
- package/build/packages/react-day-picker/src/components/Table/utils/getOutsideStartDays.d.ts +4 -0
- package/build/packages/react-day-picker/src/components/Table/utils/getWeeks.d.ts +17 -0
- package/build/packages/react-day-picker/src/components/WeekNumber/WeekNumber.d.ts +15 -0
- package/build/packages/react-day-picker/src/components/WeekNumber/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/components/YearsDropdown/YearsDropdown.d.ts +16 -0
- package/build/packages/react-day-picker/src/components/YearsDropdown/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/components/index.d.ts +13 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/DayPickerContext.d.ts +31 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/DayPickerProvider.d.ts +12 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/defaultClassNames.d.ts +5 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/formatters/formatCaption.d.ts +7 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/formatters/formatDay.d.ts +7 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/formatters/formatMonthCaption.d.ts +7 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/formatters/formatWeekNumber.d.ts +4 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/formatters/formatWeekdayName.d.ts +7 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/formatters/formatYearCaption.d.ts +6 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/formatters/index.d.ts +6 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/index.d.ts +2 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/labels/index.d.ts +7 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/labels/labelDay.d.ts +5 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/labels/labelMonthDropdown.d.ts +4 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/labels/labelNext.d.ts +5 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/labels/labelPrevious.d.ts +5 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/labels/labelWeekNumber.d.ts +5 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/labels/labelWeekday.d.ts +5 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/labels/labelYearDropdown.d.ts +4 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/useDayPicker.d.ts +8 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/utils/index.d.ts +2 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/utils/parseFromToProps.d.ts +9 -0
- package/build/packages/react-day-picker/src/contexts/DayPicker/utils/parseModifierProps.d.ts +8 -0
- package/build/packages/react-day-picker/src/contexts/Focus/FocusContext.d.ts +30 -0
- package/build/packages/react-day-picker/src/contexts/Focus/index.d.ts +2 -0
- package/build/packages/react-day-picker/src/contexts/Focus/useFocus.d.ts +3 -0
- package/build/packages/react-day-picker/src/contexts/Navigation/NavigationContext.d.ts +24 -0
- package/build/packages/react-day-picker/src/contexts/Navigation/index.d.ts +2 -0
- package/build/packages/react-day-picker/src/contexts/Navigation/useNavigation.d.ts +3 -0
- package/build/packages/react-day-picker/src/contexts/Navigation/useNavigationState.d.ts +7 -0
- package/build/packages/react-day-picker/src/contexts/Navigation/utils/getDisplayMonths.d.ts +8 -0
- package/build/packages/react-day-picker/src/contexts/Navigation/utils/getInitialMonth.d.ts +3 -0
- package/build/packages/react-day-picker/src/contexts/Navigation/utils/getNextMonth.d.ts +18 -0
- package/build/packages/react-day-picker/src/contexts/Navigation/utils/getPreviousMonth.d.ts +19 -0
- package/build/packages/react-day-picker/src/contexts/RootProvider.d.ts +8 -0
- package/build/packages/react-day-picker/src/contexts/SelectMultiple/SelectMultipleContext.d.ts +32 -0
- package/build/packages/react-day-picker/src/contexts/SelectMultiple/index.d.ts +2 -0
- package/build/packages/react-day-picker/src/contexts/SelectMultiple/useSelectMultiple.d.ts +3 -0
- package/build/packages/react-day-picker/src/contexts/SelectRange/SelectRangeContext.d.ts +32 -0
- package/build/packages/react-day-picker/src/contexts/SelectRange/index.d.ts +2 -0
- package/build/packages/react-day-picker/src/contexts/SelectRange/useSelectRange.d.ts +3 -0
- package/build/packages/react-day-picker/src/contexts/SelectRange/utils/addToRange.d.ts +8 -0
- package/build/packages/react-day-picker/src/contexts/SelectSingle/SelectSingleContext.d.ts +35 -0
- package/build/packages/react-day-picker/src/contexts/SelectSingle/index.d.ts +2 -0
- package/build/packages/react-day-picker/src/contexts/SelectSingle/useSelectSingle.d.ts +3 -0
- package/build/packages/react-day-picker/src/contexts/index.d.ts +7 -0
- package/build/packages/react-day-picker/src/hooks/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/hooks/useControlledValue/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/hooks/useControlledValue/useControlledValue.d.ts +12 -0
- package/build/packages/react-day-picker/src/hooks/useInput/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/hooks/useInput/useInput.d.ts +28 -0
- package/build/packages/react-day-picker/src/hooks/useInput/utils/isValidDate.d.ts +2 -0
- package/build/packages/react-day-picker/src/hooks/useModifiers/index.d.ts +1 -0
- package/build/packages/react-day-picker/src/hooks/useModifiers/useModifiers.d.ts +3 -0
- package/build/packages/react-day-picker/src/hooks/useModifiers/utils/getModifierStatus.d.ts +7 -0
- package/build/packages/react-day-picker/src/hooks/useModifiers/utils/isDateInRange.d.ts +3 -0
- package/build/packages/react-day-picker/src/hooks/useModifiers/utils/isMatch.d.ts +5 -0
- package/build/packages/react-day-picker/src/main.d.ts +5 -0
- package/build/packages/react-day-picker/src/types/DayPicker.d.ts +225 -0
- package/build/packages/react-day-picker/src/types/DayPickerCustom.d.ts +11 -0
- package/build/packages/react-day-picker/src/types/DayPickerMultiple.d.ts +16 -0
- package/build/packages/react-day-picker/src/types/DayPickerRange.d.ts +17 -0
- package/build/packages/react-day-picker/src/types/DayPickerSingle.d.ts +14 -0
- package/build/packages/react-day-picker/src/types/EventHandlers.d.ts +51 -0
- package/build/packages/react-day-picker/src/types/Formatters.d.ts +24 -0
- package/build/packages/react-day-picker/src/types/Labels.d.ts +28 -0
- package/build/packages/react-day-picker/src/types/Matchers.d.ts +34 -0
- package/build/packages/react-day-picker/src/types/Modifiers.d.ts +16 -0
- package/build/packages/react-day-picker/src/types/Styles.d.ts +85 -0
- package/build/packages/react-day-picker/src/types/index.d.ts +11 -0
- package/build/test/PageObjects.d.ts +3 -0
- package/build/test/customRender.d.ts +1 -1
- package/build/test/customRenderHook.d.ts +1 -1
- package/build/test/po.d.ts +29 -0
- package/build/test/setup.d.ts +0 -1
- package/build/test/utils.d.ts +2 -0
- package/build/types/DayPicker.d.ts +5 -8
- package/dist/main.js +270 -207
- package/dist/main.js.map +1 -1
- package/package.json +9 -18
- package/build/test/index.d.ts +0 -3
|
@@ -9,8 +9,7 @@ import { DayPickerContext } from './DayPickerContext.js';
|
|
|
9
9
|
import '../SelectMultiple/SelectMultipleContext.js';
|
|
10
10
|
import '../SelectRange/SelectRangeContext.js';
|
|
11
11
|
import '../SelectSingle/SelectSingleContext.js';
|
|
12
|
-
import
|
|
13
|
-
import { parseModifierProps } from './utils/parseModifierProps.js';
|
|
12
|
+
import '../Focus/FocusContext.js';
|
|
14
13
|
import { DayContent } from '../../components/DayContent/DayContent.js';
|
|
15
14
|
import { Dropdown } from '../../components/Dropdown/Dropdown.js';
|
|
16
15
|
import { Footer } from '../../components/Footer/Footer.js';
|
|
@@ -23,8 +22,8 @@ import { WeekNumber } from '../../components/WeekNumber/WeekNumber.js';
|
|
|
23
22
|
import { defaultClassNames } from './defaultClassNames.js';
|
|
24
23
|
import * as index from './formatters/index.js';
|
|
25
24
|
import * as index$1 from './labels/index.js';
|
|
26
|
-
import '
|
|
27
|
-
import '
|
|
25
|
+
import { parseFromToProps } from './utils/parseFromToProps.js';
|
|
26
|
+
import { parseModifierProps } from './utils/parseModifierProps.js';
|
|
28
27
|
|
|
29
28
|
/**
|
|
30
29
|
* The provider for the [[DayPickerContext]].
|
|
@@ -50,6 +49,7 @@ function DayPickerProvider(props) {
|
|
|
50
49
|
if (toDate) {
|
|
51
50
|
modifiers.disabled.push({ after: toDate });
|
|
52
51
|
}
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
53
53
|
initialProps.toYear; initialProps.fromYear; initialProps.toMonth; initialProps.fromMonth; var contextProps = __rest(initialProps, ["toYear", "fromYear", "toMonth", "fromMonth"]);
|
|
54
54
|
var context = __assign(__assign({}, contextProps), { captionLayout: captionLayout, fromDate: fromDate, toDate: toDate, today: today, locale: locale, modifierClassNames: (_e = initialProps.modifierClassNames) !== null && _e !== void 0 ? _e : {}, modifierPrefix: 'rdp-day_', modifiers: modifiers, numberOfMonths: numberOfMonths, styles: (_f = initialProps.styles) !== null && _f !== void 0 ? _f : {}, classNames: __assign(__assign({}, defaultClassNames), initialProps.classNames), formatters: __assign(__assign({}, index), initialProps.formatters), labels: __assign(__assign({}, index$1), initialProps.labels), components: __assign({ Caption: Caption, CaptionLabel: CaptionLabel, Day: Day, DayContent: DayContent, Dropdown: Dropdown, Footer: Footer, Head: Head, IconDropdown: IconDropdown, IconRight: IconRight, IconLeft: IconLeft, Row: Row, WeekNumber: WeekNumber }, initialProps.components) });
|
|
55
55
|
return (React.createElement(DayPickerContext.Provider, { value: context }, children));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DayPickerProvider.js","sources":["../../../src/contexts/DayPicker/DayPickerProvider.tsx"],"sourcesContent":["import React from 'react';\n\nimport enUS from 'date-fns/locale/en-US';\n\nimport { Caption } from '../../components/Caption';\nimport { CaptionLabel } from '../../components/CaptionLabel';\nimport { Day } from '../../components/Day';\nimport { DayContent } from '../../components/DayContent';\nimport { Dropdown } from '../../components/Dropdown';\nimport { Footer } from '../../components/Footer';\nimport { Head } from '../../components/Head';\nimport { IconDropdown } from '../../components/IconDropdown';\nimport { IconLeft } from '../../components/IconLeft';\nimport { IconRight } from '../../components/IconRight';\nimport { Row } from '../../components/Row';\nimport { WeekNumber } from '../../components/WeekNumber';\nimport { DayPickerProps } from '../../types';\nimport { DayPickerContext, DayPickerContextValue } from './DayPickerContext';\nimport { defaultClassNames } from './defaultClassNames';\nimport * as formatters from './formatters';\nimport * as labels from './labels';\nimport { parseFromToProps, parseModifierProps } from './utils';\n\n/** Represent the props for the [[DayPickerProvider]]. */\nexport interface DayPickerProviderProps {\n /** The props passed to the DayPicker component. */\n initialProps: DayPickerProps;\n children?: React.ReactNode;\n}\n/**\n * The provider for the [[DayPickerContext]].\n */\nexport function DayPickerProvider(props: DayPickerProviderProps): JSX.Element {\n const { children, initialProps } = props;\n\n const locale = initialProps.locale ?? enUS;\n const numberOfMonths = initialProps.numberOfMonths ?? 1;\n const today = initialProps.today ?? new Date();\n\n // Limit navigation\n const { fromDate, toDate } = parseFromToProps(initialProps);\n\n // Default caption layout. If calendar navigation is unlimited, it must be\n // always `buttons` – as we cannot display infinite options in the dropdown.\n let captionLayout = initialProps.captionLayout ?? 'buttons';\n if (!fromDate && !toDate) captionLayout = 'buttons';\n\n const modifiers = parseModifierProps(initialProps);\n\n // Disable days before/after from/toDate\n if (fromDate) {\n modifiers.disabled.push({ before: fromDate });\n }\n if (toDate) {\n modifiers.disabled.push({ after: toDate });\n }\n\n const { toYear, fromYear, toMonth, fromMonth, ...contextProps } =\n initialProps;\n\n const context: DayPickerContextValue = {\n ...contextProps,\n\n captionLayout,\n\n fromDate,\n toDate,\n today,\n\n locale,\n\n modifierClassNames: initialProps.modifierClassNames ?? {},\n modifierPrefix: 'rdp-day_',\n modifiers: modifiers,\n numberOfMonths,\n\n styles: initialProps.styles ?? {},\n classNames: {\n ...defaultClassNames,\n ...initialProps.classNames\n },\n formatters: {\n ...formatters,\n ...initialProps.formatters\n },\n labels: {\n ...labels,\n ...initialProps.labels\n },\n components: {\n Caption: Caption,\n CaptionLabel: CaptionLabel,\n Day: Day,\n DayContent: DayContent,\n Dropdown: Dropdown,\n Footer: Footer,\n Head: Head,\n IconDropdown: IconDropdown,\n IconRight: IconRight,\n IconLeft: IconLeft,\n Row: Row,\n WeekNumber: WeekNumber,\n ...initialProps.components\n }\n };\n\n return (\n <DayPickerContext.Provider value={context}>\n {children}\n </DayPickerContext.Provider>\n );\n}\n"],"names":["formatters","labels"],"mappings":"
|
|
1
|
+
{"version":3,"file":"DayPickerProvider.js","sources":["../../../src/contexts/DayPicker/DayPickerProvider.tsx"],"sourcesContent":["import React from 'react';\n\nimport enUS from 'date-fns/locale/en-US';\n\nimport { Caption } from '../../components/Caption';\nimport { CaptionLabel } from '../../components/CaptionLabel';\nimport { Day } from '../../components/Day';\nimport { DayContent } from '../../components/DayContent';\nimport { Dropdown } from '../../components/Dropdown';\nimport { Footer } from '../../components/Footer';\nimport { Head } from '../../components/Head';\nimport { IconDropdown } from '../../components/IconDropdown';\nimport { IconLeft } from '../../components/IconLeft';\nimport { IconRight } from '../../components/IconRight';\nimport { Row } from '../../components/Row';\nimport { WeekNumber } from '../../components/WeekNumber';\nimport { DayPickerProps } from '../../types';\nimport { DayPickerContext, DayPickerContextValue } from './DayPickerContext';\nimport { defaultClassNames } from './defaultClassNames';\nimport * as formatters from './formatters';\nimport * as labels from './labels';\nimport { parseFromToProps, parseModifierProps } from './utils';\n\n/** Represent the props for the [[DayPickerProvider]]. */\nexport interface DayPickerProviderProps {\n /** The props passed to the DayPicker component. */\n initialProps: DayPickerProps;\n children?: React.ReactNode;\n}\n/**\n * The provider for the [[DayPickerContext]].\n */\nexport function DayPickerProvider(props: DayPickerProviderProps): JSX.Element {\n const { children, initialProps } = props;\n\n const locale = initialProps.locale ?? enUS;\n const numberOfMonths = initialProps.numberOfMonths ?? 1;\n const today = initialProps.today ?? new Date();\n\n // Limit navigation\n const { fromDate, toDate } = parseFromToProps(initialProps);\n\n // Default caption layout. If calendar navigation is unlimited, it must be\n // always `buttons` – as we cannot display infinite options in the dropdown.\n let captionLayout = initialProps.captionLayout ?? 'buttons';\n if (!fromDate && !toDate) captionLayout = 'buttons';\n\n const modifiers = parseModifierProps(initialProps);\n\n // Disable days before/after from/toDate\n if (fromDate) {\n modifiers.disabled.push({ before: fromDate });\n }\n if (toDate) {\n modifiers.disabled.push({ after: toDate });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { toYear, fromYear, toMonth, fromMonth, ...contextProps } =\n initialProps;\n\n const context: DayPickerContextValue = {\n ...contextProps,\n\n captionLayout,\n\n fromDate,\n toDate,\n today,\n\n locale,\n\n modifierClassNames: initialProps.modifierClassNames ?? {},\n modifierPrefix: 'rdp-day_',\n modifiers: modifiers,\n numberOfMonths,\n\n styles: initialProps.styles ?? {},\n classNames: {\n ...defaultClassNames,\n ...initialProps.classNames\n },\n formatters: {\n ...formatters,\n ...initialProps.formatters\n },\n labels: {\n ...labels,\n ...initialProps.labels\n },\n components: {\n Caption: Caption,\n CaptionLabel: CaptionLabel,\n Day: Day,\n DayContent: DayContent,\n Dropdown: Dropdown,\n Footer: Footer,\n Head: Head,\n IconDropdown: IconDropdown,\n IconRight: IconRight,\n IconLeft: IconLeft,\n Row: Row,\n WeekNumber: WeekNumber,\n ...initialProps.components\n }\n };\n\n return (\n <DayPickerContext.Provider value={context}>\n {children}\n </DayPickerContext.Provider>\n );\n}\n"],"names":["formatters","labels"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA;;;SAGgB,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MAAA,YAAY,CAAC,MAAM,mCAAI,EAAE,EACjC,UAAU,wBACL,iBAAiB,GACjB,YAAY,CAAC,UAAU,GAE5B,UAAU,wBACLA,KAAU,GACV,YAAY,CAAC,UAAU,GAE5B,MAAM,wBACDC,OAAM,GACN,YAAY,CAAC,MAAM,GAExB,UAAU,aACR,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,YAAY,EAC1B,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,IACnB,YAAY,CAAC,UAAU,IAE7B,CAAC;IAEF,QACE,oBAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,OAAO,IACtC,QAAQ,CACiB,EAC5B;AACJ;;;;"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DayPickerProps, Modifiers } from '../../../types';
|
|
2
2
|
/**
|
|
3
|
-
* Parse the modifiers from the props
|
|
4
|
-
* matcher.
|
|
3
|
+
* Parse the modifiers from the props.
|
|
5
4
|
*
|
|
6
5
|
* Internally we want modifiers as an array of matchers – as opposite of the
|
|
7
6
|
* props which can accept also a matcher.
|
|
@@ -5,8 +5,7 @@ var modifierShortcuts = [
|
|
|
5
5
|
'disabled'
|
|
6
6
|
];
|
|
7
7
|
/**
|
|
8
|
-
* Parse the modifiers from the props
|
|
9
|
-
* matcher.
|
|
8
|
+
* Parse the modifiers from the props.
|
|
10
9
|
*
|
|
11
10
|
* Internally we want modifiers as an array of matchers – as opposite of the
|
|
12
11
|
* props which can accept also a matcher.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseModifierProps.js","sources":["../../../../src/contexts/DayPicker/utils/parseModifierProps.ts"],"sourcesContent":["import { DayPickerProps, InternalModifier, Modifiers } from '../../../types';\n\n/** Props that will merge into the modifiers. */\nconst modifierShortcuts: InternalModifier[] = [\n 'selected',\n 'hidden',\n 'disabled'\n];\n\n/**\n * Parse the modifiers from the props
|
|
1
|
+
{"version":3,"file":"parseModifierProps.js","sources":["../../../../src/contexts/DayPicker/utils/parseModifierProps.ts"],"sourcesContent":["import { DayPickerProps, InternalModifier, Modifiers } from '../../../types';\n\n/** Props that will merge into the modifiers. */\nconst modifierShortcuts: InternalModifier[] = [\n 'selected',\n 'hidden',\n 'disabled'\n];\n\n/**\n * Parse the modifiers from the props.\n *\n * Internally we want modifiers as an array of matchers – as opposite of the\n * props which can accept also a matcher.\n */\nexport function parseModifierProps(initialProps: DayPickerProps): Modifiers {\n const initialModifiers = initialProps.modifiers || {};\n\n const modifiers: Modifiers = {\n selected: [],\n disabled: [],\n hidden: [],\n today: [],\n range_end: [],\n range_middle: [],\n range_start: []\n };\n\n Object.entries(initialModifiers).forEach(([modifier, matcher]) => {\n if (Array.isArray(matcher)) {\n modifiers[modifier] = matcher;\n } else if (matcher) {\n modifiers[modifier] = [matcher];\n } else {\n modifiers[modifier] = [];\n }\n });\n\n modifierShortcuts.forEach((modifier) => {\n // @ts-expect-error TOFIX: initial props do not have some modifiers\n const modifierFromProp = initialProps[modifier];\n if (Array.isArray(modifierFromProp)) {\n modifiers[modifier] = modifierFromProp;\n } else if (modifierFromProp !== undefined) {\n modifiers[modifier] = [modifierFromProp];\n } else {\n modifiers[modifier] = [];\n }\n });\n\n return modifiers;\n}\n"],"names":[],"mappings":"AAEA;AACA,IAAM,iBAAiB,GAAuB;IAC5C,UAAU;IACV,QAAQ;IACR,UAAU;CACX,CAAC;AAEF;;;;;;SAMgB,kBAAkB,CAAC,YAA4B;IAC7D,IAAM,gBAAgB,GAAG,YAAY,CAAC,SAAS,IAAI,EAAE,CAAC;IAEtD,IAAM,SAAS,GAAc;QAC3B,QAAQ,EAAE,EAAE;QACZ,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,KAAK,EAAE,EAAE;QACT,SAAS,EAAE,EAAE;QACb,YAAY,EAAE,EAAE;QAChB,WAAW,EAAE,EAAE;KAChB,CAAC;IAEF,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC,UAAC,EAAmB;YAAlB,QAAQ,QAAA,EAAE,OAAO,QAAA;QAC1D,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YAC1B,SAAS,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC;SAC/B;aAAM,IAAI,OAAO,EAAE;YAClB,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;SACjC;aAAM;YACL,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;SAC1B;KACF,CAAC,CAAC;IAEH,iBAAiB,CAAC,OAAO,CAAC,UAAC,QAAQ;;QAEjC,IAAM,gBAAgB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;QAChD,IAAI,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE;YACnC,SAAS,CAAC,QAAQ,CAAC,GAAG,gBAAgB,CAAC;SACxC;aAAM,IAAI,gBAAgB,KAAK,SAAS,EAAE;YACzC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;SAC1C;aAAM;YACL,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;SAC1B;KACF,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB;;;;"}
|
|
@@ -16,6 +16,12 @@ export declare type FocusContextValue = [
|
|
|
16
16
|
focusWeekBeforeDay: () => void;
|
|
17
17
|
/** Focus the day in the week after the focused day. */
|
|
18
18
|
focusWeekAfterDay: () => void;
|
|
19
|
+
focusMonthBefore: () => void;
|
|
20
|
+
focusMonthAfter: () => void;
|
|
21
|
+
focusYearBefore: () => void;
|
|
22
|
+
focusYearAfter: () => void;
|
|
23
|
+
focusStartOfWeek: () => void;
|
|
24
|
+
focusEndOfWeek: () => void;
|
|
19
25
|
}
|
|
20
26
|
];
|
|
21
27
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { addDays, addWeeks,
|
|
2
|
+
import { addDays, addWeeks, startOfWeek, endOfWeek, addMonths, addYears, isSameMonth } from 'date-fns';
|
|
3
3
|
import { useDayPicker } from '../DayPicker/useDayPicker.js';
|
|
4
|
+
import '../DayPicker/DayPickerContext.js';
|
|
4
5
|
import '../Navigation/NavigationContext.js';
|
|
5
6
|
import { useNavigation } from '../Navigation/useNavigation.js';
|
|
6
7
|
|
|
@@ -32,37 +33,85 @@ function FocusProvider(_a) {
|
|
|
32
33
|
if (!focusedDay)
|
|
33
34
|
return;
|
|
34
35
|
var before = addDays(focusedDay, -1);
|
|
35
|
-
|
|
36
|
+
focus(before);
|
|
36
37
|
switchMonth(before, numberOfMonths * -1);
|
|
37
38
|
};
|
|
38
39
|
var focusDayAfter = function () {
|
|
39
40
|
if (!focusedDay)
|
|
40
41
|
return;
|
|
41
42
|
var after = addDays(focusedDay, 1);
|
|
42
|
-
|
|
43
|
+
focus(after);
|
|
43
44
|
switchMonth(after, numberOfMonths);
|
|
44
45
|
};
|
|
45
46
|
var focusWeekBeforeDay = function () {
|
|
46
47
|
if (!focusedDay)
|
|
47
48
|
return;
|
|
48
49
|
var up = addWeeks(focusedDay, -1);
|
|
49
|
-
|
|
50
|
+
focus(up);
|
|
50
51
|
switchMonth(up, numberOfMonths * -1);
|
|
51
52
|
};
|
|
52
53
|
var focusWeekAfterDay = function () {
|
|
53
54
|
if (!focusedDay)
|
|
54
55
|
return;
|
|
55
56
|
var down = addWeeks(focusedDay, 1);
|
|
56
|
-
|
|
57
|
+
focus(down);
|
|
57
58
|
switchMonth(down, numberOfMonths);
|
|
58
59
|
};
|
|
60
|
+
var focusStartOfWeek = function () {
|
|
61
|
+
if (!focusedDay)
|
|
62
|
+
return;
|
|
63
|
+
var dayToFocus = startOfWeek(focusedDay);
|
|
64
|
+
switchMonth(dayToFocus, numberOfMonths);
|
|
65
|
+
focus(dayToFocus);
|
|
66
|
+
};
|
|
67
|
+
var focusEndOfWeek = function () {
|
|
68
|
+
if (!focusedDay)
|
|
69
|
+
return;
|
|
70
|
+
var dayToFocus = endOfWeek(focusedDay);
|
|
71
|
+
switchMonth(dayToFocus, numberOfMonths);
|
|
72
|
+
focus(dayToFocus);
|
|
73
|
+
};
|
|
74
|
+
var focusMonthBefore = function () {
|
|
75
|
+
if (!focusedDay)
|
|
76
|
+
return;
|
|
77
|
+
var monthBefore = addMonths(focusedDay, -1);
|
|
78
|
+
switchMonth(monthBefore, numberOfMonths);
|
|
79
|
+
focus(monthBefore);
|
|
80
|
+
};
|
|
81
|
+
var focusMonthAfter = function () {
|
|
82
|
+
if (!focusedDay)
|
|
83
|
+
return;
|
|
84
|
+
var monthAfter = addMonths(focusedDay, 1);
|
|
85
|
+
switchMonth(monthAfter, numberOfMonths);
|
|
86
|
+
focus(monthAfter);
|
|
87
|
+
};
|
|
88
|
+
var focusYearBefore = function () {
|
|
89
|
+
if (!focusedDay)
|
|
90
|
+
return;
|
|
91
|
+
var yearBefore = addYears(focusedDay, -1);
|
|
92
|
+
switchMonth(yearBefore, numberOfMonths);
|
|
93
|
+
focus(yearBefore);
|
|
94
|
+
};
|
|
95
|
+
var focusYearAfter = function () {
|
|
96
|
+
if (!focusedDay)
|
|
97
|
+
return;
|
|
98
|
+
var yearAfter = addYears(focusedDay, 1);
|
|
99
|
+
switchMonth(yearAfter, numberOfMonths);
|
|
100
|
+
focus(yearAfter);
|
|
101
|
+
};
|
|
59
102
|
var setters = {
|
|
60
103
|
blur: blur,
|
|
61
104
|
focus: focus,
|
|
62
105
|
focusDayAfter: focusDayAfter,
|
|
63
106
|
focusDayBefore: focusDayBefore,
|
|
64
107
|
focusWeekAfterDay: focusWeekAfterDay,
|
|
65
|
-
focusWeekBeforeDay: focusWeekBeforeDay
|
|
108
|
+
focusWeekBeforeDay: focusWeekBeforeDay,
|
|
109
|
+
focusMonthBefore: focusMonthBefore,
|
|
110
|
+
focusMonthAfter: focusMonthAfter,
|
|
111
|
+
focusYearBefore: focusYearBefore,
|
|
112
|
+
focusYearAfter: focusYearAfter,
|
|
113
|
+
focusStartOfWeek: focusStartOfWeek,
|
|
114
|
+
focusEndOfWeek: focusEndOfWeek
|
|
66
115
|
};
|
|
67
116
|
return (React.createElement(FocusContext.Provider, { value: [focusedDay, setters] }, children));
|
|
68
117
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusContext.js","sources":["../../../src/contexts/Focus/FocusContext.tsx"],"sourcesContent":["import React from 'react';\n\nimport {
|
|
1
|
+
{"version":3,"file":"FocusContext.js","sources":["../../../src/contexts/Focus/FocusContext.tsx"],"sourcesContent":["import React from 'react';\n\nimport {\n addDays,\n addMonths,\n addWeeks,\n addYears,\n endOfWeek,\n isSameMonth,\n startOfWeek\n} from 'date-fns';\n\nimport { useDayPicker } from '../DayPicker';\nimport { useNavigation } from '../Navigation';\n\n/** Represents the value of the [[NavigationContext]]. */\nexport type FocusContextValue = [\n /** The day currently focused */\n focusedDay: Date | undefined,\n setters: {\n /** Focus the specified day. */\n focus: (day: Date) => void;\n /** Blur the focused day */\n blur: () => void;\n /** Focus the day after the focused day. */\n focusDayAfter: () => void;\n /** Focus the day before the focused day. */\n focusDayBefore: () => void;\n /** Focus the day in the week before the focused day. */\n focusWeekBeforeDay: () => void;\n /** Focus the day in the week after the focused day. */\n focusWeekAfterDay: () => void;\n /* Focus the day in the previous month. */\n focusMonthBefore: () => void;\n /* Focus the day in the next month. */\n focusMonthAfter: () => void;\n /* Focus the day in the previous year. */\n focusYearBefore: () => void;\n /* Focus the day in the next year. */\n focusYearAfter: () => void;\n /* Focus the day at the start of the week. */\n focusStartOfWeek: () => void;\n /* Focus the day at the end of the week. */\n focusEndOfWeek: () => void;\n }\n];\n\n/**\n * The Focus context shares details about the focused day for the keyboard navigation.\n *\n * Access this context from the [[useFocus]] hook.\n */\nexport const FocusContext = React.createContext<FocusContextValue | undefined>(\n undefined\n);\n\n/** The provider for the [[FocusContext]]. */\nexport function FocusProvider({\n children\n}: {\n children: React.ReactNode;\n}): JSX.Element {\n const [focusedDay, setDay] = React.useState<Date | undefined>();\n const { goToMonth, displayMonths } = useNavigation();\n const { numberOfMonths } = useDayPicker();\n\n const blur = () => setDay(undefined);\n const focus = (date: Date) => setDay(date);\n\n const switchMonth = (date: Date, offset: number) => {\n if (displayMonths.some((m) => isSameMonth(date, m))) return;\n if (offset < 0) {\n goToMonth(addMonths(date, 1 + offset));\n } else {\n goToMonth(date);\n }\n };\n\n const focusDayBefore = () => {\n if (!focusedDay) return;\n const before = addDays(focusedDay, -1);\n focus(before);\n switchMonth(before, numberOfMonths * -1);\n };\n const focusDayAfter = () => {\n if (!focusedDay) return;\n const after = addDays(focusedDay, 1);\n focus(after);\n switchMonth(after, numberOfMonths);\n };\n const focusWeekBeforeDay = () => {\n if (!focusedDay) return;\n const up = addWeeks(focusedDay, -1);\n focus(up);\n switchMonth(up, numberOfMonths * -1);\n };\n const focusWeekAfterDay = () => {\n if (!focusedDay) return;\n const down = addWeeks(focusedDay, 1);\n focus(down);\n switchMonth(down, numberOfMonths);\n };\n\n const focusStartOfWeek = (): void => {\n if (!focusedDay) return;\n const dayToFocus = startOfWeek(focusedDay);\n switchMonth(dayToFocus, numberOfMonths);\n focus(dayToFocus);\n };\n\n const focusEndOfWeek = (): void => {\n if (!focusedDay) return;\n const dayToFocus = endOfWeek(focusedDay);\n switchMonth(dayToFocus, numberOfMonths);\n focus(dayToFocus);\n };\n\n const focusMonthBefore = (): void => {\n if (!focusedDay) return;\n\n const monthBefore = addMonths(focusedDay, -1);\n switchMonth(monthBefore, numberOfMonths);\n focus(monthBefore);\n };\n\n const focusMonthAfter = () => {\n if (!focusedDay) return;\n const monthAfter = addMonths(focusedDay, 1);\n switchMonth(monthAfter, numberOfMonths);\n focus(monthAfter);\n };\n\n const focusYearBefore = () => {\n if (!focusedDay) return;\n\n const yearBefore = addYears(focusedDay, -1);\n switchMonth(yearBefore, numberOfMonths);\n focus(yearBefore);\n };\n\n const focusYearAfter = () => {\n if (!focusedDay) return;\n\n const yearAfter = addYears(focusedDay, 1);\n switchMonth(yearAfter, numberOfMonths);\n focus(yearAfter);\n };\n\n const setters = {\n blur,\n focus,\n focusDayAfter,\n focusDayBefore,\n focusWeekAfterDay,\n focusWeekBeforeDay,\n focusMonthBefore,\n focusMonthAfter,\n focusYearBefore,\n focusYearAfter,\n focusStartOfWeek,\n focusEndOfWeek\n };\n\n return (\n <FocusContext.Provider value={[focusedDay, setters]}>\n {children}\n </FocusContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;;;;;AA+CA;;;;;IAKa,YAAY,GAAG,KAAK,CAAC,aAAa,CAC7C,SAAS,EACT;AAEF;SACgB,aAAa,CAAC,EAI7B;QAHC,QAAQ,cAAA;IAIF,IAAA,KAAuB,KAAK,CAAC,QAAQ,EAAoB,EAAxD,UAAU,QAAA,EAAE,MAAM,QAAsC,CAAC;IAC1D,IAAA,KAA+B,aAAa,EAAE,EAA5C,SAAS,eAAA,EAAE,aAAa,mBAAoB,CAAC;IAC7C,IAAA,cAAc,GAAK,YAAY,EAAE,eAAnB,CAAoB;IAE1C,IAAM,IAAI,GAAG,cAAM,OAAA,MAAM,CAAC,SAAS,CAAC,GAAA,CAAC;IACrC,IAAM,KAAK,GAAG,UAAC,IAAU,IAAK,OAAA,MAAM,CAAC,IAAI,CAAC,GAAA,CAAC;IAE3C,IAAM,WAAW,GAAG,UAAC,IAAU,EAAE,MAAc;QAC7C,IAAI,aAAa,CAAC,IAAI,CAAC,UAAC,CAAC,IAAK,OAAA,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,GAAA,CAAC;YAAE,OAAO;QAC5D,IAAI,MAAM,GAAG,CAAC,EAAE;YACd,SAAS,CAAC,SAAS,CAAC,IAA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,cAAc,gBAAA;QACd,iBAAiB,mBAAA;QACjB,kBAAkB,oBAAA;QAClB,gBAAgB,kBAAA;QAChB,eAAe,iBAAA;QACf,eAAe,iBAAA;QACf,cAAc,gBAAA;QACd,gBAAgB,kBAAA;QAChB,cAAc,gBAAA;KACf,CAAC;IAEF,QACE,oBAAC,YAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,IAChD,QAAQ,CACa,EACxB;AACJ;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useDayPicker } from '../DayPicker/useDayPicker.js';
|
|
3
|
+
import '../DayPicker/DayPickerContext.js';
|
|
3
4
|
import { useNavigationState } from './useNavigationState.js';
|
|
4
5
|
import { getDisplayMonths } from './utils/getDisplayMonths.js';
|
|
5
6
|
import { getNextMonth } from './utils/getNextMonth.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NavigationContext.js","sources":["../../../src/contexts/Navigation/NavigationContext.tsx"],"sourcesContent":["import React from 'react';\n\nimport { useDayPicker } from '../DayPicker';\nimport { useNavigationState } from './useNavigationState';\nimport { getDisplayMonths } from './utils/getDisplayMonths';\nimport { getNextMonth } from './utils/getNextMonth';\nimport { getPreviousMonth } from './utils/getPreviousMonth';\n\n/** Represents the value of the [[NavigationContext]]. */\nexport interface NavigationContextValue {\n /** The current month. Note that when `numberOfMonths > 1` represent the first month in the displayed months. */\n month: Date;\n /** The months to display, according to `numberOfMonths`. */\n displayMonths: Date[];\n /** Navigate to the specified month. */\n goToMonth: (month: Date) => void;\n /** The next month to display. `undefined` if no months left */\n nextMonth?: Date;\n /** The previous month to display. `undefined` if no months left */\n previousMonth?: Date;\n}\n\n/**\n * The Navigation context shares details about the months being navigated in DayPicker.\n *\n * Access this context from the [[useNavigation]] hook.\n */\nexport const NavigationContext = React.createContext<\n NavigationContextValue | undefined\n>(undefined);\n\n/** Provides the values for the [[NavigationContext]]. */\nexport function NavigationProvider(props: {\n children?: React.ReactNode;\n}): JSX.Element {\n const context = useDayPicker();\n const [month, goToMonth] = useNavigationState();\n\n const displayMonths = getDisplayMonths(month, context);\n const nextMonth = getNextMonth(month, context);\n const previousMonth = getPreviousMonth(month, context);\n\n return (\n <NavigationContext.Provider\n value={{\n month,\n displayMonths,\n goToMonth,\n previousMonth,\n nextMonth\n }}\n >\n {props.children}\n </NavigationContext.Provider>\n );\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NavigationContext.js","sources":["../../../src/contexts/Navigation/NavigationContext.tsx"],"sourcesContent":["import React from 'react';\n\nimport { useDayPicker } from '../DayPicker';\nimport { useNavigationState } from './useNavigationState';\nimport { getDisplayMonths } from './utils/getDisplayMonths';\nimport { getNextMonth } from './utils/getNextMonth';\nimport { getPreviousMonth } from './utils/getPreviousMonth';\n\n/** Represents the value of the [[NavigationContext]]. */\nexport interface NavigationContextValue {\n /** The current month. Note that when `numberOfMonths > 1` represent the first month in the displayed months. */\n month: Date;\n /** The months to display, according to `numberOfMonths`. */\n displayMonths: Date[];\n /** Navigate to the specified month. */\n goToMonth: (month: Date) => void;\n /** The next month to display. `undefined` if no months left */\n nextMonth?: Date;\n /** The previous month to display. `undefined` if no months left */\n previousMonth?: Date;\n}\n\n/**\n * The Navigation context shares details about the months being navigated in DayPicker.\n *\n * Access this context from the [[useNavigation]] hook.\n */\nexport const NavigationContext = React.createContext<\n NavigationContextValue | undefined\n>(undefined);\n\n/** Provides the values for the [[NavigationContext]]. */\nexport function NavigationProvider(props: {\n children?: React.ReactNode;\n}): JSX.Element {\n const context = useDayPicker();\n const [month, goToMonth] = useNavigationState();\n\n const displayMonths = getDisplayMonths(month, context);\n const nextMonth = getNextMonth(month, context);\n const previousMonth = getPreviousMonth(month, context);\n\n return (\n <NavigationContext.Provider\n value={{\n month,\n displayMonths,\n goToMonth,\n previousMonth,\n nextMonth\n }}\n >\n {props.children}\n </NavigationContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;;;;;;AAsBA;;;;;IAKa,iBAAiB,GAAG,KAAK,CAAC,aAAa,CAElD,SAAS,EAAE;AAEb;SACgB,kBAAkB,CAAC,KAElC;IACC,IAAM,OAAO,GAAG,YAAY,EAAE,CAAC;IACzB,IAAA,KAAqB,kBAAkB,EAAE,EAAxC,KAAK,QAAA,EAAE,SAAS,QAAwB,CAAC;IAEhD,IAAM,aAAa,GAAG,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACvD,IAAM,SAAS,GAAG,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC/C,IAAM,aAAa,GAAG,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAEvD,QACE,oBAAC,iBAAiB,CAAC,QAAQ,IACzB,KAAK,EAAE;YACL,KAAK,OAAA;YACL,aAAa,eAAA;YACb,SAAS,WAAA;YACT,aAAa,eAAA;YACb,SAAS,WAAA;SACV,IAEA,KAAK,CAAC,QAAQ,CACY,EAC7B;AACJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNavigationState.js","sources":["../../../src/contexts/Navigation/useNavigationState.ts"],"sourcesContent":["import { useDayPicker } from '../../contexts/DayPicker';\n\nimport { getInitialMonth } from './utils/getInitialMonth';\nimport { useControlledValue } from '../../hooks/useControlledValue';\n\n/** Controls the navigation state. */\nexport function useNavigationState(): [\n /** The month DayPicker is navigating at */\n month: Date,\n /** Go to the specified month. */\n goToMonth: (month: Date) => void\n] {\n const context = useDayPicker();\n const initialMonth = getInitialMonth(context);\n const [month, setMonth] = useControlledValue(initialMonth, context.month);\n\n const goToMonth = (date: Date) => {\n if (context.disableNavigation) return;\n setMonth(date);\n };\n\n return [month, goToMonth];\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useNavigationState.js","sources":["../../../src/contexts/Navigation/useNavigationState.ts"],"sourcesContent":["import { useDayPicker } from '../../contexts/DayPicker';\n\nimport { getInitialMonth } from './utils/getInitialMonth';\nimport { useControlledValue } from '../../hooks/useControlledValue';\n\n/** Controls the navigation state. */\nexport function useNavigationState(): [\n /** The month DayPicker is navigating at */\n month: Date,\n /** Go to the specified month. */\n goToMonth: (month: Date) => void\n] {\n const context = useDayPicker();\n const initialMonth = getInitialMonth(context);\n const [month, setMonth] = useControlledValue(initialMonth, context.month);\n\n const goToMonth = (date: Date) => {\n if (context.disableNavigation) return;\n setMonth(date);\n };\n\n return [month, goToMonth];\n}\n"],"names":[],"mappings":";;;;;AAKA;SACgB,kBAAkB;IAMhC,IAAM,OAAO,GAAG,YAAY,EAAE,CAAC;IAC/B,IAAM,YAAY,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IACxC,IAAA,KAAoB,kBAAkB,CAAC,YAAY,EAAE,OAAO,CAAC,KAAK,CAAC,EAAlE,KAAK,QAAA,EAAE,QAAQ,QAAmD,CAAC;IAE1E,IAAM,SAAS,GAAG,UAAC,IAAU;QAC3B,IAAI,OAAO,CAAC,iBAAiB;YAAE,OAAO;QACtC,QAAQ,CAAC,IAAI,CAAC,CAAC;KAChB,CAAC;IAEF,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AAC5B;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RootProvider.js","sources":["../../src/contexts/RootProvider.tsx"],"sourcesContent":["import React from 'react';\n\nimport { DayPickerProps } from '../types';\
|
|
1
|
+
{"version":3,"file":"RootProvider.js","sources":["../../src/contexts/RootProvider.tsx"],"sourcesContent":["import React from 'react';\n\nimport { DayPickerProps } from '../types';\nimport { DayPickerProvider } from './DayPicker/DayPickerProvider';\nimport { FocusProvider } from './Focus/FocusContext';\nimport { NavigationProvider } from './Navigation/NavigationContext';\nimport { SelectMultipleProvider } from './SelectMultiple/SelectMultipleContext';\nimport { SelectRangeProvider } from './SelectRange/SelectRangeContext';\nimport { SelectSingleProvider } from './SelectSingle/SelectSingleContext';\n\n/** The props of [[RootProvider]]. */\nexport type RootContext = DayPickerProps & {\n children: React.ReactNode;\n};\n\n/** Provide the value for all the context providers. */\nexport function RootProvider(props: RootContext): JSX.Element {\n const { children, ...initialProps } = props;\n\n return (\n <DayPickerProvider initialProps={initialProps}>\n <NavigationProvider>\n <SelectSingleProvider initialProps={initialProps}>\n <SelectMultipleProvider initialProps={initialProps}>\n <SelectRangeProvider initialProps={initialProps}>\n <FocusProvider>{children}</FocusProvider>\n </SelectRangeProvider>\n </SelectMultipleProvider>\n </SelectSingleProvider>\n </NavigationProvider>\n </DayPickerProvider>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;AAeA;SACgB,YAAY,CAAC,KAAkB;IACrC,IAAA,QAAQ,GAAsB,KAAK,SAA3B,EAAK,YAAY,UAAK,KAAK,EAArC,YAA6B,CAAF,CAAW;IAE5C,QACE,oBAAC,iBAAiB,IAAC,YAAY,EAAE,YAAY;QAC3C,oBAAC,kBAAkB;YACjB,oBAAC,oBAAoB,IAAC,YAAY,EAAE,YAAY;gBAC9C,oBAAC,sBAAsB,IAAC,YAAY,EAAE,YAAY;oBAChD,oBAAC,mBAAmB,IAAC,YAAY,EAAE,YAAY;wBAC7C,oBAAC,aAAa,QAAE,QAAQ,CAAiB,CACrB,CACC,CACJ,CACJ,CACH,EACpB;AACJ;;;;"}
|
|
@@ -9,7 +9,7 @@ export interface SelectMultipleContextValue {
|
|
|
9
9
|
/** The modifiers for the corresponding selection. */
|
|
10
10
|
modifiers: SelectMultipleModifiers;
|
|
11
11
|
/** Event handler to attach to the day button to enable the multiple select. */
|
|
12
|
-
|
|
12
|
+
onDayClick?: DayClickEventHandler;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* The SelectMultiple context shares details about the selected days when in
|
|
@@ -27,7 +27,7 @@ function SelectMultipleProvider(props) {
|
|
|
27
27
|
function SelectMultipleProviderInternal(_a) {
|
|
28
28
|
var initialProps = _a.initialProps, children = _a.children;
|
|
29
29
|
var selected = initialProps.selected;
|
|
30
|
-
var
|
|
30
|
+
var onDayClick = function (day, modifiers, e) {
|
|
31
31
|
var _a, _b;
|
|
32
32
|
(_a = initialProps.onDayClick) === null || _a === void 0 ? void 0 : _a.call(initialProps, day, modifiers, e);
|
|
33
33
|
var isMinSelected = Boolean(initialProps.min &&
|
|
@@ -74,7 +74,7 @@ function SelectMultipleProviderInternal(_a) {
|
|
|
74
74
|
}
|
|
75
75
|
];
|
|
76
76
|
}
|
|
77
|
-
var contextValue = { selected: selected,
|
|
77
|
+
var contextValue = { selected: selected, onDayClick: onDayClick, modifiers: modifiers };
|
|
78
78
|
return (React.createElement(SelectMultipleContext.Provider, { value: contextValue }, children));
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectMultipleContext.js","sources":["../../../src/contexts/SelectMultiple/SelectMultipleContext.tsx"],"sourcesContent":["import React from 'react';\n\nimport { isSameDay } from 'date-fns';\n\nimport {\n DayClickEventHandler,\n DayPickerMultipleProps,\n DayPickerProps,\n isDayPickerMultiple,\n Modifiers\n} from '../../types';\n\n/** Represent the modifiers that are changed by the multiple selection. */\nexport type SelectMultipleModifiers = Pick<Modifiers, 'selected' | 'disabled'>;\n\n/** Represents the value of a [[SelectMultipleContext]]. */\nexport interface SelectMultipleContextValue {\n /** The days that have been selected. */\n selected: Date[] | undefined;\n /** The modifiers for the corresponding selection. */\n modifiers: SelectMultipleModifiers;\n /** Event handler to attach to the day button to enable the multiple select. */\n
|
|
1
|
+
{"version":3,"file":"SelectMultipleContext.js","sources":["../../../src/contexts/SelectMultiple/SelectMultipleContext.tsx"],"sourcesContent":["import React from 'react';\n\nimport { isSameDay } from 'date-fns';\n\nimport {\n DayClickEventHandler,\n DayPickerMultipleProps,\n DayPickerProps,\n isDayPickerMultiple,\n Modifiers\n} from '../../types';\n\n/** Represent the modifiers that are changed by the multiple selection. */\nexport type SelectMultipleModifiers = Pick<Modifiers, 'selected' | 'disabled'>;\n\n/** Represents the value of a [[SelectMultipleContext]]. */\nexport interface SelectMultipleContextValue {\n /** The days that have been selected. */\n selected: Date[] | undefined;\n /** The modifiers for the corresponding selection. */\n modifiers: SelectMultipleModifiers;\n /** Event handler to attach to the day button to enable the multiple select. */\n onDayClick?: DayClickEventHandler;\n}\n\n/**\n * The SelectMultiple context shares details about the selected days when in\n * multiple selection mode.\n *\n * Access this context from the [[useSelectMultiple]] hook.\n */\nexport const SelectMultipleContext = React.createContext<\n SelectMultipleContextValue | undefined\n>(undefined);\n\nexport type SelectMultipleProviderProps = {\n initialProps: DayPickerProps;\n children: React.ReactNode;\n};\n\n/** Provides the values for the [[SelectMultipleContext]]. */\nexport function SelectMultipleProvider(\n props: SelectMultipleProviderProps\n): JSX.Element {\n if (!isDayPickerMultiple(props.initialProps)) {\n const emptyContextValue: SelectMultipleContextValue = {\n selected: undefined,\n modifiers: {\n selected: [],\n disabled: []\n }\n };\n return (\n <SelectMultipleContext.Provider value={emptyContextValue}>\n {props.children}\n </SelectMultipleContext.Provider>\n );\n }\n return (\n <SelectMultipleProviderInternal\n initialProps={props.initialProps}\n children={props.children}\n />\n );\n}\n\ntype SelectMultipleProviderInternalProps = {\n initialProps: DayPickerMultipleProps;\n children: React.ReactNode;\n};\n\nexport function SelectMultipleProviderInternal({\n initialProps,\n children\n}: SelectMultipleProviderInternalProps): JSX.Element {\n const { selected } = initialProps;\n const onDayClick: DayClickEventHandler = (day, modifiers, e) => {\n initialProps.onDayClick?.(day, modifiers, e);\n\n const isMinSelected = Boolean(\n initialProps.min &&\n modifiers.selected &&\n selected &&\n selected.length === initialProps.min\n );\n if (isMinSelected) {\n return;\n }\n const isMaxSelected = Boolean(\n initialProps.max &&\n !modifiers.selected &&\n selected &&\n selected.length === initialProps.max\n );\n if (isMaxSelected) {\n return;\n }\n\n const days = selected ? [...selected] : [];\n if (modifiers.selected) {\n const index = days.findIndex((selectedDay) =>\n isSameDay(day, selectedDay)\n );\n days.splice(index, 1);\n } else {\n days.push(day);\n }\n initialProps.onSelect?.(days, day, modifiers, e);\n };\n\n const modifiers: SelectMultipleModifiers = {\n selected: [],\n disabled: []\n };\n\n if (selected) {\n modifiers.selected = selected;\n modifiers.disabled = [\n function disableDay(day: Date) {\n const isMaxSelected =\n initialProps.max &&\n selected &&\n selected.length > initialProps.max - 1;\n const isSelected = selected?.some((selectedDay) =>\n isSameDay(selectedDay, day)\n );\n return Boolean(isMaxSelected && !isSelected);\n }\n ];\n }\n\n const contextValue = { selected, onDayClick, modifiers };\n\n return (\n <SelectMultipleContext.Provider value={contextValue}>\n {children}\n </SelectMultipleContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;;;AAyBA;;;;;;IAMa,qBAAqB,GAAG,KAAK,CAAC,aAAa,CAEtD,SAAS,EAAE;AAOb;SACgB,sBAAsB,CACpC,KAAkC;IAElC,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;QAC5C,IAAM,iBAAiB,GAA+B;YACpD,QAAQ,EAAE,SAAS;YACnB,SAAS,EAAE;gBACT,QAAQ,EAAE,EAAE;gBACZ,QAAQ,EAAE,EAAE;aACb;SACF,CAAC;QACF,QACE,oBAAC,qBAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,iBAAiB,IACrD,KAAK,CAAC,QAAQ,CACgB,EACjC;KACH;IACD,QACE,oBAAC,8BAA8B,IAC7B,YAAY,EAAE,KAAK,CAAC,YAAY,EAChC,QAAQ,EAAE,KAAK,CAAC,QAAQ,GACxB,EACF;AACJ,CAAC;SAOe,8BAA8B,CAAC,EAGT;QAFpC,YAAY,kBAAA,EACZ,QAAQ,cAAA;IAEA,IAAA,QAAQ,GAAK,YAAY,SAAjB,CAAkB;IAClC,IAAM,UAAU,GAAyB,UAAC,GAAG,EAAE,SAAS,EAAE,CAAC;;QACzD,MAAA,YAAY,CAAC,UAAU,+CAAvB,YAAY,EAAc,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;QAE7C,IAAM,aAAa,GAAG,OA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AAQ,CAAE,IAAI,CAAC,UAAC,WAAW;oBAC5C,OAAA,SAAS,CAAC,WAAW,EAAE,GAAG,CAAC;iBAAA,CAC5B,CAAC;gBACF,OAAO,OAAO,CAAC,aAAa,IAAI,CAAC,UAAU,CAAC,CAAC;aAC9C;SACF,CAAC;KACH;IAED,IAAM,YAAY,GAAG,EAAE,QAAQ,UAAA,EAAE,UAAU,YAAA,EAAE,SAAS,WAAA,EAAE,CAAC;IAEzD,QACE,oBAAC,qBAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,IAChD,QAAQ,CACsB,EACjC;AACJ;;;;"}
|
|
@@ -9,7 +9,7 @@ export interface SelectRangeContextValue {
|
|
|
9
9
|
/** The modifiers for the corresponding selection. */
|
|
10
10
|
modifiers: SelectRangeModifiers;
|
|
11
11
|
/** Event handler to attach to the day button to enable the range select. */
|
|
12
|
-
|
|
12
|
+
onDayClick?: DayClickEventHandler;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* The SelectRange context shares details about the selected days when in
|
|
@@ -32,7 +32,7 @@ function SelectRangeProviderInternal(_a) {
|
|
|
32
32
|
var selected = initialProps.selected;
|
|
33
33
|
var min = initialProps.min;
|
|
34
34
|
var max = initialProps.max;
|
|
35
|
-
var
|
|
35
|
+
var onDayClick = function (day, modifiers, e) {
|
|
36
36
|
var _a, _b;
|
|
37
37
|
(_a = initialProps.onDayClick) === null || _a === void 0 ? void 0 : _a.call(initialProps, day, modifiers, e);
|
|
38
38
|
var newValue = addToRange(day, selected);
|
|
@@ -116,7 +116,7 @@ function SelectRangeProviderInternal(_a) {
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
-
return (React.createElement(SelectRangeContext.Provider, { value: { selected: selected,
|
|
119
|
+
return (React.createElement(SelectRangeContext.Provider, { value: { selected: selected, onDayClick: onDayClick, modifiers: modifiers } }, children));
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
export { SelectRangeContext, SelectRangeProvider, SelectRangeProviderInternal };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectRangeContext.js","sources":["../../../src/contexts/SelectRange/SelectRangeContext.tsx"],"sourcesContent":["import React from 'react';\n\nimport { differenceInCalendarDays, isAfter, isBefore } from 'date-fns';\n\nimport {\n DateRange,\n DayClickEventHandler,\n DayPickerProps,\n DayPickerRangeProps,\n isDayPickerRange,\n Modifiers\n} from '../../types';\nimport { addToRange } from './utils/addToRange';\n\n/** Represent the modifiers that are changed by the range selection. */\nexport type SelectRangeModifiers = Pick<\n Modifiers,\n 'selected' | 'range_start' | 'range_end' | 'range_middle' | 'disabled'\n>;\n\n/** Represents the value of a [[SelectRangeContext]]. */\nexport interface SelectRangeContextValue {\n /** The range of days that has been selected. */\n selected: DateRange | undefined;\n /** The modifiers for the corresponding selection. */\n modifiers: SelectRangeModifiers;\n /** Event handler to attach to the day button to enable the range select. */\n
|
|
1
|
+
{"version":3,"file":"SelectRangeContext.js","sources":["../../../src/contexts/SelectRange/SelectRangeContext.tsx"],"sourcesContent":["import React from 'react';\n\nimport { differenceInCalendarDays, isAfter, isBefore } from 'date-fns';\n\nimport {\n DateRange,\n DayClickEventHandler,\n DayPickerProps,\n DayPickerRangeProps,\n isDayPickerRange,\n Modifiers\n} from '../../types';\nimport { addToRange } from './utils/addToRange';\n\n/** Represent the modifiers that are changed by the range selection. */\nexport type SelectRangeModifiers = Pick<\n Modifiers,\n 'selected' | 'range_start' | 'range_end' | 'range_middle' | 'disabled'\n>;\n\n/** Represents the value of a [[SelectRangeContext]]. */\nexport interface SelectRangeContextValue {\n /** The range of days that has been selected. */\n selected: DateRange | undefined;\n /** The modifiers for the corresponding selection. */\n modifiers: SelectRangeModifiers;\n /** Event handler to attach to the day button to enable the range select. */\n onDayClick?: DayClickEventHandler;\n}\n\n/**\n * The SelectRange context shares details about the selected days when in\n * range selection mode.\n *\n * Access this context from the [[useSelectRange]] hook.\n */\nexport const SelectRangeContext = React.createContext<\n SelectRangeContextValue | undefined\n>(undefined);\n\ntype SelectRangeProviderProps = {\n initialProps: DayPickerProps;\n children: React.ReactNode;\n};\n\n/** Provides the values for the [[SelectRangeProvider]]. */\nexport function SelectRangeProvider(\n props: SelectRangeProviderProps\n): JSX.Element {\n if (!isDayPickerRange(props.initialProps)) {\n const emptyContextValue: SelectRangeContextValue = {\n selected: undefined,\n modifiers: {\n selected: [],\n range_start: [],\n range_end: [],\n range_middle: [],\n disabled: []\n }\n };\n return (\n <SelectRangeContext.Provider value={emptyContextValue}>\n {props.children}\n </SelectRangeContext.Provider>\n );\n }\n return (\n <SelectRangeProviderInternal\n initialProps={props.initialProps}\n children={props.children}\n />\n );\n}\n\ntype SelectRangeProviderInternalProps = {\n initialProps: DayPickerRangeProps;\n children: React.ReactNode;\n};\n\nexport function SelectRangeProviderInternal({\n initialProps,\n children\n}: SelectRangeProviderInternalProps): JSX.Element {\n const { selected } = initialProps;\n const min = initialProps.min;\n const max = initialProps.max;\n\n const onDayClick: DayClickEventHandler = (day, modifiers, e) => {\n initialProps.onDayClick?.(day, modifiers, e);\n const newValue = addToRange(day, selected);\n if (\n (min || max) &&\n selected &&\n newValue?.to &&\n newValue.from &&\n newValue.from !== newValue.to\n ) {\n const diff = Math.abs(\n differenceInCalendarDays(newValue?.to, newValue?.from)\n );\n if (min && diff < min) {\n return;\n }\n if (max && diff >= max) {\n return;\n }\n }\n initialProps.onSelect?.(newValue, day, modifiers, e);\n };\n\n const modifiers: SelectRangeModifiers = {\n selected: [],\n range_start: [],\n range_end: [],\n range_middle: [],\n disabled: []\n };\n\n if (selected) {\n modifiers.selected = [selected];\n if (selected.from) {\n modifiers.range_start = [selected.from];\n if (selected.to) {\n modifiers.range_middle = [\n {\n after: selected.from,\n before: selected.to\n }\n ];\n if (max || min) {\n modifiers.disabled = [\n (date: Date) => {\n if (\n max &&\n selected.to &&\n selected.from &&\n isBefore(date, selected.from)\n ) {\n const diff = differenceInCalendarDays(selected.to, date);\n if (diff >= max) {\n return true;\n }\n }\n if (\n max &&\n selected.to &&\n selected.from &&\n isAfter(date, selected.to)\n ) {\n const diff = differenceInCalendarDays(date, selected.from);\n if (diff >= max) {\n return true;\n }\n }\n if (min && selected.from && isBefore(date, selected.from)) {\n const diff = differenceInCalendarDays(selected.from, date);\n if (diff < min) {\n return true;\n }\n }\n if (\n min &&\n selected.to &&\n selected.from &&\n isAfter(date, selected.to)\n ) {\n const diff = differenceInCalendarDays(date, selected.from);\n if (diff < min) {\n return true;\n }\n }\n return false;\n }\n ];\n }\n modifiers.range_end = [selected.to];\n } else {\n modifiers.range_end = [selected.from];\n }\n }\n }\n return (\n <SelectRangeContext.Provider value={{ selected, onDayClick, modifiers }}>\n {children}\n </SelectRangeContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;;;AA8BA;;;;;;IAMa,kBAAkB,GAAG,KAAK,CAAC,aAAa,CAEnD,SAAS,EAAE;AAOb;SACgB,mBAAmB,CACjC,KAA+B;IAE/B,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;QACzC,IAAM,iBAAiB,GAA4B;YACjD,QAAQ,EAAE,SAAS;YACnB,SAAS,EAAE;gBACT,QAAQ,EAAE,EAAE;gBACZ,WAAW,EAAE,EAAE;gBACf,SAAS,EAAE,EAAE;gBACb,YAAY,EAAE,EAAE;gBAChB,QAAQ,EAAE,EAAE;aACb;SACF,CAAC;QACF,QACE,oBAAC,kBAAkB,CAAC,QAAQ,IAAC,KAAK,EAAE,iBAAiB,IAClD,KAAK,CAAC,QAAQ,CACa,EAC9B;KACH;IACD,QACE,oBAAC,2BAA2B,IAC1B,YAAY,EAAE,KAAK,CAAC,YAAY,EAChC,QAAQ,EAAE,KAAK,CAAC,QAAQ,GACxB,EACF;AACJ,CAAC;SAOe,2BAA2B,CAAC,EAGT;QAFjC,YAAY,kBAAA,EACZ,QAAQ,cAAA;IAEA,IAAA,QAAQ,GAAK,YAAY,SAAjB,CAAkB;IAClC,IAAM,GAAG,G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AAC,EAAE,CAAC,EAC1B;gCACA,IAAM,IAAI,GAAG,wBAAwB,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;gCAC3D,IAAI,IAAI,GAAG,GAAG,EAAE;oCACd,OAAO,IAAI,CAAC;iCACb;6BACF;4BACD,OAAO,KAAK,CAAC;yBACd;qBACF,CAAC;iBACH;gBACD,SAAS,CAAC,SAAS,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;aACrC;iBAAM;gBACL,SAAS,CAAC,SAAS,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;aACvC;SACF;KACF;IACD,QACE,oBAAC,kBAAkB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,QAAQ,UAAA,EAAE,UAAU,YAAA,EAAE,SAAS,WAAA,EAAE,IACpE,QAAQ,CACmB,EAC9B;AACJ;;;;"}
|
|
@@ -12,7 +12,7 @@ export interface SelectSingleContextValue {
|
|
|
12
12
|
/** The modifiers for the corresponding selection. */
|
|
13
13
|
modifiers: SelectSingleModifiers;
|
|
14
14
|
/** Event handler to attach to the day button to enable the single select. */
|
|
15
|
-
|
|
15
|
+
onDayClick?: DayClickEventHandler;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* The SelectSingle context shares details about the selected days when in
|
|
@@ -21,7 +21,7 @@ function SelectSingleProvider(props) {
|
|
|
21
21
|
}
|
|
22
22
|
function SelectSingleProviderInternal(_a) {
|
|
23
23
|
var initialProps = _a.initialProps, children = _a.children;
|
|
24
|
-
var
|
|
24
|
+
var onDayClick = function (day, dayModifiers, e) {
|
|
25
25
|
var _a, _b;
|
|
26
26
|
if (dayModifiers.selected && !initialProps.required) {
|
|
27
27
|
(_a = initialProps.onSelect) === null || _a === void 0 ? void 0 : _a.call(initialProps, undefined, day, dayModifiers, e);
|
|
@@ -35,7 +35,7 @@ function SelectSingleProviderInternal(_a) {
|
|
|
35
35
|
}
|
|
36
36
|
var contextValue = {
|
|
37
37
|
selected: initialProps.selected,
|
|
38
|
-
|
|
38
|
+
onDayClick: onDayClick,
|
|
39
39
|
modifiers: modifiers
|
|
40
40
|
};
|
|
41
41
|
return (React.createElement(SelectSingleContext.Provider, { value: contextValue }, children));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectSingleContext.js","sources":["../../../src/contexts/SelectSingle/SelectSingleContext.tsx"],"sourcesContent":["import React from 'react';\n\nimport { DayPickerProps } from '../../types/DayPicker';\nimport {\n DayPickerSingleProps,\n isDayPickerSingle\n} from '../../types/DayPickerSingle';\nimport { DayClickEventHandler } from '../../types/EventHandlers';\nimport { Modifiers } from '../../types/Modifiers';\n\n/** Represent the modifiers that are changed by the single selection. */\nexport type SelectSingleModifiers = Pick<Modifiers, 'selected'>;\n\n/** Represents the value of a [[SelectSingleContext]]. */\nexport interface SelectSingleContextValue {\n /** The day that has been selected. */\n selected: Date | undefined;\n /** The modifiers for the corresponding selection. */\n modifiers: SelectSingleModifiers;\n /** Event handler to attach to the day button to enable the single select. */\n
|
|
1
|
+
{"version":3,"file":"SelectSingleContext.js","sources":["../../../src/contexts/SelectSingle/SelectSingleContext.tsx"],"sourcesContent":["import React from 'react';\n\nimport { DayPickerProps } from '../../types/DayPicker';\nimport {\n DayPickerSingleProps,\n isDayPickerSingle\n} from '../../types/DayPickerSingle';\nimport { DayClickEventHandler } from '../../types/EventHandlers';\nimport { Modifiers } from '../../types/Modifiers';\n\n/** Represent the modifiers that are changed by the single selection. */\nexport type SelectSingleModifiers = Pick<Modifiers, 'selected'>;\n\n/** Represents the value of a [[SelectSingleContext]]. */\nexport interface SelectSingleContextValue {\n /** The day that has been selected. */\n selected: Date | undefined;\n /** The modifiers for the corresponding selection. */\n modifiers: SelectSingleModifiers;\n /** Event handler to attach to the day button to enable the single select. */\n onDayClick?: DayClickEventHandler;\n}\n\n/**\n * The SelectSingle context shares details about the selected days when in\n * single selection mode.\n *\n * Access this context from the [[useSelectSingle]] hook.\n */\nexport const SelectSingleContext = React.createContext<\n SelectSingleContextValue | undefined\n>(undefined);\n\ntype SelectSingleProviderProps = {\n initialProps: DayPickerProps;\n children: React.ReactNode;\n};\n\n/** Provides the values for the [[SelectSingleProvider]]. */\nexport function SelectSingleProvider(\n props: SelectSingleProviderProps\n): JSX.Element {\n if (!isDayPickerSingle(props.initialProps)) {\n const emptyContextValue: SelectSingleContextValue = {\n selected: undefined,\n modifiers: { selected: [] }\n };\n return (\n <SelectSingleContext.Provider value={emptyContextValue}>\n {props.children}\n </SelectSingleContext.Provider>\n );\n }\n return (\n <SelectSingleProviderInternal\n initialProps={props.initialProps}\n children={props.children}\n />\n );\n}\n\ntype SelectSingleProviderInternal = {\n initialProps: DayPickerSingleProps;\n children: React.ReactNode;\n};\n\nexport function SelectSingleProviderInternal({\n initialProps,\n children\n}: SelectSingleProviderInternal): JSX.Element {\n const onDayClick: DayClickEventHandler = (day, dayModifiers, e) => {\n if (dayModifiers.selected && !initialProps.required) {\n initialProps.onSelect?.(undefined, day, dayModifiers, e);\n return;\n }\n initialProps.onSelect?.(day, day, dayModifiers, e);\n };\n\n const modifiers: SelectSingleModifiers = { selected: [] };\n\n if (initialProps.selected) {\n modifiers.selected = [initialProps.selected];\n }\n\n const contextValue: SelectSingleContextValue = {\n selected: initialProps.selected,\n onDayClick,\n modifiers\n };\n return (\n <SelectSingleContext.Provider value={contextValue}>\n {children}\n </SelectSingleContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;AAuBA;;;;;;IAMa,mBAAmB,GAAG,KAAK,CAAC,aAAa,CAEpD,SAAS,EAAE;AAOb;SACgB,oBAAoB,CAClC,KAAgC;IAEhC,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;QAC1C,IAAM,iBAAiB,GAA6B;YAClD,QAAQ,EAAE,SAAS;YACnB,SAAS,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;SAC5B,CAAC;QACF,QACE,oBAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,iBAAiB,IACnD,KAAK,CAAC,QAAQ,CACc,EAC/B;KACH;IACD,QACE,oBAAC,4BAA4B,IAC3B,YAAY,EAAE,KAAK,CAAC,YAAY,EAChC,QAAQ,EAAE,KAAK,CAAC,QAAQ,GACxB,EACF;AACJ,CAAC;SAOe,4BAA4B,CAAC,EAGd;QAF7B,YAAY,kBAAA,EACZ,QAAQ,cAAA;IAER,IAAM,UAAU,GAAyB,UAAC,GAAG,EAAE,YAAY,EAAE,CAAC;;QAC5D,IAAI,YAAY,CAAC,QAAQ,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE;YACnD,MAAA,YAAY,CAAC,QAAQ,+CAArB,YAAY,EAAY,SAAS,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC;YACzD,OAAO;SACR;QACD,MAAA,YAAY,CAAC,QAAQ,+CAArB,YAAY,EAAY,GAAG,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC;KACpD,CAAC;IAEF,IAAM,SAAS,GAA0B,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAE1D,IAAI,YAAY,CAAC,QAAQ,EAAE;QACzB,SAAS,CAAC,QAAQ,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;KAC9C;IAED,IAAM,YAAY,GAA6B;QAC7C,QAAQ,EAAE,YAAY,CAAC,QAAQ;QAC/B,UAAU,YAAA;QACV,SAAS,WAAA;KACV,CAAC;IACF,QACE,oBAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,IAC9C,QAAQ,CACoB,EAC/B;AACJ;;;;"}
|
package/build/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { DayPickerProps } from '../../types/DayPicker';
|
|
3
2
|
import { DayPickerCustomProps } from '../../types';
|
|
3
|
+
import { DayPickerProps } from '../../types/DayPicker';
|
|
4
4
|
/** The props to attach to the input field when using [[useInput]]. */
|
|
5
5
|
export declare type InputHTMLAttributes = Pick<React.InputHTMLAttributes<HTMLInputElement>, 'onBlur' | 'onChange' | 'onFocus' | 'value' | 'placeholder'>;
|
|
6
6
|
/** The props to attach to the DayPicker component when using [[useInput]]. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInput.js","sources":["../../../src/hooks/useInput/useInput.ts"],"sourcesContent":["import React from 'react';\n\nimport { differenceInCalendarDays, format as _format, parse } from 'date-fns';\nimport enUS from 'date-fns/locale/en-US';\n\nimport { parseFromToProps } from '../../contexts/DayPicker/utils';\nimport {
|
|
1
|
+
{"version":3,"file":"useInput.js","sources":["../../../src/hooks/useInput/useInput.ts"],"sourcesContent":["import React from 'react';\n\nimport { differenceInCalendarDays, format as _format, parse } from 'date-fns';\nimport enUS from 'date-fns/locale/en-US';\n\nimport { parseFromToProps } from '../../contexts/DayPicker/utils';\nimport { DayPickerCustomProps } from '../../types';\nimport { DayPickerProps } from '../../types/DayPicker';\nimport {\n DayClickEventHandler,\n MonthChangeEventHandler\n} from '../../types/EventHandlers';\nimport { isValidDate } from './utils/isValidDate';\n\n/** The props to attach to the input field when using [[useInput]]. */\nexport type InputHTMLAttributes = Pick<\n React.InputHTMLAttributes<HTMLInputElement>,\n 'onBlur' | 'onChange' | 'onFocus' | 'value' | 'placeholder'\n>;\n\n/** The props to attach to the DayPicker component when using [[useInput]]. */\nexport type InputDayPickerProps = Pick<\n DayPickerCustomProps,\n | 'mode'\n | 'fromDate'\n | 'toDate'\n | 'locale'\n | 'month'\n | 'onDayClick'\n | 'onMonthChange'\n | 'selected'\n | 'today'\n>;\n\nexport interface UseInputOptions\n extends Pick<\n DayPickerProps,\n | 'locale'\n | 'fromDate'\n | 'toDate'\n | 'fromMonth'\n | 'toMonth'\n | 'fromYear'\n | 'toYear'\n | 'today'\n > {\n /** The initially selected date */\n defaultSelected?: Date;\n /** The format string for formatting the input field. See https://date-fns.org/docs/format for a list of format strings. Default to `PP`. */\n format?: string;\n /** Make the selection required. */\n required?: boolean;\n}\n\n/** Represent the value returned by [[useInput]]. */\nexport interface UseInput {\n /** The props to pass to a DayPicker component. */\n dayPickerProps: InputDayPickerProps;\n /** The props to pass to an input field. */\n inputProps: InputHTMLAttributes;\n /** A function to reset to the initial state. */\n reset: () => void;\n /** A function to set the selected day. */\n setSelected: (day: Date) => void;\n}\n\n/** Return props and setters for binding an input field to DayPicker. */\nexport function useInput(options: UseInputOptions = {}): UseInput {\n const {\n locale = enUS,\n required,\n format = 'PP',\n defaultSelected,\n today = new Date()\n } = options;\n const { fromDate, toDate } = parseFromToProps(options);\n\n // Shortcut to the DateFns functions\n const parseValue = (value: string) => parse(value, format, today, { locale });\n\n // Initialize states\n const [month, setMonth] = React.useState(defaultSelected ?? today);\n const [selectedDay, setSelectedDay] = React.useState(defaultSelected);\n const defaultInputValue = defaultSelected\n ? _format(defaultSelected, format, { locale })\n : '';\n const [inputValue, setInputValue] = React.useState(defaultInputValue);\n\n const reset = () => {\n setSelectedDay(defaultSelected);\n setMonth(defaultSelected ?? today);\n setInputValue(defaultInputValue ?? '');\n };\n\n const setSelected = (date: Date | undefined) => {\n setSelectedDay(date);\n setMonth(date ?? today);\n setInputValue(date ? _format(date, format, { locale }) : '');\n };\n\n const handleDayClick: DayClickEventHandler = (day, { selected }) => {\n if (!required && selected) {\n setSelectedDay(undefined);\n setInputValue('');\n return;\n }\n setSelectedDay(day);\n setInputValue(day ? _format(day, format, { locale }) : '');\n };\n\n const handleMonthChange: MonthChangeEventHandler = (month) => {\n setMonth(month);\n };\n\n // When changing the input field, save its value in state and check if the\n // string is a valid date. If it is a valid day, set it as selected and update\n // the calendar’s month.\n const handleChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {\n setInputValue(e.target.value);\n const day = parseValue(e.target.value);\n const isBefore = fromDate && differenceInCalendarDays(fromDate, day) > 0;\n const isAfter = toDate && differenceInCalendarDays(day, toDate) > 0;\n if (!isValidDate(day) || isBefore || isAfter) {\n setSelectedDay(undefined);\n return;\n }\n setSelectedDay(day);\n setMonth(day);\n };\n\n // Special case for _required_ fields: on blur, if the value of the input is not\n // a valid date, reset the calendar and the input value.\n const handleBlur: React.FocusEventHandler<HTMLInputElement> = (e) => {\n const day = parseValue(e.target.value);\n if (!isValidDate(day)) {\n reset();\n }\n };\n\n // When focusing, make sure DayPicker visualizes the month of the date in the\n // input field.\n const handleFocus: React.FocusEventHandler<HTMLInputElement> = (e) => {\n if (!e.target.value) {\n reset();\n return;\n }\n const day = parseValue(e.target.value);\n if (isValidDate(day)) {\n setMonth(day);\n }\n };\n\n const dayPickerProps: InputDayPickerProps = {\n mode: 'custom',\n month: month,\n onDayClick: handleDayClick,\n onMonthChange: handleMonthChange,\n selected: selectedDay,\n locale,\n fromDate: options?.fromDate,\n toDate: options?.toDate,\n today\n };\n\n const inputProps: InputHTMLAttributes = {\n onBlur: handleBlur,\n onChange: handleChange,\n onFocus: handleFocus,\n value: inputValue,\n placeholder: _format(new Date(), format, { locale })\n };\n\n return { dayPickerProps, inputProps, reset, setSelected };\n}\n"],"names":["format","_format"],"mappings":";;;;;;AAkEA;SACgB,QAAQ,CAAC,OAA6B;IAA7B,wBAAA,EAAA,YAA6B;IAElD,IAAA,KAKE,OAAO,OALI,EAAb,MAAM,mBAAG,IAAI,KAAA,EACb,QAAQ,GAIN,OAAO,SAJD,EACR,KAGE,OAAO,OAHI,EAAbA,QAAM,mBAAG,IAAI,KAAA,EACb,eAAe,GAEb,OAAO,gBAFM,EACf,KACE,OAAO,MADS,EAAlB,KAAK,mBAAG,IAAI,IAAI,EAAE,KAAA,CACR;IACN,IAAA,KAAuB,gBAAgB,CAAC,OAAO,CAAC,EAA9C,QAAQ,cAAA,EAAE,MAAM,YAA8B,CAAC;;IAGvD,IAAM,UAAU,GAAG,UAAC,KAAa,IAAK,OAAA,KAAK,CAAC,KAAK,EAAEA,QAAM,EAAE,KAAK,EAAE,EAAE,MAAM,QAAA,EAAE,CAAC,GAAA,CAAC;;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AAC,GAAG,CAAC,EAAE;YACpB,QAAQ,CAAC,GAAG,CAAC,CAAC;SACf;KACF,CAAC;IAEF,IAAM,cAAc,GAAwB;QAC1C,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,KAAK;QACZ,UAAU,EAAE,cAAc;QAC1B,aAAa,EAAE,iBAAiB;QAChC,QAAQ,EAAE,WAAW;QACrB,MAAM,QAAA;QACN,QAAQ,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ;QAC3B,MAAM,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM;QACvB,KAAK,OAAA;KACN,CAAC;IAEF,IAAM,UAAU,GAAwB;QACtC,MAAM,EAAE,UAAU;QAClB,QAAQ,EAAE,YAAY;QACtB,OAAO,EAAE,WAAW;QACpB,KAAK,EAAE,UAAU;QACjB,WAAW,EAAEC,MAAO,CAAC,IAAI,IAAI,EAAE,EAAED,QAAM,EAAE,EAAE,MAAM,QAAA,EAAE,CAAC;KACrD,CAAC;IAEF,OAAO,EAAE,cAAc,gBAAA,EAAE,UAAU,YAAA,EAAE,KAAK,OAAA,EAAE,WAAW,aAAA,EAAE,CAAC;AAC5D;;;;"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { __assign } from '../../_virtual/_tslib.js';
|
|
2
|
-
import { isDayPickerMultiple } from '../../types/DayPickerMultiple.js';
|
|
3
|
-
import { isDayPickerRange } from '../../types/DayPickerRange.js';
|
|
4
|
-
import { isDayPickerSingle } from '../../types/DayPickerSingle.js';
|
|
5
2
|
import { useDayPicker } from '../../contexts/DayPicker/useDayPicker.js';
|
|
3
|
+
import '../../contexts/DayPicker/DayPickerContext.js';
|
|
6
4
|
import '../../contexts/SelectMultiple/SelectMultipleContext.js';
|
|
7
5
|
import { useSelectMultiple } from '../../contexts/SelectMultiple/useSelectMultiple.js';
|
|
8
6
|
import '../../contexts/SelectRange/SelectRangeContext.js';
|
|
9
7
|
import { useSelectRange } from '../../contexts/SelectRange/useSelectRange.js';
|
|
10
8
|
import '../../contexts/SelectSingle/SelectSingleContext.js';
|
|
11
9
|
import { useSelectSingle } from '../../contexts/SelectSingle/useSelectSingle.js';
|
|
10
|
+
import { isDayPickerMultiple } from '../../types/DayPickerMultiple.js';
|
|
11
|
+
import { isDayPickerRange } from '../../types/DayPickerRange.js';
|
|
12
|
+
import { isDayPickerSingle } from '../../types/DayPickerSingle.js';
|
|
12
13
|
import { getModifierStatus } from './utils/getModifierStatus.js';
|
|
13
14
|
|
|
14
15
|
/** Return the modifiers and its styles for the specified date. */
|