react-day-picker 8.0.0-beta.31 → 8.0.0-beta.32
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 +7 -1
- package/README.md +1 -1
- package/build/DayPicker.d.ts +2 -2
- package/build/DayPicker.js.map +1 -1
- package/build/components/Caption/Caption.js +11 -11
- package/build/components/Caption/Caption.js.map +1 -1
- package/build/components/Day/hooks/useDay.js +1 -1
- package/build/components/Day/hooks/useDay.js.map +1 -1
- package/build/components/Day/hooks/useDayFocus.js +11 -4
- package/build/components/Day/hooks/useDayFocus.js.map +1 -1
- package/build/components/{IconPrevious/IconPrevious.d.ts → IconLeft/IconLeft.d.ts} +1 -1
- package/build/components/IconLeft/IconLeft.js +13 -0
- package/build/components/IconLeft/IconLeft.js.map +1 -0
- package/build/components/IconLeft/index.d.ts +1 -0
- package/build/components/{IconNext/IconNext.d.ts → IconRight/IconRight.d.ts} +1 -1
- package/build/components/IconRight/IconRight.js +13 -0
- package/build/components/IconRight/IconRight.js.map +1 -0
- package/build/components/IconRight/index.d.ts +1 -0
- package/build/components/Navigation/Navigation.js +4 -8
- package/build/components/Navigation/Navigation.js.map +1 -1
- package/build/components/index.d.ts +2 -2
- package/build/contexts/DayPicker/DayPickerProvider.js +5 -5
- package/build/contexts/DayPicker/DayPickerProvider.js.map +1 -1
- package/build/contexts/SelectMultiple/SelectMultipleProvider.js +2 -55
- package/build/contexts/SelectMultiple/SelectMultipleProvider.js.map +1 -1
- package/build/contexts/SelectMultiple/SelectMultipleProviderInternal.d.ts +8 -0
- package/build/contexts/SelectMultiple/SelectMultipleProviderInternal.js +61 -0
- package/build/contexts/SelectMultiple/SelectMultipleProviderInternal.js.map +1 -0
- package/build/contexts/SelectRange/SelectRangeProvider.d.ts +1 -5
- package/build/contexts/SelectRange/SelectRangeProvider.js +3 -96
- package/build/contexts/SelectRange/SelectRangeProvider.js.map +1 -1
- package/build/contexts/SelectRange/SelectRangeProviderInternal.d.ts +8 -0
- package/build/contexts/SelectRange/SelectRangeProviderInternal.js +99 -0
- package/build/contexts/SelectRange/SelectRangeProviderInternal.js.map +1 -0
- package/build/contexts/SelectSingle/SelectSingleProvider.d.ts +1 -5
- package/build/contexts/SelectSingle/SelectSingleProvider.js +2 -26
- package/build/contexts/SelectSingle/SelectSingleProvider.js.map +1 -1
- package/build/contexts/SelectSingle/SelectSingleProviderInternal.d.ts +8 -0
- package/build/contexts/SelectSingle/SelectSingleProviderInternal.js +27 -0
- package/build/contexts/SelectSingle/SelectSingleProviderInternal.js.map +1 -0
- package/build/hooks/useInput/index.d.ts +0 -1
- package/build/hooks/useInput/useInput.d.ts +48 -3
- package/build/hooks/useInput/useInput.js +6 -6
- package/build/hooks/useInput/useInput.js.map +1 -1
- package/build/main.js +4 -4
- package/build/test/PageObjects.d.ts +4 -4
- package/build/test/customRender.d.ts +1 -1
- package/build/test/customRenderHook.d.ts +2 -2
- package/build/types/Components.d.ts +4 -4
- package/build/types/DayPickerCustomProps.d.ts +11 -0
- package/build/types/{DayPickerMultiple.d.ts → DayPickerMultipleProps.d.ts} +5 -6
- package/build/types/DayPickerProps.d.ts +209 -9
- package/build/types/DayPickerRangeProps.d.ts +17 -0
- package/build/types/DayPickerSingleProps.d.ts +14 -0
- package/build/types/Labels.d.ts +1 -2
- package/build/types/index.d.ts +5 -5
- package/build/types/isDayPickerCustom.d.ts +2 -2
- package/build/types/isDayPickerCustom.js.map +1 -1
- package/build/types/isDayPickerMultiple.d.ts +2 -2
- package/build/types/isDayPickerMultiple.js.map +1 -1
- package/build/types/isDayPickerRange.d.ts +2 -2
- package/build/types/isDayPickerRange.js.map +1 -1
- package/build/types/isDayPickerSingle.d.ts +2 -2
- package/build/types/isDayPickerSingle.js.map +1 -1
- package/dist/main.js +54 -59
- package/dist/main.js.map +1 -1
- package/package.json +3 -3
- package/build/components/IconNext/IconNext.js +0 -13
- package/build/components/IconNext/IconNext.js.map +0 -1
- package/build/components/IconNext/index.d.ts +0 -1
- package/build/components/IconPrevious/IconPrevious.js +0 -13
- package/build/components/IconPrevious/IconPrevious.js.map +0 -1
- package/build/components/IconPrevious/index.d.ts +0 -1
- package/build/hooks/useInput/types/UseInput.d.ts +0 -12
- package/build/hooks/useInput/types/UseInputDayPickerProps.d.ts +0 -14
- package/build/hooks/useInput/types/UseInputFieldProps.d.ts +0 -12
- package/build/hooks/useInput/types/UseInputOptions.d.ts +0 -35
- package/build/hooks/useInput/types/index.d.ts +0 -4
- package/build/types/DayPickerBase.d.ts +0 -238
- package/build/types/DayPickerCustom.d.ts +0 -7
- package/build/types/DayPickerRange.d.ts +0 -20
- package/build/types/DayPickerSingle.d.ts +0 -15
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { __spreadArray } from '../../_virtual/_tslib.js';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { isSameDay } from 'date-fns';
|
|
4
|
+
import { SelectMultipleContext } from './SelectMultipleContext.js';
|
|
5
|
+
|
|
6
|
+
function SelectMultipleProviderInternal(_a) {
|
|
7
|
+
var initialProps = _a.initialProps, children = _a.children;
|
|
8
|
+
var selected = initialProps.selected;
|
|
9
|
+
var handleDayClick = function (day, modifiers, e) {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
(_a = initialProps.onDayClick) === null || _a === void 0 ? void 0 : _a.call(initialProps, day, modifiers, e);
|
|
12
|
+
var isMinSelected = Boolean(initialProps.min &&
|
|
13
|
+
modifiers.selected &&
|
|
14
|
+
selected &&
|
|
15
|
+
selected.length === initialProps.min);
|
|
16
|
+
if (isMinSelected) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
var isMaxSelected = Boolean(initialProps.max &&
|
|
20
|
+
!modifiers.selected &&
|
|
21
|
+
selected &&
|
|
22
|
+
selected.length === initialProps.max);
|
|
23
|
+
if (isMaxSelected) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
var days = selected ? __spreadArray([], selected, true) : [];
|
|
27
|
+
if (modifiers.selected) {
|
|
28
|
+
var index = days.findIndex(function (selectedDay) {
|
|
29
|
+
return isSameDay(day, selectedDay);
|
|
30
|
+
});
|
|
31
|
+
days.splice(index, 1);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
days.push(day);
|
|
35
|
+
}
|
|
36
|
+
(_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, days, day, modifiers, e);
|
|
37
|
+
};
|
|
38
|
+
var modifiers = {
|
|
39
|
+
selected: [],
|
|
40
|
+
disabled: []
|
|
41
|
+
};
|
|
42
|
+
if (selected) {
|
|
43
|
+
modifiers.selected = selected;
|
|
44
|
+
modifiers.disabled = [
|
|
45
|
+
function disableDay(day) {
|
|
46
|
+
var isMaxSelected = initialProps.max &&
|
|
47
|
+
selected &&
|
|
48
|
+
selected.length > initialProps.max - 1;
|
|
49
|
+
var isSelected = selected === null || selected === void 0 ? void 0 : selected.some(function (selectedDay) {
|
|
50
|
+
return isSameDay(selectedDay, day);
|
|
51
|
+
});
|
|
52
|
+
return Boolean(isMaxSelected && !isSelected);
|
|
53
|
+
}
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
var contextValue = { selected: selected, handleDayClick: handleDayClick, modifiers: modifiers };
|
|
57
|
+
return (React.createElement(SelectMultipleContext.Provider, { value: contextValue }, children));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { SelectMultipleProviderInternal };
|
|
61
|
+
//# sourceMappingURL=SelectMultipleProviderInternal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectMultipleProviderInternal.js","sources":["../../../src/contexts/SelectMultiple/SelectMultipleProviderInternal.tsx"],"sourcesContent":["import * as React from 'react';\nimport { isSameDay } from 'date-fns';\nimport { useControlledValue } from '../../hooks/useControlledValue';\nimport { DayClickEventHandler, DayPickerMultipleProps } from '../../types';\nimport {\n SelectMultipleContext,\n SelectMultipleModifiers\n} from './SelectMultipleContext';\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 handleDayClick: 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, handleDayClick, modifiers };\n\n return (\n <SelectMultipleContext.Provider value={contextValue}>\n {children}\n </SelectMultipleContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;;;SAcgB,8BAA8B,CAAC,EAGT;QAFpC,YAAY,kBAAA,EACZ,QAAQ,cAAA;IAEA,IAAA,QAAQ,GAAK,YAAY,SAAjB,CAAkB;IAClC,IAAM,cAAc,GAAyB,UAAC,GAAG,EAAE,SAAS,EAAE,CAAC;;QAC7D,MAAA,YAAY,CAAC,UAAU,+CAAvB,YAAY,EAAc,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;QAE7C,IAAM,aAAa,GAAG,OAAO,CAC3B,YAA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AI,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,cAAc,gBAAA,EAAE,SAAS,WAAA,EAAE,CAAC;IAE7D,QACE,oBAAC,qBAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,IAChD,QAAQ,CACsB,EACjC;AACJ;;;;"}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
export declare function SelectRangeProviderInternal({ initialProps, children }: {
|
|
4
|
-
initialProps: DayPickerBase & DayPickerRange;
|
|
5
|
-
children: React.ReactNode;
|
|
6
|
-
}): JSX.Element;
|
|
2
|
+
import { DayPickerProps } from '../../types';
|
|
7
3
|
declare type SelectRangeProviderProps = {
|
|
8
4
|
initialProps: DayPickerProps;
|
|
9
5
|
children: React.ReactNode;
|
|
@@ -1,102 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import { useControlledValue } from '../../hooks/useControlledValue/useControlledValue.js';
|
|
2
|
+
import 'date-fns';
|
|
4
3
|
import { isDayPickerRange } from '../../types/isDayPickerRange.js';
|
|
5
4
|
import { SelectRangeContext } from './SelectRangeContext.js';
|
|
6
|
-
import {
|
|
5
|
+
import { SelectRangeProviderInternal } from './SelectRangeProviderInternal.js';
|
|
7
6
|
|
|
8
|
-
function SelectRangeProviderInternal(_a) {
|
|
9
|
-
var initialProps = _a.initialProps, children = _a.children;
|
|
10
|
-
var _b = useControlledValue(initialProps.defaultSelected, initialProps.selected), selected = _b[0], setSelected = _b[1];
|
|
11
|
-
var min = initialProps.min;
|
|
12
|
-
var max = initialProps.max;
|
|
13
|
-
var handleDayClick = function (day, modifiers, e) {
|
|
14
|
-
var _a, _b;
|
|
15
|
-
(_a = initialProps.onDayClick) === null || _a === void 0 ? void 0 : _a.call(initialProps, day, modifiers, e);
|
|
16
|
-
var newValue = addToRange(day, selected);
|
|
17
|
-
if ((min || max) &&
|
|
18
|
-
selected &&
|
|
19
|
-
(newValue === null || newValue === void 0 ? void 0 : newValue.to) &&
|
|
20
|
-
newValue.from &&
|
|
21
|
-
newValue.from !== newValue.to) {
|
|
22
|
-
var diff = Math.abs(differenceInCalendarDays(newValue === null || newValue === void 0 ? void 0 : newValue.to, newValue === null || newValue === void 0 ? void 0 : newValue.from));
|
|
23
|
-
if (min && diff < min) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (max && diff >= max) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
setSelected(newValue);
|
|
31
|
-
(_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, newValue, day, modifiers, e);
|
|
32
|
-
};
|
|
33
|
-
var modifiers = {
|
|
34
|
-
selected: [],
|
|
35
|
-
range_start: [],
|
|
36
|
-
range_end: [],
|
|
37
|
-
range_middle: [],
|
|
38
|
-
disabled: []
|
|
39
|
-
};
|
|
40
|
-
if (selected) {
|
|
41
|
-
modifiers.selected = [selected];
|
|
42
|
-
if (selected.from) {
|
|
43
|
-
modifiers.range_start = [selected.from];
|
|
44
|
-
if (selected.to) {
|
|
45
|
-
modifiers.range_middle = [
|
|
46
|
-
{
|
|
47
|
-
after: selected.from,
|
|
48
|
-
before: selected.to
|
|
49
|
-
}
|
|
50
|
-
];
|
|
51
|
-
if (max || min) {
|
|
52
|
-
modifiers.disabled = [
|
|
53
|
-
function (date) {
|
|
54
|
-
if (max &&
|
|
55
|
-
selected.to &&
|
|
56
|
-
selected.from &&
|
|
57
|
-
isBefore(date, selected.from)) {
|
|
58
|
-
var diff = differenceInCalendarDays(selected.to, date);
|
|
59
|
-
if (diff >= max) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (max &&
|
|
64
|
-
selected.to &&
|
|
65
|
-
selected.from &&
|
|
66
|
-
isAfter(date, selected.to)) {
|
|
67
|
-
var diff = differenceInCalendarDays(date, selected.from);
|
|
68
|
-
if (diff >= max) {
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (min && selected.from && isBefore(date, selected.from)) {
|
|
73
|
-
var diff = differenceInCalendarDays(selected.from, date);
|
|
74
|
-
if (diff < min) {
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (min &&
|
|
79
|
-
selected.to &&
|
|
80
|
-
selected.from &&
|
|
81
|
-
isAfter(date, selected.to)) {
|
|
82
|
-
var diff = differenceInCalendarDays(date, selected.from);
|
|
83
|
-
if (diff < min) {
|
|
84
|
-
return true;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
];
|
|
90
|
-
}
|
|
91
|
-
modifiers.range_end = [selected.to];
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
modifiers.range_end = [selected.from];
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return (React.createElement(SelectRangeContext.Provider, { value: { selected: selected, handleDayClick: handleDayClick, modifiers: modifiers } }, children));
|
|
99
|
-
}
|
|
100
7
|
/** Provides the values for the [[SelectRangeProvider]]. */
|
|
101
8
|
function SelectRangeProvider(props) {
|
|
102
9
|
if (!isDayPickerRange(props.initialProps)) {
|
|
@@ -115,5 +22,5 @@ function SelectRangeProvider(props) {
|
|
|
115
22
|
return (React.createElement(SelectRangeProviderInternal, { initialProps: props.initialProps, children: props.children }));
|
|
116
23
|
}
|
|
117
24
|
|
|
118
|
-
export { SelectRangeProvider
|
|
25
|
+
export { SelectRangeProvider };
|
|
119
26
|
//# sourceMappingURL=SelectRangeProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectRangeProvider.js","sources":["../../../src/contexts/SelectRange/SelectRangeProvider.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {
|
|
1
|
+
{"version":3,"file":"SelectRangeProvider.js","sources":["../../../src/contexts/SelectRange/SelectRangeProvider.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { DayPickerProps, isDayPickerRange } from '../../types';\n\nimport { SelectRangeContext } from './SelectRangeContext';\nimport { SelectRangeContextValue } from '.';\nimport { SelectRangeProviderInternal } from './SelectRangeProviderInternal';\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"],"names":[],"mappings":";;;;;;AAaA;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;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { DayPickerRangeProps } from '../../types';
|
|
3
|
+
declare type SelectRangeProviderInternalProps = {
|
|
4
|
+
initialProps: DayPickerRangeProps;
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
};
|
|
7
|
+
export declare function SelectRangeProviderInternal({ initialProps, children }: SelectRangeProviderInternalProps): JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { differenceInCalendarDays, isBefore, isAfter } from 'date-fns';
|
|
3
|
+
import { SelectRangeContext } from './SelectRangeContext.js';
|
|
4
|
+
import { addToRange } from './utils/addToRange.js';
|
|
5
|
+
|
|
6
|
+
function SelectRangeProviderInternal(_a) {
|
|
7
|
+
var initialProps = _a.initialProps, children = _a.children;
|
|
8
|
+
var selected = initialProps.selected;
|
|
9
|
+
var min = initialProps.min;
|
|
10
|
+
var max = initialProps.max;
|
|
11
|
+
var handleDayClick = function (day, modifiers, e) {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
(_a = initialProps.onDayClick) === null || _a === void 0 ? void 0 : _a.call(initialProps, day, modifiers, e);
|
|
14
|
+
var newValue = addToRange(day, selected);
|
|
15
|
+
if ((min || max) &&
|
|
16
|
+
selected &&
|
|
17
|
+
(newValue === null || newValue === void 0 ? void 0 : newValue.to) &&
|
|
18
|
+
newValue.from &&
|
|
19
|
+
newValue.from !== newValue.to) {
|
|
20
|
+
var diff = Math.abs(differenceInCalendarDays(newValue === null || newValue === void 0 ? void 0 : newValue.to, newValue === null || newValue === void 0 ? void 0 : newValue.from));
|
|
21
|
+
if (min && diff < min) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (max && diff >= max) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
(_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, newValue, day, modifiers, e);
|
|
29
|
+
};
|
|
30
|
+
var modifiers = {
|
|
31
|
+
selected: [],
|
|
32
|
+
range_start: [],
|
|
33
|
+
range_end: [],
|
|
34
|
+
range_middle: [],
|
|
35
|
+
disabled: []
|
|
36
|
+
};
|
|
37
|
+
if (selected) {
|
|
38
|
+
modifiers.selected = [selected];
|
|
39
|
+
if (selected.from) {
|
|
40
|
+
modifiers.range_start = [selected.from];
|
|
41
|
+
if (selected.to) {
|
|
42
|
+
modifiers.range_middle = [
|
|
43
|
+
{
|
|
44
|
+
after: selected.from,
|
|
45
|
+
before: selected.to
|
|
46
|
+
}
|
|
47
|
+
];
|
|
48
|
+
if (max || min) {
|
|
49
|
+
modifiers.disabled = [
|
|
50
|
+
function (date) {
|
|
51
|
+
if (max &&
|
|
52
|
+
selected.to &&
|
|
53
|
+
selected.from &&
|
|
54
|
+
isBefore(date, selected.from)) {
|
|
55
|
+
var diff = differenceInCalendarDays(selected.to, date);
|
|
56
|
+
if (diff >= max) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (max &&
|
|
61
|
+
selected.to &&
|
|
62
|
+
selected.from &&
|
|
63
|
+
isAfter(date, selected.to)) {
|
|
64
|
+
var diff = differenceInCalendarDays(date, selected.from);
|
|
65
|
+
if (diff >= max) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (min && selected.from && isBefore(date, selected.from)) {
|
|
70
|
+
var diff = differenceInCalendarDays(selected.from, date);
|
|
71
|
+
if (diff < min) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (min &&
|
|
76
|
+
selected.to &&
|
|
77
|
+
selected.from &&
|
|
78
|
+
isAfter(date, selected.to)) {
|
|
79
|
+
var diff = differenceInCalendarDays(date, selected.from);
|
|
80
|
+
if (diff < min) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
modifiers.range_end = [selected.to];
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
modifiers.range_end = [selected.from];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return (React.createElement(SelectRangeContext.Provider, { value: { selected: selected, handleDayClick: handleDayClick, modifiers: modifiers } }, children));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { SelectRangeProviderInternal };
|
|
99
|
+
//# sourceMappingURL=SelectRangeProviderInternal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectRangeProviderInternal.js","sources":["../../../src/contexts/SelectRange/SelectRangeProviderInternal.tsx"],"sourcesContent":["import * as React from 'react';\nimport { differenceInCalendarDays, isAfter, isBefore } from 'date-fns';\nimport { DayClickEventHandler, DayPickerRangeProps } from '../../types';\nimport { SelectRangeContext, SelectRangeModifiers } from './SelectRangeContext';\nimport { addToRange } from './utils/addToRange';\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 handleDayClick: 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\n value={{ selected, handleDayClick, modifiers }}\n >\n {children}\n </SelectRangeContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;;;SAWgB,2BAA2B,CAAC,EAGT;QAFjC,YAAY,kBAAA,EACZ,QAAQ,cAAA;IAEA,IAAA,QAAQ,GAAK,YAAY,SAAjB,CAAkB;IAClC,IAAM,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC;IAC7B,IAAM,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC;IAE7B,IAAM,cAAc,GAAyB,UAAC,GAAG,EAAE,SAAS,EAAE,CAAC;;QAC7D,MAAA,YAAY,CAAC,UAAU,+CAAvB,YAAY,EAAc,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;QAC7C,IAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAC3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gBACL,SAAS,CAAC,SAAS,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;aACvC;SACF;KACF;IACD,QACE,oBAAC,kBAAkB,CAAC,QAAQ,IAC1B,KAAK,EAAE,EAAE,QAAQ,UAAA,EAAE,cAAc,gBAAA,EAAE,SAAS,WAAA,EAAE,IAE7C,QAAQ,CACmB,EAC9B;AACJ;;;;"}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
export declare function SelectSingleProviderInternal({ initialProps, children }: {
|
|
4
|
-
initialProps: DayPickerBase & DayPickerSingle;
|
|
5
|
-
children: React.ReactNode;
|
|
6
|
-
}): JSX.Element;
|
|
2
|
+
import { DayPickerProps } from '../../types';
|
|
7
3
|
declare type SelectSingleProviderProps = {
|
|
8
4
|
initialProps: DayPickerProps;
|
|
9
5
|
children: React.ReactNode;
|
|
@@ -1,33 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { useControlledValue } from '../../hooks/useControlledValue/useControlledValue.js';
|
|
3
2
|
import 'date-fns';
|
|
4
3
|
import { isDayPickerSingle } from '../../types/isDayPickerSingle.js';
|
|
5
4
|
import { SelectSingleContext } from './SelectSingleContext.js';
|
|
5
|
+
import { SelectSingleProviderInternal } from './SelectSingleProviderInternal.js';
|
|
6
6
|
|
|
7
|
-
function SelectSingleProviderInternal(_a) {
|
|
8
|
-
var initialProps = _a.initialProps, children = _a.children;
|
|
9
|
-
var _b = useControlledValue(initialProps.defaultSelected, initialProps.selected), selected = _b[0], setSelected = _b[1];
|
|
10
|
-
var handleDayClick = function (day, dayModifiers, e) {
|
|
11
|
-
var _a, _b;
|
|
12
|
-
if (dayModifiers.selected && !initialProps.required) {
|
|
13
|
-
setSelected(undefined);
|
|
14
|
-
(_a = initialProps.onSelect) === null || _a === void 0 ? void 0 : _a.call(initialProps, undefined, day, dayModifiers, e);
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
setSelected(day);
|
|
18
|
-
(_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, day, day, dayModifiers, e);
|
|
19
|
-
};
|
|
20
|
-
var modifiers = { selected: [] };
|
|
21
|
-
if (selected) {
|
|
22
|
-
modifiers.selected = [selected];
|
|
23
|
-
}
|
|
24
|
-
var contextValue = {
|
|
25
|
-
selected: selected,
|
|
26
|
-
handleDayClick: handleDayClick,
|
|
27
|
-
modifiers: modifiers
|
|
28
|
-
};
|
|
29
|
-
return (React.createElement(SelectSingleContext.Provider, { value: contextValue }, children));
|
|
30
|
-
}
|
|
31
7
|
/** Provides the values for the [[SelectSingleProvider]]. */
|
|
32
8
|
function SelectSingleProvider(props) {
|
|
33
9
|
if (!isDayPickerSingle(props.initialProps)) {
|
|
@@ -40,5 +16,5 @@ function SelectSingleProvider(props) {
|
|
|
40
16
|
return (React.createElement(SelectSingleProviderInternal, { initialProps: props.initialProps, children: props.children }));
|
|
41
17
|
}
|
|
42
18
|
|
|
43
|
-
export { SelectSingleProvider
|
|
19
|
+
export { SelectSingleProvider };
|
|
44
20
|
//# sourceMappingURL=SelectSingleProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectSingleProvider.js","sources":["../../../src/contexts/SelectSingle/SelectSingleProvider.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {
|
|
1
|
+
{"version":3,"file":"SelectSingleProvider.js","sources":["../../../src/contexts/SelectSingle/SelectSingleProvider.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { DayPickerProps, isDayPickerSingle } from '../../types';\nimport { SelectSingleContextValue } from './';\nimport { SelectSingleContext } from './SelectSingleContext';\nimport { SelectSingleProviderInternal } from './SelectSingleProviderInternal';\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"],"names":[],"mappings":";;;;;;AAYA;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;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { DayPickerSingleProps } from '../../types';
|
|
3
|
+
declare type SelectSingleProviderInternal = {
|
|
4
|
+
initialProps: DayPickerSingleProps;
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
};
|
|
7
|
+
export declare function SelectSingleProviderInternal({ initialProps, children }: SelectSingleProviderInternal): JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { SelectSingleContext } from './SelectSingleContext.js';
|
|
3
|
+
|
|
4
|
+
function SelectSingleProviderInternal(_a) {
|
|
5
|
+
var initialProps = _a.initialProps, children = _a.children;
|
|
6
|
+
var handleDayClick = function (day, dayModifiers, e) {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
if (dayModifiers.selected && !initialProps.required) {
|
|
9
|
+
(_a = initialProps.onSelect) === null || _a === void 0 ? void 0 : _a.call(initialProps, undefined, day, dayModifiers, e);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
(_b = initialProps.onSelect) === null || _b === void 0 ? void 0 : _b.call(initialProps, day, day, dayModifiers, e);
|
|
13
|
+
};
|
|
14
|
+
var modifiers = { selected: [] };
|
|
15
|
+
if (initialProps.selected) {
|
|
16
|
+
modifiers.selected = [initialProps.selected];
|
|
17
|
+
}
|
|
18
|
+
var contextValue = {
|
|
19
|
+
selected: initialProps.selected,
|
|
20
|
+
handleDayClick: handleDayClick,
|
|
21
|
+
modifiers: modifiers
|
|
22
|
+
};
|
|
23
|
+
return (React.createElement(SelectSingleContext.Provider, { value: contextValue }, children));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { SelectSingleProviderInternal };
|
|
27
|
+
//# sourceMappingURL=SelectSingleProviderInternal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectSingleProviderInternal.js","sources":["../../../src/contexts/SelectSingle/SelectSingleProviderInternal.tsx"],"sourcesContent":["import * as React from 'react';\nimport { DayClickEventHandler, DayPickerSingleProps } from '../../types';\nimport { SelectSingleContextValue } from './';\nimport {\n SelectSingleContext,\n SelectSingleModifiers\n} from './SelectSingleContext';\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 handleDayClick: 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 handleDayClick,\n modifiers\n };\n return (\n <SelectSingleContext.Provider value={contextValue}>\n {children}\n </SelectSingleContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;SAagB,4BAA4B,CAAC,EAGd;QAF7B,YAAY,kBAAA,EACZ,QAAQ,cAAA;IAER,IAAM,cAAc,GAAyB,UAAC,GAAG,EAAE,YAAY,EAAE,CAAC;;QAChE,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,cAAc,gBAAA;QACd,SAAS,WAAA;KACV,CAAC;IACF,QACE,oBAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,IAC9C,QAAQ,CACoB,EAC/B;AACJ;;;;"}
|
|
@@ -1,4 +1,49 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
/**
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { DayClickEventHandler, DayPickerProps, MonthChangeEventHandler } from '../../types';
|
|
3
|
+
/** Represent the props to attach to the input field. */
|
|
4
|
+
export interface UseInputFieldProps {
|
|
5
|
+
/** Event handler for the blur event. */
|
|
6
|
+
onBlur: React.FocusEventHandler;
|
|
7
|
+
/** Event handler for the change event. */
|
|
8
|
+
onChange: React.ChangeEventHandler<HTMLInputElement>;
|
|
9
|
+
/** Event handler for the focus event. */
|
|
10
|
+
onFocus: React.FocusEventHandler;
|
|
11
|
+
/** The value of the input field */
|
|
12
|
+
value: string;
|
|
13
|
+
/** The input field placeholder */
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Represent the props to attach to DayPicker component. */
|
|
17
|
+
export interface UseInputDayPickerProps {
|
|
18
|
+
mode: 'custom';
|
|
19
|
+
fromDate?: Date;
|
|
20
|
+
locale: Locale;
|
|
21
|
+
min: number;
|
|
22
|
+
month: Date;
|
|
23
|
+
onDayClick: DayClickEventHandler;
|
|
24
|
+
onMonthChange: MonthChangeEventHandler;
|
|
25
|
+
selected: Date | undefined;
|
|
26
|
+
toDate?: Date;
|
|
27
|
+
today: Date;
|
|
28
|
+
}
|
|
29
|
+
export interface UseInputOptions extends Pick<DayPickerProps, 'locale' | 'fromDate' | 'toDate' | 'fromMonth' | 'toMonth' | 'fromYear' | 'toYear' | 'today'> {
|
|
30
|
+
/** The initially selected date */
|
|
31
|
+
defaultSelected?: Date;
|
|
32
|
+
/** The format string for formatting the input field. See https://date-fns.org/docs/format for a list of format strings. Default to `PP`. */
|
|
33
|
+
format?: string;
|
|
34
|
+
/** Make the selection required. */
|
|
35
|
+
required?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** Represent the value returned by [[useInput]]. */
|
|
38
|
+
export interface UseInput {
|
|
39
|
+
/** The props to pass to a DayPicker component: `<DayPicker {...dayPickerProps} />` */
|
|
40
|
+
dayPickerProps: UseInputDayPickerProps;
|
|
41
|
+
/** The props to pass to an input field: `<input {...inputProps} />` */
|
|
42
|
+
inputProps: UseInputFieldProps;
|
|
43
|
+
/** A function to reset to the initial state. */
|
|
44
|
+
reset: () => void;
|
|
45
|
+
/** A function to set the selected day. */
|
|
46
|
+
setSelected: (day: Date) => void;
|
|
47
|
+
}
|
|
48
|
+
/** Return props and setters for binding an input field to DayPicker. */
|
|
4
49
|
export declare function useInput(options?: UseInputOptions): UseInput;
|
|
@@ -4,11 +4,10 @@ import enUS from 'date-fns/locale/en-US';
|
|
|
4
4
|
import { parseFromToProps } from '../../contexts/DayPicker/utils/parseFromToProps.js';
|
|
5
5
|
import { isValidDate } from './utils/isValidDate.js';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
/** Return props for binding an input field to DayPicker. */
|
|
7
|
+
/** Return props and setters for binding an input field to DayPicker. */
|
|
9
8
|
function useInput(options) {
|
|
10
9
|
if (options === void 0) { options = {}; }
|
|
11
|
-
var _a = options.locale, locale = _a === void 0 ? enUS : _a, required = options.required, _b = options.format, format$1 = _b === void 0 ?
|
|
10
|
+
var _a = options.locale, locale = _a === void 0 ? enUS : _a, required = options.required, _b = options.format, format$1 = _b === void 0 ? 'PP' : _b, defaultSelected = options.defaultSelected, _c = options.today, today = _c === void 0 ? new Date() : _c;
|
|
12
11
|
var _d = parseFromToProps(options), fromDate = _d.fromDate, toDate = _d.toDate;
|
|
13
12
|
var min = required ? 1 : 0;
|
|
14
13
|
// Shortcut to the DateFns functions
|
|
@@ -90,13 +89,14 @@ function useInput(options) {
|
|
|
90
89
|
today: today,
|
|
91
90
|
min: min
|
|
92
91
|
};
|
|
93
|
-
var
|
|
92
|
+
var inputProps = {
|
|
94
93
|
onBlur: handleBlur,
|
|
95
94
|
onChange: handleChange,
|
|
96
95
|
onFocus: handleFocus,
|
|
97
|
-
value: inputValue
|
|
96
|
+
value: inputValue,
|
|
97
|
+
placeholder: format(new Date(), format$1, { locale: locale })
|
|
98
98
|
};
|
|
99
|
-
return { dayPickerProps: dayPickerProps,
|
|
99
|
+
return { dayPickerProps: dayPickerProps, inputProps: inputProps, reset: reset, setSelected: setSelected };
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
export { useInput };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInput.js","sources":["../../../src/hooks/useInput/useInput.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { differenceInCalendarDays, format as _format, parse } from 'date-fns';\nimport enUS from 'date-fns/locale/en-US';\n\nimport {
|
|
1
|
+
{"version":3,"file":"useInput.js","sources":["../../../src/hooks/useInput/useInput.ts"],"sourcesContent":["import * as 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 {\n DayClickEventHandler,\n DayPickerProps,\n MonthChangeEventHandler\n} from '../../types';\nimport { isValidDate } from './utils/isValidDate';\n\n/** Represent the props to attach to the input field. */\nexport interface UseInputFieldProps {\n /** Event handler for the blur event. */\n onBlur: React.FocusEventHandler;\n /** Event handler for the change event. */\n onChange: React.ChangeEventHandler<HTMLInputElement>;\n /** Event handler for the focus event. */\n onFocus: React.FocusEventHandler;\n /** The value of the input field */\n value: string;\n /** The input field placeholder */\n placeholder?: string;\n}\n\n/** Represent the props to attach to DayPicker component. */\nexport interface UseInputDayPickerProps {\n mode: 'custom';\n fromDate?: Date;\n locale: Locale;\n min: number;\n month: Date;\n onDayClick: DayClickEventHandler;\n onMonthChange: MonthChangeEventHandler;\n selected: Date | undefined;\n toDate?: Date;\n today: Date;\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: `<DayPicker {...dayPickerProps} />` */\n dayPickerProps: UseInputDayPickerProps;\n /** The props to pass to an input field: `<input {...inputProps} />` */\n inputProps: UseInputFieldProps;\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 const min = required ? 1 : 0;\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: UseInputDayPickerProps = {\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 min\n };\n\n const inputProps: UseInputFieldProps = {\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":";;;;;;AAyEA;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;IAEvD,IAAM,GAAG,GAAG,QAAQ,GAAG,CAAC,GAAG,CAAC,CAAC;;IAG7B,IAAM,UAAU,GAAG,UAAC,KAAa,IAAK,OAAA,KAAK,CAAC,KAAK,EAAEA,QAAM,EAAE,KAAK,EAAE,EAAE,MAAM,QAAA,EAAE,CAAC,GAAA,CAAC;;IAGxE,IAAA,KAAoB,KAAK,CAAC,QAAQ,CAAC,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,KAAK,CAAC,EAA3D,KAAK,QAAA,EAAE,QA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AAQ;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;QACL,GAAG,KAAA;KACJ,CAAC;IAEF,IAAM,UAAU,GAAuB;QACrC,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;;;;"}
|
package/build/main.js
CHANGED
|
@@ -9,8 +9,8 @@ export { Dropdown } from './components/Dropdown/Dropdown.js';
|
|
|
9
9
|
export { Footer } from './components/Footer/Footer.js';
|
|
10
10
|
export { Head } from './components/Head/Head.js';
|
|
11
11
|
export { IconDropdown } from './components/IconDropdown/IconDropdown.js';
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
12
|
+
export { IconRight } from './components/IconRight/IconRight.js';
|
|
13
|
+
export { IconLeft } from './components/IconLeft/IconLeft.js';
|
|
14
14
|
export { MonthsDropdown } from './components/MonthsDropdown/MonthsDropdown.js';
|
|
15
15
|
export { Navigation } from './components/Navigation/Navigation.js';
|
|
16
16
|
export { Root } from './components/Root/Root.js';
|
|
@@ -30,10 +30,10 @@ export { SelectMultipleContext } from './contexts/SelectMultiple/SelectMultipleC
|
|
|
30
30
|
export { SelectMultipleProvider } from './contexts/SelectMultiple/SelectMultipleProvider.js';
|
|
31
31
|
export { useSelectMultiple } from './contexts/SelectMultiple/useSelectMultiple.js';
|
|
32
32
|
export { SelectRangeContext } from './contexts/SelectRange/SelectRangeContext.js';
|
|
33
|
-
export { SelectRangeProvider
|
|
33
|
+
export { SelectRangeProvider } from './contexts/SelectRange/SelectRangeProvider.js';
|
|
34
34
|
export { useSelectRange } from './contexts/SelectRange/useSelectRange.js';
|
|
35
35
|
export { SelectSingleContext } from './contexts/SelectSingle/SelectSingleContext.js';
|
|
36
|
-
export { SelectSingleProvider
|
|
36
|
+
export { SelectSingleProvider } from './contexts/SelectSingle/SelectSingleProvider.js';
|
|
37
37
|
export { useSelectSingle } from './contexts/SelectSingle/useSelectSingle.js';
|
|
38
38
|
export { isArrayOfDates } from './types/isArrayOfDates.js';
|
|
39
39
|
export { isDateAfterType } from './types/isDateAfterType.js';
|