@mui/x-date-pickers 8.0.0-alpha.13 → 8.0.0-alpha.14
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 +131 -0
- package/DatePicker/shared.d.ts +1 -1
- package/DateTimePicker/DateTimePicker.types.d.ts +2 -2
- package/DateTimePicker/DateTimePickerToolbar.d.ts +1 -1
- package/DateTimePicker/DateTimePickerToolbar.js +1 -1
- package/DateTimePicker/shared.d.ts +18 -10
- package/DateTimePicker/shared.js +23 -2
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +2 -11
- package/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +4 -7
- package/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
- package/MobileDateTimePicker/MobileDateTimePicker.d.ts +1 -2
- package/MobileDateTimePicker/MobileDateTimePicker.js +61 -6
- package/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +1 -3
- package/PickersTextField/PickersTextField.js +3 -1
- package/StaticDateTimePicker/StaticDateTimePicker.js +60 -6
- package/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +1 -2
- package/TimePicker/shared.d.ts +1 -1
- package/esm/DatePicker/shared.d.ts +1 -1
- package/esm/DateTimePicker/DateTimePicker.types.d.ts +2 -2
- package/esm/DateTimePicker/DateTimePickerToolbar.d.ts +1 -1
- package/esm/DateTimePicker/DateTimePickerToolbar.js +1 -1
- package/esm/DateTimePicker/shared.d.ts +18 -10
- package/esm/DateTimePicker/shared.js +23 -2
- package/esm/DesktopDateTimePicker/DesktopDateTimePicker.js +3 -12
- package/esm/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +4 -7
- package/esm/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
- package/esm/MobileDateTimePicker/MobileDateTimePicker.d.ts +1 -2
- package/esm/MobileDateTimePicker/MobileDateTimePicker.js +62 -7
- package/esm/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +1 -3
- package/esm/PickersTextField/PickersTextField.js +3 -1
- package/esm/StaticDateTimePicker/StaticDateTimePicker.js +61 -7
- package/esm/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +1 -2
- package/esm/TimePicker/shared.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/internals/components/PickerFieldUI.js +6 -2
- package/esm/internals/components/PickerPopper/PickerPopper.js +3 -3
- package/esm/internals/components/PickerProvider.d.ts +137 -6
- package/esm/internals/components/PickerProvider.js +1 -1
- package/esm/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +4 -7
- package/esm/internals/hooks/useField/useField.js +7 -8
- package/esm/internals/hooks/useField/useField.types.d.ts +46 -43
- package/esm/internals/hooks/useField/useField.utils.js +4 -1
- package/esm/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
- package/esm/internals/hooks/useField/useFieldState.d.ts +2 -1
- package/esm/internals/hooks/useField/useFieldState.js +136 -83
- package/esm/internals/hooks/useField/useFieldV6TextField.js +1 -1
- package/esm/internals/hooks/useField/useFieldV7TextField.js +2 -1
- package/esm/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +4 -7
- package/esm/internals/hooks/useNullableFieldPrivateContext.d.ts +5 -2
- package/esm/internals/hooks/usePicker/hooks/useOrientation.d.ts +2 -0
- package/esm/internals/hooks/usePicker/hooks/useOrientation.js +34 -0
- package/esm/internals/hooks/usePicker/hooks/useValueAndOpenStates.d.ts +19 -0
- package/esm/internals/hooks/usePicker/hooks/useValueAndOpenStates.js +210 -0
- package/esm/internals/hooks/usePicker/index.d.ts +1 -3
- package/esm/internals/hooks/usePicker/usePicker.d.ts +5 -5
- package/esm/internals/hooks/usePicker/usePicker.js +276 -34
- package/esm/internals/hooks/usePicker/usePicker.types.d.ts +181 -9
- package/esm/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +3 -4
- package/esm/internals/hooks/useValueWithTimezone.d.ts +1 -1
- package/esm/internals/index.d.ts +3 -6
- package/esm/internals/models/manager.d.ts +108 -4
- package/esm/internals/models/props/basePickerProps.d.ts +2 -2
- package/esm/internals/models/props/time.d.ts +1 -1
- package/esm/internals/utils/date-time-utils.d.ts +2 -2
- package/esm/internals/utils/valueManagers.d.ts +1 -1
- package/esm/internals/utils/valueManagers.js +10 -18
- package/esm/managers/useDateManager.d.ts +3 -4
- package/esm/managers/useDateTimeManager.d.ts +3 -4
- package/esm/managers/useTimeManager.d.ts +3 -4
- package/esm/models/adapters.d.ts +2 -1
- package/esm/models/manager.d.ts +4 -5
- package/esm/validation/useValidation.d.ts +1 -1
- package/index.js +1 -1
- package/internals/components/PickerFieldUI.js +6 -2
- package/internals/components/PickerPopper/PickerPopper.js +3 -3
- package/internals/components/PickerProvider.d.ts +137 -6
- package/internals/components/PickerProvider.js +1 -1
- package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +4 -7
- package/internals/hooks/useField/useField.js +7 -8
- package/internals/hooks/useField/useField.types.d.ts +46 -43
- package/internals/hooks/useField/useField.utils.js +4 -1
- package/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
- package/internals/hooks/useField/useFieldState.d.ts +2 -1
- package/internals/hooks/useField/useFieldState.js +135 -82
- package/internals/hooks/useField/useFieldV6TextField.js +1 -1
- package/internals/hooks/useField/useFieldV7TextField.js +2 -1
- package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +4 -7
- package/internals/hooks/useNullableFieldPrivateContext.d.ts +5 -2
- package/internals/hooks/usePicker/hooks/useOrientation.d.ts +2 -0
- package/internals/hooks/usePicker/hooks/useOrientation.js +42 -0
- package/internals/hooks/usePicker/hooks/useValueAndOpenStates.d.ts +19 -0
- package/internals/hooks/usePicker/{usePickerValue.js → hooks/useValueAndOpenStates.js} +97 -114
- package/internals/hooks/usePicker/index.d.ts +1 -3
- package/internals/hooks/usePicker/usePicker.d.ts +5 -5
- package/internals/hooks/usePicker/usePicker.js +278 -34
- package/internals/hooks/usePicker/usePicker.types.d.ts +181 -9
- package/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +3 -4
- package/internals/hooks/useValueWithTimezone.d.ts +1 -1
- package/internals/index.d.ts +3 -6
- package/internals/models/manager.d.ts +108 -4
- package/internals/models/props/basePickerProps.d.ts +2 -2
- package/internals/models/props/time.d.ts +1 -1
- package/internals/utils/date-time-utils.d.ts +2 -2
- package/internals/utils/valueManagers.d.ts +1 -1
- package/internals/utils/valueManagers.js +10 -18
- package/managers/useDateManager.d.ts +3 -4
- package/managers/useDateTimeManager.d.ts +3 -4
- package/managers/useTimeManager.d.ts +3 -4
- package/models/adapters.d.ts +2 -1
- package/models/manager.d.ts +4 -5
- package/modern/DatePicker/shared.d.ts +1 -1
- package/modern/DateTimePicker/DateTimePicker.types.d.ts +2 -2
- package/modern/DateTimePicker/DateTimePickerToolbar.d.ts +1 -1
- package/modern/DateTimePicker/DateTimePickerToolbar.js +1 -1
- package/modern/DateTimePicker/shared.d.ts +18 -10
- package/modern/DateTimePicker/shared.js +23 -2
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +3 -12
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +4 -7
- package/modern/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
- package/modern/MobileDateTimePicker/MobileDateTimePicker.d.ts +1 -2
- package/modern/MobileDateTimePicker/MobileDateTimePicker.js +62 -7
- package/modern/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +1 -3
- package/modern/PickersTextField/PickersTextField.js +3 -1
- package/modern/StaticDateTimePicker/StaticDateTimePicker.js +61 -7
- package/modern/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +1 -2
- package/modern/TimePicker/shared.d.ts +1 -1
- package/modern/index.js +1 -1
- package/modern/internals/components/PickerFieldUI.js +6 -2
- package/modern/internals/components/PickerPopper/PickerPopper.js +3 -3
- package/modern/internals/components/PickerProvider.d.ts +137 -6
- package/modern/internals/components/PickerProvider.js +1 -1
- package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +4 -7
- package/modern/internals/hooks/useField/useField.js +7 -8
- package/modern/internals/hooks/useField/useField.types.d.ts +46 -43
- package/modern/internals/hooks/useField/useField.utils.js +4 -1
- package/modern/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
- package/modern/internals/hooks/useField/useFieldState.d.ts +2 -1
- package/modern/internals/hooks/useField/useFieldState.js +136 -83
- package/modern/internals/hooks/useField/useFieldV6TextField.js +1 -1
- package/modern/internals/hooks/useField/useFieldV7TextField.js +2 -1
- package/modern/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +4 -7
- package/modern/internals/hooks/useNullableFieldPrivateContext.d.ts +5 -2
- package/modern/internals/hooks/usePicker/hooks/useOrientation.d.ts +2 -0
- package/modern/internals/hooks/usePicker/hooks/useOrientation.js +34 -0
- package/modern/internals/hooks/usePicker/hooks/useValueAndOpenStates.d.ts +19 -0
- package/modern/internals/hooks/usePicker/hooks/useValueAndOpenStates.js +210 -0
- package/modern/internals/hooks/usePicker/index.d.ts +1 -3
- package/modern/internals/hooks/usePicker/usePicker.d.ts +5 -5
- package/modern/internals/hooks/usePicker/usePicker.js +276 -34
- package/modern/internals/hooks/usePicker/usePicker.types.d.ts +181 -9
- package/modern/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +3 -4
- package/modern/internals/hooks/useValueWithTimezone.d.ts +1 -1
- package/modern/internals/index.d.ts +3 -6
- package/modern/internals/models/manager.d.ts +108 -4
- package/modern/internals/models/props/basePickerProps.d.ts +2 -2
- package/modern/internals/models/props/time.d.ts +1 -1
- package/modern/internals/utils/date-time-utils.d.ts +2 -2
- package/modern/internals/utils/valueManagers.d.ts +1 -1
- package/modern/internals/utils/valueManagers.js +10 -18
- package/modern/managers/useDateManager.d.ts +3 -4
- package/modern/managers/useDateTimeManager.d.ts +3 -4
- package/modern/managers/useTimeManager.d.ts +3 -4
- package/modern/models/adapters.d.ts +2 -1
- package/modern/models/manager.d.ts +4 -5
- package/modern/validation/useValidation.d.ts +1 -1
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/validation/useValidation.d.ts +1 -1
- package/esm/internals/hooks/useOpenState.d.ts +0 -14
- package/esm/internals/hooks/useOpenState.js +0 -37
- package/esm/internals/hooks/usePicker/usePickerProvider.d.ts +0 -65
- package/esm/internals/hooks/usePicker/usePickerProvider.js +0 -125
- package/esm/internals/hooks/usePicker/usePickerValue.d.ts +0 -12
- package/esm/internals/hooks/usePicker/usePickerValue.js +0 -226
- package/esm/internals/hooks/usePicker/usePickerValue.types.d.ts +0 -327
- package/esm/internals/hooks/usePicker/usePickerValue.types.js +0 -1
- package/esm/internals/hooks/usePicker/usePickerViews.d.ts +0 -137
- package/esm/internals/hooks/usePicker/usePickerViews.js +0 -188
- package/internals/hooks/useOpenState.d.ts +0 -14
- package/internals/hooks/useOpenState.js +0 -46
- package/internals/hooks/usePicker/usePickerProvider.d.ts +0 -65
- package/internals/hooks/usePicker/usePickerProvider.js +0 -135
- package/internals/hooks/usePicker/usePickerValue.d.ts +0 -12
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +0 -327
- package/internals/hooks/usePicker/usePickerValue.types.js +0 -5
- package/internals/hooks/usePicker/usePickerViews.d.ts +0 -137
- package/internals/hooks/usePicker/usePickerViews.js +0 -195
- package/modern/internals/hooks/useOpenState.d.ts +0 -14
- package/modern/internals/hooks/useOpenState.js +0 -37
- package/modern/internals/hooks/usePicker/usePickerProvider.d.ts +0 -65
- package/modern/internals/hooks/usePicker/usePickerProvider.js +0 -125
- package/modern/internals/hooks/usePicker/usePickerValue.d.ts +0 -12
- package/modern/internals/hooks/usePicker/usePickerValue.js +0 -226
- package/modern/internals/hooks/usePicker/usePickerValue.types.d.ts +0 -327
- package/modern/internals/hooks/usePicker/usePickerValue.types.js +0 -1
- package/modern/internals/hooks/usePicker/usePickerViews.d.ts +0 -137
- package/modern/internals/hooks/usePicker/usePickerViews.js +0 -188
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { UseFieldInternalProps } from "../useField/index.js";
|
|
3
|
-
import { Validator } from "../../../validation/index.js";
|
|
4
|
-
import { TimezoneProps, MuiPickersAdapter, PickersTimezone, PickerChangeHandlerContext, PickerValidDate, OnErrorProps, InferError, PickerValueType, PickerChangeImportance } from "../../../models/index.js";
|
|
5
|
-
import { GetDefaultReferenceDateProps } from "../../utils/getDefaultReferenceDate.js";
|
|
6
|
-
import type { PickersShortcutsItemContext } from '../../../PickersShortcuts';
|
|
7
|
-
import { InferNonNullablePickerValue, PickerValidValue } from "../../models/index.js";
|
|
8
|
-
export interface PickerValueManager<TValue extends PickerValidValue, TError> {
|
|
9
|
-
/**
|
|
10
|
-
* Determines if two values are equal.
|
|
11
|
-
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
12
|
-
* @param {MuiPickersAdapter} utils The adapter.
|
|
13
|
-
* @param {TValue} valueLeft The first value to compare.
|
|
14
|
-
* @param {TValue} valueRight The second value to compare.
|
|
15
|
-
* @returns {boolean} A boolean indicating if the two values are equal.
|
|
16
|
-
*/
|
|
17
|
-
areValuesEqual: (utils: MuiPickersAdapter, valueLeft: TValue, valueRight: TValue) => boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Value to set when clicking the "Clear" button.
|
|
20
|
-
*/
|
|
21
|
-
emptyValue: TValue;
|
|
22
|
-
/**
|
|
23
|
-
* Method returning the value to set when clicking the "Today" button
|
|
24
|
-
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
25
|
-
* @param {MuiPickersAdapter} utils The adapter.
|
|
26
|
-
* @param {PickersTimezone} timezone The current timezone.
|
|
27
|
-
* @param {PickerValueType} valueType The type of the value being edited.
|
|
28
|
-
* @returns {TValue} The value to set when clicking the "Today" button.
|
|
29
|
-
*/
|
|
30
|
-
getTodayValue: (utils: MuiPickersAdapter, timezone: PickersTimezone, valueType: PickerValueType) => TValue;
|
|
31
|
-
/**
|
|
32
|
-
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
33
|
-
* Method returning the reference value to use when mounting the component.
|
|
34
|
-
* @param {object} params The params of the method.
|
|
35
|
-
* @param {PickerValidDate | undefined} params.referenceDate The referenceDate provided by the user.
|
|
36
|
-
* @param {TValue} params.value The value provided by the user.
|
|
37
|
-
* @param {GetDefaultReferenceDateProps} params.props The validation props needed to compute the reference value.
|
|
38
|
-
* @param {MuiPickersAdapter} params.utils The adapter.
|
|
39
|
-
* @param {number} params.granularity The granularity of the selection possible on this component.
|
|
40
|
-
* @param {PickersTimezone} params.timezone The current timezone.
|
|
41
|
-
* @param {() => PickerValidDate} params.getTodayDate The reference date to use if no reference date is passed to the component.
|
|
42
|
-
* @returns {TValue} The reference value to use for non-provided dates.
|
|
43
|
-
*/
|
|
44
|
-
getInitialReferenceValue: (params: {
|
|
45
|
-
referenceDate: PickerValidDate | undefined;
|
|
46
|
-
value: TValue;
|
|
47
|
-
props: GetDefaultReferenceDateProps;
|
|
48
|
-
utils: MuiPickersAdapter;
|
|
49
|
-
granularity: number;
|
|
50
|
-
timezone: PickersTimezone;
|
|
51
|
-
getTodayDate?: () => PickerValidDate;
|
|
52
|
-
}) => InferNonNullablePickerValue<TValue>;
|
|
53
|
-
/**
|
|
54
|
-
* Method parsing the input value to replace all invalid dates by `null`.
|
|
55
|
-
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
56
|
-
* @param {MuiPickersAdapter} utils The adapter.
|
|
57
|
-
* @param {TValue} value The value to parse.
|
|
58
|
-
* @returns {TValue} The value without invalid date.
|
|
59
|
-
*/
|
|
60
|
-
cleanValue: (utils: MuiPickersAdapter, value: TValue) => TValue;
|
|
61
|
-
/**
|
|
62
|
-
* Generates the new value, given the previous value and the new proposed value.
|
|
63
|
-
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
64
|
-
* @param {MuiPickersAdapter} utils The adapter.
|
|
65
|
-
* @param {TValue} lastValidDateValue The last valid value.
|
|
66
|
-
* @param {TValue} value The proposed value.
|
|
67
|
-
* @returns {TValue} The new value.
|
|
68
|
-
*/
|
|
69
|
-
valueReducer?: (utils: MuiPickersAdapter, lastValidDateValue: TValue, value: TValue) => TValue;
|
|
70
|
-
/**
|
|
71
|
-
* Compare two errors to know if they are equal.
|
|
72
|
-
* @template TError
|
|
73
|
-
* @param {TError} error The new error
|
|
74
|
-
* @param {TError | null} prevError The previous error
|
|
75
|
-
* @returns {boolean} `true` if the new error is different from the previous one.
|
|
76
|
-
*/
|
|
77
|
-
isSameError: (error: TError, prevError: TError | null) => boolean;
|
|
78
|
-
/**
|
|
79
|
-
* Checks if the current error is empty or not.
|
|
80
|
-
* @template TError
|
|
81
|
-
* @param {TError} error The current error.
|
|
82
|
-
* @returns {boolean} `true` if the current error is not empty.
|
|
83
|
-
*/
|
|
84
|
-
hasError: (error: TError) => boolean;
|
|
85
|
-
/**
|
|
86
|
-
* The value identifying no error, used to initialise the error state.
|
|
87
|
-
*/
|
|
88
|
-
defaultErrorState: TError;
|
|
89
|
-
/**
|
|
90
|
-
* Return the timezone of the date inside a value.
|
|
91
|
-
* Throw an error on range picker if both values don't have the same timezone.
|
|
92
|
-
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
93
|
-
@param {MuiPickersAdapter} utils The utils to manipulate the date.
|
|
94
|
-
@param {TValue} value The current value.
|
|
95
|
-
@returns {string | null} The timezone of the current value.
|
|
96
|
-
*/
|
|
97
|
-
getTimezone: (utils: MuiPickersAdapter, value: TValue) => string | null;
|
|
98
|
-
/**
|
|
99
|
-
* Change the timezone of the dates inside a value.
|
|
100
|
-
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
101
|
-
@param {MuiPickersAdapter} utils The utils to manipulate the date.
|
|
102
|
-
@param {PickersTimezone} timezone The current timezone.
|
|
103
|
-
@param {TValue} value The value to convert.
|
|
104
|
-
@returns {TValue} The value with the new dates in the new timezone.
|
|
105
|
-
*/
|
|
106
|
-
setTimezone: (utils: MuiPickersAdapter, timezone: PickersTimezone, value: TValue) => TValue;
|
|
107
|
-
}
|
|
108
|
-
export type PickerSelectionState = 'partial' | 'shallow' | 'finish';
|
|
109
|
-
export interface UsePickerValueState<TValue extends PickerValidValue> {
|
|
110
|
-
/**
|
|
111
|
-
* Date displayed on the views and the field.
|
|
112
|
-
* It is updated whenever the user modifies something.
|
|
113
|
-
*/
|
|
114
|
-
draft: TValue;
|
|
115
|
-
/**
|
|
116
|
-
* Last value published (the last value for which `shouldPublishValue` returned `true`).
|
|
117
|
-
* If `onChange` is defined, it's the value that was passed on the last call to this callback.
|
|
118
|
-
*/
|
|
119
|
-
lastPublishedValue: TValue;
|
|
120
|
-
/**
|
|
121
|
-
* Last value committed (the last value for which `shouldCommitValue` returned `true`).
|
|
122
|
-
* If `onAccept` is defined, it's the value that was passed on the last call to this callback.
|
|
123
|
-
*/
|
|
124
|
-
lastCommittedValue: TValue;
|
|
125
|
-
/**
|
|
126
|
-
* Last value passed to `props.value`.
|
|
127
|
-
* Used to update the `draft` value whenever the `value` prop changes.
|
|
128
|
-
*/
|
|
129
|
-
lastControlledValue: TValue | undefined;
|
|
130
|
-
/**
|
|
131
|
-
* If we never modified the value since the mount of the component,
|
|
132
|
-
* Then we might want to apply some custom logic.
|
|
133
|
-
*
|
|
134
|
-
* For example, when the component is not controlled and `defaultValue` is defined.
|
|
135
|
-
* Then clicking on "Accept", "Today" or "Clear" should fire `onAccept` with `defaultValue`, but clicking on "Cancel" or dismissing the picker should not.
|
|
136
|
-
*/
|
|
137
|
-
hasBeenModifiedSinceMount: boolean;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Props used to handle the value that are common to all pickers.
|
|
141
|
-
*/
|
|
142
|
-
export interface UsePickerValueBaseProps<TValue extends PickerValidValue, TError> extends OnErrorProps<TValue, TError> {
|
|
143
|
-
/**
|
|
144
|
-
* The selected value.
|
|
145
|
-
* Used when the component is controlled.
|
|
146
|
-
*/
|
|
147
|
-
value?: TValue;
|
|
148
|
-
/**
|
|
149
|
-
* The default value.
|
|
150
|
-
* Used when the component is not controlled.
|
|
151
|
-
*/
|
|
152
|
-
defaultValue?: TValue;
|
|
153
|
-
/**
|
|
154
|
-
* Callback fired when the value changes.
|
|
155
|
-
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
156
|
-
* @template TError The validation error type. It will be either `string` or a `null`. It can be in `[start, end]` format in case of range value.
|
|
157
|
-
* @param {TValue} value The new value.
|
|
158
|
-
* @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
|
|
159
|
-
*/
|
|
160
|
-
onChange?: (value: TValue, context: PickerChangeHandlerContext<TError>) => void;
|
|
161
|
-
/**
|
|
162
|
-
* Callback fired when the value is accepted.
|
|
163
|
-
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
164
|
-
* @template TError The validation error type. It will be either `string` or a `null`. It can be in `[start, end]` format in case of range value.
|
|
165
|
-
* @param {TValue} value The value that was just accepted.
|
|
166
|
-
* @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
|
|
167
|
-
*/
|
|
168
|
-
onAccept?: (value: TValue, context: PickerChangeHandlerContext<TError>) => void;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Props used to handle the value of non-static pickers.
|
|
172
|
-
*/
|
|
173
|
-
export interface UsePickerValueNonStaticProps {
|
|
174
|
-
/**
|
|
175
|
-
* If `true`, the Picker will close after submitting the full date.
|
|
176
|
-
* @default false
|
|
177
|
-
*/
|
|
178
|
-
closeOnSelect?: boolean;
|
|
179
|
-
/**
|
|
180
|
-
* Control the popup or dialog open state.
|
|
181
|
-
* @default false
|
|
182
|
-
*/
|
|
183
|
-
open?: boolean;
|
|
184
|
-
/**
|
|
185
|
-
* Callback fired when the popup requests to be closed.
|
|
186
|
-
* Use in controlled mode (see `open`).
|
|
187
|
-
*/
|
|
188
|
-
onClose?: () => void;
|
|
189
|
-
/**
|
|
190
|
-
* Callback fired when the popup requests to be opened.
|
|
191
|
-
* Use in controlled mode (see `open`).
|
|
192
|
-
*/
|
|
193
|
-
onOpen?: () => void;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Props used to handle the value of the pickers.
|
|
197
|
-
*/
|
|
198
|
-
export interface UsePickerValueProps<TValue extends PickerValidValue, TError> extends UsePickerValueBaseProps<TValue, TError>, UsePickerValueNonStaticProps, TimezoneProps {
|
|
199
|
-
referenceDate?: PickerValidDate;
|
|
200
|
-
}
|
|
201
|
-
export interface UsePickerValueParams<TValue extends PickerValidValue, TExternalProps extends UsePickerValueProps<TValue, any>> {
|
|
202
|
-
props: TExternalProps;
|
|
203
|
-
valueManager: PickerValueManager<TValue, InferError<TExternalProps>>;
|
|
204
|
-
valueType: PickerValueType;
|
|
205
|
-
validator: Validator<TValue, InferError<TExternalProps>, TExternalProps>;
|
|
206
|
-
}
|
|
207
|
-
export type UsePickerValueFieldResponse<TValue extends PickerValidValue, TError> = Required<Pick<UseFieldInternalProps<TValue, any, TError>, 'value' | 'onChange'>>;
|
|
208
|
-
/**
|
|
209
|
-
* Props passed to `usePickerViews`.
|
|
210
|
-
*/
|
|
211
|
-
export interface UsePickerValueViewsResponse<TValue extends PickerValidValue> {
|
|
212
|
-
value: TValue;
|
|
213
|
-
onChange: (value: TValue, selectionState?: PickerSelectionState) => void;
|
|
214
|
-
open: boolean;
|
|
215
|
-
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Params passed to `usePickerProvider`.
|
|
219
|
-
*/
|
|
220
|
-
export interface UsePickerValueProviderParams<TValue extends PickerValidValue, TError> {
|
|
221
|
-
value: TValue;
|
|
222
|
-
contextValue: UsePickerValueContextValue<TValue, TError>;
|
|
223
|
-
actionsContextValue: UsePickerValueActionsContextValue<TValue, TError>;
|
|
224
|
-
privateContextValue: UsePickerValuePrivateContextValue;
|
|
225
|
-
isValidContextValue: (value: TValue) => boolean;
|
|
226
|
-
}
|
|
227
|
-
export interface UsePickerValueResponse<TValue extends PickerValidValue, TError> {
|
|
228
|
-
viewProps: UsePickerValueViewsResponse<TValue>;
|
|
229
|
-
provider: UsePickerValueProviderParams<TValue, TError>;
|
|
230
|
-
}
|
|
231
|
-
export interface UsePickerValueContextValue<TValue extends PickerValidValue, TError> extends UsePickerValueActionsContextValue<TValue, TError> {
|
|
232
|
-
/**
|
|
233
|
-
* The current value of the picker.
|
|
234
|
-
*/
|
|
235
|
-
value: TValue;
|
|
236
|
-
/**
|
|
237
|
-
* The timezone to use when rendering the dates.
|
|
238
|
-
* If a `timezone` prop is provided, it will be used.
|
|
239
|
-
* If the `value` prop contains a valid date, its timezone will be used.
|
|
240
|
-
* If no `value` prop is provided, but the `defaultValue` contains a valid date, its timezone will be used.
|
|
241
|
-
* If no `value` or `defaultValue` is provided, but the `referenceDate` is provided, its timezone will be used.
|
|
242
|
-
* Otherwise, the timezone will be the default one of your date library.
|
|
243
|
-
*/
|
|
244
|
-
timezone: PickersTimezone;
|
|
245
|
-
/**
|
|
246
|
-
* Whether the picker is open.
|
|
247
|
-
*/
|
|
248
|
-
open: boolean;
|
|
249
|
-
}
|
|
250
|
-
export interface UsePickerValueActionsContextValue<TValue extends PickerValidValue, TError> {
|
|
251
|
-
/**
|
|
252
|
-
* Set the current value of the picker.
|
|
253
|
-
* @param {TValue} value The new value of the picker.
|
|
254
|
-
* @param {SetValueActionOptions<TError>} options The options to customize the behavior of this update.
|
|
255
|
-
*/
|
|
256
|
-
setValue: (value: TValue, options?: SetValueActionOptions<TError>) => void;
|
|
257
|
-
/**
|
|
258
|
-
* Set the current open state of the Picker.
|
|
259
|
-
* ```ts
|
|
260
|
-
* setOpen(true); // Opens the picker.
|
|
261
|
-
* setOpen(false); // Closes the picker.
|
|
262
|
-
* setOpen((prevOpen) => !prevOpen); // Toggles the open state.
|
|
263
|
-
* ```
|
|
264
|
-
* @param {React.SetStateAction<boolean>} action The new open state of the Picker.
|
|
265
|
-
* It can be a function that will receive the current open state.
|
|
266
|
-
*/
|
|
267
|
-
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
268
|
-
/**
|
|
269
|
-
* Set the current value of the picker to be empty.
|
|
270
|
-
* The value will be `null` on single pickers and `[null, null]` on range pickers.
|
|
271
|
-
*/
|
|
272
|
-
clearValue: () => void;
|
|
273
|
-
/**
|
|
274
|
-
* Set the current value of the picker to be the current date.
|
|
275
|
-
* The value will be `today` on single pickers and `[today, today]` on range pickers.
|
|
276
|
-
* With `today` being the current date, with its time set to `00:00:00` on Date Pickers and its time set to the current time on Time and Date Pickers.
|
|
277
|
-
*/
|
|
278
|
-
setValueToToday: () => void;
|
|
279
|
-
/**
|
|
280
|
-
* Accept the current value of the picker.
|
|
281
|
-
* Will call `onAccept` if defined.
|
|
282
|
-
* If the picker is re-opened, this value will be the one used to initialize the views.
|
|
283
|
-
*/
|
|
284
|
-
acceptValueChanges: () => void;
|
|
285
|
-
/**
|
|
286
|
-
* Cancel the changes made to the current value of the picker.
|
|
287
|
-
* The value will be reset to the last accepted value.
|
|
288
|
-
*/
|
|
289
|
-
cancelValueChanges: () => void;
|
|
290
|
-
}
|
|
291
|
-
export interface UsePickerValuePrivateContextValue {
|
|
292
|
-
/**
|
|
293
|
-
* Close the picker and accepts the current value if it is not equal to the last accepted value.
|
|
294
|
-
*/
|
|
295
|
-
dismissViews: () => void;
|
|
296
|
-
}
|
|
297
|
-
export interface SetValueActionOptions<TError = string | null> {
|
|
298
|
-
/**
|
|
299
|
-
* The importance of the change when picking a value:
|
|
300
|
-
* - "accept": fires `onChange`, fires `onAccept` and closes the picker.
|
|
301
|
-
* - "set": fires `onChange` but do not fire `onAccept` and does not close the picker.
|
|
302
|
-
* @default "accept"
|
|
303
|
-
*/
|
|
304
|
-
changeImportance?: PickerChangeImportance;
|
|
305
|
-
/**
|
|
306
|
-
* The validation error associated to the current value.
|
|
307
|
-
* If not defined, the validation will be computed by the picker.
|
|
308
|
-
*/
|
|
309
|
-
validationError?: TError;
|
|
310
|
-
/**
|
|
311
|
-
* The shortcut that triggered this change.
|
|
312
|
-
* It should not be defined if the change does not come from a shortcut.
|
|
313
|
-
*/
|
|
314
|
-
shortcut?: PickersShortcutsItemContext;
|
|
315
|
-
/**
|
|
316
|
-
* Whether the value should call `onChange` and `onAccept` when the value is not controlled and has never been modified.
|
|
317
|
-
* If `true`, the `onChange` and `onAccept` callback will only be fired if the value has been modified (and is not equal to the last published value).
|
|
318
|
-
* If `false`, the `onChange` and `onAccept` callback will be fired when the value has never been modified (`onAccept` only if `changeImportance` is set to "accept").
|
|
319
|
-
* @default false
|
|
320
|
-
*/
|
|
321
|
-
skipPublicationIfPristine?: boolean;
|
|
322
|
-
/**
|
|
323
|
-
* Whether the picker should close.
|
|
324
|
-
* @default changeImportance === "accept"
|
|
325
|
-
*/
|
|
326
|
-
shouldClose?: boolean;
|
|
327
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { SxProps } from '@mui/system';
|
|
3
|
-
import { Theme } from '@mui/material/styles';
|
|
4
|
-
import { UseViewsOptions } from "../useViews.js";
|
|
5
|
-
import type { UsePickerValueViewsResponse } from './usePickerValue.types';
|
|
6
|
-
import { DateOrTimeViewWithMeridiem, PickerRangeValue, PickerValidValue, PickerValue } from "../../models/index.js";
|
|
7
|
-
import { FieldRef, PickerValidDate, TimezoneProps } from "../../../models/index.js";
|
|
8
|
-
export interface PickerViewsRendererBaseExternalProps extends Omit<UsePickerViewsProps<any, any, any>, 'openTo' | 'viewRenderers'> {}
|
|
9
|
-
export type PickerViewsRendererProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends PickerViewsRendererBaseExternalProps> = Omit<TExternalProps, 'className' | 'sx'> & Pick<UsePickerValueViewsResponse<TValue>, 'value' | 'onChange'> & {
|
|
10
|
-
view: TView;
|
|
11
|
-
views: readonly TView[];
|
|
12
|
-
focusedView: TView | null;
|
|
13
|
-
onFocusedViewChange: (viewToFocus: TView, hasFocus: boolean) => void;
|
|
14
|
-
showViewSwitcher: boolean;
|
|
15
|
-
timeViewsCount: number;
|
|
16
|
-
};
|
|
17
|
-
export type PickerViewRenderer<TValue extends PickerValidValue, TExternalProps extends PickerViewsRendererBaseExternalProps> = (props: PickerViewsRendererProps<TValue, any, TExternalProps>) => React.ReactNode;
|
|
18
|
-
export type PickerViewRendererLookup<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends PickerViewsRendererBaseExternalProps> = Record<TView, PickerViewRenderer<TValue, TExternalProps> | null>;
|
|
19
|
-
/**
|
|
20
|
-
* Props used to handle the views that are common to all pickers.
|
|
21
|
-
*/
|
|
22
|
-
export interface UsePickerViewsBaseProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, any>> extends Omit<UseViewsOptions<any, TView>, 'onChange' | 'onFocusedViewChange' | 'focusedView'>, TimezoneProps {
|
|
23
|
-
/**
|
|
24
|
-
* If `null`, the section will only have field editing.
|
|
25
|
-
* If `undefined`, internally defined view will be used.
|
|
26
|
-
*/
|
|
27
|
-
viewRenderers: PickerViewRendererLookup<TValue, TView, TExternalProps>;
|
|
28
|
-
/**
|
|
29
|
-
* The date used to generate the new value when both `value` and `defaultValue` are empty.
|
|
30
|
-
* @default The closest valid date-time using the validation props, except callbacks like `shouldDisable<...>`.
|
|
31
|
-
*/
|
|
32
|
-
referenceDate?: PickerValidDate;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Props used to handle the value of the pickers.
|
|
36
|
-
*/
|
|
37
|
-
export interface UsePickerViewsProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, any>> extends UsePickerViewsBaseProps<TValue, TView, TExternalProps> {
|
|
38
|
-
className?: string;
|
|
39
|
-
sx?: SxProps<Theme>;
|
|
40
|
-
}
|
|
41
|
-
export interface UsePickerViewParams<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, TExternalProps>> {
|
|
42
|
-
props: TExternalProps;
|
|
43
|
-
propsFromPickerValue: UsePickerValueViewsResponse<TValue>;
|
|
44
|
-
autoFocusView: boolean;
|
|
45
|
-
viewContainerRole: 'dialog' | 'tooltip' | null;
|
|
46
|
-
/**
|
|
47
|
-
* A function that intercepts the regular picker rendering.
|
|
48
|
-
* Can be used to consume the provided `viewRenderers` and render a custom component wrapping them.
|
|
49
|
-
* @param {PickerViewRendererLookup<TValue, TView, TExternalProps>} viewRenderers The `viewRenderers` that were provided to the picker component.
|
|
50
|
-
* @param {TView} popperView The current picker view.
|
|
51
|
-
* @param {any} rendererProps All the props that are being passed down to the renderer.
|
|
52
|
-
* @returns {React.ReactNode} A React node that will be rendered instead of the default renderer.
|
|
53
|
-
*/
|
|
54
|
-
rendererInterceptor?: React.JSXElementConstructor<PickerRendererInterceptorProps<TValue, TView, TExternalProps>>;
|
|
55
|
-
}
|
|
56
|
-
export interface PickerRendererInterceptorProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, TExternalProps>> {
|
|
57
|
-
viewRenderers: PickerViewRendererLookup<TValue, TView, TExternalProps>;
|
|
58
|
-
popperView: TView;
|
|
59
|
-
rendererProps: PickerViewsRendererProps<TValue, TView, TExternalProps>;
|
|
60
|
-
}
|
|
61
|
-
export interface UsePickerViewsResponse<TView extends DateOrTimeViewWithMeridiem> {
|
|
62
|
-
renderCurrentView: () => React.ReactNode;
|
|
63
|
-
provider: UsePickerViewsProviderParams<TView>;
|
|
64
|
-
}
|
|
65
|
-
export interface UsePickerViewsActionsContextValue<TView extends DateOrTimeViewWithMeridiem> {
|
|
66
|
-
/**
|
|
67
|
-
* Set the current view.
|
|
68
|
-
* @template TView
|
|
69
|
-
* @param {TView} view The view to render
|
|
70
|
-
*/
|
|
71
|
-
setView: (view: TView) => void;
|
|
72
|
-
}
|
|
73
|
-
export interface UsePickerViewsContextValue<TView extends DateOrTimeViewWithMeridiem> extends UsePickerViewsActionsContextValue<TView> {
|
|
74
|
-
/**
|
|
75
|
-
* The views that the picker must render.
|
|
76
|
-
* It is equal to the picker `views` prop if defined.
|
|
77
|
-
* Otherwise, a default set of views is provided based on the component you are using:
|
|
78
|
-
* - Date Pickers: ['year', 'day']
|
|
79
|
-
* - Time Pickers: ['hours', 'minutes']
|
|
80
|
-
* - Date Time Pickers: ['year', 'day', 'hours', 'minutes']
|
|
81
|
-
* - Date Range Pickers: ['day']
|
|
82
|
-
* - Date Time Range Pickers: ['day', 'hours', 'minutes']
|
|
83
|
-
*/
|
|
84
|
-
views: readonly TView[];
|
|
85
|
-
/**
|
|
86
|
-
* The view currently rendered.
|
|
87
|
-
*/
|
|
88
|
-
view: TView | null;
|
|
89
|
-
/**
|
|
90
|
-
* The view showed when first opening the picker.
|
|
91
|
-
*/
|
|
92
|
-
initialView: TView | null;
|
|
93
|
-
}
|
|
94
|
-
export interface UsePickerViewsPrivateContextValue {
|
|
95
|
-
/**
|
|
96
|
-
* Whether one of the view has an UI (it has a view renderer associated).
|
|
97
|
-
*/
|
|
98
|
-
hasUIView: boolean;
|
|
99
|
-
/**
|
|
100
|
-
* Check whether the current view has an UI.
|
|
101
|
-
* @returns {boolean} Whether the current view has an UI.
|
|
102
|
-
*/
|
|
103
|
-
doesTheCurrentViewHasAnUI: () => boolean;
|
|
104
|
-
/**
|
|
105
|
-
* The aria role associated with the view container.
|
|
106
|
-
* It is equal to "dialog" when the view is rendered inside a `@mui/material/Dialog`.
|
|
107
|
-
* It is equal to "dialog" when the view is rendered inside a `@mui/material/Popper` and the focus is trapped inside the view.
|
|
108
|
-
* It is equal to "tooltip" when the view is rendered inside a `@mui/material/Popper` and the focus remains inside the field.
|
|
109
|
-
* It is always equal to null if the picker does not have a field (static pickers).
|
|
110
|
-
* It is always equal to null if the component you are accessing the context from is not wrapped by a picker.
|
|
111
|
-
*/
|
|
112
|
-
viewContainerRole: 'dialog' | 'tooltip' | null;
|
|
113
|
-
}
|
|
114
|
-
export interface UsePickerViewsFieldPrivateContextValue {
|
|
115
|
-
fieldRef: React.RefObject<FieldRef<PickerValue> | FieldRef<PickerRangeValue> | null>;
|
|
116
|
-
}
|
|
117
|
-
export interface UsePickerViewsProviderParams<TView extends DateOrTimeViewWithMeridiem> {
|
|
118
|
-
hasUIView: boolean;
|
|
119
|
-
views: readonly TView[];
|
|
120
|
-
contextValue: UsePickerViewsContextValue<TView>;
|
|
121
|
-
actionsContextValue: UsePickerViewsActionsContextValue<TView>;
|
|
122
|
-
privateContextValue: UsePickerViewsPrivateContextValue;
|
|
123
|
-
fieldPrivateContextValue: UsePickerViewsFieldPrivateContextValue;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Manage the views of all the pickers:
|
|
127
|
-
* - Handles the view switch
|
|
128
|
-
* - Handles the switch between UI views and field views
|
|
129
|
-
* - Handles the focus management when switching views
|
|
130
|
-
*/
|
|
131
|
-
export declare const usePickerViews: <TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, any>>({
|
|
132
|
-
props,
|
|
133
|
-
propsFromPickerValue,
|
|
134
|
-
autoFocusView,
|
|
135
|
-
viewContainerRole,
|
|
136
|
-
rendererInterceptor: RendererInterceptor
|
|
137
|
-
}: UsePickerViewParams<TValue, TView, TExternalProps>) => UsePickerViewsResponse<TView>;
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["className", "sx"];
|
|
4
|
-
import * as React from 'react';
|
|
5
|
-
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
6
|
-
import useEventCallback from '@mui/utils/useEventCallback';
|
|
7
|
-
import { useViews } from "../useViews.js";
|
|
8
|
-
import { isTimeView } from "../../utils/time-utils.js";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Props used to handle the views that are common to all pickers.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Props used to handle the value of the pickers.
|
|
16
|
-
*/
|
|
17
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
|
-
/**
|
|
19
|
-
* Manage the views of all the pickers:
|
|
20
|
-
* - Handles the view switch
|
|
21
|
-
* - Handles the switch between UI views and field views
|
|
22
|
-
* - Handles the focus management when switching views
|
|
23
|
-
*/
|
|
24
|
-
export const usePickerViews = ({
|
|
25
|
-
props,
|
|
26
|
-
propsFromPickerValue,
|
|
27
|
-
autoFocusView,
|
|
28
|
-
viewContainerRole,
|
|
29
|
-
rendererInterceptor: RendererInterceptor
|
|
30
|
-
}) => {
|
|
31
|
-
const {
|
|
32
|
-
onChange,
|
|
33
|
-
value,
|
|
34
|
-
open,
|
|
35
|
-
setOpen
|
|
36
|
-
} = propsFromPickerValue;
|
|
37
|
-
const {
|
|
38
|
-
view: inView,
|
|
39
|
-
views,
|
|
40
|
-
openTo,
|
|
41
|
-
onViewChange,
|
|
42
|
-
viewRenderers,
|
|
43
|
-
timezone
|
|
44
|
-
} = props;
|
|
45
|
-
const propsToForwardToView = _objectWithoutPropertiesLoose(props, _excluded);
|
|
46
|
-
const fieldRef = React.useRef(null);
|
|
47
|
-
const {
|
|
48
|
-
view,
|
|
49
|
-
setView,
|
|
50
|
-
defaultView,
|
|
51
|
-
focusedView,
|
|
52
|
-
setFocusedView,
|
|
53
|
-
setValueAndGoToNextView
|
|
54
|
-
} = useViews({
|
|
55
|
-
view: inView,
|
|
56
|
-
views,
|
|
57
|
-
openTo,
|
|
58
|
-
onChange,
|
|
59
|
-
onViewChange,
|
|
60
|
-
autoFocus: autoFocusView
|
|
61
|
-
});
|
|
62
|
-
const {
|
|
63
|
-
hasUIView,
|
|
64
|
-
viewModeLookup
|
|
65
|
-
} = React.useMemo(() => views.reduce((acc, viewForReduce) => {
|
|
66
|
-
let viewMode;
|
|
67
|
-
if (viewRenderers[viewForReduce] != null) {
|
|
68
|
-
viewMode = 'UI';
|
|
69
|
-
} else {
|
|
70
|
-
viewMode = 'field';
|
|
71
|
-
}
|
|
72
|
-
acc.viewModeLookup[viewForReduce] = viewMode;
|
|
73
|
-
if (viewMode === 'UI') {
|
|
74
|
-
acc.hasUIView = true;
|
|
75
|
-
}
|
|
76
|
-
return acc;
|
|
77
|
-
}, {
|
|
78
|
-
hasUIView: false,
|
|
79
|
-
viewModeLookup: {}
|
|
80
|
-
}), [viewRenderers, views]);
|
|
81
|
-
const timeViewsCount = React.useMemo(() => views.reduce((acc, viewForReduce) => {
|
|
82
|
-
if (viewRenderers[viewForReduce] != null && isTimeView(viewForReduce)) {
|
|
83
|
-
return acc + 1;
|
|
84
|
-
}
|
|
85
|
-
return acc;
|
|
86
|
-
}, 0), [viewRenderers, views]);
|
|
87
|
-
const currentViewMode = viewModeLookup[view];
|
|
88
|
-
const doesTheCurrentViewHasAnUI = useEventCallback(() => currentViewMode === 'UI');
|
|
89
|
-
const [popperView, setPopperView] = React.useState(currentViewMode === 'UI' ? view : null);
|
|
90
|
-
if (popperView !== view && viewModeLookup[view] === 'UI') {
|
|
91
|
-
setPopperView(view);
|
|
92
|
-
}
|
|
93
|
-
useEnhancedEffect(() => {
|
|
94
|
-
// Handle case of `DateTimePicker` without time renderers
|
|
95
|
-
if (currentViewMode === 'field' && open) {
|
|
96
|
-
setOpen(false);
|
|
97
|
-
setTimeout(() => {
|
|
98
|
-
fieldRef?.current?.setSelectedSections(view);
|
|
99
|
-
// focusing the input before the range selection is done
|
|
100
|
-
// calling it outside of timeout results in an inconsistent behavior between Safari And Chrome
|
|
101
|
-
fieldRef?.current?.focusField(view);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}, [view]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
105
|
-
|
|
106
|
-
useEnhancedEffect(() => {
|
|
107
|
-
if (!open) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
let newView = view;
|
|
111
|
-
|
|
112
|
-
// If the current view is a field view, go to the last popper view
|
|
113
|
-
if (currentViewMode === 'field' && popperView != null) {
|
|
114
|
-
newView = popperView;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// If the current view is not the default view and both are UI views
|
|
118
|
-
if (newView !== defaultView && viewModeLookup[newView] === 'UI' && viewModeLookup[defaultView] === 'UI') {
|
|
119
|
-
newView = defaultView;
|
|
120
|
-
}
|
|
121
|
-
if (newView !== view) {
|
|
122
|
-
setView(newView);
|
|
123
|
-
}
|
|
124
|
-
setFocusedView(newView, true);
|
|
125
|
-
}, [open]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
126
|
-
|
|
127
|
-
const actionsContextValue = React.useMemo(() => ({
|
|
128
|
-
setView
|
|
129
|
-
}), [setView]);
|
|
130
|
-
const initialViewRef = React.useRef(openTo ?? null);
|
|
131
|
-
const contextValue = React.useMemo(() => _extends({}, actionsContextValue, {
|
|
132
|
-
views,
|
|
133
|
-
view: popperView,
|
|
134
|
-
initialView: initialViewRef.current
|
|
135
|
-
}), [actionsContextValue, views, popperView]);
|
|
136
|
-
const privateContextValue = React.useMemo(() => ({
|
|
137
|
-
hasUIView,
|
|
138
|
-
doesTheCurrentViewHasAnUI,
|
|
139
|
-
viewContainerRole
|
|
140
|
-
}), [hasUIView, doesTheCurrentViewHasAnUI, viewContainerRole]);
|
|
141
|
-
const fieldPrivateContextValue = React.useMemo(() => ({
|
|
142
|
-
fieldRef
|
|
143
|
-
}), []);
|
|
144
|
-
const providerParams = {
|
|
145
|
-
hasUIView,
|
|
146
|
-
views,
|
|
147
|
-
contextValue,
|
|
148
|
-
actionsContextValue,
|
|
149
|
-
privateContextValue,
|
|
150
|
-
fieldPrivateContextValue
|
|
151
|
-
};
|
|
152
|
-
return {
|
|
153
|
-
provider: providerParams,
|
|
154
|
-
renderCurrentView: () => {
|
|
155
|
-
if (popperView == null) {
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
const renderer = viewRenderers[popperView];
|
|
159
|
-
if (renderer == null) {
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
const rendererProps = _extends({}, propsToForwardToView, {
|
|
163
|
-
views,
|
|
164
|
-
timezone,
|
|
165
|
-
value,
|
|
166
|
-
onChange: setValueAndGoToNextView,
|
|
167
|
-
view: popperView,
|
|
168
|
-
onViewChange: setView,
|
|
169
|
-
showViewSwitcher: timeViewsCount > 1,
|
|
170
|
-
timeViewsCount
|
|
171
|
-
}, viewContainerRole === 'tooltip' ? {
|
|
172
|
-
focusedView: null,
|
|
173
|
-
onFocusedViewChange: () => {}
|
|
174
|
-
} : {
|
|
175
|
-
focusedView,
|
|
176
|
-
onFocusedViewChange: setFocusedView
|
|
177
|
-
});
|
|
178
|
-
if (RendererInterceptor) {
|
|
179
|
-
return /*#__PURE__*/_jsx(RendererInterceptor, {
|
|
180
|
-
viewRenderers: viewRenderers,
|
|
181
|
-
popperView: popperView,
|
|
182
|
-
rendererProps: rendererProps
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
return renderer(rendererProps);
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
export interface OpenStateProps {
|
|
3
|
-
open?: boolean;
|
|
4
|
-
onOpen?: () => void;
|
|
5
|
-
onClose?: () => void;
|
|
6
|
-
}
|
|
7
|
-
export declare const useOpenState: ({
|
|
8
|
-
open,
|
|
9
|
-
onOpen,
|
|
10
|
-
onClose
|
|
11
|
-
}: OpenStateProps) => {
|
|
12
|
-
open: boolean;
|
|
13
|
-
setOpen: (action: React.SetStateAction<boolean>) => void;
|
|
14
|
-
};
|