@mui/x-date-pickers 8.0.0-alpha.5 → 8.0.0-alpha.7
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/AdapterDateFns/AdapterDateFns.d.ts +2 -4
- package/AdapterDateFns/AdapterDateFns.js +49 -47
- package/AdapterDateFnsBase/AdapterDateFnsBase.d.ts +1 -1
- package/AdapterDateFnsJalali/AdapterDateFnsJalali.d.ts +2 -4
- package/AdapterDateFnsJalali/AdapterDateFnsJalali.js +48 -46
- package/{AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.d.ts → AdapterDateFnsJalaliV2/AdapterDateFnsJalaliV2.d.ts} +2 -2
- package/{AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.js → AdapterDateFnsJalaliV2/AdapterDateFnsJalaliV2.js} +45 -52
- package/AdapterDateFnsJalaliV2/index.d.ts +1 -0
- package/AdapterDateFnsJalaliV2/index.js +1 -0
- package/{AdapterDateFnsJalaliV3 → AdapterDateFnsJalaliV2}/package.json +1 -1
- package/{AdapterDateFnsV3/AdapterDateFnsV3.d.ts → AdapterDateFnsV2/AdapterDateFnsV2.d.ts} +2 -2
- package/{AdapterDateFnsV3/AdapterDateFnsV3.js → AdapterDateFnsV2/AdapterDateFnsV2.js} +46 -54
- package/AdapterDateFnsV2/index.d.ts +1 -0
- package/AdapterDateFnsV2/index.js +1 -0
- package/{AdapterDateFnsV3 → AdapterDateFnsV2}/package.json +1 -1
- package/AdapterDayjs/AdapterDayjs.d.ts +1 -1
- package/AdapterLuxon/AdapterLuxon.d.ts +1 -1
- package/AdapterMoment/AdapterMoment.d.ts +1 -1
- package/CHANGELOG.md +206 -1
- package/DateCalendar/DateCalendar.js +1 -1
- package/DateCalendar/PickersFadeTransitionGroup.d.ts +1 -1
- package/DateCalendar/PickersSlideTransition.d.ts +1 -1
- package/DateField/useDateField.d.ts +1 -1
- package/DateField/useDateField.js +13 -11
- package/DatePicker/DatePicker.js +1 -1
- package/DatePicker/DatePicker.types.d.ts +5 -0
- package/DatePicker/DatePickerToolbar.d.ts +1 -3
- package/DatePicker/DatePickerToolbar.js +10 -25
- package/DatePicker/shared.d.ts +1 -1
- package/DateTimeField/useDateTimeField.d.ts +1 -1
- package/DateTimeField/useDateTimeField.js +13 -11
- package/DateTimePicker/DateTimePicker.js +2 -2
- package/DateTimePicker/DateTimePicker.types.d.ts +2 -2
- package/DateTimePicker/DateTimePickerTabs.d.ts +2 -5
- package/DateTimePicker/DateTimePickerTabs.js +7 -14
- package/DateTimePicker/DateTimePickerToolbar.d.ts +12 -4
- package/DateTimePicker/DateTimePickerToolbar.js +42 -48
- package/DateTimePicker/shared.d.ts +3 -3
- package/DesktopDatePicker/DesktopDatePicker.js +9 -3
- package/DesktopDatePicker/DesktopDatePicker.types.d.ts +7 -3
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +13 -10
- package/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +2 -2
- package/DesktopDateTimePicker/DesktopDateTimePickerLayout.d.ts +1 -2
- package/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +1 -15
- package/DesktopTimePicker/DesktopTimePicker.js +3 -7
- package/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
- package/MobileDatePicker/MobileDatePicker.js +2 -2
- package/MobileDatePicker/MobileDatePicker.types.d.ts +2 -3
- package/MobileDateTimePicker/MobileDateTimePicker.js +2 -2
- package/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +4 -4
- package/MobileTimePicker/MobileTimePicker.js +2 -2
- package/MobileTimePicker/MobileTimePicker.types.d.ts +4 -4
- package/PickersActionBar/PickersActionBar.d.ts +6 -7
- package/PickersActionBar/PickersActionBar.js +18 -16
- package/PickersLayout/PickersLayout.d.ts +2 -2
- package/PickersLayout/PickersLayout.js +1 -15
- package/PickersLayout/PickersLayout.types.d.ts +12 -15
- package/PickersLayout/usePickerLayout.d.ts +2 -2
- package/PickersLayout/usePickerLayout.js +13 -47
- package/PickersShortcuts/PickersShortcuts.d.ts +2 -5
- package/PickersShortcuts/PickersShortcuts.js +13 -10
- package/PickersShortcuts/index.d.ts +1 -1
- package/PickersTextField/PickersInputBase/PickersInputBase.js +7 -0
- package/PickersTextField/PickersTextField.js +1 -1
- package/StaticDatePicker/StaticDatePicker.types.d.ts +2 -3
- package/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +2 -2
- package/StaticTimePicker/StaticTimePicker.types.d.ts +2 -2
- package/TimeField/useTimeField.d.ts +1 -1
- package/TimeField/useTimeField.js +13 -11
- package/TimePicker/TimePicker.js +2 -2
- package/TimePicker/TimePicker.types.d.ts +2 -2
- package/TimePicker/TimePickerToolbar.d.ts +1 -2
- package/TimePicker/TimePickerToolbar.js +23 -35
- package/TimePicker/shared.d.ts +1 -1
- package/hooks/index.d.ts +2 -0
- package/hooks/index.js +3 -1
- package/hooks/useIsValidValue.d.ts +7 -0
- package/hooks/useIsValidValue.js +11 -0
- package/hooks/usePickerActionsContext.d.ts +7 -0
- package/hooks/usePickerActionsContext.js +15 -0
- package/hooks/usePickerContext.d.ts +3 -1
- package/hooks/usePickerContext.js +1 -2
- package/index.d.ts +1 -0
- package/index.js +3 -2
- package/internals/components/PickerProvider.d.ts +14 -8
- package/internals/components/PickerProvider.js +17 -6
- package/internals/components/PickersModalDialog.d.ts +1 -3
- package/internals/components/PickersModalDialog.js +9 -3
- package/internals/components/PickersPopper.d.ts +1 -3
- package/internals/components/PickersPopper.js +11 -6
- package/internals/components/PickersToolbar.d.ts +2 -3
- package/internals/components/PickersToolbar.js +1 -1
- package/internals/hooks/date-helpers-hooks.js +4 -3
- package/internals/hooks/useDesktopPicker/useDesktopPicker.js +10 -12
- package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +7 -7
- package/internals/hooks/useField/buildSectionsFromFormat.js +1 -1
- package/internals/hooks/useField/index.d.ts +1 -1
- package/internals/hooks/useField/index.js +1 -1
- package/internals/hooks/useField/useField.d.ts +10 -1
- package/internals/hooks/useField/useField.js +17 -1
- package/internals/hooks/useField/useField.utils.js +2 -2
- package/internals/hooks/useField/useFieldState.js +2 -2
- package/internals/hooks/useField/useFieldV6TextField.js +2 -2
- package/internals/hooks/useMobilePicker/useMobilePicker.js +9 -10
- package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +7 -7
- package/internals/hooks/useOpenState.js +3 -2
- package/internals/hooks/usePicker/usePicker.d.ts +1 -1
- package/internals/hooks/usePicker/usePicker.js +0 -8
- package/internals/hooks/usePicker/usePicker.types.d.ts +6 -7
- package/internals/hooks/usePicker/usePickerProvider.d.ts +5 -5
- package/internals/hooks/usePicker/usePickerProvider.js +8 -5
- package/internals/hooks/usePicker/usePickerValue.d.ts +1 -1
- package/internals/hooks/usePicker/usePickerValue.js +82 -217
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +82 -67
- package/internals/hooks/usePicker/usePickerViews.d.ts +35 -20
- package/internals/hooks/usePicker/usePickerViews.js +22 -14
- package/internals/hooks/useStaticPicker/useStaticPicker.js +1 -4
- package/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +6 -6
- package/internals/hooks/useUtils.js +1 -1
- package/internals/index.d.ts +9 -7
- package/internals/index.js +5 -3
- package/internals/models/index.d.ts +1 -0
- package/internals/models/index.js +2 -1
- package/internals/models/manager.d.ts +12 -0
- package/internals/models/manager.js +1 -0
- package/internals/models/props/basePickerProps.d.ts +2 -2
- package/internals/models/props/tabs.d.ts +0 -13
- package/internals/models/props/toolbar.d.ts +1 -20
- package/internals/utils/date-utils.js +1 -1
- package/internals/utils/valueManagers.js +4 -4
- package/locales/index.d.ts +1 -0
- package/locales/index.js +1 -0
- package/locales/nbNO.js +15 -19
- package/locales/utils/getPickersLocalization.js +1 -1
- package/locales/zhTW.d.ts +80 -0
- package/locales/zhTW.js +73 -0
- package/managers/index.d.ts +6 -0
- package/managers/index.js +3 -0
- package/managers/package.json +6 -0
- package/managers/useDateManager.d.ts +27 -0
- package/managers/useDateManager.js +47 -0
- package/managers/useDateTimeManager.d.ts +28 -0
- package/managers/useDateTimeManager.js +52 -0
- package/managers/useTimeManager.d.ts +28 -0
- package/managers/useTimeManager.js +43 -0
- package/models/adapters.d.ts +1 -1
- package/models/index.d.ts +1 -0
- package/models/index.js +1 -0
- package/models/manager.d.ts +78 -0
- package/models/manager.js +1 -0
- package/models/pickers.d.ts +7 -0
- package/modern/AdapterDateFns/AdapterDateFns.js +49 -47
- package/modern/AdapterDateFnsJalali/AdapterDateFnsJalali.js +48 -46
- package/modern/{AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.js → AdapterDateFnsJalaliV2/AdapterDateFnsJalaliV2.js} +45 -52
- package/modern/AdapterDateFnsJalaliV2/index.js +1 -0
- package/modern/{AdapterDateFnsV3/AdapterDateFnsV3.js → AdapterDateFnsV2/AdapterDateFnsV2.js} +46 -54
- package/modern/AdapterDateFnsV2/index.js +1 -0
- package/modern/DateCalendar/DateCalendar.js +1 -1
- package/modern/DateField/useDateField.js +13 -11
- package/modern/DatePicker/DatePicker.js +1 -1
- package/modern/DatePicker/DatePickerToolbar.js +10 -25
- package/modern/DateTimeField/useDateTimeField.js +13 -11
- package/modern/DateTimePicker/DateTimePicker.js +2 -2
- package/modern/DateTimePicker/DateTimePickerTabs.js +7 -14
- package/modern/DateTimePicker/DateTimePickerToolbar.js +42 -48
- package/modern/DesktopDatePicker/DesktopDatePicker.js +9 -3
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +13 -10
- package/modern/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +1 -15
- package/modern/DesktopTimePicker/DesktopTimePicker.js +3 -7
- package/modern/MobileDatePicker/MobileDatePicker.js +2 -2
- package/modern/MobileDateTimePicker/MobileDateTimePicker.js +2 -2
- package/modern/MobileTimePicker/MobileTimePicker.js +2 -2
- package/modern/PickersActionBar/PickersActionBar.js +18 -16
- package/modern/PickersLayout/PickersLayout.js +1 -15
- package/modern/PickersLayout/usePickerLayout.js +13 -47
- package/modern/PickersShortcuts/PickersShortcuts.js +13 -10
- package/modern/PickersTextField/PickersInputBase/PickersInputBase.js +7 -0
- package/modern/PickersTextField/PickersTextField.js +1 -1
- package/modern/TimeField/useTimeField.js +13 -11
- package/modern/TimePicker/TimePicker.js +2 -2
- package/modern/TimePicker/TimePickerToolbar.js +23 -35
- package/modern/hooks/index.js +3 -1
- package/modern/hooks/useIsValidValue.js +11 -0
- package/modern/hooks/usePickerActionsContext.js +15 -0
- package/modern/hooks/usePickerContext.js +1 -2
- package/modern/index.js +3 -2
- package/modern/internals/components/PickerProvider.js +17 -6
- package/modern/internals/components/PickersModalDialog.js +9 -3
- package/modern/internals/components/PickersPopper.js +11 -6
- package/modern/internals/components/PickersToolbar.js +1 -1
- package/modern/internals/hooks/date-helpers-hooks.js +4 -3
- package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.js +10 -12
- package/modern/internals/hooks/useField/buildSectionsFromFormat.js +1 -1
- package/modern/internals/hooks/useField/index.js +1 -1
- package/modern/internals/hooks/useField/useField.js +17 -1
- package/modern/internals/hooks/useField/useField.utils.js +2 -2
- package/modern/internals/hooks/useField/useFieldState.js +2 -2
- package/modern/internals/hooks/useField/useFieldV6TextField.js +2 -2
- package/modern/internals/hooks/useMobilePicker/useMobilePicker.js +9 -10
- package/modern/internals/hooks/useOpenState.js +3 -2
- package/modern/internals/hooks/usePicker/usePicker.js +0 -8
- package/modern/internals/hooks/usePicker/usePickerProvider.js +8 -5
- package/modern/internals/hooks/usePicker/usePickerValue.js +82 -217
- package/modern/internals/hooks/usePicker/usePickerViews.js +22 -14
- package/modern/internals/hooks/useStaticPicker/useStaticPicker.js +1 -4
- package/modern/internals/hooks/useUtils.js +1 -1
- package/modern/internals/index.js +5 -3
- package/modern/internals/models/index.js +2 -1
- package/modern/internals/models/manager.js +1 -0
- package/modern/internals/utils/date-utils.js +1 -1
- package/modern/internals/utils/valueManagers.js +4 -4
- package/modern/locales/index.js +1 -0
- package/modern/locales/nbNO.js +15 -19
- package/modern/locales/utils/getPickersLocalization.js +1 -1
- package/modern/locales/zhTW.js +73 -0
- package/modern/managers/index.js +3 -0
- package/modern/managers/useDateManager.js +47 -0
- package/modern/managers/useDateTimeManager.js +52 -0
- package/modern/managers/useTimeManager.js +43 -0
- package/modern/models/index.js +1 -0
- package/modern/models/manager.js +1 -0
- package/node/AdapterDateFns/AdapterDateFns.js +97 -97
- package/node/AdapterDateFnsJalali/AdapterDateFnsJalali.js +97 -96
- package/node/{AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.js → AdapterDateFnsJalaliV2/AdapterDateFnsJalaliV2.js} +94 -101
- package/node/{AdapterDateFnsJalaliV3 → AdapterDateFnsJalaliV2}/index.js +1 -1
- package/node/AdapterDateFnsV2/AdapterDateFnsV2.js +291 -0
- package/node/{AdapterDateFnsV3 → AdapterDateFnsV2}/index.js +1 -1
- package/node/DateCalendar/DateCalendar.js +1 -1
- package/node/DateField/useDateField.js +12 -10
- package/node/DatePicker/DatePicker.js +1 -1
- package/node/DatePicker/DatePickerToolbar.js +10 -25
- package/node/DateTimeField/useDateTimeField.js +12 -10
- package/node/DateTimePicker/DateTimePicker.js +2 -2
- package/node/DateTimePicker/DateTimePickerTabs.js +7 -14
- package/node/DateTimePicker/DateTimePickerToolbar.js +43 -49
- package/node/DesktopDatePicker/DesktopDatePicker.js +9 -3
- package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +13 -10
- package/node/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +1 -15
- package/node/DesktopTimePicker/DesktopTimePicker.js +3 -7
- package/node/MobileDatePicker/MobileDatePicker.js +2 -2
- package/node/MobileDateTimePicker/MobileDateTimePicker.js +2 -2
- package/node/MobileTimePicker/MobileTimePicker.js +2 -2
- package/node/PickersActionBar/PickersActionBar.js +20 -18
- package/node/PickersLayout/PickersLayout.js +1 -15
- package/node/PickersLayout/usePickerLayout.js +17 -51
- package/node/PickersShortcuts/PickersShortcuts.js +13 -10
- package/node/PickersTextField/PickersInputBase/PickersInputBase.js +7 -0
- package/node/PickersTextField/PickersTextField.js +1 -1
- package/node/TimeField/useTimeField.js +12 -10
- package/node/TimePicker/TimePicker.js +2 -2
- package/node/TimePicker/TimePickerToolbar.js +23 -35
- package/node/hooks/index.js +15 -1
- package/node/hooks/useIsValidValue.js +18 -0
- package/node/hooks/usePickerActionsContext.js +22 -0
- package/node/hooks/usePickerContext.js +1 -1
- package/node/index.js +13 -1
- package/node/internals/components/PickerProvider.js +18 -7
- package/node/internals/components/PickersModalDialog.js +9 -3
- package/node/internals/components/PickersPopper.js +11 -6
- package/node/internals/components/PickersToolbar.js +1 -1
- package/node/internals/hooks/date-helpers-hooks.js +4 -3
- package/node/internals/hooks/useDesktopPicker/useDesktopPicker.js +10 -12
- package/node/internals/hooks/useField/buildSectionsFromFormat.js +1 -1
- package/node/internals/hooks/useField/index.js +6 -0
- package/node/internals/hooks/useField/useField.js +18 -1
- package/node/internals/hooks/useField/useField.utils.js +2 -2
- package/node/internals/hooks/useField/useFieldState.js +2 -2
- package/node/internals/hooks/useField/useFieldV6TextField.js +2 -2
- package/node/internals/hooks/useMobilePicker/useMobilePicker.js +9 -10
- package/node/internals/hooks/useOpenState.js +4 -2
- package/node/internals/hooks/usePicker/usePicker.js +0 -9
- package/node/internals/hooks/usePicker/usePickerProvider.js +8 -5
- package/node/internals/hooks/usePicker/usePickerValue.js +82 -217
- package/node/internals/hooks/usePicker/usePickerViews.js +22 -15
- package/node/internals/hooks/useStaticPicker/useStaticPicker.js +1 -4
- package/node/internals/hooks/useUtils.js +1 -1
- package/node/internals/index.js +28 -20
- package/node/internals/models/index.js +11 -0
- package/node/internals/models/manager.js +5 -0
- package/node/internals/utils/date-utils.js +1 -1
- package/node/internals/utils/valueManagers.js +4 -4
- package/node/locales/index.js +11 -0
- package/node/locales/nbNO.js +15 -19
- package/node/locales/utils/getPickersLocalization.js +1 -1
- package/node/locales/zhTW.js +79 -0
- package/node/managers/index.js +26 -0
- package/node/managers/useDateManager.js +55 -0
- package/node/managers/useDateTimeManager.js +60 -0
- package/node/managers/useTimeManager.js +51 -0
- package/node/models/index.js +11 -0
- package/node/models/manager.js +5 -0
- package/package.json +3 -3
- package/themeAugmentation/props.d.ts +2 -3
- package/validation/extractValidationProps.d.ts +1 -1
- package/AdapterDateFnsJalaliV3/index.d.ts +0 -1
- package/AdapterDateFnsJalaliV3/index.js +0 -1
- package/AdapterDateFnsV3/index.d.ts +0 -1
- package/AdapterDateFnsV3/index.js +0 -1
- package/internals/hooks/defaultizedFieldProps.d.ts +0 -18
- package/internals/hooks/defaultizedFieldProps.js +0 -40
- package/modern/AdapterDateFnsJalaliV3/index.js +0 -1
- package/modern/AdapterDateFnsV3/index.js +0 -1
- package/modern/internals/hooks/defaultizedFieldProps.js +0 -40
- package/node/AdapterDateFnsV3/AdapterDateFnsV3.js +0 -299
- package/node/internals/hooks/defaultizedFieldProps.js +0 -50
|
@@ -5,106 +5,6 @@ import { useOpenState } from "../useOpenState.js";
|
|
|
5
5
|
import { useLocalizationContext, useUtils } from "../useUtils.js";
|
|
6
6
|
import { useValidation } from "../../../validation/index.js";
|
|
7
7
|
import { useValueWithTimezone } from "../useValueWithTimezone.js";
|
|
8
|
-
/**
|
|
9
|
-
* Decide if the new value should be published
|
|
10
|
-
* The published value will be passed to `onChange` if defined.
|
|
11
|
-
*/
|
|
12
|
-
const shouldPublishValue = params => {
|
|
13
|
-
const {
|
|
14
|
-
action,
|
|
15
|
-
hasChanged,
|
|
16
|
-
dateState,
|
|
17
|
-
isControlled
|
|
18
|
-
} = params;
|
|
19
|
-
const isCurrentValueTheDefaultValue = !isControlled && !dateState.hasBeenModifiedSinceMount;
|
|
20
|
-
|
|
21
|
-
// The field is responsible for only calling `onChange` when needed.
|
|
22
|
-
if (action.name === 'setValueFromField') {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
if (action.name === 'setValueFromAction') {
|
|
26
|
-
// If the component is not controlled, and the value has not been modified since the mount,
|
|
27
|
-
// Then we want to publish the default value whenever the user pressed the "Accept", "Today" or "Clear" button.
|
|
28
|
-
if (isCurrentValueTheDefaultValue && ['accept', 'today', 'clear'].includes(action.pickerAction)) {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
return hasChanged(dateState.lastPublishedValue);
|
|
32
|
-
}
|
|
33
|
-
if (action.name === 'setValueFromView' && action.selectionState !== 'shallow') {
|
|
34
|
-
// On the first view,
|
|
35
|
-
// If the value is not controlled, then clicking on any value (including the one equal to `defaultValue`) should call `onChange`
|
|
36
|
-
if (isCurrentValueTheDefaultValue) {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
return hasChanged(dateState.lastPublishedValue);
|
|
40
|
-
}
|
|
41
|
-
if (action.name === 'setValueFromShortcut') {
|
|
42
|
-
// On the first view,
|
|
43
|
-
// If the value is not controlled, then clicking on any value (including the one equal to `defaultValue`) should call `onChange`
|
|
44
|
-
if (isCurrentValueTheDefaultValue) {
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
return hasChanged(dateState.lastPublishedValue);
|
|
48
|
-
}
|
|
49
|
-
return false;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Decide if the new value should be committed.
|
|
54
|
-
* The committed value will be passed to `onAccept` if defined.
|
|
55
|
-
* It will also be used as a reset target when calling the `cancel` picker action (when clicking on the "Cancel" button).
|
|
56
|
-
*/
|
|
57
|
-
const shouldCommitValue = params => {
|
|
58
|
-
const {
|
|
59
|
-
action,
|
|
60
|
-
hasChanged,
|
|
61
|
-
dateState,
|
|
62
|
-
isControlled,
|
|
63
|
-
closeOnSelect
|
|
64
|
-
} = params;
|
|
65
|
-
const isCurrentValueTheDefaultValue = !isControlled && !dateState.hasBeenModifiedSinceMount;
|
|
66
|
-
if (action.name === 'setValueFromAction') {
|
|
67
|
-
// If the component is not controlled, and the value has not been modified since the mount,
|
|
68
|
-
// Then we want to commit the default value whenever the user pressed the "Accept", "Today" or "Clear" button.
|
|
69
|
-
if (isCurrentValueTheDefaultValue && ['accept', 'today', 'clear'].includes(action.pickerAction)) {
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
return hasChanged(dateState.lastCommittedValue);
|
|
73
|
-
}
|
|
74
|
-
if (action.name === 'setValueFromView' && action.selectionState === 'finish' && closeOnSelect) {
|
|
75
|
-
// On picker where the 1st view is also the last view,
|
|
76
|
-
// If the value is not controlled, then clicking on any value (including the one equal to `defaultValue`) should call `onAccept`
|
|
77
|
-
if (isCurrentValueTheDefaultValue) {
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
return hasChanged(dateState.lastCommittedValue);
|
|
81
|
-
}
|
|
82
|
-
if (action.name === 'setValueFromShortcut') {
|
|
83
|
-
return action.changeImportance === 'accept' && hasChanged(dateState.lastCommittedValue);
|
|
84
|
-
}
|
|
85
|
-
return false;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Decide if the picker should be closed after the value is updated.
|
|
90
|
-
*/
|
|
91
|
-
const shouldClosePicker = params => {
|
|
92
|
-
const {
|
|
93
|
-
action,
|
|
94
|
-
closeOnSelect
|
|
95
|
-
} = params;
|
|
96
|
-
if (action.name === 'setValueFromAction') {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
if (action.name === 'setValueFromView') {
|
|
100
|
-
return action.selectionState === 'finish' && closeOnSelect;
|
|
101
|
-
}
|
|
102
|
-
if (action.name === 'setValueFromShortcut') {
|
|
103
|
-
return action.changeImportance === 'accept';
|
|
104
|
-
}
|
|
105
|
-
return false;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
8
|
/**
|
|
109
9
|
* Manage the value lifecycle of all the pickers.
|
|
110
10
|
*/
|
|
@@ -112,7 +12,6 @@ export const usePickerValue = ({
|
|
|
112
12
|
props,
|
|
113
13
|
valueManager,
|
|
114
14
|
valueType,
|
|
115
|
-
variant,
|
|
116
15
|
validator
|
|
117
16
|
}) => {
|
|
118
17
|
const {
|
|
@@ -120,7 +19,7 @@ export const usePickerValue = ({
|
|
|
120
19
|
onChange,
|
|
121
20
|
value: inValueWithoutRenderTimezone,
|
|
122
21
|
defaultValue: inDefaultValue,
|
|
123
|
-
closeOnSelect =
|
|
22
|
+
closeOnSelect = false,
|
|
124
23
|
timezone: timezoneProp,
|
|
125
24
|
referenceDate
|
|
126
25
|
} = props;
|
|
@@ -200,43 +99,49 @@ export const usePickerValue = ({
|
|
|
200
99
|
value: dateState.draft,
|
|
201
100
|
onError: props.onError
|
|
202
101
|
});
|
|
203
|
-
const
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
102
|
+
const setValue = useEventCallback((newValue, options) => {
|
|
103
|
+
const {
|
|
104
|
+
changeImportance = 'accept',
|
|
105
|
+
skipPublicationIfPristine = false,
|
|
106
|
+
validationError,
|
|
107
|
+
shortcut
|
|
108
|
+
} = options ?? {};
|
|
109
|
+
let shouldPublish;
|
|
110
|
+
let shouldCommit;
|
|
111
|
+
if (!skipPublicationIfPristine && !isControlled && !dateState.hasBeenModifiedSinceMount) {
|
|
112
|
+
// If the value is not controlled and the value has never been modified before,
|
|
113
|
+
// Then clicking on any value (including the one equal to `defaultValue`) should call `onChange` and `onAccept`
|
|
114
|
+
shouldPublish = true;
|
|
115
|
+
shouldCommit = changeImportance === 'accept';
|
|
116
|
+
} else {
|
|
117
|
+
shouldPublish = !valueManager.areValuesEqual(utils, newValue, dateState.lastPublishedValue);
|
|
118
|
+
shouldCommit = changeImportance === 'accept' && !valueManager.areValuesEqual(utils, newValue, dateState.lastCommittedValue);
|
|
119
|
+
}
|
|
214
120
|
setDateState(prev => _extends({}, prev, {
|
|
215
|
-
draft:
|
|
216
|
-
lastPublishedValue: shouldPublish ?
|
|
217
|
-
lastCommittedValue: shouldCommit ?
|
|
121
|
+
draft: newValue,
|
|
122
|
+
lastPublishedValue: shouldPublish ? newValue : prev.lastPublishedValue,
|
|
123
|
+
lastCommittedValue: shouldCommit ? newValue : prev.lastCommittedValue,
|
|
218
124
|
hasBeenModifiedSinceMount: true
|
|
219
125
|
}));
|
|
220
126
|
let cachedContext = null;
|
|
221
127
|
const getContext = () => {
|
|
222
128
|
if (!cachedContext) {
|
|
223
|
-
const validationError = action.name === 'setValueFromField' ? action.context.validationError : getValidationErrorForNewValue(action.value);
|
|
224
129
|
cachedContext = {
|
|
225
|
-
validationError
|
|
130
|
+
validationError: validationError == null ? getValidationErrorForNewValue(newValue) : validationError
|
|
226
131
|
};
|
|
227
|
-
if (
|
|
228
|
-
cachedContext.shortcut =
|
|
132
|
+
if (shortcut) {
|
|
133
|
+
cachedContext.shortcut = shortcut;
|
|
229
134
|
}
|
|
230
135
|
}
|
|
231
136
|
return cachedContext;
|
|
232
137
|
};
|
|
233
138
|
if (shouldPublish) {
|
|
234
|
-
handleValueChange(
|
|
139
|
+
handleValueChange(newValue, getContext());
|
|
235
140
|
}
|
|
236
141
|
if (shouldCommit && onAccept) {
|
|
237
|
-
onAccept(
|
|
142
|
+
onAccept(newValue, getContext());
|
|
238
143
|
}
|
|
239
|
-
if (
|
|
144
|
+
if (changeImportance === 'accept') {
|
|
240
145
|
setOpen(false);
|
|
241
146
|
}
|
|
242
147
|
});
|
|
@@ -251,85 +156,6 @@ export const usePickerValue = ({
|
|
|
251
156
|
hasBeenModifiedSinceMount: true
|
|
252
157
|
}));
|
|
253
158
|
}
|
|
254
|
-
const handleClear = useEventCallback(() => {
|
|
255
|
-
updateDate({
|
|
256
|
-
value: valueManager.emptyValue,
|
|
257
|
-
name: 'setValueFromAction',
|
|
258
|
-
pickerAction: 'clear'
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
const handleAccept = useEventCallback(() => {
|
|
262
|
-
updateDate({
|
|
263
|
-
value: dateState.lastPublishedValue,
|
|
264
|
-
name: 'setValueFromAction',
|
|
265
|
-
pickerAction: 'accept'
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
const handleDismiss = useEventCallback(() => {
|
|
269
|
-
updateDate({
|
|
270
|
-
value: dateState.lastPublishedValue,
|
|
271
|
-
name: 'setValueFromAction',
|
|
272
|
-
pickerAction: 'dismiss'
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
const handleCancel = useEventCallback(() => {
|
|
276
|
-
updateDate({
|
|
277
|
-
value: dateState.lastCommittedValue,
|
|
278
|
-
name: 'setValueFromAction',
|
|
279
|
-
pickerAction: 'cancel'
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
const handleSetToday = useEventCallback(() => {
|
|
283
|
-
updateDate({
|
|
284
|
-
value: valueManager.getTodayValue(utils, timezone, valueType),
|
|
285
|
-
name: 'setValueFromAction',
|
|
286
|
-
pickerAction: 'today'
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
const handleOpen = useEventCallback(event => {
|
|
290
|
-
event.preventDefault();
|
|
291
|
-
setOpen(true);
|
|
292
|
-
});
|
|
293
|
-
const handleClose = useEventCallback(event => {
|
|
294
|
-
event?.preventDefault();
|
|
295
|
-
setOpen(false);
|
|
296
|
-
});
|
|
297
|
-
const handleChange = useEventCallback((newValue, selectionState = 'partial') => updateDate({
|
|
298
|
-
name: 'setValueFromView',
|
|
299
|
-
value: newValue,
|
|
300
|
-
selectionState
|
|
301
|
-
}));
|
|
302
|
-
const handleSelectShortcut = useEventCallback((newValue, changeImportance, shortcut) => updateDate({
|
|
303
|
-
name: 'setValueFromShortcut',
|
|
304
|
-
value: newValue,
|
|
305
|
-
changeImportance,
|
|
306
|
-
shortcut
|
|
307
|
-
}));
|
|
308
|
-
const handleChangeFromField = useEventCallback((newValue, context) => updateDate({
|
|
309
|
-
name: 'setValueFromField',
|
|
310
|
-
value: newValue,
|
|
311
|
-
context
|
|
312
|
-
}));
|
|
313
|
-
const actions = {
|
|
314
|
-
onClear: handleClear,
|
|
315
|
-
onAccept: handleAccept,
|
|
316
|
-
onDismiss: handleDismiss,
|
|
317
|
-
onCancel: handleCancel,
|
|
318
|
-
onSetToday: handleSetToday,
|
|
319
|
-
onOpen: handleOpen,
|
|
320
|
-
onClose: handleClose
|
|
321
|
-
};
|
|
322
|
-
const fieldResponse = {
|
|
323
|
-
value: dateState.draft,
|
|
324
|
-
onChange: handleChangeFromField
|
|
325
|
-
};
|
|
326
|
-
const valueWithoutError = React.useMemo(() => valueManager.cleanValue(utils, dateState.draft), [utils, valueManager, dateState.draft]);
|
|
327
|
-
const viewResponse = {
|
|
328
|
-
value: valueWithoutError,
|
|
329
|
-
onChange: handleChange,
|
|
330
|
-
onClose: handleClose,
|
|
331
|
-
open
|
|
332
|
-
};
|
|
333
159
|
const isValid = testedValue => {
|
|
334
160
|
const error = validator({
|
|
335
161
|
adapter,
|
|
@@ -339,28 +165,67 @@ export const usePickerValue = ({
|
|
|
339
165
|
});
|
|
340
166
|
return !valueManager.hasError(error);
|
|
341
167
|
};
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
168
|
+
const clearValue = useEventCallback(() => setValue(valueManager.emptyValue));
|
|
169
|
+
const setValueToToday = useEventCallback(() => setValue(valueManager.getTodayValue(utils, timezone, valueType)));
|
|
170
|
+
const acceptValueChanges = useEventCallback(() => setValue(dateState.lastPublishedValue));
|
|
171
|
+
const cancelValueChanges = useEventCallback(() => setValue(dateState.lastCommittedValue, {
|
|
172
|
+
skipPublicationIfPristine: true
|
|
173
|
+
}));
|
|
174
|
+
const dismissViews = useEventCallback(() => {
|
|
175
|
+
setValue(dateState.lastPublishedValue, {
|
|
176
|
+
skipPublicationIfPristine: true
|
|
177
|
+
});
|
|
347
178
|
});
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
353
|
-
}
|
|
179
|
+
const fieldResponse = {
|
|
180
|
+
value: dateState.draft,
|
|
181
|
+
onChange: (newValue, context) => setValue(newValue, {
|
|
182
|
+
validationError: context.validationError
|
|
183
|
+
})
|
|
184
|
+
};
|
|
185
|
+
const setValueFromView = useEventCallback((newValue, selectionState = 'partial') => {
|
|
186
|
+
// TODO: Expose a new method (private?) like `setView` that only updates the draft value.
|
|
187
|
+
if (selectionState === 'shallow') {
|
|
188
|
+
setDateState(prev => _extends({}, prev, {
|
|
189
|
+
draft: newValue,
|
|
190
|
+
hasBeenModifiedSinceMount: true
|
|
191
|
+
}));
|
|
192
|
+
}
|
|
193
|
+
setValue(newValue, {
|
|
194
|
+
changeImportance: selectionState === 'finish' && closeOnSelect ? 'accept' : 'set'
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
const valueWithoutError = React.useMemo(() => valueManager.cleanValue(utils, dateState.draft), [utils, valueManager, dateState.draft]);
|
|
198
|
+
const viewResponse = {
|
|
199
|
+
value: valueWithoutError,
|
|
200
|
+
onChange: setValueFromView,
|
|
201
|
+
open,
|
|
202
|
+
setOpen
|
|
203
|
+
};
|
|
204
|
+
const actionsContextValue = React.useMemo(() => ({
|
|
205
|
+
setValue,
|
|
206
|
+
setOpen,
|
|
207
|
+
clearValue,
|
|
208
|
+
setValueToToday,
|
|
209
|
+
acceptValueChanges,
|
|
210
|
+
cancelValueChanges
|
|
211
|
+
}), [setValue, setOpen, clearValue, setValueToToday, acceptValueChanges, cancelValueChanges]);
|
|
212
|
+
const contextValue = React.useMemo(() => _extends({}, actionsContextValue, {
|
|
213
|
+
open,
|
|
214
|
+
value: dateState.draft
|
|
215
|
+
}), [actionsContextValue, open, dateState.draft]);
|
|
216
|
+
const privateContextValue = React.useMemo(() => ({
|
|
217
|
+
dismissViews
|
|
218
|
+
}), [dismissViews]);
|
|
354
219
|
const providerParams = {
|
|
355
220
|
value: valueWithoutError,
|
|
356
|
-
contextValue
|
|
221
|
+
contextValue,
|
|
222
|
+
actionsContextValue,
|
|
223
|
+
privateContextValue,
|
|
224
|
+
isValidContextValue: isValid
|
|
357
225
|
};
|
|
358
226
|
return {
|
|
359
|
-
open,
|
|
360
227
|
fieldProps: fieldResponse,
|
|
361
228
|
viewProps: viewResponse,
|
|
362
|
-
layoutProps: layoutResponse,
|
|
363
|
-
actions,
|
|
364
229
|
provider: providerParams
|
|
365
230
|
};
|
|
366
231
|
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { UseFieldInternalProps } from '../useField';
|
|
3
3
|
import { Validator } from '../../../validation';
|
|
4
|
-
import {
|
|
5
|
-
import { TimezoneProps, MuiPickersAdapter, PickersTimezone, PickerChangeHandlerContext, PickerValidDate, OnErrorProps, InferError, PickerValueType } from '../../../models';
|
|
4
|
+
import { TimezoneProps, MuiPickersAdapter, PickersTimezone, PickerChangeHandlerContext, PickerValidDate, OnErrorProps, InferError, PickerValueType, PickerChangeImportance } from '../../../models';
|
|
6
5
|
import { GetDefaultReferenceDateProps } from '../../utils/getDefaultReferenceDate';
|
|
7
|
-
import {
|
|
6
|
+
import type { PickersShortcutsItemContext } from '../../../PickersShortcuts';
|
|
8
7
|
import { InferNonNullablePickerValue, PickerValidValue } from '../../models';
|
|
9
8
|
export interface PickerValueManager<TValue extends PickerValidValue, TError> {
|
|
10
9
|
/**
|
|
@@ -137,37 +136,6 @@ export interface UsePickerValueState<TValue extends PickerValidValue> {
|
|
|
137
136
|
*/
|
|
138
137
|
hasBeenModifiedSinceMount: boolean;
|
|
139
138
|
}
|
|
140
|
-
export interface PickerValueUpdaterParams<TValue extends PickerValidValue, TError> {
|
|
141
|
-
action: PickerValueUpdateAction<TValue, TError>;
|
|
142
|
-
dateState: UsePickerValueState<TValue>;
|
|
143
|
-
/**
|
|
144
|
-
* Check if the new draft value has changed compared to some given value.
|
|
145
|
-
* @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.
|
|
146
|
-
* @param {TValue} comparisonValue The value to compare the new draft value with.
|
|
147
|
-
* @returns {boolean} `true` if the new draft value is equal to the comparison value.
|
|
148
|
-
*/
|
|
149
|
-
hasChanged: (comparisonValue: TValue) => boolean;
|
|
150
|
-
isControlled: boolean;
|
|
151
|
-
closeOnSelect: boolean;
|
|
152
|
-
}
|
|
153
|
-
export type PickerValueUpdateAction<TValue extends PickerValidValue, TError> = {
|
|
154
|
-
name: 'setValueFromView';
|
|
155
|
-
value: TValue;
|
|
156
|
-
selectionState: PickerSelectionState;
|
|
157
|
-
} | {
|
|
158
|
-
name: 'setValueFromField';
|
|
159
|
-
value: TValue;
|
|
160
|
-
context: FieldChangeHandlerContext<TError>;
|
|
161
|
-
} | {
|
|
162
|
-
name: 'setValueFromAction';
|
|
163
|
-
value: TValue;
|
|
164
|
-
pickerAction: 'accept' | 'today' | 'cancel' | 'dismiss' | 'clear';
|
|
165
|
-
} | {
|
|
166
|
-
name: 'setValueFromShortcut';
|
|
167
|
-
value: TValue;
|
|
168
|
-
changeImportance: PickerShortcutChangeImportance;
|
|
169
|
-
shortcut: PickersShortcutsItemContext;
|
|
170
|
-
};
|
|
171
139
|
/**
|
|
172
140
|
* Props used to handle the value that are common to all pickers.
|
|
173
141
|
*/
|
|
@@ -204,8 +172,8 @@ export interface UsePickerValueBaseProps<TValue extends PickerValidValue, TError
|
|
|
204
172
|
*/
|
|
205
173
|
export interface UsePickerValueNonStaticProps {
|
|
206
174
|
/**
|
|
207
|
-
* If `true`, the
|
|
208
|
-
* @default
|
|
175
|
+
* If `true`, the Picker will close after submitting the full date.
|
|
176
|
+
* @default false
|
|
209
177
|
*/
|
|
210
178
|
closeOnSelect?: boolean;
|
|
211
179
|
/**
|
|
@@ -234,18 +202,8 @@ export interface UsePickerValueParams<TValue extends PickerValidValue, TExternal
|
|
|
234
202
|
props: TExternalProps;
|
|
235
203
|
valueManager: PickerValueManager<TValue, InferError<TExternalProps>>;
|
|
236
204
|
valueType: PickerValueType;
|
|
237
|
-
variant: PickerVariant;
|
|
238
205
|
validator: Validator<TValue, InferError<TExternalProps>, TExternalProps>;
|
|
239
206
|
}
|
|
240
|
-
export interface UsePickerValueActions {
|
|
241
|
-
onAccept: () => void;
|
|
242
|
-
onClear: () => void;
|
|
243
|
-
onDismiss: () => void;
|
|
244
|
-
onCancel: () => void;
|
|
245
|
-
onSetToday: () => void;
|
|
246
|
-
onOpen: (event: React.UIEvent) => void;
|
|
247
|
-
onClose: (event?: React.UIEvent) => void;
|
|
248
|
-
}
|
|
249
207
|
export type UsePickerValueFieldResponse<TValue extends PickerValidValue, TError> = Required<Pick<UseFieldInternalProps<TValue, any, TError>, 'value' | 'onChange'>>;
|
|
250
208
|
/**
|
|
251
209
|
* Props passed to `usePickerViews`.
|
|
@@ -254,35 +212,42 @@ export interface UsePickerValueViewsResponse<TValue extends PickerValidValue> {
|
|
|
254
212
|
value: TValue;
|
|
255
213
|
onChange: (value: TValue, selectionState?: PickerSelectionState) => void;
|
|
256
214
|
open: boolean;
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Props passed to `usePickerLayoutProps`.
|
|
261
|
-
*/
|
|
262
|
-
export interface UsePickerValueLayoutResponse<TValue extends PickerValidValue> extends UsePickerValueActions {
|
|
263
|
-
value: TValue;
|
|
264
|
-
onChange: (newValue: TValue) => void;
|
|
265
|
-
onSelectShortcut: (newValue: TValue, changeImportance: PickerShortcutChangeImportance, shortcut: PickersShortcutsItemContext) => void;
|
|
266
|
-
isValid: (value: TValue) => boolean;
|
|
215
|
+
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
267
216
|
}
|
|
268
217
|
/**
|
|
269
218
|
* Params passed to `usePickerProvider`.
|
|
270
219
|
*/
|
|
271
|
-
export interface UsePickerValueProviderParams<TValue extends PickerValidValue> {
|
|
220
|
+
export interface UsePickerValueProviderParams<TValue extends PickerValidValue, TError> {
|
|
272
221
|
value: TValue;
|
|
273
|
-
contextValue: UsePickerValueContextValue
|
|
222
|
+
contextValue: UsePickerValueContextValue<TValue, TError>;
|
|
223
|
+
actionsContextValue: UsePickerValueActionsContextValue<TValue, TError>;
|
|
224
|
+
privateContextValue: UsePickerValuePrivateContextValue;
|
|
225
|
+
isValidContextValue: (value: TValue) => boolean;
|
|
274
226
|
}
|
|
275
227
|
export interface UsePickerValueResponse<TValue extends PickerValidValue, TError> {
|
|
276
|
-
open: boolean;
|
|
277
|
-
actions: UsePickerValueActions;
|
|
278
228
|
viewProps: UsePickerValueViewsResponse<TValue>;
|
|
279
229
|
fieldProps: UsePickerValueFieldResponse<TValue, TError>;
|
|
280
|
-
|
|
281
|
-
|
|
230
|
+
provider: UsePickerValueProviderParams<TValue, TError>;
|
|
231
|
+
}
|
|
232
|
+
export interface UsePickerValueContextValue<TValue extends PickerValidValue, TError> extends UsePickerValueActionsContextValue<TValue, TError> {
|
|
233
|
+
/**
|
|
234
|
+
* The current value of the picker.
|
|
235
|
+
*/
|
|
236
|
+
value: TValue;
|
|
237
|
+
/**
|
|
238
|
+
* `true` if the picker is open, `false` otherwise.
|
|
239
|
+
*/
|
|
240
|
+
open: boolean;
|
|
282
241
|
}
|
|
283
|
-
export interface
|
|
242
|
+
export interface UsePickerValueActionsContextValue<TValue extends PickerValidValue, TError> {
|
|
284
243
|
/**
|
|
285
|
-
*
|
|
244
|
+
* Set the current value of the picker.
|
|
245
|
+
* @param {TValue} value The new value of the picker.
|
|
246
|
+
* @param {SetValueActionOptions<TError>} options The options to customize the behavior of this update.
|
|
247
|
+
*/
|
|
248
|
+
setValue: (value: TValue, options?: SetValueActionOptions<TError>) => void;
|
|
249
|
+
/**
|
|
250
|
+
* Set the current open state of the Picker.
|
|
286
251
|
* ```ts
|
|
287
252
|
* setOpen(true); // Opens the picker.
|
|
288
253
|
* setOpen(false); // Closes the picker.
|
|
@@ -293,7 +258,57 @@ export interface UsePickerValueContextValue {
|
|
|
293
258
|
*/
|
|
294
259
|
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
295
260
|
/**
|
|
296
|
-
*
|
|
261
|
+
* Set the current value of the picker to be empty.
|
|
262
|
+
* The value will be `null` on single pickers and `[null, null]` on range pickers.
|
|
297
263
|
*/
|
|
298
|
-
|
|
264
|
+
clearValue: () => void;
|
|
265
|
+
/**
|
|
266
|
+
* Set the current value of the picker to be the current date.
|
|
267
|
+
* The value will be `today` on single pickers and `[today, today]` on range pickers.
|
|
268
|
+
* 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.
|
|
269
|
+
*/
|
|
270
|
+
setValueToToday: () => void;
|
|
271
|
+
/**
|
|
272
|
+
* Accept the current value of the picker.
|
|
273
|
+
* Will call `onAccept` if defined.
|
|
274
|
+
* If the picker is re-opened, this value will be the one used to initialize the views.
|
|
275
|
+
*/
|
|
276
|
+
acceptValueChanges: () => void;
|
|
277
|
+
/**
|
|
278
|
+
* Cancel the changes made to the current value of the picker.
|
|
279
|
+
* The value will be reset to the last accepted value.
|
|
280
|
+
*/
|
|
281
|
+
cancelValueChanges: () => void;
|
|
282
|
+
}
|
|
283
|
+
export interface UsePickerValuePrivateContextValue {
|
|
284
|
+
/**
|
|
285
|
+
* Closes the picker and accepts the current value if it is not equal to the last accepted value.
|
|
286
|
+
*/
|
|
287
|
+
dismissViews: () => void;
|
|
288
|
+
}
|
|
289
|
+
export interface SetValueActionOptions<TError = string> {
|
|
290
|
+
/**
|
|
291
|
+
* Importance of the change when picking a value:
|
|
292
|
+
* - "accept": fires `onChange`, fires `onAccept` and closes the picker.
|
|
293
|
+
* - "set": fires `onChange` but do not fire `onAccept` and does not close the picker.
|
|
294
|
+
* @default "accept"
|
|
295
|
+
*/
|
|
296
|
+
changeImportance?: PickerChangeImportance;
|
|
297
|
+
/**
|
|
298
|
+
* The validation error associated to the current value.
|
|
299
|
+
* If not defined, the validation will be re-applied by the picker.
|
|
300
|
+
*/
|
|
301
|
+
validationError?: TError;
|
|
302
|
+
/**
|
|
303
|
+
* The shortcut that triggered this change.
|
|
304
|
+
* Should not be defined if the change does not come from a shortcut.
|
|
305
|
+
*/
|
|
306
|
+
shortcut?: PickersShortcutsItemContext;
|
|
307
|
+
/**
|
|
308
|
+
* Decide if the value should call `onChange` and `onAccept` when the value is not controlled and has never been modified.
|
|
309
|
+
* 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).
|
|
310
|
+
* 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").
|
|
311
|
+
* @default false
|
|
312
|
+
*/
|
|
313
|
+
skipPublicationIfPristine?: boolean;
|
|
299
314
|
}
|
|
@@ -5,9 +5,9 @@ import { UseViewsOptions } from '../useViews';
|
|
|
5
5
|
import type { UsePickerValueViewsResponse } from './usePickerValue.types';
|
|
6
6
|
import { DateOrTimeViewWithMeridiem, PickerRangeValue, PickerValidValue, PickerValue } from '../../models';
|
|
7
7
|
import { FieldRef, PickerValidDate, TimezoneProps } from '../../../models';
|
|
8
|
-
interface PickerViewsRendererBaseExternalProps
|
|
8
|
+
export interface PickerViewsRendererBaseExternalProps extends Omit<UsePickerViewsProps<any, any, any>, 'openTo' | 'viewRenderers'> {
|
|
9
9
|
}
|
|
10
|
-
export type PickerViewsRendererProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends PickerViewsRendererBaseExternalProps
|
|
10
|
+
export type PickerViewsRendererProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends PickerViewsRendererBaseExternalProps> = Omit<TExternalProps, 'className' | 'sx'> & Pick<UsePickerValueViewsResponse<TValue>, 'value' | 'onChange'> & {
|
|
11
11
|
view: TView;
|
|
12
12
|
views: readonly TView[];
|
|
13
13
|
focusedView: TView | null;
|
|
@@ -15,19 +15,17 @@ export type PickerViewsRendererProps<TValue extends PickerValidValue, TView exte
|
|
|
15
15
|
showViewSwitcher: boolean;
|
|
16
16
|
timeViewsCount: number;
|
|
17
17
|
};
|
|
18
|
-
export type PickerViewRenderer<TValue extends PickerValidValue,
|
|
19
|
-
export type PickerViewRendererLookup<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends PickerViewsRendererBaseExternalProps<
|
|
20
|
-
[K in TView]: PickerViewRenderer<TValue, K, TExternalProps, TAdditionalProps> | null;
|
|
21
|
-
};
|
|
18
|
+
export type PickerViewRenderer<TValue extends PickerValidValue, TExternalProps extends PickerViewsRendererBaseExternalProps> = (props: PickerViewsRendererProps<TValue, any, TExternalProps>) => React.ReactNode;
|
|
19
|
+
export type PickerViewRendererLookup<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends PickerViewsRendererBaseExternalProps> = Record<TView, PickerViewRenderer<TValue, TExternalProps> | null>;
|
|
22
20
|
/**
|
|
23
21
|
* Props used to handle the views that are common to all pickers.
|
|
24
22
|
*/
|
|
25
|
-
export interface UsePickerViewsBaseProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, any
|
|
23
|
+
export interface UsePickerViewsBaseProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, any>> extends Omit<UseViewsOptions<any, TView>, 'onChange' | 'onFocusedViewChange' | 'focusedView'>, TimezoneProps {
|
|
26
24
|
/**
|
|
27
25
|
* If `null`, the section will only have field editing.
|
|
28
26
|
* If `undefined`, internally defined view will be used.
|
|
29
27
|
*/
|
|
30
|
-
viewRenderers: PickerViewRendererLookup<TValue, TView, TExternalProps
|
|
28
|
+
viewRenderers: PickerViewRendererLookup<TValue, TView, TExternalProps>;
|
|
31
29
|
/**
|
|
32
30
|
* If `true`, disable heavy animations.
|
|
33
31
|
* @default `@media(prefers-reduced-motion: reduce)` || `navigator.userAgent` matches Android <10 or iOS <13
|
|
@@ -42,40 +40,58 @@ export interface UsePickerViewsBaseProps<TValue extends PickerValidValue, TView
|
|
|
42
40
|
/**
|
|
43
41
|
* Props used to handle the value of the pickers.
|
|
44
42
|
*/
|
|
45
|
-
export interface UsePickerViewsProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, any
|
|
43
|
+
export interface UsePickerViewsProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, any>> extends UsePickerViewsBaseProps<TValue, TView, TExternalProps> {
|
|
46
44
|
className?: string;
|
|
47
45
|
sx?: SxProps<Theme>;
|
|
48
46
|
}
|
|
49
|
-
export interface UsePickerViewParams<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, TExternalProps
|
|
47
|
+
export interface UsePickerViewParams<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, TExternalProps>> {
|
|
50
48
|
props: TExternalProps;
|
|
51
49
|
propsFromPickerValue: UsePickerValueViewsResponse<TValue>;
|
|
52
|
-
additionalViewProps: TAdditionalProps;
|
|
53
50
|
autoFocusView: boolean;
|
|
54
|
-
fieldRef
|
|
51
|
+
fieldRef?: React.RefObject<FieldRef<PickerValue> | FieldRef<PickerRangeValue> | null>;
|
|
55
52
|
/**
|
|
56
53
|
* A function that intercepts the regular picker rendering.
|
|
57
54
|
* Can be used to consume the provided `viewRenderers` and render a custom component wrapping them.
|
|
58
|
-
* @param {PickerViewRendererLookup<TValue, TView, TExternalProps
|
|
55
|
+
* @param {PickerViewRendererLookup<TValue, TView, TExternalProps>} viewRenderers The `viewRenderers` that were provided to the picker component.
|
|
59
56
|
* @param {TView} popperView The current picker view.
|
|
60
57
|
* @param {any} rendererProps All the props that are being passed down to the renderer.
|
|
61
58
|
* @returns {React.ReactNode} A React node that will be rendered instead of the default renderer.
|
|
62
59
|
*/
|
|
63
|
-
rendererInterceptor?:
|
|
60
|
+
rendererInterceptor?: React.JSXElementConstructor<PickerRendererInterceptorProps<TValue, TView, TExternalProps>>;
|
|
61
|
+
}
|
|
62
|
+
export interface PickerRendererInterceptorProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, TExternalProps>> {
|
|
63
|
+
viewRenderers: PickerViewRendererLookup<TValue, TView, TExternalProps>;
|
|
64
|
+
popperView: TView;
|
|
65
|
+
rendererProps: PickerViewsRendererProps<TValue, TView, TExternalProps>;
|
|
64
66
|
}
|
|
65
67
|
export interface UsePickerViewsResponse<TView extends DateOrTimeViewWithMeridiem> {
|
|
66
68
|
renderCurrentView: () => React.ReactNode;
|
|
67
69
|
shouldRestoreFocus: () => boolean;
|
|
68
|
-
layoutProps: UsePickerViewsLayoutResponse<TView>;
|
|
69
70
|
provider: UsePickerViewsProviderParams<TView>;
|
|
70
71
|
}
|
|
71
|
-
export interface
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
export interface UsePickerViewsActionsContextValue<TView extends DateOrTimeViewWithMeridiem> {
|
|
73
|
+
/**
|
|
74
|
+
* Set the current view.
|
|
75
|
+
* @template TView
|
|
76
|
+
* @param {TView} view The view to render
|
|
77
|
+
*/
|
|
78
|
+
setView: (view: TView) => void;
|
|
79
|
+
}
|
|
80
|
+
export interface UsePickerViewsContextValue<TView extends DateOrTimeViewWithMeridiem> extends UsePickerViewsActionsContextValue<TView> {
|
|
81
|
+
/**
|
|
82
|
+
* Available views.
|
|
83
|
+
*/
|
|
74
84
|
views: readonly TView[];
|
|
85
|
+
/**
|
|
86
|
+
* View currently rendered.
|
|
87
|
+
*/
|
|
88
|
+
view: TView | null;
|
|
75
89
|
}
|
|
76
90
|
export interface UsePickerViewsProviderParams<TView extends DateOrTimeViewWithMeridiem> {
|
|
77
91
|
hasUIView: boolean;
|
|
78
92
|
views: readonly TView[];
|
|
93
|
+
contextValue: UsePickerViewsContextValue<TView>;
|
|
94
|
+
actionsContextValue: UsePickerViewsActionsContextValue<TView>;
|
|
79
95
|
}
|
|
80
96
|
/**
|
|
81
97
|
* Manage the views of all the pickers:
|
|
@@ -83,5 +99,4 @@ export interface UsePickerViewsProviderParams<TView extends DateOrTimeViewWithMe
|
|
|
83
99
|
* - Handles the switch between UI views and field views
|
|
84
100
|
* - Handles the focus management when switching views
|
|
85
101
|
*/
|
|
86
|
-
export declare const usePickerViews: <TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, any
|
|
87
|
-
export {};
|
|
102
|
+
export declare const usePickerViews: <TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, any>>({ props, propsFromPickerValue, autoFocusView, rendererInterceptor: RendererInterceptor, fieldRef, }: UsePickerViewParams<TValue, TView, TExternalProps>) => UsePickerViewsResponse<TView>;
|