@mui/x-date-pickers 8.0.0-alpha.1 → 8.0.0-alpha.11
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/AdapterMoment/AdapterMoment.js +10 -0
- package/CHANGELOG.md +2007 -230
- package/DateCalendar/DateCalendar.js +41 -22
- package/DateCalendar/DateCalendar.types.d.ts +2 -1
- package/DateCalendar/DayCalendar.d.ts +1 -2
- package/DateCalendar/DayCalendar.js +12 -36
- package/DateCalendar/PickersFadeTransitionGroup.d.ts +1 -1
- package/DateCalendar/PickersFadeTransitionGroup.js +4 -6
- package/DateCalendar/PickersSlideTransition.d.ts +1 -1
- package/DateCalendar/PickersSlideTransition.js +12 -5
- package/DateCalendar/useCalendarState.d.ts +13 -27
- package/DateCalendar/useCalendarState.js +65 -55
- package/DateField/DateField.js +29 -33
- package/DateField/DateField.types.d.ts +7 -15
- package/DateField/useDateField.d.ts +1 -1
- package/DateField/useDateField.js +14 -11
- package/DatePicker/DatePicker.js +1 -1
- package/DatePicker/DatePicker.types.d.ts +7 -3
- package/DatePicker/DatePickerToolbar.d.ts +1 -2
- package/DatePicker/DatePickerToolbar.js +17 -33
- package/DatePicker/shared.d.ts +6 -5
- package/DateTimeField/DateTimeField.js +29 -33
- package/DateTimeField/DateTimeField.types.d.ts +7 -16
- package/DateTimeField/useDateTimeField.d.ts +1 -1
- package/DateTimeField/useDateTimeField.js +14 -11
- package/DateTimePicker/DateTimePicker.js +2 -2
- package/DateTimePicker/DateTimePicker.types.d.ts +4 -5
- package/DateTimePicker/DateTimePickerTabs.d.ts +2 -5
- package/DateTimePicker/DateTimePickerTabs.js +15 -20
- package/DateTimePicker/DateTimePickerToolbar.d.ts +16 -5
- package/DateTimePicker/DateTimePickerToolbar.js +88 -80
- package/DateTimePicker/shared.d.ts +8 -8
- package/DayCalendarSkeleton/DayCalendarSkeleton.js +10 -19
- package/DesktopDatePicker/DesktopDatePicker.js +11 -17
- package/DesktopDatePicker/DesktopDatePicker.types.d.ts +7 -3
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +17 -27
- package/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +2 -2
- package/DesktopDateTimePicker/DesktopDateTimePickerLayout.d.ts +2 -2
- package/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +9 -34
- package/DesktopTimePicker/DesktopTimePicker.js +6 -22
- package/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
- package/DigitalClock/DigitalClock.js +13 -11
- package/DigitalClock/DigitalClock.types.d.ts +8 -2
- package/MobileDatePicker/MobileDatePicker.js +4 -14
- package/MobileDatePicker/MobileDatePicker.types.d.ts +2 -3
- package/MobileDateTimePicker/MobileDateTimePicker.js +4 -14
- package/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +4 -4
- package/MobileTimePicker/MobileTimePicker.js +4 -14
- package/MobileTimePicker/MobileTimePicker.types.d.ts +4 -4
- package/MonthCalendar/MonthCalendar.d.ts +1 -1
- package/MonthCalendar/MonthCalendar.js +31 -11
- package/MonthCalendar/MonthCalendar.types.d.ts +2 -2
- package/MonthCalendar/MonthCalendarButton.d.ts +24 -0
- package/{modern/MonthCalendar/PickersMonth.js → MonthCalendar/MonthCalendarButton.js} +20 -61
- package/MonthCalendar/index.d.ts +0 -3
- package/MonthCalendar/index.js +1 -2
- package/MonthCalendar/monthCalendarClasses.d.ts +7 -1
- package/MonthCalendar/monthCalendarClasses.js +1 -1
- package/MultiSectionDigitalClock/MultiSectionDigitalClock.js +11 -7
- package/MultiSectionDigitalClock/MultiSectionDigitalClock.types.d.ts +6 -6
- package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.d.ts +4 -4
- package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +14 -10
- package/PickersActionBar/PickersActionBar.d.ts +6 -7
- package/PickersActionBar/PickersActionBar.js +26 -17
- package/PickersCalendarHeader/PickersCalendarHeader.js +12 -9
- package/PickersCalendarHeader/PickersCalendarHeader.types.d.ts +4 -6
- package/PickersLayout/PickersLayout.d.ts +7 -5
- package/PickersLayout/PickersLayout.js +23 -42
- package/PickersLayout/PickersLayout.types.d.ts +20 -22
- package/PickersLayout/usePickerLayout.d.ts +5 -4
- package/PickersLayout/usePickerLayout.js +26 -53
- package/PickersSectionList/PickersSectionList.js +21 -16
- package/PickersSectionList/PickersSectionList.types.d.ts +13 -6
- package/PickersShortcuts/PickersShortcuts.d.ts +9 -11
- package/PickersShortcuts/PickersShortcuts.js +21 -11
- package/PickersShortcuts/index.d.ts +1 -1
- package/PickersTextField/PickersFilledInput/PickersFilledInput.d.ts +7 -0
- package/PickersTextField/PickersFilledInput/PickersFilledInput.js +34 -28
- package/PickersTextField/PickersFilledInput/pickersFilledInputClasses.d.ts +1 -1
- package/PickersTextField/PickersInput/PickersInput.js +20 -14
- package/PickersTextField/PickersInput/pickersInputClasses.d.ts +3 -2
- package/PickersTextField/PickersInput/pickersInputClasses.js +1 -1
- package/PickersTextField/PickersInputBase/PickersInputBase.d.ts +3 -6
- package/PickersTextField/PickersInputBase/PickersInputBase.js +45 -38
- package/PickersTextField/PickersInputBase/PickersInputBase.types.d.ts +1 -0
- package/PickersTextField/PickersOutlinedInput/Outline.d.ts +0 -1
- package/PickersTextField/PickersOutlinedInput/Outline.js +13 -10
- package/PickersTextField/PickersOutlinedInput/PickersOutlinedInput.js +8 -14
- package/PickersTextField/PickersTextField.js +75 -62
- package/PickersTextField/PickersTextField.types.d.ts +43 -4
- package/PickersTextField/usePickerTextFieldOwnerState.d.ts +4 -0
- package/PickersTextField/usePickerTextFieldOwnerState.js +11 -0
- package/README.md +8 -5
- package/StaticDatePicker/StaticDatePicker.js +2 -2
- package/StaticDatePicker/StaticDatePicker.types.d.ts +2 -3
- package/StaticDateTimePicker/StaticDateTimePicker.js +2 -2
- package/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +2 -2
- package/StaticTimePicker/StaticTimePicker.js +2 -2
- package/StaticTimePicker/StaticTimePicker.types.d.ts +2 -2
- package/TimeClock/Clock.d.ts +4 -0
- package/TimeClock/Clock.js +27 -27
- package/TimeClock/ClockNumber.js +15 -11
- package/TimeClock/ClockPointer.d.ts +6 -1
- package/TimeClock/ClockPointer.js +16 -10
- package/TimeClock/TimeClock.js +30 -12
- package/TimeField/TimeField.js +28 -32
- package/TimeField/TimeField.types.d.ts +7 -16
- package/TimeField/useTimeField.d.ts +1 -1
- package/TimeField/useTimeField.js +14 -11
- package/TimePicker/TimePicker.js +2 -2
- package/TimePicker/TimePicker.types.d.ts +4 -5
- package/TimePicker/TimePickerToolbar.d.ts +1 -3
- package/TimePicker/TimePickerToolbar.js +36 -51
- package/TimePicker/shared.d.ts +6 -6
- package/YearCalendar/YearCalendar.js +46 -13
- package/YearCalendar/YearCalendar.types.d.ts +2 -2
- package/YearCalendar/YearCalendarButton.d.ts +23 -0
- package/{modern/YearCalendar/PickersYear.js → YearCalendar/YearCalendarButton.js} +20 -59
- package/YearCalendar/index.d.ts +0 -3
- package/YearCalendar/index.js +1 -2
- package/YearCalendar/yearCalendarClasses.d.ts +7 -1
- package/YearCalendar/yearCalendarClasses.js +1 -1
- package/hooks/index.d.ts +2 -0
- package/hooks/index.js +3 -1
- package/hooks/useClearableField.d.ts +5 -3
- package/hooks/useClearableField.js +4 -2
- package/hooks/useIsValidValue.d.ts +7 -0
- package/hooks/useIsValidValue.js +11 -0
- package/hooks/useParsedFormat.d.ts +9 -7
- package/hooks/useParsedFormat.js +11 -13
- package/hooks/usePickerActionsContext.d.ts +7 -0
- package/hooks/usePickerActionsContext.js +15 -0
- package/hooks/usePickerContext.d.ts +5 -1
- package/hooks/usePickerContext.js +2 -2
- package/hooks/useSplitFieldProps.d.ts +12 -3
- package/hooks/useSplitFieldProps.js +8 -3
- package/index.d.ts +1 -0
- package/index.js +3 -2
- package/internals/components/PickerFieldUI.d.ts +133 -0
- package/internals/components/PickerFieldUI.js +317 -0
- package/internals/components/{PickersPopper.d.ts → PickerPopper/PickerPopper.d.ts} +26 -25
- package/{modern/internals/components/PickersPopper.js → internals/components/PickerPopper/PickerPopper.js} +47 -47
- package/internals/components/PickerPopper/index.d.ts +4 -0
- package/internals/components/PickerPopper/index.js +2 -0
- package/internals/components/PickerPopper/pickerPopperClasses.d.ts +9 -0
- package/internals/components/PickerPopper/pickerPopperClasses.js +6 -0
- package/internals/components/PickerProvider.d.ts +86 -32
- package/internals/components/PickerProvider.js +25 -7
- package/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +12 -11
- package/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.types.d.ts +11 -8
- package/internals/components/PickersModalDialog.d.ts +1 -3
- package/internals/components/PickersModalDialog.js +9 -3
- package/internals/components/PickersToolbar.d.ts +2 -3
- package/internals/components/PickersToolbar.js +15 -12
- package/internals/components/PickersToolbarButton.js +4 -6
- package/internals/components/PickersToolbarText.js +11 -13
- package/internals/hooks/date-helpers-hooks.js +4 -3
- package/internals/hooks/useClockReferenceDate.d.ts +2 -1
- package/internals/hooks/useDesktopPicker/useDesktopPicker.d.ts +1 -1
- package/internals/hooks/useDesktopPicker/useDesktopPicker.js +35 -120
- package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +16 -38
- package/internals/hooks/useField/buildSectionsFromFormat.js +1 -1
- package/internals/hooks/useField/index.d.ts +2 -0
- package/internals/hooks/useField/index.js +2 -1
- package/internals/hooks/useField/useField.d.ts +3 -3
- package/internals/hooks/useField/useField.js +17 -4
- package/internals/hooks/useField/useField.types.d.ts +55 -48
- package/internals/hooks/useField/useField.utils.d.ts +4 -3
- package/internals/hooks/useField/useField.utils.js +2 -2
- package/internals/hooks/useField/useFieldCharacterEditing.d.ts +6 -5
- package/internals/hooks/useField/useFieldInternalPropsWithDefaults.d.ts +15 -0
- package/internals/hooks/useField/useFieldInternalPropsWithDefaults.js +47 -0
- package/internals/hooks/useField/useFieldState.d.ts +9 -8
- package/internals/hooks/useField/useFieldState.js +2 -3
- package/internals/hooks/useField/useFieldV6TextField.d.ts +4 -3
- package/internals/hooks/useField/useFieldV6TextField.js +5 -2
- package/internals/hooks/useField/useFieldV7TextField.js +6 -3
- package/internals/hooks/useFieldOwnerState.d.ts +6 -0
- package/internals/hooks/useFieldOwnerState.js +16 -0
- package/internals/hooks/useMobilePicker/useMobilePicker.d.ts +1 -1
- package/internals/hooks/useMobilePicker/useMobilePicker.js +34 -68
- package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +15 -22
- package/internals/hooks/useNullablePickerContext.d.ts +5 -0
- package/internals/hooks/useNullablePickerContext.js +10 -0
- package/internals/hooks/useOpenState.d.ts +3 -2
- package/internals/hooks/useOpenState.js +11 -9
- package/internals/hooks/usePicker/index.d.ts +1 -1
- package/internals/hooks/usePicker/usePicker.d.ts +3 -4
- package/internals/hooks/usePicker/usePicker.js +4 -20
- package/internals/hooks/usePicker/usePicker.types.d.ts +10 -10
- package/internals/hooks/usePicker/usePickerProvider.d.ts +45 -10
- package/internals/hooks/usePicker/usePickerProvider.js +50 -16
- package/internals/hooks/usePicker/usePickerValue.d.ts +3 -2
- package/internals/hooks/usePicker/usePickerValue.js +84 -214
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +130 -75
- package/internals/hooks/usePicker/usePickerViews.d.ts +59 -41
- package/internals/hooks/usePicker/usePickerViews.js +31 -20
- package/internals/hooks/useReduceAnimations.d.ts +2 -0
- package/internals/hooks/{useDefaultReduceAnimations.js → useReduceAnimations.js} +5 -2
- package/internals/hooks/useStaticPicker/useStaticPicker.d.ts +1 -1
- package/internals/hooks/useStaticPicker/useStaticPicker.js +7 -12
- package/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +7 -13
- package/internals/hooks/useToolbarOwnerState.d.ts +10 -0
- package/internals/hooks/useToolbarOwnerState.js +13 -0
- package/internals/hooks/useUtils.d.ts +4 -3
- package/internals/hooks/useUtils.js +1 -1
- package/internals/hooks/useValueWithTimezone.d.ts +5 -4
- package/internals/hooks/useViews.d.ts +5 -5
- package/internals/index.d.ts +27 -18
- package/internals/index.js +13 -8
- package/internals/models/common.d.ts +1 -1
- package/internals/models/fields.d.ts +8 -24
- package/internals/models/index.d.ts +1 -0
- package/internals/models/index.js +2 -1
- package/internals/models/manager.d.ts +15 -0
- package/internals/models/manager.js +1 -0
- package/internals/models/pickers.d.ts +1 -0
- package/internals/models/pickers.js +1 -0
- package/internals/models/props/basePickerProps.d.ts +3 -33
- package/internals/models/props/tabs.d.ts +0 -13
- package/internals/models/props/time.d.ts +2 -1
- package/internals/models/props/toolbar.d.ts +1 -19
- package/internals/models/value.d.ts +9 -0
- package/internals/utils/date-utils.d.ts +1 -1
- package/internals/utils/date-utils.js +1 -1
- package/internals/utils/utils.d.ts +3 -0
- package/internals/utils/utils.js +11 -1
- package/internals/utils/valueManagers.d.ts +4 -3
- 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/nlNL.js +7 -7
- package/locales/roRO.js +15 -18
- package/locales/utils/getPickersLocalization.d.ts +0 -7
- package/locales/utils/getPickersLocalization.js +0 -13
- 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 +55 -0
- package/managers/useDateTimeManager.d.ts +28 -0
- package/managers/useDateTimeManager.js +60 -0
- package/managers/useTimeManager.d.ts +28 -0
- package/managers/useTimeManager.js +51 -0
- package/models/adapters.d.ts +5 -5
- package/models/fields.d.ts +33 -9
- package/models/index.d.ts +1 -0
- package/models/index.js +1 -0
- package/models/manager.d.ts +87 -0
- package/models/manager.js +1 -0
- package/models/pickers.d.ts +7 -0
- package/models/validation.d.ts +2 -1
- 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/AdapterMoment/AdapterMoment.js +10 -0
- package/modern/DateCalendar/DateCalendar.js +41 -22
- package/modern/DateCalendar/DayCalendar.js +12 -36
- package/modern/DateCalendar/PickersFadeTransitionGroup.js +4 -6
- package/modern/DateCalendar/PickersSlideTransition.js +12 -5
- package/modern/DateCalendar/useCalendarState.js +65 -55
- package/modern/DateField/DateField.js +29 -33
- package/modern/DateField/useDateField.js +14 -11
- package/modern/DatePicker/DatePicker.js +1 -1
- package/modern/DatePicker/DatePickerToolbar.js +17 -33
- package/modern/DateTimeField/DateTimeField.js +29 -33
- package/modern/DateTimeField/useDateTimeField.js +14 -11
- package/modern/DateTimePicker/DateTimePicker.js +2 -2
- package/modern/DateTimePicker/DateTimePickerTabs.js +15 -20
- package/modern/DateTimePicker/DateTimePickerToolbar.js +88 -80
- package/modern/DayCalendarSkeleton/DayCalendarSkeleton.js +10 -19
- package/modern/DesktopDatePicker/DesktopDatePicker.js +11 -17
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +17 -27
- package/modern/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +9 -34
- package/modern/DesktopTimePicker/DesktopTimePicker.js +6 -22
- package/modern/DigitalClock/DigitalClock.js +13 -11
- package/modern/MobileDatePicker/MobileDatePicker.js +4 -14
- package/modern/MobileDateTimePicker/MobileDateTimePicker.js +4 -14
- package/modern/MobileTimePicker/MobileTimePicker.js +4 -14
- package/modern/MonthCalendar/MonthCalendar.js +31 -11
- package/{MonthCalendar/PickersMonth.js → modern/MonthCalendar/MonthCalendarButton.js} +20 -61
- package/modern/MonthCalendar/index.js +1 -2
- package/modern/MonthCalendar/monthCalendarClasses.js +1 -1
- package/modern/MultiSectionDigitalClock/MultiSectionDigitalClock.js +11 -7
- package/modern/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +14 -10
- package/modern/PickersActionBar/PickersActionBar.js +26 -17
- package/modern/PickersCalendarHeader/PickersCalendarHeader.js +12 -9
- package/modern/PickersLayout/PickersLayout.js +23 -42
- package/modern/PickersLayout/usePickerLayout.js +26 -53
- package/modern/PickersSectionList/PickersSectionList.js +21 -16
- package/modern/PickersShortcuts/PickersShortcuts.js +21 -11
- package/modern/PickersTextField/PickersFilledInput/PickersFilledInput.js +34 -28
- package/modern/PickersTextField/PickersInput/PickersInput.js +20 -14
- package/modern/PickersTextField/PickersInput/pickersInputClasses.js +1 -1
- package/modern/PickersTextField/PickersInputBase/PickersInputBase.js +45 -38
- package/modern/PickersTextField/PickersOutlinedInput/Outline.js +13 -10
- package/modern/PickersTextField/PickersOutlinedInput/PickersOutlinedInput.js +8 -14
- package/modern/PickersTextField/PickersTextField.js +75 -62
- package/modern/PickersTextField/usePickerTextFieldOwnerState.js +11 -0
- package/modern/StaticDatePicker/StaticDatePicker.js +2 -2
- package/modern/StaticDateTimePicker/StaticDateTimePicker.js +2 -2
- package/modern/StaticTimePicker/StaticTimePicker.js +2 -2
- package/modern/TimeClock/Clock.js +27 -27
- package/modern/TimeClock/ClockNumber.js +15 -11
- package/modern/TimeClock/ClockPointer.js +16 -10
- package/modern/TimeClock/TimeClock.js +30 -12
- package/modern/TimeField/TimeField.js +28 -32
- package/modern/TimeField/useTimeField.js +14 -11
- package/modern/TimePicker/TimePicker.js +2 -2
- package/modern/TimePicker/TimePickerToolbar.js +36 -51
- package/modern/YearCalendar/YearCalendar.js +46 -13
- package/{YearCalendar/PickersYear.js → modern/YearCalendar/YearCalendarButton.js} +20 -59
- package/modern/YearCalendar/index.js +1 -2
- package/modern/YearCalendar/yearCalendarClasses.js +1 -1
- package/modern/hooks/index.js +3 -1
- package/modern/hooks/useClearableField.js +4 -2
- package/modern/hooks/useIsValidValue.js +11 -0
- package/modern/hooks/useParsedFormat.js +11 -13
- package/modern/hooks/usePickerActionsContext.js +15 -0
- package/modern/hooks/usePickerContext.js +2 -2
- package/modern/hooks/useSplitFieldProps.js +8 -3
- package/modern/index.js +3 -2
- package/modern/internals/components/PickerFieldUI.js +317 -0
- package/{internals/components/PickersPopper.js → modern/internals/components/PickerPopper/PickerPopper.js} +47 -47
- package/modern/internals/components/PickerPopper/index.js +2 -0
- package/modern/internals/components/PickerPopper/pickerPopperClasses.js +6 -0
- package/modern/internals/components/PickerProvider.js +25 -7
- package/modern/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +12 -11
- package/modern/internals/components/PickersModalDialog.js +9 -3
- package/modern/internals/components/PickersToolbar.js +15 -12
- package/modern/internals/components/PickersToolbarButton.js +4 -6
- package/modern/internals/components/PickersToolbarText.js +11 -13
- package/modern/internals/hooks/date-helpers-hooks.js +4 -3
- package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.js +35 -120
- package/modern/internals/hooks/useField/buildSectionsFromFormat.js +1 -1
- package/modern/internals/hooks/useField/index.js +2 -1
- package/modern/internals/hooks/useField/useField.js +17 -4
- package/modern/internals/hooks/useField/useField.utils.js +2 -2
- package/modern/internals/hooks/useField/useFieldInternalPropsWithDefaults.js +47 -0
- package/modern/internals/hooks/useField/useFieldState.js +2 -3
- package/modern/internals/hooks/useField/useFieldV6TextField.js +5 -2
- package/modern/internals/hooks/useField/useFieldV7TextField.js +6 -3
- package/modern/internals/hooks/useFieldOwnerState.js +16 -0
- package/modern/internals/hooks/useMobilePicker/useMobilePicker.js +34 -68
- package/modern/internals/hooks/useNullablePickerContext.js +10 -0
- package/modern/internals/hooks/useOpenState.js +11 -9
- package/modern/internals/hooks/usePicker/usePicker.js +4 -20
- package/modern/internals/hooks/usePicker/usePickerProvider.js +50 -16
- package/modern/internals/hooks/usePicker/usePickerValue.js +84 -214
- package/modern/internals/hooks/usePicker/usePickerViews.js +31 -20
- package/modern/internals/hooks/{useDefaultReduceAnimations.js → useReduceAnimations.js} +5 -2
- package/modern/internals/hooks/useStaticPicker/useStaticPicker.js +7 -12
- package/modern/internals/hooks/useToolbarOwnerState.js +13 -0
- package/modern/internals/hooks/useUtils.js +1 -1
- package/modern/internals/index.js +13 -8
- package/modern/internals/models/index.js +2 -1
- package/modern/internals/models/manager.js +1 -0
- package/modern/internals/models/pickers.js +1 -0
- package/modern/internals/utils/date-utils.js +1 -1
- package/modern/internals/utils/utils.js +11 -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/nlNL.js +7 -7
- package/modern/locales/roRO.js +15 -18
- package/modern/locales/utils/getPickersLocalization.js +0 -13
- package/modern/locales/zhTW.js +73 -0
- package/modern/managers/index.js +3 -0
- package/modern/managers/useDateManager.js +55 -0
- package/modern/managers/useDateTimeManager.js +60 -0
- package/modern/managers/useTimeManager.js +51 -0
- package/modern/models/index.js +1 -0
- package/modern/models/manager.js +1 -0
- package/modern/validation/useValidation.js +1 -1
- package/modern/validation/validateDate.js +8 -0
- package/modern/validation/validateDateTime.js +8 -0
- package/modern/validation/validateTime.js +8 -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/AdapterMoment/AdapterMoment.js +10 -0
- package/node/DateCalendar/DateCalendar.js +41 -22
- package/node/DateCalendar/DayCalendar.js +12 -37
- package/node/DateCalendar/PickersFadeTransitionGroup.js +4 -6
- package/node/DateCalendar/PickersSlideTransition.js +12 -5
- package/node/DateCalendar/useCalendarState.js +66 -57
- package/node/DateField/DateField.js +29 -33
- package/node/DateField/useDateField.js +13 -10
- package/node/DatePicker/DatePicker.js +1 -1
- package/node/DatePicker/DatePickerToolbar.js +17 -33
- package/node/DateTimeField/DateTimeField.js +29 -33
- package/node/DateTimeField/useDateTimeField.js +13 -10
- package/node/DateTimePicker/DateTimePicker.js +2 -2
- package/node/DateTimePicker/DateTimePickerTabs.js +15 -20
- package/node/DateTimePicker/DateTimePickerToolbar.js +89 -80
- package/node/DayCalendarSkeleton/DayCalendarSkeleton.js +10 -19
- package/node/DesktopDatePicker/DesktopDatePicker.js +11 -17
- package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +17 -27
- package/node/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +10 -35
- package/node/DesktopTimePicker/DesktopTimePicker.js +6 -22
- package/node/DigitalClock/DigitalClock.js +13 -11
- package/node/MobileDatePicker/MobileDatePicker.js +4 -14
- package/node/MobileDateTimePicker/MobileDateTimePicker.js +4 -14
- package/node/MobileTimePicker/MobileTimePicker.js +4 -14
- package/node/MonthCalendar/MonthCalendar.js +31 -11
- package/node/MonthCalendar/{PickersMonth.js → MonthCalendarButton.js} +20 -61
- package/node/MonthCalendar/index.js +1 -8
- package/node/MonthCalendar/monthCalendarClasses.js +1 -1
- package/node/MultiSectionDigitalClock/MultiSectionDigitalClock.js +11 -7
- package/node/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +13 -10
- package/node/PickersActionBar/PickersActionBar.js +28 -19
- package/node/PickersCalendarHeader/PickersCalendarHeader.js +12 -9
- package/node/PickersLayout/PickersLayout.js +23 -42
- package/node/PickersLayout/usePickerLayout.js +30 -57
- package/node/PickersSectionList/PickersSectionList.js +21 -16
- package/node/PickersShortcuts/PickersShortcuts.js +21 -11
- package/node/PickersTextField/PickersFilledInput/PickersFilledInput.js +34 -28
- package/node/PickersTextField/PickersInput/PickersInput.js +20 -14
- package/node/PickersTextField/PickersInput/pickersInputClasses.js +1 -1
- package/node/PickersTextField/PickersInputBase/PickersInputBase.js +45 -38
- package/node/PickersTextField/PickersOutlinedInput/Outline.js +13 -10
- package/node/PickersTextField/PickersOutlinedInput/PickersOutlinedInput.js +8 -14
- package/node/PickersTextField/PickersTextField.js +75 -62
- package/node/PickersTextField/usePickerTextFieldOwnerState.js +18 -0
- package/node/StaticDatePicker/StaticDatePicker.js +2 -2
- package/node/StaticDateTimePicker/StaticDateTimePicker.js +2 -2
- package/node/StaticTimePicker/StaticTimePicker.js +2 -2
- package/node/TimeClock/Clock.js +27 -27
- package/node/TimeClock/ClockNumber.js +15 -11
- package/node/TimeClock/ClockPointer.js +15 -10
- package/node/TimeClock/TimeClock.js +30 -12
- package/node/TimeField/TimeField.js +28 -32
- package/node/TimeField/useTimeField.js +13 -10
- package/node/TimePicker/TimePicker.js +2 -2
- package/node/TimePicker/TimePickerToolbar.js +36 -51
- package/node/YearCalendar/YearCalendar.js +45 -12
- package/node/YearCalendar/{PickersYear.js → YearCalendarButton.js} +20 -59
- package/node/YearCalendar/index.js +1 -8
- package/node/YearCalendar/yearCalendarClasses.js +1 -1
- package/node/hooks/index.js +15 -1
- package/node/hooks/useClearableField.js +4 -2
- package/node/hooks/useIsValidValue.js +18 -0
- package/node/hooks/useParsedFormat.js +11 -13
- package/node/hooks/usePickerActionsContext.js +22 -0
- package/node/hooks/usePickerContext.js +5 -4
- package/node/hooks/useSplitFieldProps.js +7 -2
- package/node/index.js +13 -1
- package/node/internals/components/PickerFieldUI.js +329 -0
- package/node/internals/components/{PickersPopper.js → PickerPopper/PickerPopper.js} +48 -48
- package/node/internals/components/PickerPopper/index.js +25 -0
- package/node/internals/components/PickerPopper/pickerPopperClasses.js +14 -0
- package/node/internals/components/PickerProvider.js +27 -9
- package/node/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +12 -11
- package/node/internals/components/PickersModalDialog.js +9 -3
- package/node/internals/components/PickersToolbar.js +15 -12
- package/node/internals/components/PickersToolbarButton.js +4 -6
- package/node/internals/components/PickersToolbarText.js +10 -12
- package/node/internals/hooks/date-helpers-hooks.js +4 -3
- package/node/internals/hooks/useDesktopPicker/useDesktopPicker.js +37 -122
- package/node/internals/hooks/useField/buildSectionsFromFormat.js +1 -1
- package/node/internals/hooks/useField/index.js +8 -1
- package/node/internals/hooks/useField/useField.js +16 -3
- package/node/internals/hooks/useField/useField.utils.js +2 -2
- package/node/internals/hooks/useField/useFieldInternalPropsWithDefaults.js +56 -0
- package/node/internals/hooks/useField/useFieldState.js +2 -3
- package/node/internals/hooks/useField/useFieldV6TextField.js +5 -2
- package/node/internals/hooks/useField/useFieldV7TextField.js +6 -3
- package/node/internals/hooks/useFieldOwnerState.js +24 -0
- package/node/internals/hooks/useMobilePicker/useMobilePicker.js +35 -69
- package/node/internals/hooks/useNullablePickerContext.js +16 -0
- package/node/internals/hooks/useOpenState.js +12 -9
- package/node/internals/hooks/usePicker/usePicker.js +4 -20
- package/node/internals/hooks/usePicker/usePickerProvider.js +51 -17
- package/node/internals/hooks/usePicker/usePickerValue.js +84 -213
- package/node/internals/hooks/usePicker/usePickerViews.js +31 -21
- package/node/internals/hooks/{useDefaultReduceAnimations.js → useReduceAnimations.js} +7 -4
- package/node/internals/hooks/useStaticPicker/useStaticPicker.js +7 -12
- package/node/internals/hooks/useToolbarOwnerState.js +21 -0
- package/node/internals/hooks/useUtils.js +1 -1
- package/node/internals/index.js +87 -34
- package/node/internals/models/index.js +11 -0
- package/node/internals/models/manager.js +5 -0
- package/node/internals/models/pickers.js +5 -0
- package/node/internals/utils/date-utils.js +1 -1
- package/node/internals/utils/utils.js +14 -2
- 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/nlNL.js +7 -7
- package/node/locales/roRO.js +15 -18
- package/node/locales/utils/getPickersLocalization.js +2 -16
- package/node/locales/zhTW.js +79 -0
- package/node/managers/index.js +26 -0
- package/node/managers/useDateManager.js +63 -0
- package/node/managers/useDateTimeManager.js +68 -0
- package/node/managers/useTimeManager.js +59 -0
- package/node/models/index.js +11 -0
- package/node/models/manager.js +5 -0
- package/node/validation/useValidation.js +1 -1
- package/node/validation/validateDate.js +8 -0
- package/node/validation/validateDateTime.js +8 -0
- package/node/validation/validateTime.js +8 -0
- package/package.json +5 -5
- package/themeAugmentation/components.d.ts +3 -11
- package/themeAugmentation/overrides.d.ts +5 -7
- package/themeAugmentation/props.d.ts +7 -9
- package/validation/extractValidationProps.d.ts +1 -1
- package/validation/useValidation.d.ts +7 -6
- package/validation/useValidation.js +1 -1
- package/validation/validateDate.d.ts +12 -3
- package/validation/validateDate.js +8 -0
- package/validation/validateDateTime.d.ts +12 -4
- package/validation/validateDateTime.js +8 -0
- package/validation/validateTime.d.ts +12 -3
- package/validation/validateTime.js +8 -0
- 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/MonthCalendar/PickersMonth.d.ts +0 -28
- package/MonthCalendar/pickersMonthClasses.d.ts +0 -13
- package/MonthCalendar/pickersMonthClasses.js +0 -5
- package/YearCalendar/PickersYear.d.ts +0 -27
- package/YearCalendar/pickersYearClasses.d.ts +0 -13
- package/YearCalendar/pickersYearClasses.js +0 -5
- package/internals/components/pickersPopperClasses.d.ts +0 -9
- package/internals/components/pickersPopperClasses.js +0 -5
- package/internals/hooks/defaultizedFieldProps.d.ts +0 -18
- package/internals/hooks/defaultizedFieldProps.js +0 -40
- package/internals/hooks/useDefaultReduceAnimations.d.ts +0 -2
- package/internals/hooks/useIsLandscape.d.ts +0 -4
- package/internals/hooks/useIsLandscape.js +0 -35
- package/internals/hooks/usePicker/usePickerLayoutProps.d.ts +0 -32
- package/internals/hooks/usePicker/usePickerLayoutProps.js +0 -31
- package/internals/utils/convertFieldResponseIntoMuiTextFieldProps.d.ts +0 -3
- package/internals/utils/convertFieldResponseIntoMuiTextFieldProps.js +0 -44
- package/modern/AdapterDateFnsJalaliV3/index.js +0 -1
- package/modern/AdapterDateFnsV3/index.js +0 -1
- package/modern/MonthCalendar/pickersMonthClasses.js +0 -5
- package/modern/YearCalendar/pickersYearClasses.js +0 -5
- package/modern/internals/components/pickersPopperClasses.js +0 -5
- package/modern/internals/hooks/defaultizedFieldProps.js +0 -40
- package/modern/internals/hooks/useIsLandscape.js +0 -35
- package/modern/internals/hooks/usePicker/usePickerLayoutProps.js +0 -31
- package/modern/internals/utils/convertFieldResponseIntoMuiTextFieldProps.js +0 -44
- package/node/AdapterDateFnsV3/AdapterDateFnsV3.js +0 -299
- package/node/MonthCalendar/pickersMonthClasses.js +0 -12
- package/node/YearCalendar/pickersYearClasses.js +0 -12
- package/node/internals/components/pickersPopperClasses.js +0 -12
- package/node/internals/hooks/defaultizedFieldProps.js +0 -50
- package/node/internals/hooks/useIsLandscape.js +0 -43
- package/node/internals/hooks/usePicker/usePickerLayoutProps.js +0 -38
- package/node/internals/utils/convertFieldResponseIntoMuiTextFieldProps.js +0 -52
|
@@ -5,107 +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
|
-
/**
|
|
10
|
-
* Decide if the new value should be published
|
|
11
|
-
* The published value will be passed to `onChange` if defined.
|
|
12
|
-
*/
|
|
13
|
-
const shouldPublishValue = params => {
|
|
14
|
-
const {
|
|
15
|
-
action,
|
|
16
|
-
hasChanged,
|
|
17
|
-
dateState,
|
|
18
|
-
isControlled
|
|
19
|
-
} = params;
|
|
20
|
-
const isCurrentValueTheDefaultValue = !isControlled && !dateState.hasBeenModifiedSinceMount;
|
|
21
|
-
|
|
22
|
-
// The field is responsible for only calling `onChange` when needed.
|
|
23
|
-
if (action.name === 'setValueFromField') {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
if (action.name === 'setValueFromAction') {
|
|
27
|
-
// If the component is not controlled, and the value has not been modified since the mount,
|
|
28
|
-
// Then we want to publish the default value whenever the user pressed the "Accept", "Today" or "Clear" button.
|
|
29
|
-
if (isCurrentValueTheDefaultValue && ['accept', 'today', 'clear'].includes(action.pickerAction)) {
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
return hasChanged(dateState.lastPublishedValue);
|
|
33
|
-
}
|
|
34
|
-
if (action.name === 'setValueFromView' && action.selectionState !== 'shallow') {
|
|
35
|
-
// On the first view,
|
|
36
|
-
// If the value is not controlled, then clicking on any value (including the one equal to `defaultValue`) should call `onChange`
|
|
37
|
-
if (isCurrentValueTheDefaultValue) {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
return hasChanged(dateState.lastPublishedValue);
|
|
41
|
-
}
|
|
42
|
-
if (action.name === 'setValueFromShortcut') {
|
|
43
|
-
// On the first view,
|
|
44
|
-
// If the value is not controlled, then clicking on any value (including the one equal to `defaultValue`) should call `onChange`
|
|
45
|
-
if (isCurrentValueTheDefaultValue) {
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
return hasChanged(dateState.lastPublishedValue);
|
|
49
|
-
}
|
|
50
|
-
return false;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Decide if the new value should be committed.
|
|
55
|
-
* The committed value will be passed to `onAccept` if defined.
|
|
56
|
-
* It will also be used as a reset target when calling the `cancel` picker action (when clicking on the "Cancel" button).
|
|
57
|
-
*/
|
|
58
|
-
const shouldCommitValue = params => {
|
|
59
|
-
const {
|
|
60
|
-
action,
|
|
61
|
-
hasChanged,
|
|
62
|
-
dateState,
|
|
63
|
-
isControlled,
|
|
64
|
-
closeOnSelect
|
|
65
|
-
} = params;
|
|
66
|
-
const isCurrentValueTheDefaultValue = !isControlled && !dateState.hasBeenModifiedSinceMount;
|
|
67
|
-
if (action.name === 'setValueFromAction') {
|
|
68
|
-
// If the component is not controlled, and the value has not been modified since the mount,
|
|
69
|
-
// Then we want to commit the default value whenever the user pressed the "Accept", "Today" or "Clear" button.
|
|
70
|
-
if (isCurrentValueTheDefaultValue && ['accept', 'today', 'clear'].includes(action.pickerAction)) {
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
return hasChanged(dateState.lastCommittedValue);
|
|
74
|
-
}
|
|
75
|
-
if (action.name === 'setValueFromView' && action.selectionState === 'finish' && closeOnSelect) {
|
|
76
|
-
// On picker where the 1st view is also the last view,
|
|
77
|
-
// If the value is not controlled, then clicking on any value (including the one equal to `defaultValue`) should call `onAccept`
|
|
78
|
-
if (isCurrentValueTheDefaultValue) {
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
return hasChanged(dateState.lastCommittedValue);
|
|
82
|
-
}
|
|
83
|
-
if (action.name === 'setValueFromShortcut') {
|
|
84
|
-
return action.changeImportance === 'accept' && hasChanged(dateState.lastCommittedValue);
|
|
85
|
-
}
|
|
86
|
-
return false;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Decide if the picker should be closed after the value is updated.
|
|
91
|
-
*/
|
|
92
|
-
const shouldClosePicker = params => {
|
|
93
|
-
const {
|
|
94
|
-
action,
|
|
95
|
-
closeOnSelect
|
|
96
|
-
} = params;
|
|
97
|
-
if (action.name === 'setValueFromAction') {
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
if (action.name === 'setValueFromView') {
|
|
101
|
-
return action.selectionState === 'finish' && closeOnSelect;
|
|
102
|
-
}
|
|
103
|
-
if (action.name === 'setValueFromShortcut') {
|
|
104
|
-
return action.changeImportance === 'accept';
|
|
105
|
-
}
|
|
106
|
-
return false;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
8
|
/**
|
|
110
9
|
* Manage the value lifecycle of all the pickers.
|
|
111
10
|
*/
|
|
@@ -113,7 +12,6 @@ export const usePickerValue = ({
|
|
|
113
12
|
props,
|
|
114
13
|
valueManager,
|
|
115
14
|
valueType,
|
|
116
|
-
variant,
|
|
117
15
|
validator
|
|
118
16
|
}) => {
|
|
119
17
|
const {
|
|
@@ -121,7 +19,7 @@ export const usePickerValue = ({
|
|
|
121
19
|
onChange,
|
|
122
20
|
value: inValueWithoutRenderTimezone,
|
|
123
21
|
defaultValue: inDefaultValue,
|
|
124
|
-
closeOnSelect =
|
|
22
|
+
closeOnSelect = false,
|
|
125
23
|
timezone: timezoneProp,
|
|
126
24
|
referenceDate
|
|
127
25
|
} = props;
|
|
@@ -151,8 +49,8 @@ export const usePickerValue = ({
|
|
|
151
49
|
const utils = useUtils();
|
|
152
50
|
const adapter = useLocalizationContext();
|
|
153
51
|
const {
|
|
154
|
-
|
|
155
|
-
|
|
52
|
+
open,
|
|
53
|
+
setOpen
|
|
156
54
|
} = useOpenState(props);
|
|
157
55
|
const {
|
|
158
56
|
timezone,
|
|
@@ -201,44 +99,51 @@ export const usePickerValue = ({
|
|
|
201
99
|
value: dateState.draft,
|
|
202
100
|
onError: props.onError
|
|
203
101
|
});
|
|
204
|
-
const
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
102
|
+
const setValue = useEventCallback((newValue, options) => {
|
|
103
|
+
const {
|
|
104
|
+
changeImportance = 'accept',
|
|
105
|
+
skipPublicationIfPristine = false,
|
|
106
|
+
validationError,
|
|
107
|
+
shortcut,
|
|
108
|
+
shouldClose = changeImportance === 'accept'
|
|
109
|
+
} = options ?? {};
|
|
110
|
+
let shouldPublish;
|
|
111
|
+
let shouldCommit;
|
|
112
|
+
if (!skipPublicationIfPristine && !isControlled && !dateState.hasBeenModifiedSinceMount) {
|
|
113
|
+
// If the value is not controlled and the value has never been modified before,
|
|
114
|
+
// Then clicking on any value (including the one equal to `defaultValue`) should call `onChange` and `onAccept`
|
|
115
|
+
shouldPublish = true;
|
|
116
|
+
shouldCommit = changeImportance === 'accept';
|
|
117
|
+
} else {
|
|
118
|
+
shouldPublish = !valueManager.areValuesEqual(utils, newValue, dateState.lastPublishedValue);
|
|
119
|
+
shouldCommit = changeImportance === 'accept' && !valueManager.areValuesEqual(utils, newValue, dateState.lastCommittedValue);
|
|
120
|
+
}
|
|
215
121
|
setDateState(prev => _extends({}, prev, {
|
|
216
|
-
draft:
|
|
217
|
-
lastPublishedValue: shouldPublish ?
|
|
218
|
-
lastCommittedValue: shouldCommit ?
|
|
122
|
+
draft: newValue,
|
|
123
|
+
lastPublishedValue: shouldPublish ? newValue : prev.lastPublishedValue,
|
|
124
|
+
lastCommittedValue: shouldCommit ? newValue : prev.lastCommittedValue,
|
|
219
125
|
hasBeenModifiedSinceMount: true
|
|
220
126
|
}));
|
|
221
127
|
let cachedContext = null;
|
|
222
128
|
const getContext = () => {
|
|
223
129
|
if (!cachedContext) {
|
|
224
|
-
const validationError = action.name === 'setValueFromField' ? action.context.validationError : getValidationErrorForNewValue(action.value);
|
|
225
130
|
cachedContext = {
|
|
226
|
-
validationError
|
|
131
|
+
validationError: validationError == null ? getValidationErrorForNewValue(newValue) : validationError
|
|
227
132
|
};
|
|
228
|
-
if (
|
|
229
|
-
cachedContext.shortcut =
|
|
133
|
+
if (shortcut) {
|
|
134
|
+
cachedContext.shortcut = shortcut;
|
|
230
135
|
}
|
|
231
136
|
}
|
|
232
137
|
return cachedContext;
|
|
233
138
|
};
|
|
234
139
|
if (shouldPublish) {
|
|
235
|
-
handleValueChange(
|
|
140
|
+
handleValueChange(newValue, getContext());
|
|
236
141
|
}
|
|
237
142
|
if (shouldCommit && onAccept) {
|
|
238
|
-
onAccept(
|
|
143
|
+
onAccept(newValue, getContext());
|
|
239
144
|
}
|
|
240
145
|
if (shouldClose) {
|
|
241
|
-
|
|
146
|
+
setOpen(false);
|
|
242
147
|
}
|
|
243
148
|
});
|
|
244
149
|
if (dateState.lastControlledValue !== inValueWithoutRenderTimezone) {
|
|
@@ -252,85 +157,6 @@ export const usePickerValue = ({
|
|
|
252
157
|
hasBeenModifiedSinceMount: true
|
|
253
158
|
}));
|
|
254
159
|
}
|
|
255
|
-
const handleClear = useEventCallback(() => {
|
|
256
|
-
updateDate({
|
|
257
|
-
value: valueManager.emptyValue,
|
|
258
|
-
name: 'setValueFromAction',
|
|
259
|
-
pickerAction: 'clear'
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
const handleAccept = useEventCallback(() => {
|
|
263
|
-
updateDate({
|
|
264
|
-
value: dateState.lastPublishedValue,
|
|
265
|
-
name: 'setValueFromAction',
|
|
266
|
-
pickerAction: 'accept'
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
const handleDismiss = useEventCallback(() => {
|
|
270
|
-
updateDate({
|
|
271
|
-
value: dateState.lastPublishedValue,
|
|
272
|
-
name: 'setValueFromAction',
|
|
273
|
-
pickerAction: 'dismiss'
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
const handleCancel = useEventCallback(() => {
|
|
277
|
-
updateDate({
|
|
278
|
-
value: dateState.lastCommittedValue,
|
|
279
|
-
name: 'setValueFromAction',
|
|
280
|
-
pickerAction: 'cancel'
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
const handleSetToday = useEventCallback(() => {
|
|
284
|
-
updateDate({
|
|
285
|
-
value: valueManager.getTodayValue(utils, timezone, valueType),
|
|
286
|
-
name: 'setValueFromAction',
|
|
287
|
-
pickerAction: 'today'
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
const handleOpen = useEventCallback(event => {
|
|
291
|
-
event.preventDefault();
|
|
292
|
-
setIsOpen(true);
|
|
293
|
-
});
|
|
294
|
-
const handleClose = useEventCallback(event => {
|
|
295
|
-
event?.preventDefault();
|
|
296
|
-
setIsOpen(false);
|
|
297
|
-
});
|
|
298
|
-
const handleChange = useEventCallback((newValue, selectionState = 'partial') => updateDate({
|
|
299
|
-
name: 'setValueFromView',
|
|
300
|
-
value: newValue,
|
|
301
|
-
selectionState
|
|
302
|
-
}));
|
|
303
|
-
const handleSelectShortcut = useEventCallback((newValue, changeImportance, shortcut) => updateDate({
|
|
304
|
-
name: 'setValueFromShortcut',
|
|
305
|
-
value: newValue,
|
|
306
|
-
changeImportance,
|
|
307
|
-
shortcut
|
|
308
|
-
}));
|
|
309
|
-
const handleChangeFromField = useEventCallback((newValue, context) => updateDate({
|
|
310
|
-
name: 'setValueFromField',
|
|
311
|
-
value: newValue,
|
|
312
|
-
context
|
|
313
|
-
}));
|
|
314
|
-
const actions = {
|
|
315
|
-
onClear: handleClear,
|
|
316
|
-
onAccept: handleAccept,
|
|
317
|
-
onDismiss: handleDismiss,
|
|
318
|
-
onCancel: handleCancel,
|
|
319
|
-
onSetToday: handleSetToday,
|
|
320
|
-
onOpen: handleOpen,
|
|
321
|
-
onClose: handleClose
|
|
322
|
-
};
|
|
323
|
-
const fieldResponse = {
|
|
324
|
-
value: dateState.draft,
|
|
325
|
-
onChange: handleChangeFromField
|
|
326
|
-
};
|
|
327
|
-
const viewValue = React.useMemo(() => valueManager.cleanValue(utils, dateState.draft), [utils, valueManager, dateState.draft]);
|
|
328
|
-
const viewResponse = {
|
|
329
|
-
value: viewValue,
|
|
330
|
-
onChange: handleChange,
|
|
331
|
-
onClose: handleClose,
|
|
332
|
-
open: isOpen
|
|
333
|
-
};
|
|
334
160
|
const isValid = testedValue => {
|
|
335
161
|
const error = validator({
|
|
336
162
|
adapter,
|
|
@@ -340,17 +166,61 @@ export const usePickerValue = ({
|
|
|
340
166
|
});
|
|
341
167
|
return !valueManager.hasError(error);
|
|
342
168
|
};
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
169
|
+
const clearValue = useEventCallback(() => setValue(valueManager.emptyValue));
|
|
170
|
+
const setValueToToday = useEventCallback(() => setValue(valueManager.getTodayValue(utils, timezone, valueType)));
|
|
171
|
+
const acceptValueChanges = useEventCallback(() => setValue(dateState.lastPublishedValue));
|
|
172
|
+
const cancelValueChanges = useEventCallback(() => setValue(dateState.lastCommittedValue, {
|
|
173
|
+
skipPublicationIfPristine: true
|
|
174
|
+
}));
|
|
175
|
+
const dismissViews = useEventCallback(() => {
|
|
176
|
+
setValue(dateState.lastPublishedValue, {
|
|
177
|
+
skipPublicationIfPristine: true
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
const setValueFromView = useEventCallback((newValue, selectionState = 'partial') => {
|
|
181
|
+
// TODO: Expose a new method (private?) like `setView` that only updates the draft value.
|
|
182
|
+
if (selectionState === 'shallow') {
|
|
183
|
+
setDateState(prev => _extends({}, prev, {
|
|
184
|
+
draft: newValue,
|
|
185
|
+
hasBeenModifiedSinceMount: true
|
|
186
|
+
}));
|
|
187
|
+
}
|
|
188
|
+
setValue(newValue, {
|
|
189
|
+
changeImportance: selectionState === 'finish' && closeOnSelect ? 'accept' : 'set'
|
|
190
|
+
});
|
|
348
191
|
});
|
|
192
|
+
const valueWithoutError = React.useMemo(() => valueManager.cleanValue(utils, dateState.draft), [utils, valueManager, dateState.draft]);
|
|
193
|
+
const viewResponse = {
|
|
194
|
+
value: valueWithoutError,
|
|
195
|
+
onChange: setValueFromView,
|
|
196
|
+
open,
|
|
197
|
+
setOpen
|
|
198
|
+
};
|
|
199
|
+
const actionsContextValue = React.useMemo(() => ({
|
|
200
|
+
setValue,
|
|
201
|
+
setOpen,
|
|
202
|
+
clearValue,
|
|
203
|
+
setValueToToday,
|
|
204
|
+
acceptValueChanges,
|
|
205
|
+
cancelValueChanges
|
|
206
|
+
}), [setValue, setOpen, clearValue, setValueToToday, acceptValueChanges, cancelValueChanges]);
|
|
207
|
+
const contextValue = React.useMemo(() => _extends({}, actionsContextValue, {
|
|
208
|
+
value: dateState.draft,
|
|
209
|
+
timezone,
|
|
210
|
+
open
|
|
211
|
+
}), [actionsContextValue, timezone, open, dateState.draft]);
|
|
212
|
+
const privateContextValue = React.useMemo(() => ({
|
|
213
|
+
dismissViews
|
|
214
|
+
}), [dismissViews]);
|
|
215
|
+
const providerParams = {
|
|
216
|
+
value: dateState.draft,
|
|
217
|
+
contextValue,
|
|
218
|
+
actionsContextValue,
|
|
219
|
+
privateContextValue,
|
|
220
|
+
isValidContextValue: isValid
|
|
221
|
+
};
|
|
349
222
|
return {
|
|
350
|
-
open: isOpen,
|
|
351
|
-
fieldProps: fieldResponse,
|
|
352
223
|
viewProps: viewResponse,
|
|
353
|
-
|
|
354
|
-
actions
|
|
224
|
+
provider: providerParams
|
|
355
225
|
};
|
|
356
226
|
};
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { UseFieldInternalProps } from '../useField';
|
|
2
3
|
import { Validator } from '../../../validation';
|
|
3
|
-
import {
|
|
4
|
-
import { FieldSection, TimezoneProps, MuiPickersAdapter, PickersTimezone, PickerChangeHandlerContext, PickerValidDate, OnErrorProps, InferError, PickerValueType } from '../../../models';
|
|
4
|
+
import { TimezoneProps, MuiPickersAdapter, PickersTimezone, PickerChangeHandlerContext, PickerValidDate, OnErrorProps, InferError, PickerValueType, PickerChangeImportance } from '../../../models';
|
|
5
5
|
import { GetDefaultReferenceDateProps } from '../../utils/getDefaultReferenceDate';
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import type { PickersShortcutsItemContext } from '../../../PickersShortcuts';
|
|
7
|
+
import { InferNonNullablePickerValue, PickerValidValue } from '../../models';
|
|
8
|
+
export interface PickerValueManager<TValue extends PickerValidValue, TError> {
|
|
8
9
|
/**
|
|
9
10
|
* Determines if two values are equal.
|
|
10
|
-
* @template TValue
|
|
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.
|
|
11
12
|
* @param {MuiPickersAdapter} utils The adapter.
|
|
12
13
|
* @param {TValue} valueLeft The first value to compare.
|
|
13
14
|
* @param {TValue} valueRight The second value to compare.
|
|
@@ -20,7 +21,7 @@ export interface PickerValueManager<TValue, TError> {
|
|
|
20
21
|
emptyValue: TValue;
|
|
21
22
|
/**
|
|
22
23
|
* Method returning the value to set when clicking the "Today" button
|
|
23
|
-
* @template TValue
|
|
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.
|
|
24
25
|
* @param {MuiPickersAdapter} utils The adapter.
|
|
25
26
|
* @param {PickersTimezone} timezone The current timezone.
|
|
26
27
|
* @param {PickerValueType} valueType The type of the value being edited.
|
|
@@ -28,7 +29,7 @@ export interface PickerValueManager<TValue, TError> {
|
|
|
28
29
|
*/
|
|
29
30
|
getTodayValue: (utils: MuiPickersAdapter, timezone: PickersTimezone, valueType: PickerValueType) => TValue;
|
|
30
31
|
/**
|
|
31
|
-
* @template TValue
|
|
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.
|
|
32
33
|
* Method returning the reference value to use when mounting the component.
|
|
33
34
|
* @param {object} params The params of the method.
|
|
34
35
|
* @param {PickerValidDate | undefined} params.referenceDate The referenceDate provided by the user.
|
|
@@ -48,10 +49,10 @@ export interface PickerValueManager<TValue, TError> {
|
|
|
48
49
|
granularity: number;
|
|
49
50
|
timezone: PickersTimezone;
|
|
50
51
|
getTodayDate?: () => PickerValidDate;
|
|
51
|
-
}) => TValue
|
|
52
|
+
}) => InferNonNullablePickerValue<TValue>;
|
|
52
53
|
/**
|
|
53
54
|
* Method parsing the input value to replace all invalid dates by `null`.
|
|
54
|
-
* @template TValue
|
|
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.
|
|
55
56
|
* @param {MuiPickersAdapter} utils The adapter.
|
|
56
57
|
* @param {TValue} value The value to parse.
|
|
57
58
|
* @returns {TValue} The value without invalid date.
|
|
@@ -59,7 +60,7 @@ export interface PickerValueManager<TValue, TError> {
|
|
|
59
60
|
cleanValue: (utils: MuiPickersAdapter, value: TValue) => TValue;
|
|
60
61
|
/**
|
|
61
62
|
* Generates the new value, given the previous value and the new proposed value.
|
|
62
|
-
* @template TValue
|
|
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.
|
|
63
64
|
* @param {MuiPickersAdapter} utils The adapter.
|
|
64
65
|
* @param {TValue} lastValidDateValue The last valid value.
|
|
65
66
|
* @param {TValue} value The proposed value.
|
|
@@ -88,7 +89,7 @@ export interface PickerValueManager<TValue, TError> {
|
|
|
88
89
|
/**
|
|
89
90
|
* Return the timezone of the date inside a value.
|
|
90
91
|
* Throw an error on range picker if both values don't have the same timezone.
|
|
91
|
-
@template TValue
|
|
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.
|
|
92
93
|
@param {MuiPickersAdapter} utils The utils to manipulate the date.
|
|
93
94
|
@param {TValue} value The current value.
|
|
94
95
|
@returns {string | null} The timezone of the current value.
|
|
@@ -96,7 +97,7 @@ export interface PickerValueManager<TValue, TError> {
|
|
|
96
97
|
getTimezone: (utils: MuiPickersAdapter, value: TValue) => string | null;
|
|
97
98
|
/**
|
|
98
99
|
* Change the timezone of the dates inside a value.
|
|
99
|
-
@template TValue
|
|
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.
|
|
100
101
|
@param {MuiPickersAdapter} utils The utils to manipulate the date.
|
|
101
102
|
@param {PickersTimezone} timezone The current timezone.
|
|
102
103
|
@param {TValue} value The value to convert.
|
|
@@ -105,19 +106,19 @@ export interface PickerValueManager<TValue, TError> {
|
|
|
105
106
|
setTimezone: (utils: MuiPickersAdapter, timezone: PickersTimezone, value: TValue) => TValue;
|
|
106
107
|
}
|
|
107
108
|
export type PickerSelectionState = 'partial' | 'shallow' | 'finish';
|
|
108
|
-
export interface UsePickerValueState<TValue> {
|
|
109
|
+
export interface UsePickerValueState<TValue extends PickerValidValue> {
|
|
109
110
|
/**
|
|
110
111
|
* Date displayed on the views and the field.
|
|
111
112
|
* It is updated whenever the user modifies something.
|
|
112
113
|
*/
|
|
113
114
|
draft: TValue;
|
|
114
115
|
/**
|
|
115
|
-
* Last value published (
|
|
116
|
+
* Last value published (the last value for which `shouldPublishValue` returned `true`).
|
|
116
117
|
* If `onChange` is defined, it's the value that was passed on the last call to this callback.
|
|
117
118
|
*/
|
|
118
119
|
lastPublishedValue: TValue;
|
|
119
120
|
/**
|
|
120
|
-
* Last value committed (
|
|
121
|
+
* Last value committed (the last value for which `shouldCommitValue` returned `true`).
|
|
121
122
|
* If `onAccept` is defined, it's the value that was passed on the last call to this callback.
|
|
122
123
|
*/
|
|
123
124
|
lastCommittedValue: TValue;
|
|
@@ -135,41 +136,10 @@ export interface UsePickerValueState<TValue> {
|
|
|
135
136
|
*/
|
|
136
137
|
hasBeenModifiedSinceMount: boolean;
|
|
137
138
|
}
|
|
138
|
-
export interface PickerValueUpdaterParams<TValue, TError> {
|
|
139
|
-
action: PickerValueUpdateAction<TValue, TError>;
|
|
140
|
-
dateState: UsePickerValueState<TValue>;
|
|
141
|
-
/**
|
|
142
|
-
* Check if the new draft value has changed compared to some given value.
|
|
143
|
-
* @template TValue
|
|
144
|
-
* @param {TValue} comparisonValue The value to compare the new draft value with.
|
|
145
|
-
* @returns {boolean} `true` if the new draft value is equal to the comparison value.
|
|
146
|
-
*/
|
|
147
|
-
hasChanged: (comparisonValue: TValue) => boolean;
|
|
148
|
-
isControlled: boolean;
|
|
149
|
-
closeOnSelect: boolean;
|
|
150
|
-
}
|
|
151
|
-
export type PickerValueUpdateAction<TValue, TError> = {
|
|
152
|
-
name: 'setValueFromView';
|
|
153
|
-
value: TValue;
|
|
154
|
-
selectionState: PickerSelectionState;
|
|
155
|
-
} | {
|
|
156
|
-
name: 'setValueFromField';
|
|
157
|
-
value: TValue;
|
|
158
|
-
context: FieldChangeHandlerContext<TError>;
|
|
159
|
-
} | {
|
|
160
|
-
name: 'setValueFromAction';
|
|
161
|
-
value: TValue;
|
|
162
|
-
pickerAction: 'accept' | 'today' | 'cancel' | 'dismiss' | 'clear';
|
|
163
|
-
} | {
|
|
164
|
-
name: 'setValueFromShortcut';
|
|
165
|
-
value: TValue;
|
|
166
|
-
changeImportance: PickerShortcutChangeImportance;
|
|
167
|
-
shortcut: PickersShortcutsItemContext;
|
|
168
|
-
};
|
|
169
139
|
/**
|
|
170
140
|
* Props used to handle the value that are common to all pickers.
|
|
171
141
|
*/
|
|
172
|
-
export interface UsePickerValueBaseProps<TValue, TError> extends OnErrorProps<TValue, TError> {
|
|
142
|
+
export interface UsePickerValueBaseProps<TValue extends PickerValidValue, TError> extends OnErrorProps<TValue, TError> {
|
|
173
143
|
/**
|
|
174
144
|
* The selected value.
|
|
175
145
|
* Used when the component is controlled.
|
|
@@ -202,8 +172,8 @@ export interface UsePickerValueBaseProps<TValue, TError> extends OnErrorProps<TV
|
|
|
202
172
|
*/
|
|
203
173
|
export interface UsePickerValueNonStaticProps {
|
|
204
174
|
/**
|
|
205
|
-
* If `true`, the
|
|
206
|
-
* @default
|
|
175
|
+
* If `true`, the Picker will close after submitting the full date.
|
|
176
|
+
* @default false
|
|
207
177
|
*/
|
|
208
178
|
closeOnSelect?: boolean;
|
|
209
179
|
/**
|
|
@@ -225,48 +195,133 @@ export interface UsePickerValueNonStaticProps {
|
|
|
225
195
|
/**
|
|
226
196
|
* Props used to handle the value of the pickers.
|
|
227
197
|
*/
|
|
228
|
-
export interface UsePickerValueProps<TValue, TError> extends UsePickerValueBaseProps<TValue, TError>, UsePickerValueNonStaticProps, TimezoneProps {
|
|
198
|
+
export interface UsePickerValueProps<TValue extends PickerValidValue, TError> extends UsePickerValueBaseProps<TValue, TError>, UsePickerValueNonStaticProps, TimezoneProps {
|
|
229
199
|
referenceDate?: PickerValidDate;
|
|
230
200
|
}
|
|
231
|
-
export interface UsePickerValueParams<TValue, TExternalProps extends UsePickerValueProps<TValue, any>> {
|
|
201
|
+
export interface UsePickerValueParams<TValue extends PickerValidValue, TExternalProps extends UsePickerValueProps<TValue, any>> {
|
|
232
202
|
props: TExternalProps;
|
|
233
203
|
valueManager: PickerValueManager<TValue, InferError<TExternalProps>>;
|
|
234
204
|
valueType: PickerValueType;
|
|
235
|
-
variant: PickerVariant;
|
|
236
205
|
validator: Validator<TValue, InferError<TExternalProps>, TExternalProps>;
|
|
237
206
|
}
|
|
238
|
-
export
|
|
239
|
-
onAccept: () => void;
|
|
240
|
-
onClear: () => void;
|
|
241
|
-
onDismiss: () => void;
|
|
242
|
-
onCancel: () => void;
|
|
243
|
-
onSetToday: () => void;
|
|
244
|
-
onOpen: (event: React.UIEvent) => void;
|
|
245
|
-
onClose: (event?: React.UIEvent) => void;
|
|
246
|
-
}
|
|
247
|
-
export type UsePickerValueFieldResponse<TValue, TSection extends FieldSection, TError> = Required<Pick<UseFieldInternalProps<TValue, TSection, any, TError>, 'value' | 'onChange'>>;
|
|
207
|
+
export type UsePickerValueFieldResponse<TValue extends PickerValidValue, TError> = Required<Pick<UseFieldInternalProps<TValue, any, TError>, 'value' | 'onChange'>>;
|
|
248
208
|
/**
|
|
249
209
|
* Props passed to `usePickerViews`.
|
|
250
210
|
*/
|
|
251
|
-
export interface UsePickerValueViewsResponse<TValue> {
|
|
211
|
+
export interface UsePickerValueViewsResponse<TValue extends PickerValidValue> {
|
|
252
212
|
value: TValue;
|
|
253
213
|
onChange: (value: TValue, selectionState?: PickerSelectionState) => void;
|
|
254
214
|
open: boolean;
|
|
255
|
-
|
|
215
|
+
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
256
216
|
}
|
|
257
217
|
/**
|
|
258
|
-
*
|
|
218
|
+
* Params passed to `usePickerProvider`.
|
|
259
219
|
*/
|
|
260
|
-
export interface
|
|
220
|
+
export interface UsePickerValueProviderParams<TValue extends PickerValidValue, TError> {
|
|
261
221
|
value: TValue;
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
222
|
+
contextValue: UsePickerValueContextValue<TValue, TError>;
|
|
223
|
+
actionsContextValue: UsePickerValueActionsContextValue<TValue, TError>;
|
|
224
|
+
privateContextValue: UsePickerValuePrivateContextValue;
|
|
225
|
+
isValidContextValue: (value: TValue) => boolean;
|
|
265
226
|
}
|
|
266
|
-
export interface UsePickerValueResponse<TValue
|
|
267
|
-
open: boolean;
|
|
268
|
-
actions: UsePickerValueActions;
|
|
227
|
+
export interface UsePickerValueResponse<TValue extends PickerValidValue, TError> {
|
|
269
228
|
viewProps: UsePickerValueViewsResponse<TValue>;
|
|
270
|
-
|
|
271
|
-
|
|
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;
|
|
272
327
|
}
|