@fluentui/react-datepicker-compat 0.1.4 → 0.1.6
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.json +169 -1
- package/CHANGELOG.md +43 -2
- package/dist/index.d.ts +4 -1
- package/lib/Calendar.js +0 -1
- package/lib/Calendar.js.map +1 -1
- package/lib/CalendarDay.js +0 -1
- package/lib/CalendarDay.js.map +1 -1
- package/lib/CalendarDayGrid.js +0 -1
- package/lib/CalendarDayGrid.js.map +1 -1
- package/lib/CalendarMonth.js +0 -1
- package/lib/CalendarMonth.js.map +1 -1
- package/lib/CalendarPicker.js +0 -1
- package/lib/CalendarPicker.js.map +1 -1
- package/lib/CalendarYear.js +0 -1
- package/lib/CalendarYear.js.map +1 -1
- package/lib/DatePicker.js +0 -1
- package/lib/DatePicker.js.map +1 -1
- package/lib/components/Calendar/Calendar.js +278 -300
- package/lib/components/Calendar/Calendar.js.map +1 -1
- package/lib/components/Calendar/Calendar.types.js +7 -12
- package/lib/components/Calendar/Calendar.types.js.map +1 -1
- package/lib/components/Calendar/defaults.js +0 -1
- package/lib/components/Calendar/defaults.js.map +1 -1
- package/lib/components/Calendar/index.js +0 -1
- package/lib/components/Calendar/index.js.map +1 -1
- package/lib/components/Calendar/useCalendarStyles.styles.js.map +1 -1
- package/lib/components/CalendarDay/CalendarDay.js +100 -128
- package/lib/components/CalendarDay/CalendarDay.js.map +1 -1
- package/lib/components/CalendarDay/CalendarDay.types.js +0 -1
- package/lib/components/CalendarDay/CalendarDay.types.js.map +1 -1
- package/lib/components/CalendarDay/index.js +0 -1
- package/lib/components/CalendarDay/index.js.map +1 -1
- package/lib/components/CalendarDay/useCalendarDayStyles.styles.js.map +1 -1
- package/lib/components/CalendarDayGrid/CalendarDayGrid.js +146 -159
- package/lib/components/CalendarDayGrid/CalendarDayGrid.js.map +1 -1
- package/lib/components/CalendarDayGrid/CalendarDayGrid.types.js +0 -1
- package/lib/components/CalendarDayGrid/CalendarDayGrid.types.js.map +1 -1
- package/lib/components/CalendarDayGrid/CalendarGridDayCell.js +150 -179
- package/lib/components/CalendarDayGrid/CalendarGridDayCell.js.map +1 -1
- package/lib/components/CalendarDayGrid/CalendarGridRow.js +20 -34
- package/lib/components/CalendarDayGrid/CalendarGridRow.js.map +1 -1
- package/lib/components/CalendarDayGrid/CalendarMonthHeaderRow.js +29 -39
- package/lib/components/CalendarDayGrid/CalendarMonthHeaderRow.js.map +1 -1
- package/lib/components/CalendarDayGrid/index.js +0 -1
- package/lib/components/CalendarDayGrid/index.js.map +1 -1
- package/lib/components/CalendarDayGrid/useCalendarDayGridStyles.styles.js.map +1 -1
- package/lib/components/CalendarDayGrid/useWeekCornerStyles.styles.js.map +1 -1
- package/lib/components/CalendarDayGrid/useWeeks.js +34 -36
- package/lib/components/CalendarDayGrid/useWeeks.js.map +1 -1
- package/lib/components/CalendarMonth/CalendarMonth.js +238 -258
- package/lib/components/CalendarMonth/CalendarMonth.js.map +1 -1
- package/lib/components/CalendarMonth/CalendarMonth.types.js +0 -1
- package/lib/components/CalendarMonth/CalendarMonth.types.js.map +1 -1
- package/lib/components/CalendarMonth/index.js +0 -1
- package/lib/components/CalendarMonth/index.js.map +1 -1
- package/lib/components/CalendarMonth/useCalendarMonthStyles.js +2 -4
- package/lib/components/CalendarMonth/useCalendarMonthStyles.js.map +1 -1
- package/lib/components/CalendarPicker/CalendarPicker.types.js +1 -2
- package/lib/components/CalendarPicker/CalendarPicker.types.js.map +1 -1
- package/lib/components/CalendarPicker/index.js +0 -1
- package/lib/components/CalendarPicker/index.js.map +1 -1
- package/lib/components/CalendarPicker/useCalendarPickerStyles.styles.js.map +1 -1
- package/lib/components/CalendarYear/CalendarYear.js +260 -312
- package/lib/components/CalendarYear/CalendarYear.js.map +1 -1
- package/lib/components/CalendarYear/CalendarYear.types.js +0 -1
- package/lib/components/CalendarYear/CalendarYear.types.js.map +1 -1
- package/lib/components/CalendarYear/index.js +0 -1
- package/lib/components/CalendarYear/index.js.map +1 -1
- package/lib/components/CalendarYear/useCalendarYearStyles.styles.js.map +1 -1
- package/lib/components/DatePicker/DatePicker.js +4 -5
- package/lib/components/DatePicker/DatePicker.js.map +1 -1
- package/lib/components/DatePicker/DatePicker.types.js +0 -1
- package/lib/components/DatePicker/DatePicker.types.js.map +1 -1
- package/lib/components/DatePicker/defaults.js +9 -10
- package/lib/components/DatePicker/defaults.js.map +1 -1
- package/lib/components/DatePicker/index.js +0 -1
- package/lib/components/DatePicker/index.js.map +1 -1
- package/lib/components/DatePicker/renderDatePicker.js +5 -12
- package/lib/components/DatePicker/renderDatePicker.js.map +1 -1
- package/lib/components/DatePicker/useDatePicker.js +402 -354
- package/lib/components/DatePicker/useDatePicker.js.map +1 -1
- package/lib/components/DatePicker/useDatePickerStyles.styles.js.map +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/utils/animations.js +72 -73
- package/lib/utils/animations.js.map +1 -1
- package/lib/utils/constants.js +50 -52
- package/lib/utils/constants.js.map +1 -1
- package/lib/utils/dateFormatting/dateFormatting.defaults.js +71 -34
- package/lib/utils/dateFormatting/dateFormatting.defaults.js.map +1 -1
- package/lib/utils/dateFormatting/dateFormatting.types.js +1 -2
- package/lib/utils/dateFormatting/dateFormatting.types.js.map +1 -1
- package/lib/utils/dateFormatting/index.js +0 -1
- package/lib/utils/dateFormatting/index.js.map +1 -1
- package/lib/utils/dateGrid/dateGrid.types.js +1 -2
- package/lib/utils/dateGrid/dateGrid.types.js.map +1 -1
- package/lib/utils/dateGrid/findAvailableDate.js +14 -21
- package/lib/utils/dateGrid/findAvailableDate.js.map +1 -1
- package/lib/utils/dateGrid/getBoundedDateRange.js +11 -11
- package/lib/utils/dateGrid/getBoundedDateRange.js.map +1 -1
- package/lib/utils/dateGrid/getDateRangeTypeToUse.js +6 -8
- package/lib/utils/dateGrid/getDateRangeTypeToUse.js.map +1 -1
- package/lib/utils/dateGrid/getDayGrid.js +59 -73
- package/lib/utils/dateGrid/getDayGrid.js.map +1 -1
- package/lib/utils/dateGrid/index.js +0 -1
- package/lib/utils/dateGrid/index.js.map +1 -1
- package/lib/utils/dateGrid/isAfterMaxDate.js +3 -7
- package/lib/utils/dateGrid/isAfterMaxDate.js.map +1 -1
- package/lib/utils/dateGrid/isBeforeMinDate.js +3 -7
- package/lib/utils/dateGrid/isBeforeMinDate.js.map +1 -1
- package/lib/utils/dateGrid/isContiguous.js +11 -12
- package/lib/utils/dateGrid/isContiguous.js.map +1 -1
- package/lib/utils/dateGrid/isRestrictedDate.js +7 -13
- package/lib/utils/dateGrid/isRestrictedDate.js.map +1 -1
- package/lib/utils/dateMath/dateMath.js +179 -198
- package/lib/utils/dateMath/dateMath.js.map +1 -1
- package/lib/utils/dateMath/index.js +0 -1
- package/lib/utils/dateMath/index.js.map +1 -1
- package/lib/utils/dom.js +5 -6
- package/lib/utils/dom.js.map +1 -1
- package/lib/utils/focus.js +17 -19
- package/lib/utils/focus.js.map +1 -1
- package/lib/utils/index.js +0 -1
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/usePopupPositioning.js +12 -16
- package/lib/utils/usePopupPositioning.js.map +1 -1
- package/lib-commonjs/Calendar.js +0 -3
- package/lib-commonjs/Calendar.js.map +1 -1
- package/lib-commonjs/CalendarDay.js +0 -3
- package/lib-commonjs/CalendarDay.js.map +1 -1
- package/lib-commonjs/CalendarDayGrid.js +0 -3
- package/lib-commonjs/CalendarDayGrid.js.map +1 -1
- package/lib-commonjs/CalendarMonth.js +0 -3
- package/lib-commonjs/CalendarMonth.js.map +1 -1
- package/lib-commonjs/CalendarPicker.js +0 -3
- package/lib-commonjs/CalendarPicker.js.map +1 -1
- package/lib-commonjs/CalendarYear.js +0 -3
- package/lib-commonjs/CalendarYear.js.map +1 -1
- package/lib-commonjs/DatePicker.js +0 -3
- package/lib-commonjs/DatePicker.js.map +1 -1
- package/lib-commonjs/components/Calendar/Calendar.js +1 -3
- package/lib-commonjs/components/Calendar/Calendar.js.map +1 -1
- package/lib-commonjs/components/Calendar/Calendar.types.js +5 -7
- package/lib-commonjs/components/Calendar/Calendar.types.js.map +1 -1
- package/lib-commonjs/components/Calendar/defaults.js +1 -3
- package/lib-commonjs/components/Calendar/defaults.js.map +1 -1
- package/lib-commonjs/components/Calendar/index.js +0 -3
- package/lib-commonjs/components/Calendar/index.js.map +1 -1
- package/lib-commonjs/components/Calendar/useCalendarStyles.styles.js +0 -2
- package/lib-commonjs/components/Calendar/useCalendarStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CalendarDay/CalendarDay.js +1 -3
- package/lib-commonjs/components/CalendarDay/CalendarDay.js.map +1 -1
- package/lib-commonjs/components/CalendarDay/CalendarDay.types.js +0 -3
- package/lib-commonjs/components/CalendarDay/CalendarDay.types.js.map +1 -1
- package/lib-commonjs/components/CalendarDay/index.js +0 -3
- package/lib-commonjs/components/CalendarDay/index.js.map +1 -1
- package/lib-commonjs/components/CalendarDay/useCalendarDayStyles.styles.js +0 -2
- package/lib-commonjs/components/CalendarDay/useCalendarDayStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/CalendarDayGrid.js +7 -9
- package/lib-commonjs/components/CalendarDayGrid/CalendarDayGrid.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/CalendarDayGrid.types.js +0 -3
- package/lib-commonjs/components/CalendarDayGrid/CalendarDayGrid.types.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/CalendarGridDayCell.js +1 -3
- package/lib-commonjs/components/CalendarDayGrid/CalendarGridDayCell.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/CalendarGridRow.js +1 -3
- package/lib-commonjs/components/CalendarDayGrid/CalendarGridRow.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/CalendarMonthHeaderRow.js +1 -3
- package/lib-commonjs/components/CalendarDayGrid/CalendarMonthHeaderRow.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/index.js +0 -3
- package/lib-commonjs/components/CalendarDayGrid/index.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/useCalendarDayGridStyles.styles.js +0 -2
- package/lib-commonjs/components/CalendarDayGrid/useCalendarDayGridStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/useWeekCornerStyles.styles.js +0 -2
- package/lib-commonjs/components/CalendarDayGrid/useWeekCornerStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/useWeeks.js +9 -11
- package/lib-commonjs/components/CalendarDayGrid/useWeeks.js.map +1 -1
- package/lib-commonjs/components/CalendarMonth/CalendarMonth.js +1 -3
- package/lib-commonjs/components/CalendarMonth/CalendarMonth.js.map +1 -1
- package/lib-commonjs/components/CalendarMonth/CalendarMonth.types.js +0 -3
- package/lib-commonjs/components/CalendarMonth/CalendarMonth.types.js.map +1 -1
- package/lib-commonjs/components/CalendarMonth/index.js +0 -3
- package/lib-commonjs/components/CalendarMonth/index.js.map +1 -1
- package/lib-commonjs/components/CalendarMonth/useCalendarMonthStyles.js +1 -3
- package/lib-commonjs/components/CalendarMonth/useCalendarMonthStyles.js.map +1 -1
- package/lib-commonjs/components/CalendarPicker/CalendarPicker.types.js +0 -3
- package/lib-commonjs/components/CalendarPicker/CalendarPicker.types.js.map +1 -1
- package/lib-commonjs/components/CalendarPicker/index.js +0 -3
- package/lib-commonjs/components/CalendarPicker/index.js.map +1 -1
- package/lib-commonjs/components/CalendarPicker/useCalendarPickerStyles.styles.js +0 -2
- package/lib-commonjs/components/CalendarPicker/useCalendarPickerStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CalendarYear/CalendarYear.js +1 -3
- package/lib-commonjs/components/CalendarYear/CalendarYear.js.map +1 -1
- package/lib-commonjs/components/CalendarYear/CalendarYear.types.js +0 -3
- package/lib-commonjs/components/CalendarYear/CalendarYear.types.js.map +1 -1
- package/lib-commonjs/components/CalendarYear/index.js +0 -3
- package/lib-commonjs/components/CalendarYear/index.js.map +1 -1
- package/lib-commonjs/components/CalendarYear/useCalendarYearStyles.styles.js +0 -2
- package/lib-commonjs/components/CalendarYear/useCalendarYearStyles.styles.js.map +1 -1
- package/lib-commonjs/components/DatePicker/DatePicker.js +1 -3
- package/lib-commonjs/components/DatePicker/DatePicker.js.map +1 -1
- package/lib-commonjs/components/DatePicker/DatePicker.types.js +0 -3
- package/lib-commonjs/components/DatePicker/DatePicker.types.js.map +1 -1
- package/lib-commonjs/components/DatePicker/defaults.js +1 -3
- package/lib-commonjs/components/DatePicker/defaults.js.map +1 -1
- package/lib-commonjs/components/DatePicker/index.js +0 -3
- package/lib-commonjs/components/DatePicker/index.js.map +1 -1
- package/lib-commonjs/components/DatePicker/renderDatePicker.js +1 -3
- package/lib-commonjs/components/DatePicker/renderDatePicker.js.map +1 -1
- package/lib-commonjs/components/DatePicker/useDatePicker.js +14 -17
- package/lib-commonjs/components/DatePicker/useDatePicker.js.map +1 -1
- package/lib-commonjs/components/DatePicker/useDatePickerStyles.styles.js +0 -2
- package/lib-commonjs/components/DatePicker/useDatePickerStyles.styles.js.map +1 -1
- package/lib-commonjs/index.js +0 -3
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/utils/animations.js +4 -6
- package/lib-commonjs/utils/animations.js.map +1 -1
- package/lib-commonjs/utils/constants.js +7 -9
- package/lib-commonjs/utils/constants.js.map +1 -1
- package/lib-commonjs/utils/dateFormatting/dateFormatting.defaults.js +1 -3
- package/lib-commonjs/utils/dateFormatting/dateFormatting.defaults.js.map +1 -1
- package/lib-commonjs/utils/dateFormatting/dateFormatting.types.js +0 -3
- package/lib-commonjs/utils/dateFormatting/dateFormatting.types.js.map +1 -1
- package/lib-commonjs/utils/dateFormatting/index.js +0 -3
- package/lib-commonjs/utils/dateFormatting/index.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/dateGrid.types.js +0 -3
- package/lib-commonjs/utils/dateGrid/dateGrid.types.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/findAvailableDate.js +1 -3
- package/lib-commonjs/utils/dateGrid/findAvailableDate.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/getBoundedDateRange.js +1 -3
- package/lib-commonjs/utils/dateGrid/getBoundedDateRange.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/getDateRangeTypeToUse.js +1 -3
- package/lib-commonjs/utils/dateGrid/getDateRangeTypeToUse.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/getDayGrid.js +1 -3
- package/lib-commonjs/utils/dateGrid/getDayGrid.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/index.js +0 -3
- package/lib-commonjs/utils/dateGrid/index.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/isAfterMaxDate.js +1 -3
- package/lib-commonjs/utils/dateGrid/isAfterMaxDate.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/isBeforeMinDate.js +1 -3
- package/lib-commonjs/utils/dateGrid/isBeforeMinDate.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/isContiguous.js +1 -3
- package/lib-commonjs/utils/dateGrid/isContiguous.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/isRestrictedDate.js +1 -3
- package/lib-commonjs/utils/dateGrid/isRestrictedDate.js.map +1 -1
- package/lib-commonjs/utils/dateMath/dateMath.js +1 -3
- package/lib-commonjs/utils/dateMath/dateMath.js.map +1 -1
- package/lib-commonjs/utils/dateMath/index.js +0 -3
- package/lib-commonjs/utils/dateMath/index.js.map +1 -1
- package/lib-commonjs/utils/dom.js +1 -3
- package/lib-commonjs/utils/dom.js.map +1 -1
- package/lib-commonjs/utils/focus.js +1 -3
- package/lib-commonjs/utils/focus.js.map +1 -1
- package/lib-commonjs/utils/index.js +0 -3
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/usePopupPositioning.js +1 -3
- package/lib-commonjs/utils/usePopupPositioning.js.map +1 -1
- package/package.json +14 -14
|
@@ -5,73 +5,84 @@ import { CalendarMonthRegular } from '@fluentui/react-icons';
|
|
|
5
5
|
import { compareDatePart, DayOfWeek, FirstWeekOfYear } from '../../utils';
|
|
6
6
|
import { defaultDatePickerStrings } from './defaults';
|
|
7
7
|
import { Input } from '@fluentui/react-input';
|
|
8
|
-
import { mergeCallbacks, resolveShorthand, useControllableState, useId, useMergedRefs, useOnClickOutside, useOnScrollOutside } from '@fluentui/react-utilities';
|
|
8
|
+
import { mergeCallbacks, resolveShorthand, useControllableState, useFirstMount, useId, useMergedRefs, useOnClickOutside, useOnScrollOutside } from '@fluentui/react-utilities';
|
|
9
9
|
import { useFieldContext_unstable as useFieldContext } from '@fluentui/react-field';
|
|
10
10
|
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
|
11
11
|
import { useModalAttributes } from '@fluentui/react-tabster';
|
|
12
12
|
import { usePopupPositioning } from '../../utils/usePopupPositioning';
|
|
13
13
|
function isDateOutOfBounds(date, minDate, maxDate) {
|
|
14
|
-
|
|
14
|
+
return !!minDate && compareDatePart(minDate, date) > 0 || !!maxDate && compareDatePart(maxDate, date) < 0;
|
|
15
15
|
}
|
|
16
16
|
function useFocusLogic() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
const inputRef = React.useRef(null);
|
|
18
|
+
const preventFocusOpeningPicker = React.useRef(false);
|
|
19
|
+
const focus = ()=>{
|
|
20
|
+
var _inputRef_current, _inputRef_current_focus;
|
|
21
|
+
(_inputRef_current = inputRef.current) === null || _inputRef_current === void 0 ? void 0 : (_inputRef_current_focus = _inputRef_current.focus) === null || _inputRef_current_focus === void 0 ? void 0 : _inputRef_current_focus.call(_inputRef_current);
|
|
22
|
+
};
|
|
23
|
+
const preventNextFocusOpeningPicker = ()=>{
|
|
24
|
+
preventFocusOpeningPicker.current = true;
|
|
25
|
+
};
|
|
26
|
+
return [
|
|
27
|
+
focus,
|
|
28
|
+
inputRef,
|
|
29
|
+
preventFocusOpeningPicker,
|
|
30
|
+
preventNextFocusOpeningPicker
|
|
31
|
+
];
|
|
27
32
|
}
|
|
28
33
|
function usePopupVisibility(props) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
const [open, setOpen] = useControllableState({
|
|
35
|
+
initialState: false,
|
|
36
|
+
defaultState: props.defaultOpen,
|
|
37
|
+
state: props.open
|
|
38
|
+
});
|
|
39
|
+
const isMounted = React.useRef(false);
|
|
40
|
+
React.useEffect(()=>{
|
|
41
|
+
if (isMounted.current && !open) {
|
|
42
|
+
var // If DatePicker's menu (Calendar) is closed, run onAfterMenuDismiss
|
|
43
|
+
_props_onOpenChange;
|
|
44
|
+
(_props_onOpenChange = props.onOpenChange) === null || _props_onOpenChange === void 0 ? void 0 : _props_onOpenChange.call(props, false);
|
|
45
|
+
}
|
|
46
|
+
isMounted.current = true;
|
|
47
|
+
}, // Should only run on allowTextInput or open change
|
|
48
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
49
|
+
[
|
|
50
|
+
props.allowTextInput,
|
|
51
|
+
open
|
|
52
|
+
]);
|
|
53
|
+
return [
|
|
54
|
+
open,
|
|
55
|
+
setOpen
|
|
56
|
+
];
|
|
48
57
|
}
|
|
49
|
-
function useSelectedDate({
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
58
|
+
function useSelectedDate({ formatDate , onSelectDate , value }) {
|
|
59
|
+
const [selectedDate, setSelectedDateState] = useControllableState({
|
|
60
|
+
initialState: null,
|
|
61
|
+
state: value
|
|
62
|
+
});
|
|
63
|
+
const [formattedDate, setFormattedDate] = React.useState(()=>value && formatDate ? formatDate(value) : '');
|
|
64
|
+
const setSelectedDate = (newDate)=>{
|
|
65
|
+
onSelectDate === null || onSelectDate === void 0 ? void 0 : onSelectDate(newDate);
|
|
66
|
+
setSelectedDateState(newDate);
|
|
67
|
+
setFormattedDate(newDate && formatDate ? formatDate(newDate) : '');
|
|
68
|
+
};
|
|
69
|
+
React.useEffect(()=>{
|
|
70
|
+
setFormattedDate(value && formatDate ? formatDate(value) : '');
|
|
71
|
+
}, [
|
|
72
|
+
formatDate,
|
|
73
|
+
value
|
|
74
|
+
]);
|
|
75
|
+
return [
|
|
76
|
+
selectedDate,
|
|
77
|
+
formattedDate,
|
|
78
|
+
setSelectedDate,
|
|
79
|
+
setFormattedDate
|
|
80
|
+
];
|
|
70
81
|
}
|
|
71
|
-
const defaultFormatDate = date
|
|
72
|
-
const defaultParseDateFromString = dateStr
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
const defaultFormatDate = (date)=>date ? date.toDateString() : '';
|
|
83
|
+
const defaultParseDateFromString = (dateStr)=>{
|
|
84
|
+
const date = Date.parse(dateStr);
|
|
85
|
+
return date ? new Date(date) : null;
|
|
75
86
|
};
|
|
76
87
|
/**
|
|
77
88
|
* Create the state required to render DatePicker.
|
|
@@ -81,310 +92,347 @@ const defaultParseDateFromString = dateStr => {
|
|
|
81
92
|
*
|
|
82
93
|
* @param props - props from this instance of DatePicker
|
|
83
94
|
* @param ref - reference to root Input slot
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const popupSurfaceId = useId('datePicker-popupSurface');
|
|
130
|
-
const validateTextInput = React.useCallback((date = null) => {
|
|
131
|
-
let error;
|
|
132
|
-
if (allowTextInput) {
|
|
133
|
-
if (formattedDate || date) {
|
|
134
|
-
// Don't parse if the selected date has the same formatted string as what we're about to parse.
|
|
135
|
-
// The formatted string might be ambiguous (ex: "1/2/3" or "New Year Eve") and the parser might
|
|
136
|
-
// not be able to come up with the exact same date.
|
|
137
|
-
if (selectedDate && formatDate && formatDate(date !== null && date !== void 0 ? date : selectedDate) === formattedDate) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
date = date || parseDateFromString(formattedDate);
|
|
141
|
-
// Check if date is null or date is an invalid date
|
|
142
|
-
if (!date || isNaN(date.getTime())) {
|
|
143
|
-
// Reset input if formatting is available
|
|
144
|
-
setSelectedDate(selectedDate);
|
|
145
|
-
error = 'invalid-input';
|
|
146
|
-
} else {
|
|
147
|
-
if (isDateOutOfBounds(date, minDate, maxDate)) {
|
|
148
|
-
error = 'out-of-bounds';
|
|
149
|
-
} else {
|
|
150
|
-
setSelectedDate(date);
|
|
151
|
-
}
|
|
95
|
+
*/ export const useDatePicker_unstable = (props, ref)=>{
|
|
96
|
+
const { allowTextInput =false , allFocusable =false , borderless =false , dateTimeFormatter , defaultOpen =false , disableAutoFocus =true , firstDayOfWeek =DayOfWeek.Sunday , firstWeekOfYear =FirstWeekOfYear.FirstDay , formatDate =defaultFormatDate , highlightCurrentMonth =false , highlightSelectedMonth =false , initialPickerDate =new Date() , inlinePopup =false , isMonthPickerVisible =true , maxDate , minDate , onOpenChange , onSelectDate: onUserSelectDate , openOnClick =true , onValidationResult , parseDateFromString =defaultParseDateFromString , showCloseButton =false , showGoToToday =true , showMonthPickerAsOverlay =false , showWeekNumbers =false , strings =defaultDatePickerStrings , today , underlined =false , value , ...restOfProps } = props;
|
|
97
|
+
const calendar = React.useRef(null);
|
|
98
|
+
const [focus, rootRef, preventFocusOpeningPicker, preventNextFocusOpeningPicker] = useFocusLogic();
|
|
99
|
+
const [selectedDate, formattedDate, setSelectedDate, setFormattedDate] = useSelectedDate({
|
|
100
|
+
formatDate,
|
|
101
|
+
onSelectDate: onUserSelectDate,
|
|
102
|
+
value
|
|
103
|
+
});
|
|
104
|
+
const [open, setOpenState] = usePopupVisibility(props);
|
|
105
|
+
const fieldContext = useFieldContext();
|
|
106
|
+
var _fieldContext_required;
|
|
107
|
+
const required = (_fieldContext_required = fieldContext === null || fieldContext === void 0 ? void 0 : fieldContext.required) !== null && _fieldContext_required !== void 0 ? _fieldContext_required : props.required;
|
|
108
|
+
const popupSurfaceId = useId('datePicker-popupSurface');
|
|
109
|
+
const validateTextInput = React.useCallback((date = null)=>{
|
|
110
|
+
let error;
|
|
111
|
+
if (allowTextInput) {
|
|
112
|
+
if (formattedDate || date) {
|
|
113
|
+
// Don't parse if the selected date has the same formatted string as what we're about to parse.
|
|
114
|
+
// The formatted string might be ambiguous (ex: "1/2/3" or "New Year Eve") and the parser might
|
|
115
|
+
// not be able to come up with the exact same date.
|
|
116
|
+
if (selectedDate && formatDate && formatDate(date !== null && date !== void 0 ? date : selectedDate) === formattedDate) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
date = date || parseDateFromString(formattedDate);
|
|
120
|
+
// Check if date is null or date is an invalid date
|
|
121
|
+
if (!date || isNaN(date.getTime())) {
|
|
122
|
+
// Reset input if formatting is available
|
|
123
|
+
setSelectedDate(selectedDate);
|
|
124
|
+
error = 'invalid-input';
|
|
125
|
+
} else {
|
|
126
|
+
if (isDateOutOfBounds(date, minDate, maxDate)) {
|
|
127
|
+
error = 'out-of-bounds';
|
|
128
|
+
} else {
|
|
129
|
+
setSelectedDate(date);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
if (required) {
|
|
134
|
+
error = 'required-input';
|
|
135
|
+
}
|
|
136
|
+
onUserSelectDate === null || onUserSelectDate === void 0 ? void 0 : onUserSelectDate(date);
|
|
137
|
+
}
|
|
138
|
+
} else if (required && !formattedDate) {
|
|
139
|
+
error = 'required-input';
|
|
152
140
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
141
|
+
onValidationResult === null || onValidationResult === void 0 ? void 0 : onValidationResult({
|
|
142
|
+
error
|
|
143
|
+
});
|
|
144
|
+
}, [
|
|
145
|
+
allowTextInput,
|
|
146
|
+
formatDate,
|
|
147
|
+
formattedDate,
|
|
148
|
+
maxDate,
|
|
149
|
+
minDate,
|
|
150
|
+
onUserSelectDate,
|
|
151
|
+
onValidationResult,
|
|
152
|
+
parseDateFromString,
|
|
153
|
+
required,
|
|
154
|
+
selectedDate,
|
|
155
|
+
setSelectedDate
|
|
156
|
+
]);
|
|
157
|
+
const setOpen = React.useCallback((newState)=>{
|
|
158
|
+
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(newState);
|
|
159
|
+
setOpenState(newState);
|
|
160
|
+
}, [
|
|
161
|
+
onOpenChange,
|
|
162
|
+
setOpenState
|
|
163
|
+
]);
|
|
164
|
+
const dismissDatePickerPopup = React.useCallback((newlySelectedDate)=>{
|
|
165
|
+
if (open) {
|
|
166
|
+
setOpen(false);
|
|
167
|
+
validateTextInput(newlySelectedDate);
|
|
168
|
+
if (!allowTextInput && newlySelectedDate) {
|
|
169
|
+
setSelectedDate(newlySelectedDate);
|
|
170
|
+
}
|
|
156
171
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}, [allowTextInput, formatDate, formattedDate, maxDate, minDate, onUserSelectDate, onValidationResult, parseDateFromString, required, selectedDate, setSelectedDate]);
|
|
166
|
-
const setOpen = React.useCallback(newState => {
|
|
167
|
-
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(newState);
|
|
168
|
-
setOpenState(newState);
|
|
169
|
-
}, [onOpenChange, setOpenState]);
|
|
170
|
-
const dismissDatePickerPopup = React.useCallback(newlySelectedDate => {
|
|
171
|
-
if (open) {
|
|
172
|
-
setOpen(false);
|
|
173
|
-
validateTextInput(newlySelectedDate);
|
|
174
|
-
if (!allowTextInput && newlySelectedDate) {
|
|
175
|
-
setSelectedDate(newlySelectedDate);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}, [allowTextInput, open, setOpen, setSelectedDate, validateTextInput]);
|
|
179
|
-
const showDatePickerPopup = React.useCallback(() => {
|
|
180
|
-
if (!open) {
|
|
181
|
-
preventNextFocusOpeningPicker();
|
|
182
|
-
setOpen(true);
|
|
183
|
-
}
|
|
184
|
-
}, [open, preventNextFocusOpeningPicker, setOpen]);
|
|
185
|
-
/**
|
|
186
|
-
* Callback for closing the calendar callout
|
|
187
|
-
*/
|
|
188
|
-
const calendarDismissed = React.useCallback(newlySelectedDate => {
|
|
189
|
-
preventNextFocusOpeningPicker();
|
|
190
|
-
dismissDatePickerPopup(newlySelectedDate);
|
|
191
|
-
}, [dismissDatePickerPopup, preventNextFocusOpeningPicker]);
|
|
192
|
-
const onInputChange = React.useCallback((ev, data) => {
|
|
193
|
-
const {
|
|
194
|
-
value: newValue
|
|
195
|
-
} = data;
|
|
196
|
-
if (allowTextInput) {
|
|
197
|
-
if (open) {
|
|
198
|
-
dismissDatePickerPopup();
|
|
199
|
-
}
|
|
200
|
-
setFormattedDate(newValue);
|
|
201
|
-
}
|
|
202
|
-
}, [allowTextInput, dismissDatePickerPopup, open, setFormattedDate]);
|
|
203
|
-
const onInputBlur = React.useCallback(() => {
|
|
204
|
-
validateTextInput();
|
|
205
|
-
}, [validateTextInput]);
|
|
206
|
-
const onInputKeyDown = React.useCallback(ev => {
|
|
207
|
-
switch (ev.key) {
|
|
208
|
-
case Enter:
|
|
209
|
-
ev.preventDefault();
|
|
210
|
-
ev.stopPropagation();
|
|
172
|
+
}, [
|
|
173
|
+
allowTextInput,
|
|
174
|
+
open,
|
|
175
|
+
setOpen,
|
|
176
|
+
setSelectedDate,
|
|
177
|
+
validateTextInput
|
|
178
|
+
]);
|
|
179
|
+
const showDatePickerPopup = React.useCallback(()=>{
|
|
211
180
|
if (!open) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
181
|
+
preventNextFocusOpeningPicker();
|
|
182
|
+
setOpen(true);
|
|
183
|
+
}
|
|
184
|
+
}, [
|
|
185
|
+
open,
|
|
186
|
+
preventNextFocusOpeningPicker,
|
|
187
|
+
setOpen
|
|
188
|
+
]);
|
|
189
|
+
/**
|
|
190
|
+
* Callback for closing the calendar callout
|
|
191
|
+
*/ const calendarDismissed = React.useCallback((newlySelectedDate)=>{
|
|
192
|
+
preventNextFocusOpeningPicker();
|
|
193
|
+
dismissDatePickerPopup(newlySelectedDate);
|
|
194
|
+
}, [
|
|
195
|
+
dismissDatePickerPopup,
|
|
196
|
+
preventNextFocusOpeningPicker
|
|
197
|
+
]);
|
|
198
|
+
const onInputChange = React.useCallback((ev, data)=>{
|
|
199
|
+
const { value: newValue } = data;
|
|
200
|
+
if (allowTextInput) {
|
|
201
|
+
if (open) {
|
|
202
|
+
dismissDatePickerPopup();
|
|
203
|
+
}
|
|
204
|
+
setFormattedDate(newValue);
|
|
205
|
+
}
|
|
206
|
+
}, [
|
|
207
|
+
allowTextInput,
|
|
208
|
+
dismissDatePickerPopup,
|
|
209
|
+
open,
|
|
210
|
+
setFormattedDate
|
|
211
|
+
]);
|
|
212
|
+
const onInputBlur = React.useCallback(()=>{
|
|
213
|
+
validateTextInput();
|
|
214
|
+
}, [
|
|
215
|
+
validateTextInput
|
|
216
|
+
]);
|
|
217
|
+
const onInputKeyDown = React.useCallback((ev)=>{
|
|
218
|
+
switch(ev.key){
|
|
219
|
+
case Enter:
|
|
220
|
+
ev.preventDefault();
|
|
221
|
+
ev.stopPropagation();
|
|
222
|
+
if (!open) {
|
|
223
|
+
validateTextInput();
|
|
224
|
+
showDatePickerPopup();
|
|
225
|
+
} else {
|
|
226
|
+
// When DatePicker allows input date string directly,
|
|
227
|
+
// it is expected to hit another enter to close the popup
|
|
228
|
+
if (props.allowTextInput) {
|
|
229
|
+
dismissDatePickerPopup();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
break;
|
|
233
|
+
case Escape:
|
|
234
|
+
ev.stopPropagation();
|
|
235
|
+
ev.preventDefault();
|
|
236
|
+
if (open) {
|
|
237
|
+
calendarDismissed();
|
|
238
|
+
}
|
|
239
|
+
break;
|
|
240
|
+
case ArrowDown:
|
|
241
|
+
ev.preventDefault();
|
|
242
|
+
if (ev.altKey && !open) {
|
|
243
|
+
showDatePickerPopup();
|
|
244
|
+
}
|
|
245
|
+
break;
|
|
246
|
+
default:
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
}, [
|
|
250
|
+
calendarDismissed,
|
|
251
|
+
dismissDatePickerPopup,
|
|
252
|
+
open,
|
|
253
|
+
props.allowTextInput,
|
|
254
|
+
showDatePickerPopup,
|
|
255
|
+
validateTextInput
|
|
256
|
+
]);
|
|
257
|
+
const onInputFocus = React.useCallback(()=>{
|
|
258
|
+
if (disableAutoFocus) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (!allowTextInput) {
|
|
262
|
+
if (!preventFocusOpeningPicker.current) {
|
|
263
|
+
showDatePickerPopup();
|
|
264
|
+
}
|
|
265
|
+
preventFocusOpeningPicker.current = false;
|
|
266
|
+
}
|
|
267
|
+
}, [
|
|
268
|
+
allowTextInput,
|
|
269
|
+
disableAutoFocus,
|
|
270
|
+
preventFocusOpeningPicker,
|
|
271
|
+
showDatePickerPopup
|
|
272
|
+
]);
|
|
273
|
+
const onInputClick = React.useCallback(()=>{
|
|
274
|
+
// default openOnClick to !props.disableAutoFocus for legacy support of disableAutoFocus behavior
|
|
275
|
+
if ((props.openOnClick || !props.disableAutoFocus) && !open && !props.disabled) {
|
|
276
|
+
showDatePickerPopup();
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (allowTextInput) {
|
|
218
280
|
dismissDatePickerPopup();
|
|
219
|
-
}
|
|
220
281
|
}
|
|
221
|
-
|
|
222
|
-
|
|
282
|
+
}, [
|
|
283
|
+
allowTextInput,
|
|
284
|
+
dismissDatePickerPopup,
|
|
285
|
+
open,
|
|
286
|
+
props.disabled,
|
|
287
|
+
props.disableAutoFocus,
|
|
288
|
+
props.openOnClick,
|
|
289
|
+
showDatePickerPopup
|
|
290
|
+
]);
|
|
291
|
+
const onIconClick = (ev)=>{
|
|
223
292
|
ev.stopPropagation();
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
293
|
+
if (!open && !props.disabled) {
|
|
294
|
+
showDatePickerPopup();
|
|
295
|
+
} else if (props.allowTextInput) {
|
|
296
|
+
dismissDatePickerPopup();
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
const inputAppearance = underlined ? 'underline' : borderless ? 'filled-lighter' : 'outline';
|
|
300
|
+
const [triggerWrapperRef, popupRef] = usePopupPositioning(props);
|
|
301
|
+
const rootShorthand = resolveShorthand(restOfProps, {
|
|
302
|
+
required: true,
|
|
303
|
+
defaultProps: {
|
|
304
|
+
appearance: inputAppearance,
|
|
305
|
+
'aria-controls': open ? popupSurfaceId : undefined,
|
|
306
|
+
'aria-expanded': open,
|
|
307
|
+
'aria-haspopup': 'dialog',
|
|
308
|
+
contentAfter: /*#__PURE__*/ React.createElement(CalendarMonthRegular, {
|
|
309
|
+
onClick: onIconClick
|
|
310
|
+
}),
|
|
311
|
+
readOnly: !allowTextInput,
|
|
312
|
+
role: 'combobox',
|
|
313
|
+
root: {
|
|
314
|
+
'aria-owns': open ? popupSurfaceId : undefined,
|
|
315
|
+
ref: useMergedRefs(triggerWrapperRef, ref)
|
|
316
|
+
},
|
|
317
|
+
input: {
|
|
318
|
+
ref: rootRef
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
rootShorthand.onChange = mergeCallbacks(rootShorthand.onChange, onInputChange);
|
|
323
|
+
rootShorthand.onBlur = mergeCallbacks(rootShorthand.onBlur, onInputBlur);
|
|
324
|
+
rootShorthand.onKeyDown = mergeCallbacks(rootShorthand.onKeyDown, onInputKeyDown);
|
|
325
|
+
rootShorthand.onFocus = mergeCallbacks(rootShorthand.onFocus, onInputFocus);
|
|
326
|
+
rootShorthand.onClick = mergeCallbacks(rootShorthand.onClick, onInputClick);
|
|
327
|
+
const { modalAttributes } = useModalAttributes({
|
|
328
|
+
trapFocus: true,
|
|
329
|
+
alwaysFocusable: true,
|
|
330
|
+
legacyTrapFocus: false
|
|
331
|
+
});
|
|
332
|
+
const popupSurfaceShorthand = open ? resolveShorthand(props.popupSurface, {
|
|
333
|
+
required: true,
|
|
334
|
+
defaultProps: {
|
|
335
|
+
'aria-label': 'Calendar',
|
|
336
|
+
'aria-modal': true,
|
|
337
|
+
id: popupSurfaceId,
|
|
338
|
+
role: 'dialog',
|
|
339
|
+
ref: popupRef,
|
|
340
|
+
...modalAttributes
|
|
341
|
+
}
|
|
342
|
+
}) : undefined;
|
|
343
|
+
const { targetDocument } = useFluent();
|
|
344
|
+
useOnClickOutside({
|
|
345
|
+
element: targetDocument,
|
|
346
|
+
callback: (ev)=>dismissDatePickerPopup(),
|
|
347
|
+
refs: [
|
|
348
|
+
triggerWrapperRef,
|
|
349
|
+
popupRef
|
|
350
|
+
],
|
|
351
|
+
disabled: !open
|
|
352
|
+
});
|
|
353
|
+
useOnScrollOutside({
|
|
354
|
+
element: targetDocument,
|
|
355
|
+
callback: (ev)=>dismissDatePickerPopup(),
|
|
356
|
+
refs: [
|
|
357
|
+
triggerWrapperRef,
|
|
358
|
+
popupRef
|
|
359
|
+
],
|
|
360
|
+
disabled: !open
|
|
361
|
+
});
|
|
362
|
+
// When the popup is opened, focus should go to the calendar.
|
|
363
|
+
// In v8 this was done by focusing after the callout was positioned, but in v9 this can be simulated by using a
|
|
364
|
+
// useEffect hook.
|
|
365
|
+
React.useEffect(()=>{
|
|
366
|
+
if (open && !props.disabled && calendar.current) {
|
|
367
|
+
calendar.current.focus();
|
|
368
|
+
}
|
|
369
|
+
}, [
|
|
370
|
+
disableAutoFocus,
|
|
371
|
+
open,
|
|
372
|
+
props.disabled
|
|
373
|
+
]);
|
|
374
|
+
const isFirstMount = useFirstMount();
|
|
375
|
+
// When the popup is closed, focus should go back to the input.
|
|
376
|
+
React.useEffect(()=>{
|
|
377
|
+
if (!open && !props.disabled && !isFirstMount) {
|
|
378
|
+
focus();
|
|
227
379
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
380
|
+
// Focus function keeps changing, so we need to skip it in the deps
|
|
381
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
382
|
+
}, [
|
|
383
|
+
isFirstMount,
|
|
384
|
+
open,
|
|
385
|
+
props.disabled
|
|
386
|
+
]);
|
|
387
|
+
const calendarShorthand = resolveShorthand(props.calendar, {
|
|
388
|
+
required: true,
|
|
389
|
+
defaultProps: {
|
|
390
|
+
allFocusable,
|
|
391
|
+
componentRef: calendar,
|
|
392
|
+
dateTimeFormatter,
|
|
393
|
+
firstDayOfWeek,
|
|
394
|
+
firstWeekOfYear,
|
|
395
|
+
highlightCurrentMonth,
|
|
396
|
+
highlightSelectedMonth,
|
|
397
|
+
isMonthPickerVisible,
|
|
398
|
+
maxDate,
|
|
399
|
+
minDate,
|
|
400
|
+
showCloseButton,
|
|
401
|
+
showGoToToday,
|
|
402
|
+
showMonthPickerAsOverlay,
|
|
403
|
+
showWeekNumbers,
|
|
404
|
+
strings,
|
|
405
|
+
today,
|
|
406
|
+
value: selectedDate || initialPickerDate
|
|
233
407
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
} else if (props.allowTextInput) {
|
|
265
|
-
dismissDatePickerPopup();
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
const inputAppearance = underlined ? 'underline' : borderless ? 'filled-lighter' : 'outline';
|
|
269
|
-
const [triggerWrapperRef, popupRef] = usePopupPositioning(props);
|
|
270
|
-
const rootShorthand = resolveShorthand(restOfProps, {
|
|
271
|
-
required: true,
|
|
272
|
-
defaultProps: {
|
|
273
|
-
appearance: inputAppearance,
|
|
274
|
-
'aria-controls': open ? popupSurfaceId : undefined,
|
|
275
|
-
'aria-expanded': open,
|
|
276
|
-
'aria-haspopup': 'dialog',
|
|
277
|
-
contentAfter: /*#__PURE__*/React.createElement(CalendarMonthRegular, {
|
|
278
|
-
onClick: onIconClick
|
|
279
|
-
}),
|
|
280
|
-
readOnly: !allowTextInput,
|
|
281
|
-
role: 'combobox',
|
|
282
|
-
root: {
|
|
283
|
-
'aria-owns': open ? popupSurfaceId : undefined,
|
|
284
|
-
ref: useMergedRefs(triggerWrapperRef, ref)
|
|
285
|
-
},
|
|
286
|
-
input: {
|
|
287
|
-
ref: rootRef
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
rootShorthand.onChange = mergeCallbacks(rootShorthand.onChange, onInputChange);
|
|
292
|
-
rootShorthand.onBlur = mergeCallbacks(rootShorthand.onBlur, onInputBlur);
|
|
293
|
-
rootShorthand.onKeyDown = mergeCallbacks(rootShorthand.onKeyDown, onInputKeyDown);
|
|
294
|
-
rootShorthand.onFocus = mergeCallbacks(rootShorthand.onFocus, onInputFocus);
|
|
295
|
-
rootShorthand.onClick = mergeCallbacks(rootShorthand.onClick, onInputClick);
|
|
296
|
-
const {
|
|
297
|
-
modalAttributes
|
|
298
|
-
} = useModalAttributes({
|
|
299
|
-
trapFocus: true,
|
|
300
|
-
alwaysFocusable: true,
|
|
301
|
-
legacyTrapFocus: false
|
|
302
|
-
});
|
|
303
|
-
const popupSurfaceShorthand = open ? resolveShorthand(props.popupSurface, {
|
|
304
|
-
required: true,
|
|
305
|
-
defaultProps: {
|
|
306
|
-
'aria-label': 'Calendar',
|
|
307
|
-
'aria-modal': true,
|
|
308
|
-
id: popupSurfaceId,
|
|
309
|
-
role: 'dialog',
|
|
310
|
-
ref: popupRef,
|
|
311
|
-
...modalAttributes
|
|
312
|
-
}
|
|
313
|
-
}) : undefined;
|
|
314
|
-
const {
|
|
315
|
-
targetDocument
|
|
316
|
-
} = useFluent();
|
|
317
|
-
useOnClickOutside({
|
|
318
|
-
element: targetDocument,
|
|
319
|
-
callback: ev => dismissDatePickerPopup(),
|
|
320
|
-
refs: [triggerWrapperRef, popupRef],
|
|
321
|
-
disabled: !open
|
|
322
|
-
});
|
|
323
|
-
useOnScrollOutside({
|
|
324
|
-
element: targetDocument,
|
|
325
|
-
callback: ev => dismissDatePickerPopup(),
|
|
326
|
-
refs: [triggerWrapperRef, popupRef],
|
|
327
|
-
disabled: !open
|
|
328
|
-
});
|
|
329
|
-
// When the popup is opened, focus should go to the calendar.
|
|
330
|
-
// In v8 this was done by focusing after the callout was positioned, but in v9 this can be simulated by using a
|
|
331
|
-
// useEffect hook.
|
|
332
|
-
React.useEffect(() => {
|
|
333
|
-
if (open && !props.disabled && calendar.current) {
|
|
334
|
-
calendar.current.focus();
|
|
335
|
-
}
|
|
336
|
-
}, [disableAutoFocus, open, props.disabled]);
|
|
337
|
-
// When the popup is closed, focus should go back to the input.
|
|
338
|
-
React.useEffect(() => {
|
|
339
|
-
if (!open && !props.disabled) {
|
|
340
|
-
focus();
|
|
341
|
-
}
|
|
342
|
-
}, [open, props.disabled, focus]);
|
|
343
|
-
const calendarShorthand = resolveShorthand(props.calendar, {
|
|
344
|
-
required: true,
|
|
345
|
-
defaultProps: {
|
|
346
|
-
allFocusable,
|
|
347
|
-
componentRef: calendar,
|
|
348
|
-
dateTimeFormatter,
|
|
349
|
-
firstDayOfWeek,
|
|
350
|
-
firstWeekOfYear,
|
|
351
|
-
highlightCurrentMonth,
|
|
352
|
-
highlightSelectedMonth,
|
|
353
|
-
isMonthPickerVisible,
|
|
354
|
-
maxDate,
|
|
355
|
-
minDate,
|
|
356
|
-
showCloseButton,
|
|
357
|
-
showGoToToday,
|
|
358
|
-
showMonthPickerAsOverlay,
|
|
359
|
-
showWeekNumbers,
|
|
360
|
-
strings,
|
|
361
|
-
today,
|
|
362
|
-
value: selectedDate || initialPickerDate
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
calendarShorthand.onDismiss = mergeCallbacks(calendarShorthand.onDismiss, calendarDismissed);
|
|
366
|
-
calendarShorthand.onSelectDate = mergeCallbacks(calendarShorthand.onSelectDate, calendarDismissed);
|
|
367
|
-
React.useImperativeHandle(props.componentRef, () => ({
|
|
368
|
-
focus,
|
|
369
|
-
reset() {
|
|
370
|
-
setOpen(false);
|
|
371
|
-
setSelectedDate(undefined);
|
|
372
|
-
},
|
|
373
|
-
showDatePickerPopup
|
|
374
|
-
}), [focus, setOpen, setSelectedDate, showDatePickerPopup]);
|
|
375
|
-
const state = {
|
|
376
|
-
disabled: !!props.disabled,
|
|
377
|
-
inlinePopup,
|
|
378
|
-
components: {
|
|
379
|
-
root: Input,
|
|
380
|
-
calendar: Calendar,
|
|
381
|
-
popupSurface: 'div'
|
|
382
|
-
},
|
|
383
|
-
calendar: calendarShorthand,
|
|
384
|
-
root: rootShorthand,
|
|
385
|
-
popupSurface: popupSurfaceShorthand
|
|
386
|
-
};
|
|
387
|
-
state.root.value = formattedDate;
|
|
388
|
-
return state;
|
|
408
|
+
});
|
|
409
|
+
calendarShorthand.onDismiss = mergeCallbacks(calendarShorthand.onDismiss, calendarDismissed);
|
|
410
|
+
calendarShorthand.onSelectDate = mergeCallbacks(calendarShorthand.onSelectDate, calendarDismissed);
|
|
411
|
+
React.useImperativeHandle(props.componentRef, ()=>({
|
|
412
|
+
focus,
|
|
413
|
+
reset () {
|
|
414
|
+
setOpen(false);
|
|
415
|
+
setSelectedDate(null);
|
|
416
|
+
},
|
|
417
|
+
showDatePickerPopup
|
|
418
|
+
}), [
|
|
419
|
+
focus,
|
|
420
|
+
setOpen,
|
|
421
|
+
setSelectedDate,
|
|
422
|
+
showDatePickerPopup
|
|
423
|
+
]);
|
|
424
|
+
const state = {
|
|
425
|
+
disabled: !!props.disabled,
|
|
426
|
+
inlinePopup,
|
|
427
|
+
components: {
|
|
428
|
+
root: Input,
|
|
429
|
+
calendar: Calendar,
|
|
430
|
+
popupSurface: 'div'
|
|
431
|
+
},
|
|
432
|
+
calendar: calendarShorthand,
|
|
433
|
+
root: rootShorthand,
|
|
434
|
+
popupSurface: popupSurfaceShorthand
|
|
435
|
+
};
|
|
436
|
+
state.root.value = formattedDate;
|
|
437
|
+
return state;
|
|
389
438
|
};
|
|
390
|
-
//# sourceMappingURL=useDatePicker.js.map
|