@mui/x-date-pickers 8.0.0-alpha.0 → 8.0.0-alpha.2
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/AdapterMoment/AdapterMoment.js +10 -0
- package/CHANGELOG.md +651 -6
- package/DateCalendar/DateCalendar.js +1 -0
- package/DateCalendar/DateCalendar.types.d.ts +2 -1
- package/DateCalendar/PickersFadeTransitionGroup.js +4 -6
- package/DateCalendar/PickersSlideTransition.js +12 -5
- package/DateCalendar/useCalendarState.d.ts +6 -4
- package/DateField/DateField.js +5 -4
- package/DateField/DateField.types.d.ts +10 -9
- package/DatePicker/DatePicker.types.d.ts +3 -3
- package/DatePicker/DatePickerToolbar.d.ts +3 -2
- package/DatePicker/DatePickerToolbar.js +0 -12
- package/DatePicker/shared.d.ts +6 -5
- package/DateTimeField/DateTimeField.js +5 -4
- package/DateTimeField/DateTimeField.types.d.ts +10 -10
- package/DateTimePicker/DateTimePicker.types.d.ts +3 -3
- package/DateTimePicker/DateTimePickerTabs.js +8 -6
- package/DateTimePicker/DateTimePickerToolbar.d.ts +3 -4
- package/DateTimePicker/DateTimePickerToolbar.js +6 -15
- package/DateTimePicker/shared.d.ts +6 -6
- package/DayCalendarSkeleton/DayCalendarSkeleton.js +10 -19
- package/DesktopDateTimePicker/DesktopDateTimePickerLayout.d.ts +2 -1
- package/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +10 -33
- package/DigitalClock/DigitalClock.js +1 -0
- package/MonthCalendar/MonthCalendar.js +1 -0
- package/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
- package/MultiSectionDigitalClock/MultiSectionDigitalClock.types.d.ts +6 -6
- package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.d.ts +4 -4
- package/PickersCalendarHeader/PickersCalendarHeader.js +8 -7
- package/PickersCalendarHeader/PickersCalendarHeader.types.d.ts +3 -4
- package/PickersLayout/PickersLayout.d.ts +7 -5
- package/PickersLayout/PickersLayout.js +22 -39
- package/PickersLayout/PickersLayout.types.d.ts +14 -15
- package/PickersLayout/usePickerLayout.d.ts +5 -4
- package/PickersLayout/usePickerLayout.js +20 -17
- package/PickersShortcuts/PickersShortcuts.d.ts +7 -6
- package/PickersTextField/PickersInputBase/PickersInputBase.js +10 -9
- package/PickersTextField/PickersTextField.js +2 -2
- package/README.md +9 -6
- package/TimeClock/Clock.js +1 -0
- package/TimeClock/TimeClock.js +1 -0
- package/TimeField/TimeField.js +5 -4
- package/TimeField/TimeField.types.d.ts +10 -10
- package/TimePicker/TimePicker.types.d.ts +3 -3
- package/TimePicker/TimePickerToolbar.d.ts +2 -3
- package/TimePicker/TimePickerToolbar.js +6 -15
- package/TimePicker/shared.d.ts +6 -6
- package/YearCalendar/YearCalendar.js +1 -0
- package/hooks/useParsedFormat.d.ts +2 -2
- package/hooks/useParsedFormat.js +1 -1
- package/hooks/useSplitFieldProps.d.ts +3 -3
- package/index.js +1 -1
- package/internals/components/PickerProvider.d.ts +26 -0
- package/internals/components/PickerProvider.js +3 -1
- package/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +11 -10
- package/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.types.d.ts +11 -8
- package/internals/components/PickersToolbar.d.ts +3 -3
- package/internals/components/PickersToolbar.js +2 -4
- package/internals/hooks/useClockReferenceDate.d.ts +2 -1
- package/internals/hooks/useDesktopPicker/useDesktopPicker.js +1 -1
- package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +14 -14
- package/internals/hooks/useField/useField.d.ts +3 -3
- package/internals/hooks/useField/useField.types.d.ts +46 -46
- package/internals/hooks/useField/useField.utils.d.ts +4 -3
- package/internals/hooks/useField/useFieldCharacterEditing.d.ts +6 -5
- package/internals/hooks/useField/useFieldState.d.ts +9 -8
- package/internals/hooks/useField/useFieldState.js +1 -1
- package/internals/hooks/useField/useFieldV6TextField.d.ts +4 -3
- package/internals/hooks/useField/useFieldV7TextField.js +2 -1
- package/internals/hooks/useFieldOwnerState.d.ts +6 -0
- package/internals/hooks/useFieldOwnerState.js +12 -0
- package/internals/hooks/useMobilePicker/useMobilePicker.js +1 -1
- package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +11 -11
- package/internals/hooks/usePicker/usePicker.d.ts +3 -3
- package/internals/hooks/usePicker/usePicker.js +10 -19
- package/internals/hooks/usePicker/usePicker.types.d.ts +8 -8
- package/internals/hooks/usePicker/usePickerProvider.d.ts +21 -6
- package/internals/hooks/usePicker/usePickerProvider.js +61 -5
- package/internals/hooks/usePicker/usePickerValue.d.ts +3 -2
- package/internals/hooks/usePicker/usePickerValue.js +18 -7
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +32 -30
- package/internals/hooks/usePicker/usePickerViews.d.ts +11 -10
- package/internals/hooks/usePicker/usePickerViews.js +1 -0
- package/internals/hooks/useStaticPicker/useStaticPicker.js +1 -1
- package/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +5 -6
- package/internals/hooks/useValueWithTimezone.d.ts +20 -15
- package/internals/hooks/useValueWithTimezone.js +13 -1
- package/internals/hooks/useViews.d.ts +5 -5
- package/internals/index.d.ts +5 -3
- package/internals/index.js +1 -0
- package/internals/models/common.d.ts +2 -1
- package/internals/models/fields.d.ts +6 -1
- package/internals/models/pickers.d.ts +1 -0
- package/internals/models/pickers.js +1 -0
- package/internals/models/props/basePickerProps.d.ts +4 -3
- package/internals/models/props/time.d.ts +2 -1
- package/internals/models/props/toolbar.d.ts +2 -2
- package/internals/models/value.d.ts +9 -0
- package/internals/utils/date-utils.d.ts +3 -3
- package/internals/utils/valueManagers.d.ts +4 -3
- package/locales/nlNL.js +7 -7
- package/models/adapters.d.ts +4 -4
- package/models/common.d.ts +1 -0
- package/models/fields.d.ts +19 -6
- package/models/pickers.d.ts +18 -0
- package/models/validation.d.ts +2 -1
- package/modern/AdapterMoment/AdapterMoment.js +10 -0
- package/modern/DateCalendar/DateCalendar.js +1 -0
- package/modern/DateCalendar/PickersFadeTransitionGroup.js +4 -6
- package/modern/DateCalendar/PickersSlideTransition.js +12 -5
- package/modern/DateField/DateField.js +5 -4
- package/modern/DatePicker/DatePickerToolbar.js +0 -12
- package/modern/DateTimeField/DateTimeField.js +5 -4
- package/modern/DateTimePicker/DateTimePickerTabs.js +8 -6
- package/modern/DateTimePicker/DateTimePickerToolbar.js +6 -15
- package/modern/DayCalendarSkeleton/DayCalendarSkeleton.js +10 -19
- package/modern/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +10 -33
- package/modern/DigitalClock/DigitalClock.js +1 -0
- package/modern/MonthCalendar/MonthCalendar.js +1 -0
- package/modern/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
- package/modern/PickersCalendarHeader/PickersCalendarHeader.js +8 -7
- package/modern/PickersLayout/PickersLayout.js +22 -39
- package/modern/PickersLayout/usePickerLayout.js +20 -17
- package/modern/PickersTextField/PickersInputBase/PickersInputBase.js +10 -9
- package/modern/PickersTextField/PickersTextField.js +2 -2
- package/modern/TimeClock/Clock.js +1 -0
- package/modern/TimeClock/TimeClock.js +1 -0
- package/modern/TimeField/TimeField.js +5 -4
- package/modern/TimePicker/TimePickerToolbar.js +6 -15
- package/modern/YearCalendar/YearCalendar.js +1 -0
- package/modern/hooks/useParsedFormat.js +1 -1
- package/modern/index.js +1 -1
- package/modern/internals/components/PickerProvider.js +3 -1
- package/modern/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +11 -10
- package/modern/internals/components/PickersToolbar.js +2 -4
- package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.js +1 -1
- package/modern/internals/hooks/useField/useFieldState.js +1 -1
- package/modern/internals/hooks/useField/useFieldV7TextField.js +2 -1
- package/modern/internals/hooks/useFieldOwnerState.js +12 -0
- package/modern/internals/hooks/useMobilePicker/useMobilePicker.js +1 -1
- package/modern/internals/hooks/usePicker/usePicker.js +10 -19
- package/modern/internals/hooks/usePicker/usePickerProvider.js +61 -5
- package/modern/internals/hooks/usePicker/usePickerValue.js +18 -7
- package/modern/internals/hooks/usePicker/usePickerViews.js +1 -0
- package/modern/internals/hooks/useStaticPicker/useStaticPicker.js +1 -1
- package/modern/internals/hooks/useValueWithTimezone.js +13 -1
- package/modern/internals/index.js +1 -0
- package/modern/internals/models/pickers.js +1 -0
- package/modern/locales/nlNL.js +7 -7
- 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/AdapterMoment/AdapterMoment.js +10 -0
- package/node/DateCalendar/DateCalendar.js +1 -0
- package/node/DateCalendar/PickersFadeTransitionGroup.js +4 -6
- package/node/DateCalendar/PickersSlideTransition.js +12 -5
- package/node/DateField/DateField.js +5 -4
- package/node/DatePicker/DatePickerToolbar.js +0 -12
- package/node/DateTimeField/DateTimeField.js +5 -4
- package/node/DateTimePicker/DateTimePickerTabs.js +8 -6
- package/node/DateTimePicker/DateTimePickerToolbar.js +6 -15
- package/node/DayCalendarSkeleton/DayCalendarSkeleton.js +10 -19
- package/node/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +11 -34
- package/node/DigitalClock/DigitalClock.js +1 -0
- package/node/MonthCalendar/MonthCalendar.js +1 -0
- package/node/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
- package/node/PickersCalendarHeader/PickersCalendarHeader.js +8 -7
- package/node/PickersLayout/PickersLayout.js +22 -39
- package/node/PickersLayout/usePickerLayout.js +20 -17
- package/node/PickersTextField/PickersInputBase/PickersInputBase.js +10 -9
- package/node/PickersTextField/PickersTextField.js +2 -2
- package/node/TimeClock/Clock.js +1 -0
- package/node/TimeClock/TimeClock.js +1 -0
- package/node/TimeField/TimeField.js +5 -4
- package/node/TimePicker/TimePickerToolbar.js +6 -15
- package/node/YearCalendar/YearCalendar.js +1 -0
- package/node/hooks/useParsedFormat.js +1 -1
- package/node/index.js +1 -1
- package/node/internals/components/PickerProvider.js +3 -1
- package/node/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +11 -10
- package/node/internals/components/PickersToolbar.js +2 -4
- package/node/internals/hooks/useDesktopPicker/useDesktopPicker.js +1 -1
- package/node/internals/hooks/useField/useFieldState.js +1 -1
- package/node/internals/hooks/useField/useFieldV7TextField.js +2 -1
- package/node/internals/hooks/useFieldOwnerState.js +20 -0
- package/node/internals/hooks/useMobilePicker/useMobilePicker.js +1 -1
- package/node/internals/hooks/usePicker/usePicker.js +11 -19
- package/node/internals/hooks/usePicker/usePickerProvider.js +64 -5
- package/node/internals/hooks/usePicker/usePickerValue.js +18 -6
- package/node/internals/hooks/usePicker/usePickerViews.js +1 -0
- package/node/internals/hooks/useStaticPicker/useStaticPicker.js +1 -1
- package/node/internals/hooks/useValueWithTimezone.js +13 -1
- package/node/internals/index.js +7 -0
- package/node/internals/models/pickers.js +5 -0
- package/node/locales/nlNL.js +7 -7
- 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 +4 -4
- package/themeAugmentation/overrides.d.ts +1 -1
- package/themeAugmentation/props.d.ts +3 -2
- 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/internals/hooks/useIsLandscape.d.ts +0 -4
- package/internals/hooks/useIsLandscape.js +0 -35
- package/internals/hooks/usePicker/usePickerLayoutProps.d.ts +0 -33
- package/internals/hooks/usePicker/usePickerLayoutProps.js +0 -34
- package/internals/hooks/usePicker/usePickerOwnerState.d.ts +0 -10
- package/internals/hooks/usePicker/usePickerOwnerState.js +0 -16
- package/modern/internals/hooks/useIsLandscape.js +0 -35
- package/modern/internals/hooks/usePicker/usePickerLayoutProps.js +0 -34
- package/modern/internals/hooks/usePicker/usePickerOwnerState.js +0 -16
- package/node/internals/hooks/useIsLandscape.js +0 -43
- package/node/internals/hooks/usePicker/usePickerLayoutProps.js +0 -41
- package/node/internals/hooks/usePicker/usePickerOwnerState.js +0 -23
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { UsePickerValueParams, UsePickerValueProps, UsePickerValueBaseProps, UsePickerValueResponse } from './usePickerValue.types';
|
|
2
2
|
import { UsePickerViewsProps, UsePickerViewParams, UsePickerViewsResponse, UsePickerViewsBaseProps } from './usePickerViews';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { UsePickerProviderParameters, UsePickerProviderReturnValue } from './usePickerProvider';
|
|
3
|
+
import { PickerOwnerState } from '../../../models';
|
|
4
|
+
import { DateOrTimeViewWithMeridiem, PickerValidValue } from '../../models';
|
|
5
|
+
import { UsePickerProviderParameters, UsePickerProviderProps, UsePickerProviderReturnValue } from './usePickerProvider';
|
|
7
6
|
/**
|
|
8
7
|
* Props common to all picker headless implementations.
|
|
9
8
|
*/
|
|
10
|
-
export interface UsePickerBaseProps<TValue, TView extends DateOrTimeViewWithMeridiem, TError, TExternalProps extends UsePickerViewsProps<TValue, TView, any, any>, TAdditionalProps extends {}> extends UsePickerValueBaseProps<TValue, TError>, UsePickerViewsBaseProps<TValue, TView, TExternalProps, TAdditionalProps>,
|
|
9
|
+
export interface UsePickerBaseProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError, TExternalProps extends UsePickerViewsProps<TValue, TView, any, any>, TAdditionalProps extends {}> extends UsePickerValueBaseProps<TValue, TError>, UsePickerViewsBaseProps<TValue, TView, TExternalProps, TAdditionalProps>, UsePickerProviderProps {
|
|
11
10
|
}
|
|
12
|
-
export interface UsePickerProps<TValue, TView extends DateOrTimeViewWithMeridiem, TError, TExternalProps extends UsePickerViewsProps<TValue, TView, any, any>, TAdditionalProps extends {}> extends UsePickerValueProps<TValue, TError>, UsePickerViewsProps<TValue, TView, TExternalProps, TAdditionalProps>,
|
|
11
|
+
export interface UsePickerProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError, TExternalProps extends UsePickerViewsProps<TValue, TView, any, any>, TAdditionalProps extends {}> extends UsePickerValueProps<TValue, TError>, UsePickerViewsProps<TValue, TView, TExternalProps, TAdditionalProps>, UsePickerProviderProps {
|
|
13
12
|
}
|
|
14
|
-
export interface UsePickerParams<TValue
|
|
13
|
+
export interface UsePickerParams<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerProps<TValue, TView, any, any, any>, TAdditionalProps extends {}> extends Pick<UsePickerValueParams<TValue, TExternalProps>, 'valueManager' | 'valueType' | 'variant' | 'validator'>, Pick<UsePickerViewParams<TValue, TView, TExternalProps, TAdditionalProps>, 'additionalViewProps' | 'autoFocusView' | 'rendererInterceptor' | 'fieldRef'>, Pick<UsePickerProviderParameters<TValue>, 'localeText'> {
|
|
15
14
|
props: TExternalProps;
|
|
16
15
|
}
|
|
17
|
-
export interface UsePickerResponse<TValue
|
|
16
|
+
export interface UsePickerResponse<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError> extends Omit<UsePickerValueResponse<TValue, TError>, 'viewProps' | 'layoutProps'>, Omit<UsePickerViewsResponse<TView>, 'layoutProps' | 'views'> {
|
|
18
17
|
ownerState: PickerOwnerState;
|
|
19
18
|
providerProps: UsePickerProviderReturnValue;
|
|
19
|
+
layoutProps: UsePickerValueResponse<TValue, TError>['layoutProps'] & UsePickerViewsResponse<TView>['layoutProps'];
|
|
20
20
|
}
|
|
@@ -1,10 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { UsePickerValueResponse } from './usePickerValue.types';
|
|
1
|
+
import { PickerValueManager, UsePickerValueResponse } from './usePickerValue.types';
|
|
3
2
|
import { PickerProviderProps } from '../../components/PickerProvider';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import type { UsePickerProps } from './usePicker.types';
|
|
4
|
+
import { DateOrTimeViewWithMeridiem, FormProps, PickerOrientation, PickerValidValue, PickerVariant } from '../../models';
|
|
5
|
+
export declare const usePickerOrientation: (views: readonly DateOrTimeViewWithMeridiem[], customOrientation: PickerOrientation | undefined) => PickerOrientation;
|
|
6
|
+
export declare function usePickerProvider<TValue extends PickerValidValue>(parameters: UsePickerProviderParameters<TValue>): UsePickerProviderReturnValue;
|
|
7
|
+
export interface UsePickerProviderParameters<TValue extends PickerValidValue> extends Pick<PickerProviderProps, 'localeText'> {
|
|
8
|
+
props: UsePickerProps<TValue, any, any, any, any>;
|
|
9
|
+
pickerValueResponse: UsePickerValueResponse<TValue, any>;
|
|
10
|
+
valueManager: PickerValueManager<TValue, any>;
|
|
11
|
+
variant: PickerVariant;
|
|
12
|
+
views: readonly DateOrTimeViewWithMeridiem[];
|
|
7
13
|
}
|
|
8
14
|
export interface UsePickerProviderReturnValue extends Omit<PickerProviderProps, 'children'> {
|
|
9
15
|
}
|
|
10
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Props used to create the private context.
|
|
18
|
+
* Those props are exposed on all the pickers.
|
|
19
|
+
*/
|
|
20
|
+
export interface UsePickerProviderProps extends FormProps {
|
|
21
|
+
/**
|
|
22
|
+
* Force rendering in particular orientation.
|
|
23
|
+
*/
|
|
24
|
+
orientation?: PickerOrientation;
|
|
25
|
+
}
|
|
@@ -1,15 +1,66 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
3
|
+
import { useUtils } from "../useUtils.js";
|
|
4
|
+
import { arrayIncludes } from "../../utils/utils.js";
|
|
5
|
+
function getOrientation() {
|
|
6
|
+
if (typeof window === 'undefined') {
|
|
7
|
+
return 'portrait';
|
|
8
|
+
}
|
|
9
|
+
if (window.screen && window.screen.orientation && window.screen.orientation.angle) {
|
|
10
|
+
return Math.abs(window.screen.orientation.angle) === 90 ? 'landscape' : 'portrait';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Support IOS safari
|
|
14
|
+
if (window.orientation) {
|
|
15
|
+
return Math.abs(Number(window.orientation)) === 90 ? 'landscape' : 'portrait';
|
|
16
|
+
}
|
|
17
|
+
return 'portrait';
|
|
18
|
+
}
|
|
19
|
+
export const usePickerOrientation = (views, customOrientation) => {
|
|
20
|
+
const [orientation, setOrientation] = React.useState(getOrientation);
|
|
21
|
+
useEnhancedEffect(() => {
|
|
22
|
+
const eventHandler = () => {
|
|
23
|
+
setOrientation(getOrientation());
|
|
24
|
+
};
|
|
25
|
+
window.addEventListener('orientationchange', eventHandler);
|
|
26
|
+
return () => {
|
|
27
|
+
window.removeEventListener('orientationchange', eventHandler);
|
|
28
|
+
};
|
|
29
|
+
}, []);
|
|
30
|
+
if (arrayIncludes(views, ['hours', 'minutes', 'seconds'])) {
|
|
31
|
+
// could not display 13:34:44 in landscape mode
|
|
32
|
+
return 'portrait';
|
|
33
|
+
}
|
|
34
|
+
return customOrientation ?? orientation;
|
|
35
|
+
};
|
|
2
36
|
export function usePickerProvider(parameters) {
|
|
3
37
|
const {
|
|
38
|
+
props,
|
|
4
39
|
pickerValueResponse,
|
|
5
|
-
|
|
6
|
-
localeText
|
|
40
|
+
valueManager,
|
|
41
|
+
localeText,
|
|
42
|
+
variant,
|
|
43
|
+
views
|
|
7
44
|
} = parameters;
|
|
45
|
+
const utils = useUtils();
|
|
46
|
+
const orientation = usePickerOrientation(views, props.orientation);
|
|
47
|
+
const ownerState = React.useMemo(() => ({
|
|
48
|
+
isPickerValueEmpty: valueManager.areValuesEqual(utils, pickerValueResponse.viewProps.value, valueManager.emptyValue),
|
|
49
|
+
isPickerOpen: pickerValueResponse.open,
|
|
50
|
+
isPickerDisabled: props.disabled ?? false,
|
|
51
|
+
isPickerReadOnly: props.readOnly ?? false,
|
|
52
|
+
pickerOrientation: orientation,
|
|
53
|
+
pickerVariant: variant
|
|
54
|
+
}), [utils, valueManager, pickerValueResponse.viewProps.value, pickerValueResponse.open, orientation, variant, props.disabled, props.readOnly]);
|
|
8
55
|
const contextValue = React.useMemo(() => ({
|
|
9
56
|
onOpen: pickerValueResponse.actions.onOpen,
|
|
10
57
|
onClose: pickerValueResponse.actions.onClose,
|
|
11
|
-
open: pickerValueResponse.open
|
|
12
|
-
|
|
58
|
+
open: pickerValueResponse.open,
|
|
59
|
+
disabled: props.disabled ?? false,
|
|
60
|
+
readOnly: props.readOnly ?? false,
|
|
61
|
+
variant,
|
|
62
|
+
orientation
|
|
63
|
+
}), [pickerValueResponse.actions.onOpen, pickerValueResponse.actions.onClose, pickerValueResponse.open, variant, orientation, props.disabled, props.readOnly]);
|
|
13
64
|
const privateContextValue = React.useMemo(() => ({
|
|
14
65
|
ownerState
|
|
15
66
|
}), [ownerState]);
|
|
@@ -18,4 +69,9 @@ export function usePickerProvider(parameters) {
|
|
|
18
69
|
contextValue,
|
|
19
70
|
privateContextValue
|
|
20
71
|
};
|
|
21
|
-
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Props used to create the private context.
|
|
76
|
+
* Those props are exposed on all the pickers.
|
|
77
|
+
*/
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InferError } from '../../../models';
|
|
2
2
|
import { UsePickerValueProps, UsePickerValueParams, UsePickerValueResponse } from './usePickerValue.types';
|
|
3
|
+
import { PickerValidValue } from '../../models';
|
|
3
4
|
/**
|
|
4
5
|
* Manage the value lifecycle of all the pickers.
|
|
5
6
|
*/
|
|
6
|
-
export declare const usePickerValue: <TValue
|
|
7
|
+
export declare const usePickerValue: <TValue extends PickerValidValue, TExternalProps extends UsePickerValueProps<TValue, any>>({ props, valueManager, valueType, variant, validator, }: UsePickerValueParams<TValue, TExternalProps>) => UsePickerValueResponse<TValue, InferError<TExternalProps>>;
|
|
@@ -5,7 +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
8
|
/**
|
|
10
9
|
* Decide if the new value should be published
|
|
11
10
|
* The published value will be passed to `onChange` if defined.
|
|
@@ -113,7 +112,7 @@ export const usePickerValue = ({
|
|
|
113
112
|
props,
|
|
114
113
|
valueManager,
|
|
115
114
|
valueType,
|
|
116
|
-
|
|
115
|
+
variant,
|
|
117
116
|
validator
|
|
118
117
|
}) => {
|
|
119
118
|
const {
|
|
@@ -121,8 +120,9 @@ export const usePickerValue = ({
|
|
|
121
120
|
onChange,
|
|
122
121
|
value: inValueWithoutRenderTimezone,
|
|
123
122
|
defaultValue: inDefaultValue,
|
|
124
|
-
closeOnSelect =
|
|
125
|
-
timezone: timezoneProp
|
|
123
|
+
closeOnSelect = variant === 'desktop',
|
|
124
|
+
timezone: timezoneProp,
|
|
125
|
+
referenceDate
|
|
126
126
|
} = props;
|
|
127
127
|
const {
|
|
128
128
|
current: defaultValue
|
|
@@ -130,6 +130,7 @@ export const usePickerValue = ({
|
|
|
130
130
|
const {
|
|
131
131
|
current: isControlled
|
|
132
132
|
} = React.useRef(inValueWithoutRenderTimezone !== undefined);
|
|
133
|
+
const [previousTimezoneProp, setPreviousTimezoneProp] = React.useState(timezoneProp);
|
|
133
134
|
|
|
134
135
|
/* eslint-disable react-hooks/rules-of-hooks, react-hooks/exhaustive-deps */
|
|
135
136
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -160,6 +161,7 @@ export const usePickerValue = ({
|
|
|
160
161
|
timezone: timezoneProp,
|
|
161
162
|
value: inValueWithoutRenderTimezone,
|
|
162
163
|
defaultValue,
|
|
164
|
+
referenceDate,
|
|
163
165
|
onChange,
|
|
164
166
|
valueManager
|
|
165
167
|
});
|
|
@@ -176,10 +178,19 @@ export const usePickerValue = ({
|
|
|
176
178
|
draft: initialValue,
|
|
177
179
|
lastPublishedValue: initialValue,
|
|
178
180
|
lastCommittedValue: initialValue,
|
|
179
|
-
lastControlledValue:
|
|
181
|
+
lastControlledValue: inValueWithoutRenderTimezone,
|
|
180
182
|
hasBeenModifiedSinceMount: false
|
|
181
183
|
};
|
|
182
184
|
});
|
|
185
|
+
const timezoneFromDraftValue = valueManager.getTimezone(utils, dateState.draft);
|
|
186
|
+
if (previousTimezoneProp !== timezoneProp) {
|
|
187
|
+
setPreviousTimezoneProp(timezoneProp);
|
|
188
|
+
if (timezoneProp && timezoneFromDraftValue && timezoneProp !== timezoneFromDraftValue) {
|
|
189
|
+
setDateState(prev => _extends({}, prev, {
|
|
190
|
+
draft: valueManager.setTimezone(utils, timezoneProp, prev.draft)
|
|
191
|
+
}));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
183
194
|
const {
|
|
184
195
|
getValidationErrorForNewValue
|
|
185
196
|
} = useValidation({
|
|
@@ -229,10 +240,10 @@ export const usePickerValue = ({
|
|
|
229
240
|
setIsOpen(false);
|
|
230
241
|
}
|
|
231
242
|
});
|
|
232
|
-
if (
|
|
243
|
+
if (dateState.lastControlledValue !== inValueWithoutRenderTimezone) {
|
|
233
244
|
const isUpdateComingFromPicker = valueManager.areValuesEqual(utils, dateState.draft, inValueWithTimezoneToRender);
|
|
234
245
|
setDateState(prev => _extends({}, prev, {
|
|
235
|
-
lastControlledValue:
|
|
246
|
+
lastControlledValue: inValueWithoutRenderTimezone
|
|
236
247
|
}, isUpdateComingFromPicker ? {} : {
|
|
237
248
|
lastCommittedValue: inValueWithTimezoneToRender,
|
|
238
249
|
lastPublishedValue: inValueWithTimezoneToRender,
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { FieldChangeHandlerContext, UseFieldInternalProps } from '../useField';
|
|
2
2
|
import { Validator } from '../../../validation';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { PickerVariant } from '../../models/common';
|
|
4
|
+
import { TimezoneProps, MuiPickersAdapter, PickersTimezone, PickerChangeHandlerContext, PickerValidDate, OnErrorProps, InferError, PickerValueType } from '../../../models';
|
|
5
5
|
import { GetDefaultReferenceDateProps } from '../../utils/getDefaultReferenceDate';
|
|
6
6
|
import { PickerShortcutChangeImportance, PickersShortcutsItemContext } from '../../../PickersShortcuts';
|
|
7
|
-
|
|
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,15 +21,15 @@ 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
|
-
* @param {
|
|
27
|
+
* @param {PickerValueType} valueType The type of the value being edited.
|
|
27
28
|
* @returns {TValue} The value to set when clicking the "Today" button.
|
|
28
29
|
*/
|
|
29
|
-
getTodayValue: (utils: MuiPickersAdapter, timezone: PickersTimezone, valueType:
|
|
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,24 +106,24 @@ 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;
|
|
124
125
|
/**
|
|
125
|
-
* Last value passed
|
|
126
|
+
* Last value passed to `props.value`.
|
|
126
127
|
* Used to update the `draft` value whenever the `value` prop changes.
|
|
127
128
|
*/
|
|
128
129
|
lastControlledValue: TValue | undefined;
|
|
@@ -135,12 +136,12 @@ export interface UsePickerValueState<TValue> {
|
|
|
135
136
|
*/
|
|
136
137
|
hasBeenModifiedSinceMount: boolean;
|
|
137
138
|
}
|
|
138
|
-
export interface PickerValueUpdaterParams<TValue, TError> {
|
|
139
|
+
export interface PickerValueUpdaterParams<TValue extends PickerValidValue, TError> {
|
|
139
140
|
action: PickerValueUpdateAction<TValue, TError>;
|
|
140
141
|
dateState: UsePickerValueState<TValue>;
|
|
141
142
|
/**
|
|
142
143
|
* Check if the new draft value has changed compared to some given value.
|
|
143
|
-
* @template TValue
|
|
144
|
+
* @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.
|
|
144
145
|
* @param {TValue} comparisonValue The value to compare the new draft value with.
|
|
145
146
|
* @returns {boolean} `true` if the new draft value is equal to the comparison value.
|
|
146
147
|
*/
|
|
@@ -148,7 +149,7 @@ export interface PickerValueUpdaterParams<TValue, TError> {
|
|
|
148
149
|
isControlled: boolean;
|
|
149
150
|
closeOnSelect: boolean;
|
|
150
151
|
}
|
|
151
|
-
export type PickerValueUpdateAction<TValue, TError> = {
|
|
152
|
+
export type PickerValueUpdateAction<TValue extends PickerValidValue, TError> = {
|
|
152
153
|
name: 'setValueFromView';
|
|
153
154
|
value: TValue;
|
|
154
155
|
selectionState: PickerSelectionState;
|
|
@@ -169,7 +170,7 @@ export type PickerValueUpdateAction<TValue, TError> = {
|
|
|
169
170
|
/**
|
|
170
171
|
* Props used to handle the value that are common to all pickers.
|
|
171
172
|
*/
|
|
172
|
-
export interface UsePickerValueBaseProps<TValue, TError> extends OnErrorProps<TValue, TError> {
|
|
173
|
+
export interface UsePickerValueBaseProps<TValue extends PickerValidValue, TError> extends OnErrorProps<TValue, TError> {
|
|
173
174
|
/**
|
|
174
175
|
* The selected value.
|
|
175
176
|
* Used when the component is controlled.
|
|
@@ -225,13 +226,14 @@ export interface UsePickerValueNonStaticProps {
|
|
|
225
226
|
/**
|
|
226
227
|
* Props used to handle the value of the pickers.
|
|
227
228
|
*/
|
|
228
|
-
export interface UsePickerValueProps<TValue, TError> extends UsePickerValueBaseProps<TValue, TError>, UsePickerValueNonStaticProps, TimezoneProps {
|
|
229
|
+
export interface UsePickerValueProps<TValue extends PickerValidValue, TError> extends UsePickerValueBaseProps<TValue, TError>, UsePickerValueNonStaticProps, TimezoneProps {
|
|
230
|
+
referenceDate?: PickerValidDate;
|
|
229
231
|
}
|
|
230
|
-
export interface UsePickerValueParams<TValue, TExternalProps extends UsePickerValueProps<TValue, any>> {
|
|
232
|
+
export interface UsePickerValueParams<TValue extends PickerValidValue, TExternalProps extends UsePickerValueProps<TValue, any>> {
|
|
231
233
|
props: TExternalProps;
|
|
232
234
|
valueManager: PickerValueManager<TValue, InferError<TExternalProps>>;
|
|
233
|
-
valueType:
|
|
234
|
-
|
|
235
|
+
valueType: PickerValueType;
|
|
236
|
+
variant: PickerVariant;
|
|
235
237
|
validator: Validator<TValue, InferError<TExternalProps>, TExternalProps>;
|
|
236
238
|
}
|
|
237
239
|
export interface UsePickerValueActions {
|
|
@@ -243,11 +245,11 @@ export interface UsePickerValueActions {
|
|
|
243
245
|
onOpen: (event: React.UIEvent) => void;
|
|
244
246
|
onClose: (event?: React.UIEvent) => void;
|
|
245
247
|
}
|
|
246
|
-
export type UsePickerValueFieldResponse<TValue
|
|
248
|
+
export type UsePickerValueFieldResponse<TValue extends PickerValidValue, TError> = Required<Pick<UseFieldInternalProps<TValue, any, TError>, 'value' | 'onChange'>>;
|
|
247
249
|
/**
|
|
248
250
|
* Props passed to `usePickerViews`.
|
|
249
251
|
*/
|
|
250
|
-
export interface UsePickerValueViewsResponse<TValue> {
|
|
252
|
+
export interface UsePickerValueViewsResponse<TValue extends PickerValidValue> {
|
|
251
253
|
value: TValue;
|
|
252
254
|
onChange: (value: TValue, selectionState?: PickerSelectionState) => void;
|
|
253
255
|
open: boolean;
|
|
@@ -256,16 +258,16 @@ export interface UsePickerValueViewsResponse<TValue> {
|
|
|
256
258
|
/**
|
|
257
259
|
* Props passed to `usePickerLayoutProps`.
|
|
258
260
|
*/
|
|
259
|
-
export interface UsePickerValueLayoutResponse<TValue> extends UsePickerValueActions {
|
|
261
|
+
export interface UsePickerValueLayoutResponse<TValue extends PickerValidValue> extends UsePickerValueActions {
|
|
260
262
|
value: TValue;
|
|
261
263
|
onChange: (newValue: TValue) => void;
|
|
262
264
|
onSelectShortcut: (newValue: TValue, changeImportance: PickerShortcutChangeImportance, shortcut: PickersShortcutsItemContext) => void;
|
|
263
265
|
isValid: (value: TValue) => boolean;
|
|
264
266
|
}
|
|
265
|
-
export interface UsePickerValueResponse<TValue
|
|
267
|
+
export interface UsePickerValueResponse<TValue extends PickerValidValue, TError> {
|
|
266
268
|
open: boolean;
|
|
267
269
|
actions: UsePickerValueActions;
|
|
268
270
|
viewProps: UsePickerValueViewsResponse<TValue>;
|
|
269
|
-
fieldProps: UsePickerValueFieldResponse<TValue,
|
|
271
|
+
fieldProps: UsePickerValueFieldResponse<TValue, TError>;
|
|
270
272
|
layoutProps: UsePickerValueLayoutResponse<TValue>;
|
|
271
273
|
}
|
|
@@ -3,11 +3,11 @@ import { SxProps } from '@mui/system';
|
|
|
3
3
|
import { Theme } from '@mui/material/styles';
|
|
4
4
|
import { UseViewsOptions } from '../useViews';
|
|
5
5
|
import type { UsePickerValueViewsResponse } from './usePickerValue.types';
|
|
6
|
-
import { DateOrTimeViewWithMeridiem } from '../../models';
|
|
7
|
-
import { FieldRef,
|
|
6
|
+
import { DateOrTimeViewWithMeridiem, PickerRangeValue, PickerValidValue, PickerValue } from '../../models';
|
|
7
|
+
import { FieldRef, PickerValidDate, TimezoneProps } from '../../../models';
|
|
8
8
|
interface PickerViewsRendererBaseExternalProps<TView extends DateOrTimeViewWithMeridiem> extends Omit<UsePickerViewsProps<any, TView, any, any>, 'openTo' | 'viewRenderers'> {
|
|
9
9
|
}
|
|
10
|
-
export type PickerViewsRendererProps<TValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends PickerViewsRendererBaseExternalProps<TView>, TAdditionalProps extends {}> = Omit<TExternalProps, 'className' | 'sx'> & TAdditionalProps & UsePickerValueViewsResponse<TValue> & {
|
|
10
|
+
export type PickerViewsRendererProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends PickerViewsRendererBaseExternalProps<TView>, TAdditionalProps extends {}> = Omit<TExternalProps, 'className' | 'sx'> & TAdditionalProps & UsePickerValueViewsResponse<TValue> & {
|
|
11
11
|
view: TView;
|
|
12
12
|
views: readonly TView[];
|
|
13
13
|
focusedView: TView | null;
|
|
@@ -15,14 +15,14 @@ export type PickerViewsRendererProps<TValue, TView extends DateOrTimeViewWithMer
|
|
|
15
15
|
showViewSwitcher: boolean;
|
|
16
16
|
timeViewsCount: number;
|
|
17
17
|
};
|
|
18
|
-
export type PickerViewRenderer<TValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends PickerViewsRendererBaseExternalProps<TView>, TAdditionalProps extends {}> = (props: PickerViewsRendererProps<TValue, TView, TExternalProps, TAdditionalProps>) => React.ReactNode;
|
|
19
|
-
export type PickerViewRendererLookup<TValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends PickerViewsRendererBaseExternalProps<any>, TAdditionalProps extends {}> = {
|
|
18
|
+
export type PickerViewRenderer<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends PickerViewsRendererBaseExternalProps<TView>, TAdditionalProps extends {}> = (props: PickerViewsRendererProps<TValue, TView, TExternalProps, TAdditionalProps>) => React.ReactNode;
|
|
19
|
+
export type PickerViewRendererLookup<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends PickerViewsRendererBaseExternalProps<any>, TAdditionalProps extends {}> = {
|
|
20
20
|
[K in TView]: PickerViewRenderer<TValue, K, TExternalProps, TAdditionalProps> | null;
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
23
|
* Props used to handle the views that are common to all pickers.
|
|
24
24
|
*/
|
|
25
|
-
export interface UsePickerViewsBaseProps<TValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, any, any>, TAdditionalProps extends {}> extends Omit<UseViewsOptions<any, TView>, 'onChange' | 'onFocusedViewChange' | 'focusedView'>, TimezoneProps {
|
|
25
|
+
export interface UsePickerViewsBaseProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, any, any>, TAdditionalProps extends {}> extends Omit<UseViewsOptions<any, TView>, 'onChange' | 'onFocusedViewChange' | 'focusedView'>, TimezoneProps {
|
|
26
26
|
/**
|
|
27
27
|
* If `null`, the section will only have field editing.
|
|
28
28
|
* If `undefined`, internally defined view will be used.
|
|
@@ -52,16 +52,16 @@ export interface UsePickerViewsNonStaticProps {
|
|
|
52
52
|
/**
|
|
53
53
|
* Props used to handle the value of the pickers.
|
|
54
54
|
*/
|
|
55
|
-
export interface UsePickerViewsProps<TValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, any, any>, TAdditionalProps extends {}> extends UsePickerViewsBaseProps<TValue, TView, TExternalProps, TAdditionalProps> {
|
|
55
|
+
export interface UsePickerViewsProps<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, any, any>, TAdditionalProps extends {}> extends UsePickerViewsBaseProps<TValue, TView, TExternalProps, TAdditionalProps> {
|
|
56
56
|
className?: string;
|
|
57
57
|
sx?: SxProps<Theme>;
|
|
58
58
|
}
|
|
59
|
-
export interface UsePickerViewParams<TValue
|
|
59
|
+
export interface UsePickerViewParams<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, TExternalProps, TAdditionalProps>, TAdditionalProps extends {}> {
|
|
60
60
|
props: TExternalProps;
|
|
61
61
|
propsFromPickerValue: UsePickerValueViewsResponse<TValue>;
|
|
62
62
|
additionalViewProps: TAdditionalProps;
|
|
63
63
|
autoFocusView: boolean;
|
|
64
|
-
fieldRef: React.RefObject<FieldRef<
|
|
64
|
+
fieldRef: React.RefObject<FieldRef<PickerValue> | FieldRef<PickerRangeValue>> | undefined;
|
|
65
65
|
/**
|
|
66
66
|
* A function that intercepts the regular picker rendering.
|
|
67
67
|
* Can be used to consume the provided `viewRenderers` and render a custom component wrapping them.
|
|
@@ -77,6 +77,7 @@ export interface UsePickerViewsResponse<TView extends DateOrTimeViewWithMeridiem
|
|
|
77
77
|
* Indicates if the the picker has at least one view that should be rendered in UI.
|
|
78
78
|
*/
|
|
79
79
|
hasUIView: boolean;
|
|
80
|
+
views: readonly TView[];
|
|
80
81
|
renderCurrentView: () => React.ReactNode;
|
|
81
82
|
shouldRestoreFocus: () => boolean;
|
|
82
83
|
layoutProps: UsePickerViewsLayoutResponse<TView>;
|
|
@@ -92,5 +93,5 @@ export interface UsePickerViewsLayoutResponse<TView extends DateOrTimeViewWithMe
|
|
|
92
93
|
* - Handles the switch between UI views and field views
|
|
93
94
|
* - Handles the focus management when switching views
|
|
94
95
|
*/
|
|
95
|
-
export declare const usePickerViews: <TValue
|
|
96
|
+
export declare const usePickerViews: <TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerViewsProps<TValue, TView, any, any>, TAdditionalProps extends {}>({ props, propsFromPickerValue, additionalViewProps, autoFocusView, rendererInterceptor, fieldRef, }: UsePickerViewParams<TValue, TView, TExternalProps, TAdditionalProps>) => UsePickerViewsResponse<TView>;
|
|
96
97
|
export {};
|
|
@@ -48,7 +48,7 @@ export const useStaticPicker = _ref => {
|
|
|
48
48
|
fieldRef: undefined,
|
|
49
49
|
localeText,
|
|
50
50
|
additionalViewProps: {},
|
|
51
|
-
|
|
51
|
+
variant: displayStaticWrapperAs
|
|
52
52
|
}));
|
|
53
53
|
const Layout = slots?.layout ?? PickerStaticLayout;
|
|
54
54
|
const renderPicker = () => /*#__PURE__*/_jsx(PickerProvider, _extends({}, providerProps, {
|
|
@@ -3,11 +3,10 @@ import { ExportedPickersLayoutSlots, ExportedPickersLayoutSlotProps } from '../.
|
|
|
3
3
|
import { BasePickerProps } from '../../models/props/basePickerProps';
|
|
4
4
|
import { UsePickerParams } from '../usePicker';
|
|
5
5
|
import { UsePickerViewsProps } from '../usePicker/usePickerViews';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
export interface UseStaticPickerSlots<TView extends DateOrTimeViewWithMeridiem> extends ExportedPickersLayoutSlots<PickerValidDate | null, TView> {
|
|
6
|
+
import { DateOrTimeViewWithMeridiem, PickerValue } from '../../models';
|
|
7
|
+
export interface UseStaticPickerSlots<TView extends DateOrTimeViewWithMeridiem> extends ExportedPickersLayoutSlots<PickerValue, TView> {
|
|
9
8
|
}
|
|
10
|
-
export interface UseStaticPickerSlotProps<TView extends DateOrTimeViewWithMeridiem> extends ExportedPickersLayoutSlotProps<
|
|
9
|
+
export interface UseStaticPickerSlotProps<TView extends DateOrTimeViewWithMeridiem> extends ExportedPickersLayoutSlotProps<PickerValue, TView> {
|
|
11
10
|
}
|
|
12
11
|
export interface StaticOnlyPickerProps {
|
|
13
12
|
/**
|
|
@@ -27,7 +26,7 @@ export interface StaticOnlyPickerProps {
|
|
|
27
26
|
*/
|
|
28
27
|
onClose?: () => void;
|
|
29
28
|
}
|
|
30
|
-
export interface UseStaticPickerProps<TView extends DateOrTimeViewWithMeridiem, TError, TExternalProps extends UsePickerViewsProps<
|
|
29
|
+
export interface UseStaticPickerProps<TView extends DateOrTimeViewWithMeridiem, TError, TExternalProps extends UsePickerViewsProps<PickerValue, TView, any, any>> extends BasePickerProps<PickerValue, TView, TError, TExternalProps, {}>, StaticOnlyPickerProps {
|
|
31
30
|
/**
|
|
32
31
|
* Overridable component slots.
|
|
33
32
|
* @default {}
|
|
@@ -39,7 +38,7 @@ export interface UseStaticPickerProps<TView extends DateOrTimeViewWithMeridiem,
|
|
|
39
38
|
*/
|
|
40
39
|
slotProps?: UseStaticPickerSlotProps<TView>;
|
|
41
40
|
}
|
|
42
|
-
export interface UseStaticPickerParams<TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UseStaticPickerProps<TView, any, TExternalProps>> extends Pick<UsePickerParams<
|
|
41
|
+
export interface UseStaticPickerParams<TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UseStaticPickerProps<TView, any, TExternalProps>> extends Pick<UsePickerParams<PickerValue, TView, TExternalProps, {}>, 'valueManager' | 'valueType' | 'validator'> {
|
|
43
42
|
props: TExternalProps;
|
|
44
43
|
/**
|
|
45
44
|
* Ref to pass to the root element
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import type { PickerValueManager } from './usePicker';
|
|
2
|
-
import { PickersTimezone } from '../../models';
|
|
2
|
+
import { PickersTimezone, PickerValidDate } from '../../models';
|
|
3
|
+
import { PickerValidValue } from '../models';
|
|
3
4
|
/**
|
|
4
5
|
* Hooks making sure that:
|
|
5
6
|
* - The value returned by `onChange` always have the timezone of `props.value` or `props.defaultValue` if defined
|
|
6
7
|
* - The value rendered is always the one from `props.timezone` if defined
|
|
7
8
|
*/
|
|
8
|
-
export declare const useValueWithTimezone: <TValue, TChange extends (...params: any[]) => void>({ timezone: timezoneProp, value: valueProp, defaultValue, onChange, valueManager, }: {
|
|
9
|
-
timezone: PickersTimezone | undefined;
|
|
10
|
-
value: TValue | undefined;
|
|
11
|
-
defaultValue: TValue | undefined;
|
|
12
|
-
onChange: TChange | undefined;
|
|
13
|
-
valueManager: PickerValueManager<TValue, any>;
|
|
14
|
-
}) => {
|
|
9
|
+
export declare const useValueWithTimezone: <TValue extends PickerValidValue, TChange extends (...params: any[]) => void>({ timezone: timezoneProp, value: valueProp, defaultValue, referenceDate, onChange, valueManager, }: UseValueWithTimezoneParameters<TValue, TChange>) => {
|
|
15
10
|
value: TValue;
|
|
16
11
|
handleValueChange: TChange;
|
|
17
12
|
timezone: string;
|
|
@@ -19,15 +14,25 @@ export declare const useValueWithTimezone: <TValue, TChange extends (...params:
|
|
|
19
14
|
/**
|
|
20
15
|
* Wrapper around `useControlled` and `useValueWithTimezone`
|
|
21
16
|
*/
|
|
22
|
-
export declare const useControlledValueWithTimezone: <TValue, TChange extends (...params: any[]) => void>({ name, timezone: timezoneProp, value: valueProp, defaultValue, onChange: onChangeProp, valueManager, }: {
|
|
23
|
-
|
|
17
|
+
export declare const useControlledValueWithTimezone: <TValue extends PickerValidValue, TChange extends (...params: any[]) => void>({ name, timezone: timezoneProp, value: valueProp, defaultValue, referenceDate, onChange: onChangeProp, valueManager, }: UseControlledValueWithTimezoneParameters<TValue, TChange>) => {
|
|
18
|
+
value: TValue;
|
|
19
|
+
handleValueChange: TChange;
|
|
20
|
+
timezone: string;
|
|
21
|
+
};
|
|
22
|
+
interface UseValueWithTimezoneParameters<TValue extends PickerValidValue, TChange extends (...params: any[]) => void> {
|
|
24
23
|
timezone: PickersTimezone | undefined;
|
|
25
24
|
value: TValue | undefined;
|
|
26
25
|
defaultValue: TValue | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* The reference date as passed to `props.referenceDate`.
|
|
28
|
+
* It does not need to have its default value.
|
|
29
|
+
* This is only used to determine the timezone to use when `props.value` and `props.defaultValue` are not defined.
|
|
30
|
+
*/
|
|
31
|
+
referenceDate: PickerValidDate | undefined;
|
|
27
32
|
onChange: TChange | undefined;
|
|
28
33
|
valueManager: PickerValueManager<TValue, any>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
34
|
+
}
|
|
35
|
+
interface UseControlledValueWithTimezoneParameters<TValue extends PickerValidValue, TChange extends (...params: any[]) => void> extends UseValueWithTimezoneParameters<TValue, TChange> {
|
|
36
|
+
name: string;
|
|
37
|
+
}
|
|
38
|
+
export {};
|