@mui/x-date-pickers 8.0.0-alpha.6 → 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 +127 -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 -2
- package/DatePicker/DatePickerToolbar.js +7 -11
- 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/DateTimePickerTabs.js +2 -2
- package/DateTimePicker/DateTimePickerToolbar.d.ts +6 -2
- package/DateTimePicker/DateTimePickerToolbar.js +36 -31
- package/DateTimePicker/shared.d.ts +1 -1
- package/DesktopDatePicker/DesktopDatePicker.js +9 -3
- package/DesktopDatePicker/DesktopDatePicker.types.d.ts +5 -0
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +13 -10
- package/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +1 -5
- package/DesktopTimePicker/DesktopTimePicker.js +3 -7
- package/MobileDatePicker/MobileDatePicker.js +2 -2
- package/MobileDateTimePicker/MobileDateTimePicker.js +2 -2
- package/MobileTimePicker/MobileTimePicker.js +2 -2
- package/PickersActionBar/PickersActionBar.d.ts +6 -3
- package/PickersActionBar/PickersActionBar.js +6 -3
- package/PickersLayout/PickersLayout.js +1 -5
- package/PickersLayout/PickersLayout.types.d.ts +2 -3
- package/PickersLayout/usePickerLayout.js +12 -31
- 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/TimeField/useTimeField.d.ts +1 -1
- package/TimeField/useTimeField.js +13 -11
- package/TimePicker/TimePicker.js +2 -2
- package/TimePicker/TimePickerToolbar.d.ts +1 -2
- package/TimePicker/TimePickerToolbar.js +20 -18
- package/TimePicker/shared.d.ts +1 -1
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +2 -1
- package/hooks/useIsValidValue.d.ts +7 -0
- package/hooks/useIsValidValue.js +11 -0
- package/hooks/usePickerActionsContext.d.ts +3 -1
- package/hooks/usePickerActionsContext.js +0 -1
- package/hooks/usePickerContext.d.ts +2 -2
- package/hooks/usePickerContext.js +1 -1
- package/index.d.ts +1 -0
- package/index.js +3 -2
- package/internals/components/PickerProvider.d.ts +11 -10
- package/internals/components/PickerProvider.js +8 -3
- 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 +1 -3
- package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +2 -2
- 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 +1 -3
- package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +2 -2
- package/internals/hooks/useOpenState.js +3 -2
- package/internals/hooks/usePicker/usePicker.d.ts +1 -1
- package/internals/hooks/usePicker/usePicker.js +0 -6
- package/internals/hooks/usePicker/usePicker.types.d.ts +5 -6
- package/internals/hooks/usePicker/usePickerProvider.d.ts +5 -5
- package/internals/hooks/usePicker/usePickerProvider.js +4 -2
- package/internals/hooks/usePicker/usePickerValue.d.ts +1 -1
- package/internals/hooks/usePicker/usePickerValue.js +67 -184
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +48 -54
- package/internals/hooks/usePicker/usePickerViews.d.ts +27 -23
- package/internals/hooks/usePicker/usePickerViews.js +17 -11
- package/internals/hooks/useStaticPicker/useStaticPicker.js +1 -4
- package/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +2 -2
- package/internals/hooks/useUtils.js +1 -1
- package/internals/index.d.ts +5 -3
- 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/toolbar.d.ts +1 -5
- 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 +7 -11
- package/modern/DateTimeField/useDateTimeField.js +13 -11
- package/modern/DateTimePicker/DateTimePicker.js +2 -2
- package/modern/DateTimePicker/DateTimePickerTabs.js +2 -2
- package/modern/DateTimePicker/DateTimePickerToolbar.js +36 -31
- package/modern/DesktopDatePicker/DesktopDatePicker.js +9 -3
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +13 -10
- package/modern/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +1 -5
- 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 +6 -3
- package/modern/PickersLayout/PickersLayout.js +1 -5
- package/modern/PickersLayout/usePickerLayout.js +12 -31
- 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 +20 -18
- package/modern/hooks/index.js +2 -1
- package/modern/hooks/useIsValidValue.js +11 -0
- package/modern/hooks/usePickerActionsContext.js +0 -1
- package/modern/hooks/usePickerContext.js +1 -1
- package/modern/index.js +3 -2
- package/modern/internals/components/PickerProvider.js +8 -3
- 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 +1 -3
- 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 +1 -3
- package/modern/internals/hooks/useOpenState.js +3 -2
- package/modern/internals/hooks/usePicker/usePicker.js +0 -6
- package/modern/internals/hooks/usePicker/usePickerProvider.js +4 -2
- package/modern/internals/hooks/usePicker/usePickerValue.js +67 -184
- package/modern/internals/hooks/usePicker/usePickerViews.js +17 -11
- 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 +7 -11
- package/node/DateTimeField/useDateTimeField.js +12 -10
- package/node/DateTimePicker/DateTimePicker.js +2 -2
- package/node/DateTimePicker/DateTimePickerTabs.js +2 -2
- package/node/DateTimePicker/DateTimePickerToolbar.js +36 -31
- package/node/DesktopDatePicker/DesktopDatePicker.js +9 -3
- package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +13 -10
- package/node/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +1 -5
- 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 +8 -5
- package/node/PickersLayout/PickersLayout.js +1 -5
- package/node/PickersLayout/usePickerLayout.js +16 -35
- 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 +20 -18
- package/node/hooks/index.js +8 -1
- package/node/hooks/useIsValidValue.js +18 -0
- package/node/hooks/usePickerContext.js +1 -1
- package/node/index.js +13 -1
- package/node/internals/components/PickerProvider.js +8 -3
- 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 +1 -3
- 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 +1 -3
- package/node/internals/hooks/useOpenState.js +4 -2
- package/node/internals/hooks/usePicker/usePicker.js +0 -7
- package/node/internals/hooks/usePicker/usePickerProvider.js +4 -2
- package/node/internals/hooks/usePicker/usePickerValue.js +67 -184
- package/node/internals/hooks/usePicker/usePickerViews.js +17 -12
- package/node/internals/hooks/useStaticPicker/useStaticPicker.js +1 -4
- package/node/internals/hooks/useUtils.js +1 -1
- package/node/internals/index.js +26 -18
- 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 +1 -1
- 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
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { UsePickerValueParams, UsePickerValueProps, UsePickerValueBaseProps, UsePickerValueResponse } from './usePickerValue.types';
|
|
2
2
|
import { UsePickerViewsProps, UsePickerViewParams, UsePickerViewsResponse, UsePickerViewsBaseProps } from './usePickerViews';
|
|
3
|
-
import { PickerOwnerState } from '../../../models';
|
|
3
|
+
import { InferError, PickerOwnerState } from '../../../models';
|
|
4
4
|
import { DateOrTimeViewWithMeridiem, PickerValidValue } from '../../models';
|
|
5
5
|
import { UsePickerProviderParameters, UsePickerProviderProps, UsePickerProviderReturnValue } from './usePickerProvider';
|
|
6
6
|
/**
|
|
7
7
|
* Props common to all picker headless implementations.
|
|
8
8
|
*/
|
|
9
|
-
export interface UsePickerBaseProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError, TExternalProps extends UsePickerViewsProps<TValue, TView, any
|
|
9
|
+
export interface UsePickerBaseProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError, TExternalProps extends UsePickerViewsProps<TValue, TView, any>> extends UsePickerValueBaseProps<TValue, TError>, UsePickerViewsBaseProps<TValue, TView, TExternalProps>, UsePickerProviderProps {
|
|
10
10
|
}
|
|
11
|
-
export interface UsePickerProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError, TExternalProps extends UsePickerViewsProps<TValue, TView, any
|
|
11
|
+
export interface UsePickerProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError, TExternalProps extends UsePickerViewsProps<TValue, TView, any>> extends UsePickerValueProps<TValue, TError>, UsePickerViewsProps<TValue, TView, TExternalProps>, UsePickerProviderProps {
|
|
12
12
|
}
|
|
13
|
-
export interface UsePickerParams<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerProps<TValue, TView, any, any
|
|
13
|
+
export interface UsePickerParams<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerProps<TValue, TView, any, any>> extends Pick<UsePickerValueParams<TValue, TExternalProps>, 'valueManager' | 'valueType' | 'validator'>, Pick<UsePickerViewParams<TValue, TView, TExternalProps>, 'autoFocusView' | 'rendererInterceptor' | 'fieldRef'>, Pick<UsePickerProviderParameters<TValue, TView, InferError<TExternalProps>>, 'localeText' | 'variant'> {
|
|
14
14
|
props: TExternalProps;
|
|
15
15
|
}
|
|
16
16
|
export interface UsePickerResponse<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError> extends Pick<UsePickerValueResponse<TValue, TError>, 'fieldProps'>, Pick<UsePickerViewsResponse<TView>, 'shouldRestoreFocus' | 'renderCurrentView'> {
|
|
17
17
|
ownerState: PickerOwnerState;
|
|
18
|
-
providerProps: UsePickerProviderReturnValue
|
|
19
|
-
layoutProps: UsePickerValueResponse<TValue, TError>['layoutProps'];
|
|
18
|
+
providerProps: UsePickerProviderReturnValue<TValue>;
|
|
20
19
|
hasUIView: boolean;
|
|
21
20
|
}
|
|
@@ -4,15 +4,15 @@ import type { UsePickerProps } from './usePicker.types';
|
|
|
4
4
|
import { DateOrTimeViewWithMeridiem, FormProps, PickerOrientation, PickerValidValue, PickerVariant } from '../../models';
|
|
5
5
|
import { UsePickerViewsProviderParams } from './usePickerViews';
|
|
6
6
|
export declare const usePickerOrientation: (views: readonly DateOrTimeViewWithMeridiem[], customOrientation: PickerOrientation | undefined) => PickerOrientation;
|
|
7
|
-
export declare function usePickerProvider<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem>(parameters: UsePickerProviderParameters<TValue, TView>): UsePickerProviderReturnValue
|
|
8
|
-
export interface UsePickerProviderParameters<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem> extends Pick<PickerProviderProps
|
|
9
|
-
props: UsePickerProps<TValue, any, any, any
|
|
7
|
+
export declare function usePickerProvider<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError>(parameters: UsePickerProviderParameters<TValue, TView, TError>): UsePickerProviderReturnValue<TValue>;
|
|
8
|
+
export interface UsePickerProviderParameters<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError> extends Pick<PickerProviderProps<TValue>, 'localeText'> {
|
|
9
|
+
props: UsePickerProps<TValue, any, any, any>;
|
|
10
10
|
valueManager: PickerValueManager<TValue, any>;
|
|
11
11
|
variant: PickerVariant;
|
|
12
|
-
paramsFromUsePickerValue: UsePickerValueProviderParams<TValue>;
|
|
12
|
+
paramsFromUsePickerValue: UsePickerValueProviderParams<TValue, TError>;
|
|
13
13
|
paramsFromUsePickerViews: UsePickerViewsProviderParams<TView>;
|
|
14
14
|
}
|
|
15
|
-
export interface UsePickerProviderReturnValue extends Omit<PickerProviderProps
|
|
15
|
+
export interface UsePickerProviderReturnValue<TValue extends PickerValidValue> extends Omit<PickerProviderProps<TValue>, 'children'> {
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Props used to create the picker's contexts.
|
|
@@ -62,11 +62,13 @@ export function usePickerProvider(parameters) {
|
|
|
62
62
|
const privateContextValue = React.useMemo(() => _extends({}, paramsFromUsePickerValue.privateContextValue, {
|
|
63
63
|
ownerState
|
|
64
64
|
}), [paramsFromUsePickerValue, ownerState]);
|
|
65
|
+
const actionsContextValue = React.useMemo(() => _extends({}, paramsFromUsePickerValue.actionsContextValue, paramsFromUsePickerViews.actionsContextValue), [paramsFromUsePickerValue.actionsContextValue, paramsFromUsePickerViews.actionsContextValue]);
|
|
65
66
|
return {
|
|
66
67
|
localeText,
|
|
67
68
|
contextValue,
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
privateContextValue,
|
|
70
|
+
actionsContextValue,
|
|
71
|
+
isValidContextValue: paramsFromUsePickerValue.isValidContextValue
|
|
70
72
|
};
|
|
71
73
|
}
|
|
72
74
|
|
|
@@ -4,4 +4,4 @@ import { PickerValidValue } from '../../models';
|
|
|
4
4
|
/**
|
|
5
5
|
* Manage the value lifecycle of all the pickers.
|
|
6
6
|
*/
|
|
7
|
-
export declare const usePickerValue: <TValue extends PickerValidValue, TExternalProps extends UsePickerValueProps<TValue, any>>({ props, valueManager, valueType,
|
|
7
|
+
export declare const usePickerValue: <TValue extends PickerValidValue, TExternalProps extends UsePickerValueProps<TValue, any>>({ props, valueManager, valueType, validator, }: UsePickerValueParams<TValue, TExternalProps>) => UsePickerValueResponse<TValue, InferError<TExternalProps>>;
|
|
@@ -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,33 +156,6 @@ export const usePickerValue = ({
|
|
|
251
156
|
hasBeenModifiedSinceMount: true
|
|
252
157
|
}));
|
|
253
158
|
}
|
|
254
|
-
const handleChange = useEventCallback((newValue, selectionState = 'partial') => updateDate({
|
|
255
|
-
name: 'setValueFromView',
|
|
256
|
-
value: newValue,
|
|
257
|
-
selectionState
|
|
258
|
-
}));
|
|
259
|
-
const handleSelectShortcut = useEventCallback((newValue, changeImportance, shortcut) => updateDate({
|
|
260
|
-
name: 'setValueFromShortcut',
|
|
261
|
-
value: newValue,
|
|
262
|
-
changeImportance,
|
|
263
|
-
shortcut
|
|
264
|
-
}));
|
|
265
|
-
const handleChangeFromField = useEventCallback((newValue, context) => updateDate({
|
|
266
|
-
name: 'setValueFromField',
|
|
267
|
-
value: newValue,
|
|
268
|
-
context
|
|
269
|
-
}));
|
|
270
|
-
const fieldResponse = {
|
|
271
|
-
value: dateState.draft,
|
|
272
|
-
onChange: handleChangeFromField
|
|
273
|
-
};
|
|
274
|
-
const valueWithoutError = React.useMemo(() => valueManager.cleanValue(utils, dateState.draft), [utils, valueManager, dateState.draft]);
|
|
275
|
-
const viewResponse = {
|
|
276
|
-
value: valueWithoutError,
|
|
277
|
-
onChange: handleChange,
|
|
278
|
-
open,
|
|
279
|
-
setOpen
|
|
280
|
-
};
|
|
281
159
|
const isValid = testedValue => {
|
|
282
160
|
const error = validator({
|
|
283
161
|
adapter,
|
|
@@ -287,49 +165,54 @@ export const usePickerValue = ({
|
|
|
287
165
|
});
|
|
288
166
|
return !valueManager.hasError(error);
|
|
289
167
|
};
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
};
|
|
296
|
-
const clearValue = useEventCallback(() => updateDate({
|
|
297
|
-
value: valueManager.emptyValue,
|
|
298
|
-
name: 'setValueFromAction',
|
|
299
|
-
pickerAction: 'clear'
|
|
300
|
-
}));
|
|
301
|
-
const setValueToToday = useEventCallback(() => updateDate({
|
|
302
|
-
value: valueManager.getTodayValue(utils, timezone, valueType),
|
|
303
|
-
name: 'setValueFromAction',
|
|
304
|
-
pickerAction: 'today'
|
|
305
|
-
}));
|
|
306
|
-
const acceptValueChanges = useEventCallback(() => updateDate({
|
|
307
|
-
value: dateState.lastPublishedValue,
|
|
308
|
-
name: 'setValueFromAction',
|
|
309
|
-
pickerAction: 'accept'
|
|
310
|
-
}));
|
|
311
|
-
const cancelValueChanges = useEventCallback(() => updateDate({
|
|
312
|
-
value: dateState.lastCommittedValue,
|
|
313
|
-
name: 'setValueFromAction',
|
|
314
|
-
pickerAction: 'cancel'
|
|
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
|
|
315
173
|
}));
|
|
316
174
|
const dismissViews = useEventCallback(() => {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
name: 'setValueFromAction',
|
|
320
|
-
pickerAction: 'dismiss'
|
|
175
|
+
setValue(dateState.lastPublishedValue, {
|
|
176
|
+
skipPublicationIfPristine: true
|
|
321
177
|
});
|
|
322
178
|
});
|
|
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
|
+
};
|
|
323
204
|
const actionsContextValue = React.useMemo(() => ({
|
|
205
|
+
setValue,
|
|
324
206
|
setOpen,
|
|
325
207
|
clearValue,
|
|
326
208
|
setValueToToday,
|
|
327
209
|
acceptValueChanges,
|
|
328
210
|
cancelValueChanges
|
|
329
|
-
}), [setOpen, clearValue, setValueToToday, acceptValueChanges, cancelValueChanges]);
|
|
211
|
+
}), [setValue, setOpen, clearValue, setValueToToday, acceptValueChanges, cancelValueChanges]);
|
|
330
212
|
const contextValue = React.useMemo(() => _extends({}, actionsContextValue, {
|
|
331
|
-
open
|
|
332
|
-
|
|
213
|
+
open,
|
|
214
|
+
value: dateState.draft
|
|
215
|
+
}), [actionsContextValue, open, dateState.draft]);
|
|
333
216
|
const privateContextValue = React.useMemo(() => ({
|
|
334
217
|
dismissViews
|
|
335
218
|
}), [dismissViews]);
|
|
@@ -337,12 +220,12 @@ export const usePickerValue = ({
|
|
|
337
220
|
value: valueWithoutError,
|
|
338
221
|
contextValue,
|
|
339
222
|
actionsContextValue,
|
|
340
|
-
privateContextValue
|
|
223
|
+
privateContextValue,
|
|
224
|
+
isValidContextValue: isValid
|
|
341
225
|
};
|
|
342
226
|
return {
|
|
343
227
|
fieldProps: fieldResponse,
|
|
344
228
|
viewProps: viewResponse,
|
|
345
|
-
layoutProps: layoutResponse,
|
|
346
229
|
provider: providerParams
|
|
347
230
|
};
|
|
348
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,7 +202,6 @@ 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
207
|
export type UsePickerValueFieldResponse<TValue extends PickerValidValue, TError> = Required<Pick<UseFieldInternalProps<TValue, any, TError>, 'value' | 'onChange'>>;
|
|
@@ -247,37 +214,38 @@ export interface UsePickerValueViewsResponse<TValue extends PickerValidValue> {
|
|
|
247
214
|
open: boolean;
|
|
248
215
|
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
249
216
|
}
|
|
250
|
-
/**
|
|
251
|
-
* Props passed to `usePickerLayoutProps`.
|
|
252
|
-
*/
|
|
253
|
-
export interface UsePickerValueLayoutResponse<TValue extends PickerValidValue> {
|
|
254
|
-
value: TValue;
|
|
255
|
-
onChange: (newValue: TValue) => void;
|
|
256
|
-
onSelectShortcut: (newValue: TValue, changeImportance: PickerShortcutChangeImportance, shortcut: PickersShortcutsItemContext) => void;
|
|
257
|
-
isValid: (value: TValue) => boolean;
|
|
258
|
-
}
|
|
259
217
|
/**
|
|
260
218
|
* Params passed to `usePickerProvider`.
|
|
261
219
|
*/
|
|
262
|
-
export interface UsePickerValueProviderParams<TValue extends PickerValidValue> {
|
|
220
|
+
export interface UsePickerValueProviderParams<TValue extends PickerValidValue, TError> {
|
|
263
221
|
value: TValue;
|
|
264
|
-
contextValue: UsePickerValueContextValue
|
|
265
|
-
actionsContextValue: UsePickerValueActionsContextValue
|
|
222
|
+
contextValue: UsePickerValueContextValue<TValue, TError>;
|
|
223
|
+
actionsContextValue: UsePickerValueActionsContextValue<TValue, TError>;
|
|
266
224
|
privateContextValue: UsePickerValuePrivateContextValue;
|
|
225
|
+
isValidContextValue: (value: TValue) => boolean;
|
|
267
226
|
}
|
|
268
227
|
export interface UsePickerValueResponse<TValue extends PickerValidValue, TError> {
|
|
269
228
|
viewProps: UsePickerValueViewsResponse<TValue>;
|
|
270
229
|
fieldProps: UsePickerValueFieldResponse<TValue, TError>;
|
|
271
|
-
|
|
272
|
-
provider: UsePickerValueProviderParams<TValue>;
|
|
230
|
+
provider: UsePickerValueProviderParams<TValue, TError>;
|
|
273
231
|
}
|
|
274
|
-
export interface UsePickerValueContextValue extends UsePickerValueActionsContextValue {
|
|
232
|
+
export interface UsePickerValueContextValue<TValue extends PickerValidValue, TError> extends UsePickerValueActionsContextValue<TValue, TError> {
|
|
233
|
+
/**
|
|
234
|
+
* The current value of the picker.
|
|
235
|
+
*/
|
|
236
|
+
value: TValue;
|
|
275
237
|
/**
|
|
276
238
|
* `true` if the picker is open, `false` otherwise.
|
|
277
239
|
*/
|
|
278
240
|
open: boolean;
|
|
279
241
|
}
|
|
280
|
-
export interface UsePickerValueActionsContextValue {
|
|
242
|
+
export interface UsePickerValueActionsContextValue<TValue extends PickerValidValue, TError> {
|
|
243
|
+
/**
|
|
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;
|
|
281
249
|
/**
|
|
282
250
|
* Set the current open state of the Picker.
|
|
283
251
|
* ```ts
|
|
@@ -318,3 +286,29 @@ export interface UsePickerValuePrivateContextValue {
|
|
|
318
286
|
*/
|
|
319
287
|
dismissViews: () => void;
|
|
320
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;
|
|
314
|
+
}
|