@mui/x-date-pickers 8.0.0-alpha.13 → 8.0.0-alpha.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +131 -0
- package/DatePicker/shared.d.ts +1 -1
- package/DateTimePicker/DateTimePicker.types.d.ts +2 -2
- package/DateTimePicker/DateTimePickerToolbar.d.ts +1 -1
- package/DateTimePicker/DateTimePickerToolbar.js +1 -1
- package/DateTimePicker/shared.d.ts +18 -10
- package/DateTimePicker/shared.js +23 -2
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +2 -11
- package/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +4 -7
- package/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
- package/MobileDateTimePicker/MobileDateTimePicker.d.ts +1 -2
- package/MobileDateTimePicker/MobileDateTimePicker.js +61 -6
- package/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +1 -3
- package/PickersTextField/PickersTextField.js +3 -1
- package/StaticDateTimePicker/StaticDateTimePicker.js +60 -6
- package/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +1 -2
- package/TimePicker/shared.d.ts +1 -1
- package/esm/DatePicker/shared.d.ts +1 -1
- package/esm/DateTimePicker/DateTimePicker.types.d.ts +2 -2
- package/esm/DateTimePicker/DateTimePickerToolbar.d.ts +1 -1
- package/esm/DateTimePicker/DateTimePickerToolbar.js +1 -1
- package/esm/DateTimePicker/shared.d.ts +18 -10
- package/esm/DateTimePicker/shared.js +23 -2
- package/esm/DesktopDateTimePicker/DesktopDateTimePicker.js +3 -12
- package/esm/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +4 -7
- package/esm/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
- package/esm/MobileDateTimePicker/MobileDateTimePicker.d.ts +1 -2
- package/esm/MobileDateTimePicker/MobileDateTimePicker.js +62 -7
- package/esm/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +1 -3
- package/esm/PickersTextField/PickersTextField.js +3 -1
- package/esm/StaticDateTimePicker/StaticDateTimePicker.js +61 -7
- package/esm/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +1 -2
- package/esm/TimePicker/shared.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/internals/components/PickerFieldUI.js +6 -2
- package/esm/internals/components/PickerPopper/PickerPopper.js +3 -3
- package/esm/internals/components/PickerProvider.d.ts +137 -6
- package/esm/internals/components/PickerProvider.js +1 -1
- package/esm/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +4 -7
- package/esm/internals/hooks/useField/useField.js +7 -8
- package/esm/internals/hooks/useField/useField.types.d.ts +46 -43
- package/esm/internals/hooks/useField/useField.utils.js +4 -1
- package/esm/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
- package/esm/internals/hooks/useField/useFieldState.d.ts +2 -1
- package/esm/internals/hooks/useField/useFieldState.js +136 -83
- package/esm/internals/hooks/useField/useFieldV6TextField.js +1 -1
- package/esm/internals/hooks/useField/useFieldV7TextField.js +2 -1
- package/esm/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +4 -7
- package/esm/internals/hooks/useNullableFieldPrivateContext.d.ts +5 -2
- package/esm/internals/hooks/usePicker/hooks/useOrientation.d.ts +2 -0
- package/esm/internals/hooks/usePicker/hooks/useOrientation.js +34 -0
- package/esm/internals/hooks/usePicker/hooks/useValueAndOpenStates.d.ts +19 -0
- package/esm/internals/hooks/usePicker/hooks/useValueAndOpenStates.js +210 -0
- package/esm/internals/hooks/usePicker/index.d.ts +1 -3
- package/esm/internals/hooks/usePicker/usePicker.d.ts +5 -5
- package/esm/internals/hooks/usePicker/usePicker.js +276 -34
- package/esm/internals/hooks/usePicker/usePicker.types.d.ts +181 -9
- package/esm/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +3 -4
- package/esm/internals/hooks/useValueWithTimezone.d.ts +1 -1
- package/esm/internals/index.d.ts +3 -6
- package/esm/internals/models/manager.d.ts +108 -4
- package/esm/internals/models/props/basePickerProps.d.ts +2 -2
- package/esm/internals/models/props/time.d.ts +1 -1
- package/esm/internals/utils/date-time-utils.d.ts +2 -2
- package/esm/internals/utils/valueManagers.d.ts +1 -1
- package/esm/internals/utils/valueManagers.js +10 -18
- package/esm/managers/useDateManager.d.ts +3 -4
- package/esm/managers/useDateTimeManager.d.ts +3 -4
- package/esm/managers/useTimeManager.d.ts +3 -4
- package/esm/models/adapters.d.ts +2 -1
- package/esm/models/manager.d.ts +4 -5
- package/esm/validation/useValidation.d.ts +1 -1
- package/index.js +1 -1
- package/internals/components/PickerFieldUI.js +6 -2
- package/internals/components/PickerPopper/PickerPopper.js +3 -3
- package/internals/components/PickerProvider.d.ts +137 -6
- package/internals/components/PickerProvider.js +1 -1
- package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +4 -7
- package/internals/hooks/useField/useField.js +7 -8
- package/internals/hooks/useField/useField.types.d.ts +46 -43
- package/internals/hooks/useField/useField.utils.js +4 -1
- package/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
- package/internals/hooks/useField/useFieldState.d.ts +2 -1
- package/internals/hooks/useField/useFieldState.js +135 -82
- package/internals/hooks/useField/useFieldV6TextField.js +1 -1
- package/internals/hooks/useField/useFieldV7TextField.js +2 -1
- package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +4 -7
- package/internals/hooks/useNullableFieldPrivateContext.d.ts +5 -2
- package/internals/hooks/usePicker/hooks/useOrientation.d.ts +2 -0
- package/internals/hooks/usePicker/hooks/useOrientation.js +42 -0
- package/internals/hooks/usePicker/hooks/useValueAndOpenStates.d.ts +19 -0
- package/internals/hooks/usePicker/{usePickerValue.js → hooks/useValueAndOpenStates.js} +97 -114
- package/internals/hooks/usePicker/index.d.ts +1 -3
- package/internals/hooks/usePicker/usePicker.d.ts +5 -5
- package/internals/hooks/usePicker/usePicker.js +278 -34
- package/internals/hooks/usePicker/usePicker.types.d.ts +181 -9
- package/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +3 -4
- package/internals/hooks/useValueWithTimezone.d.ts +1 -1
- package/internals/index.d.ts +3 -6
- package/internals/models/manager.d.ts +108 -4
- package/internals/models/props/basePickerProps.d.ts +2 -2
- package/internals/models/props/time.d.ts +1 -1
- package/internals/utils/date-time-utils.d.ts +2 -2
- package/internals/utils/valueManagers.d.ts +1 -1
- package/internals/utils/valueManagers.js +10 -18
- package/managers/useDateManager.d.ts +3 -4
- package/managers/useDateTimeManager.d.ts +3 -4
- package/managers/useTimeManager.d.ts +3 -4
- package/models/adapters.d.ts +2 -1
- package/models/manager.d.ts +4 -5
- package/modern/DatePicker/shared.d.ts +1 -1
- package/modern/DateTimePicker/DateTimePicker.types.d.ts +2 -2
- package/modern/DateTimePicker/DateTimePickerToolbar.d.ts +1 -1
- package/modern/DateTimePicker/DateTimePickerToolbar.js +1 -1
- package/modern/DateTimePicker/shared.d.ts +18 -10
- package/modern/DateTimePicker/shared.js +23 -2
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +3 -12
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +4 -7
- package/modern/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
- package/modern/MobileDateTimePicker/MobileDateTimePicker.d.ts +1 -2
- package/modern/MobileDateTimePicker/MobileDateTimePicker.js +62 -7
- package/modern/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +1 -3
- package/modern/PickersTextField/PickersTextField.js +3 -1
- package/modern/StaticDateTimePicker/StaticDateTimePicker.js +61 -7
- package/modern/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +1 -2
- package/modern/TimePicker/shared.d.ts +1 -1
- package/modern/index.js +1 -1
- package/modern/internals/components/PickerFieldUI.js +6 -2
- package/modern/internals/components/PickerPopper/PickerPopper.js +3 -3
- package/modern/internals/components/PickerProvider.d.ts +137 -6
- package/modern/internals/components/PickerProvider.js +1 -1
- package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +4 -7
- package/modern/internals/hooks/useField/useField.js +7 -8
- package/modern/internals/hooks/useField/useField.types.d.ts +46 -43
- package/modern/internals/hooks/useField/useField.utils.js +4 -1
- package/modern/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
- package/modern/internals/hooks/useField/useFieldState.d.ts +2 -1
- package/modern/internals/hooks/useField/useFieldState.js +136 -83
- package/modern/internals/hooks/useField/useFieldV6TextField.js +1 -1
- package/modern/internals/hooks/useField/useFieldV7TextField.js +2 -1
- package/modern/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +4 -7
- package/modern/internals/hooks/useNullableFieldPrivateContext.d.ts +5 -2
- package/modern/internals/hooks/usePicker/hooks/useOrientation.d.ts +2 -0
- package/modern/internals/hooks/usePicker/hooks/useOrientation.js +34 -0
- package/modern/internals/hooks/usePicker/hooks/useValueAndOpenStates.d.ts +19 -0
- package/modern/internals/hooks/usePicker/hooks/useValueAndOpenStates.js +210 -0
- package/modern/internals/hooks/usePicker/index.d.ts +1 -3
- package/modern/internals/hooks/usePicker/usePicker.d.ts +5 -5
- package/modern/internals/hooks/usePicker/usePicker.js +276 -34
- package/modern/internals/hooks/usePicker/usePicker.types.d.ts +181 -9
- package/modern/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +3 -4
- package/modern/internals/hooks/useValueWithTimezone.d.ts +1 -1
- package/modern/internals/index.d.ts +3 -6
- package/modern/internals/models/manager.d.ts +108 -4
- package/modern/internals/models/props/basePickerProps.d.ts +2 -2
- package/modern/internals/models/props/time.d.ts +1 -1
- package/modern/internals/utils/date-time-utils.d.ts +2 -2
- package/modern/internals/utils/valueManagers.d.ts +1 -1
- package/modern/internals/utils/valueManagers.js +10 -18
- package/modern/managers/useDateManager.d.ts +3 -4
- package/modern/managers/useDateTimeManager.d.ts +3 -4
- package/modern/managers/useTimeManager.d.ts +3 -4
- package/modern/models/adapters.d.ts +2 -1
- package/modern/models/manager.d.ts +4 -5
- package/modern/validation/useValidation.d.ts +1 -1
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/validation/useValidation.d.ts +1 -1
- package/esm/internals/hooks/useOpenState.d.ts +0 -14
- package/esm/internals/hooks/useOpenState.js +0 -37
- package/esm/internals/hooks/usePicker/usePickerProvider.d.ts +0 -65
- package/esm/internals/hooks/usePicker/usePickerProvider.js +0 -125
- package/esm/internals/hooks/usePicker/usePickerValue.d.ts +0 -12
- package/esm/internals/hooks/usePicker/usePickerValue.js +0 -226
- package/esm/internals/hooks/usePicker/usePickerValue.types.d.ts +0 -327
- package/esm/internals/hooks/usePicker/usePickerValue.types.js +0 -1
- package/esm/internals/hooks/usePicker/usePickerViews.d.ts +0 -137
- package/esm/internals/hooks/usePicker/usePickerViews.js +0 -188
- package/internals/hooks/useOpenState.d.ts +0 -14
- package/internals/hooks/useOpenState.js +0 -46
- package/internals/hooks/usePicker/usePickerProvider.d.ts +0 -65
- package/internals/hooks/usePicker/usePickerProvider.js +0 -135
- package/internals/hooks/usePicker/usePickerValue.d.ts +0 -12
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +0 -327
- package/internals/hooks/usePicker/usePickerValue.types.js +0 -5
- package/internals/hooks/usePicker/usePickerViews.d.ts +0 -137
- package/internals/hooks/usePicker/usePickerViews.js +0 -195
- package/modern/internals/hooks/useOpenState.d.ts +0 -14
- package/modern/internals/hooks/useOpenState.js +0 -37
- package/modern/internals/hooks/usePicker/usePickerProvider.d.ts +0 -65
- package/modern/internals/hooks/usePicker/usePickerProvider.js +0 -125
- package/modern/internals/hooks/usePicker/usePickerValue.d.ts +0 -12
- package/modern/internals/hooks/usePicker/usePickerValue.js +0 -226
- package/modern/internals/hooks/usePicker/usePickerValue.types.d.ts +0 -327
- package/modern/internals/hooks/usePicker/usePickerValue.types.js +0 -1
- package/modern/internals/hooks/usePicker/usePickerViews.d.ts +0 -137
- package/modern/internals/hooks/usePicker/usePickerViews.js +0 -188
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MuiPickersAdapterContextValue } from "../LocalizationProvider/LocalizationProvider.js";
|
|
2
2
|
import { OnErrorProps, PickersTimezone } from "../models/index.js";
|
|
3
|
-
import type { PickerValueManager } from '../internals/
|
|
3
|
+
import type { PickerValueManager } from '../internals/models';
|
|
4
4
|
import { PickerValidValue } from "../internals/models/index.js";
|
|
5
5
|
export type Validator<TValue extends PickerValidValue, TError, TValidationProps> = {
|
|
6
6
|
(params: {
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
export interface OpenStateProps {
|
|
3
|
-
open?: boolean;
|
|
4
|
-
onOpen?: () => void;
|
|
5
|
-
onClose?: () => void;
|
|
6
|
-
}
|
|
7
|
-
export declare const useOpenState: ({
|
|
8
|
-
open,
|
|
9
|
-
onOpen,
|
|
10
|
-
onClose
|
|
11
|
-
}: OpenStateProps) => {
|
|
12
|
-
open: boolean;
|
|
13
|
-
setOpen: (action: React.SetStateAction<boolean>) => void;
|
|
14
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import useEventCallback from '@mui/utils/useEventCallback';
|
|
3
|
-
export const useOpenState = ({
|
|
4
|
-
open,
|
|
5
|
-
onOpen,
|
|
6
|
-
onClose
|
|
7
|
-
}) => {
|
|
8
|
-
const isControllingOpenProp = React.useRef(typeof open === 'boolean').current;
|
|
9
|
-
const [openState, setOpenState] = React.useState(false);
|
|
10
|
-
|
|
11
|
-
// It is required to update inner state in useEffect in order to avoid situation when
|
|
12
|
-
// Our component is not mounted yet, but `open` state is set to `true` (for example initially opened)
|
|
13
|
-
React.useEffect(() => {
|
|
14
|
-
if (isControllingOpenProp) {
|
|
15
|
-
if (typeof open !== 'boolean') {
|
|
16
|
-
throw new Error('You must not mix controlling and uncontrolled mode for `open` prop');
|
|
17
|
-
}
|
|
18
|
-
setOpenState(open);
|
|
19
|
-
}
|
|
20
|
-
}, [isControllingOpenProp, open]);
|
|
21
|
-
const setOpen = useEventCallback(action => {
|
|
22
|
-
const newOpen = typeof action === 'function' ? action(openState) : action;
|
|
23
|
-
if (!isControllingOpenProp) {
|
|
24
|
-
setOpenState(newOpen);
|
|
25
|
-
}
|
|
26
|
-
if (newOpen && onOpen) {
|
|
27
|
-
onOpen();
|
|
28
|
-
}
|
|
29
|
-
if (!newOpen && onClose) {
|
|
30
|
-
onClose();
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
return {
|
|
34
|
-
open: openState,
|
|
35
|
-
setOpen
|
|
36
|
-
};
|
|
37
|
-
};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { PickerValueManager, UsePickerValueProviderParams } from "./usePickerValue.types.js";
|
|
3
|
-
import { PickerProviderProps } from "../../components/PickerProvider.js";
|
|
4
|
-
import type { UsePickerProps } from './usePicker.types';
|
|
5
|
-
import { DateOrTimeViewWithMeridiem, FormProps, PickerOrientation, PickerValidValue, PickerVariant } from "../../models/index.js";
|
|
6
|
-
import { UsePickerViewsProviderParams } from "./usePickerViews.js";
|
|
7
|
-
import type { UseFieldInternalProps } from '../useField';
|
|
8
|
-
import { ExportedBaseToolbarProps } from "../../models/props/toolbar.js";
|
|
9
|
-
export declare const usePickerOrientation: (views: readonly DateOrTimeViewWithMeridiem[], customOrientation: PickerOrientation | undefined) => PickerOrientation;
|
|
10
|
-
export declare function usePickerProvider<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError>(parameters: UsePickerProviderParameters<TValue, TView, TError>): UsePickerProviderReturnValue<TValue>;
|
|
11
|
-
export interface UsePickerProviderParameters<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError> extends Pick<PickerProviderProps<TValue>, 'localeText'> {
|
|
12
|
-
ref: React.ForwardedRef<HTMLDivElement> | undefined;
|
|
13
|
-
props: UsePickerProps<TValue, any, any, any> & UsePickerProviderNonStaticProps & {
|
|
14
|
-
slotProps?: {
|
|
15
|
-
toolbar?: ExportedBaseToolbarProps;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
valueManager: PickerValueManager<TValue, any>;
|
|
19
|
-
variant: PickerVariant;
|
|
20
|
-
paramsFromUsePickerValue: UsePickerValueProviderParams<TValue, TError>;
|
|
21
|
-
paramsFromUsePickerViews: UsePickerViewsProviderParams<TView>;
|
|
22
|
-
}
|
|
23
|
-
export interface UsePickerProviderReturnValue<TValue extends PickerValidValue> extends Omit<PickerProviderProps<TValue>, 'children'> {}
|
|
24
|
-
/**
|
|
25
|
-
* Props used to create the picker's contexts.
|
|
26
|
-
* Those props are exposed on all the pickers.
|
|
27
|
-
*/
|
|
28
|
-
export interface UsePickerProviderProps extends FormProps {
|
|
29
|
-
/**
|
|
30
|
-
* Force rendering in particular orientation.
|
|
31
|
-
*/
|
|
32
|
-
orientation?: PickerOrientation;
|
|
33
|
-
/**
|
|
34
|
-
* If `true`, disable heavy animations.
|
|
35
|
-
* @default `@media(prefers-reduced-motion: reduce)` || `navigator.userAgent` matches Android <10 or iOS <13
|
|
36
|
-
*/
|
|
37
|
-
reduceAnimations?: boolean;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Props used to create the picker's contexts and that are not available on static pickers.
|
|
41
|
-
*/
|
|
42
|
-
export interface UsePickerProviderNonStaticProps extends Pick<UseFieldInternalProps<any, any, any>, 'formatDensity' | 'enableAccessibleFieldDOMStructure' | 'selectedSections' | 'onSelectedSectionsChange'> {
|
|
43
|
-
/**
|
|
44
|
-
* Format of the date when rendered in the input(s).
|
|
45
|
-
* Defaults to localized format based on the used `views`.
|
|
46
|
-
*/
|
|
47
|
-
format?: string;
|
|
48
|
-
/**
|
|
49
|
-
* If `true`, the open picker button will not be rendered (renders only the field).
|
|
50
|
-
* @default false
|
|
51
|
-
*/
|
|
52
|
-
disableOpenPicker?: boolean;
|
|
53
|
-
/**
|
|
54
|
-
* The label content.
|
|
55
|
-
*/
|
|
56
|
-
label?: React.ReactNode;
|
|
57
|
-
/**
|
|
58
|
-
* Pass a ref to the `input` element.
|
|
59
|
-
*/
|
|
60
|
-
inputRef?: React.Ref<HTMLInputElement>;
|
|
61
|
-
/**
|
|
62
|
-
* Name attribute used by the `input` element in the Field.
|
|
63
|
-
*/
|
|
64
|
-
name?: string;
|
|
65
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
4
|
-
import useForkRef from '@mui/utils/useForkRef';
|
|
5
|
-
import useId from '@mui/utils/useId';
|
|
6
|
-
import { useUtils } from "../useUtils.js";
|
|
7
|
-
import { arrayIncludes } from "../../utils/utils.js";
|
|
8
|
-
import { useReduceAnimations } from "../useReduceAnimations.js";
|
|
9
|
-
function getOrientation() {
|
|
10
|
-
if (typeof window === 'undefined') {
|
|
11
|
-
return 'portrait';
|
|
12
|
-
}
|
|
13
|
-
if (window.screen && window.screen.orientation && window.screen.orientation.angle) {
|
|
14
|
-
return Math.abs(window.screen.orientation.angle) === 90 ? 'landscape' : 'portrait';
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Support IOS safari
|
|
18
|
-
if (window.orientation) {
|
|
19
|
-
return Math.abs(Number(window.orientation)) === 90 ? 'landscape' : 'portrait';
|
|
20
|
-
}
|
|
21
|
-
return 'portrait';
|
|
22
|
-
}
|
|
23
|
-
export const usePickerOrientation = (views, customOrientation) => {
|
|
24
|
-
const [orientation, setOrientation] = React.useState(getOrientation);
|
|
25
|
-
useEnhancedEffect(() => {
|
|
26
|
-
const eventHandler = () => {
|
|
27
|
-
setOrientation(getOrientation());
|
|
28
|
-
};
|
|
29
|
-
window.addEventListener('orientationchange', eventHandler);
|
|
30
|
-
return () => {
|
|
31
|
-
window.removeEventListener('orientationchange', eventHandler);
|
|
32
|
-
};
|
|
33
|
-
}, []);
|
|
34
|
-
if (arrayIncludes(views, ['hours', 'minutes', 'seconds'])) {
|
|
35
|
-
// could not display 13:34:44 in landscape mode
|
|
36
|
-
return 'portrait';
|
|
37
|
-
}
|
|
38
|
-
return customOrientation ?? orientation;
|
|
39
|
-
};
|
|
40
|
-
export function usePickerProvider(parameters) {
|
|
41
|
-
const {
|
|
42
|
-
ref,
|
|
43
|
-
props,
|
|
44
|
-
valueManager,
|
|
45
|
-
localeText,
|
|
46
|
-
variant,
|
|
47
|
-
paramsFromUsePickerValue,
|
|
48
|
-
paramsFromUsePickerViews
|
|
49
|
-
} = parameters;
|
|
50
|
-
const utils = useUtils();
|
|
51
|
-
const orientation = usePickerOrientation(paramsFromUsePickerViews.views, props.orientation);
|
|
52
|
-
const reduceAnimations = useReduceAnimations(props.reduceAnimations);
|
|
53
|
-
const triggerRef = React.useRef(null);
|
|
54
|
-
const popupRef = React.useRef(null);
|
|
55
|
-
const rootRefObject = React.useRef(null);
|
|
56
|
-
const rootRef = useForkRef(ref, rootRefObject);
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* TODO: Improve how we generate the aria-label and aria-labelledby attributes.
|
|
60
|
-
*/
|
|
61
|
-
const labelId = useId();
|
|
62
|
-
const ownerState = React.useMemo(() => ({
|
|
63
|
-
isPickerValueEmpty: valueManager.areValuesEqual(utils, paramsFromUsePickerValue.value, valueManager.emptyValue),
|
|
64
|
-
isPickerOpen: paramsFromUsePickerValue.contextValue.open,
|
|
65
|
-
isPickerDisabled: props.disabled ?? false,
|
|
66
|
-
isPickerReadOnly: props.readOnly ?? false,
|
|
67
|
-
pickerOrientation: orientation,
|
|
68
|
-
pickerVariant: variant
|
|
69
|
-
}), [utils, valueManager, paramsFromUsePickerValue.value, paramsFromUsePickerValue.contextValue.open, orientation, variant, props.disabled, props.readOnly]);
|
|
70
|
-
const triggerStatus = React.useMemo(() => {
|
|
71
|
-
if (props.disableOpenPicker || !paramsFromUsePickerViews.hasUIView) {
|
|
72
|
-
return 'hidden';
|
|
73
|
-
}
|
|
74
|
-
if (props.disabled || props.readOnly) {
|
|
75
|
-
return 'disabled';
|
|
76
|
-
}
|
|
77
|
-
return 'enabled';
|
|
78
|
-
}, [props.disableOpenPicker, paramsFromUsePickerViews.hasUIView, props.disabled, props.readOnly]);
|
|
79
|
-
const contextValue = React.useMemo(() => _extends({}, paramsFromUsePickerValue.contextValue, paramsFromUsePickerViews.contextValue, {
|
|
80
|
-
disabled: props.disabled ?? false,
|
|
81
|
-
readOnly: props.readOnly ?? false,
|
|
82
|
-
autoFocus: props.autoFocus ?? false,
|
|
83
|
-
variant,
|
|
84
|
-
orientation,
|
|
85
|
-
popupRef,
|
|
86
|
-
reduceAnimations,
|
|
87
|
-
triggerRef,
|
|
88
|
-
triggerStatus,
|
|
89
|
-
fieldFormat: props.format ?? '',
|
|
90
|
-
name: props.name,
|
|
91
|
-
label: props.label,
|
|
92
|
-
rootSx: props.sx,
|
|
93
|
-
rootRef,
|
|
94
|
-
rootClassName: props.className
|
|
95
|
-
}), [paramsFromUsePickerValue.contextValue, paramsFromUsePickerViews.contextValue, rootRef, variant, orientation, reduceAnimations, props.disabled, props.readOnly, props.autoFocus, props.format, props.className, props.name, props.label, props.sx, triggerRef, triggerStatus]);
|
|
96
|
-
const privateContextValue = React.useMemo(() => _extends({}, paramsFromUsePickerValue.privateContextValue, paramsFromUsePickerViews.privateContextValue, {
|
|
97
|
-
ownerState,
|
|
98
|
-
rootRefObject,
|
|
99
|
-
labelId
|
|
100
|
-
}), [paramsFromUsePickerValue.privateContextValue, paramsFromUsePickerViews.privateContextValue, ownerState, labelId]);
|
|
101
|
-
const actionsContextValue = React.useMemo(() => _extends({}, paramsFromUsePickerValue.actionsContextValue, paramsFromUsePickerViews.actionsContextValue), [paramsFromUsePickerValue.actionsContextValue, paramsFromUsePickerViews.actionsContextValue]);
|
|
102
|
-
const fieldPrivateContextValue = React.useMemo(() => _extends({}, paramsFromUsePickerViews.fieldPrivateContextValue, {
|
|
103
|
-
formatDensity: props.formatDensity,
|
|
104
|
-
enableAccessibleFieldDOMStructure: props.enableAccessibleFieldDOMStructure,
|
|
105
|
-
selectedSections: props.selectedSections,
|
|
106
|
-
onSelectedSectionsChange: props.onSelectedSectionsChange
|
|
107
|
-
}), [paramsFromUsePickerViews.fieldPrivateContextValue, props.formatDensity, props.enableAccessibleFieldDOMStructure, props.selectedSections, props.onSelectedSectionsChange]);
|
|
108
|
-
return {
|
|
109
|
-
localeText,
|
|
110
|
-
contextValue,
|
|
111
|
-
privateContextValue,
|
|
112
|
-
actionsContextValue,
|
|
113
|
-
fieldPrivateContextValue,
|
|
114
|
-
isValidContextValue: paramsFromUsePickerValue.isValidContextValue
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Props used to create the picker's contexts.
|
|
120
|
-
* Those props are exposed on all the pickers.
|
|
121
|
-
*/
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Props used to create the picker's contexts and that are not available on static pickers.
|
|
125
|
-
*/
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { InferError } from "../../../models/index.js";
|
|
2
|
-
import { UsePickerValueProps, UsePickerValueParams, UsePickerValueResponse } from "./usePickerValue.types.js";
|
|
3
|
-
import { PickerValidValue } from "../../models/index.js";
|
|
4
|
-
/**
|
|
5
|
-
* Manage the value lifecycle of all the pickers.
|
|
6
|
-
*/
|
|
7
|
-
export declare const usePickerValue: <TValue extends PickerValidValue, TExternalProps extends UsePickerValueProps<TValue, any>>({
|
|
8
|
-
props,
|
|
9
|
-
valueManager,
|
|
10
|
-
valueType,
|
|
11
|
-
validator
|
|
12
|
-
}: UsePickerValueParams<TValue, TExternalProps>) => UsePickerValueResponse<TValue, InferError<TExternalProps>>;
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import useEventCallback from '@mui/utils/useEventCallback';
|
|
4
|
-
import { useOpenState } from "../useOpenState.js";
|
|
5
|
-
import { useLocalizationContext, useUtils } from "../useUtils.js";
|
|
6
|
-
import { useValidation } from "../../../validation/index.js";
|
|
7
|
-
import { useValueWithTimezone } from "../useValueWithTimezone.js";
|
|
8
|
-
/**
|
|
9
|
-
* Manage the value lifecycle of all the pickers.
|
|
10
|
-
*/
|
|
11
|
-
export const usePickerValue = ({
|
|
12
|
-
props,
|
|
13
|
-
valueManager,
|
|
14
|
-
valueType,
|
|
15
|
-
validator
|
|
16
|
-
}) => {
|
|
17
|
-
const {
|
|
18
|
-
onAccept,
|
|
19
|
-
onChange,
|
|
20
|
-
value: inValueWithoutRenderTimezone,
|
|
21
|
-
defaultValue: inDefaultValue,
|
|
22
|
-
closeOnSelect = false,
|
|
23
|
-
timezone: timezoneProp,
|
|
24
|
-
referenceDate
|
|
25
|
-
} = props;
|
|
26
|
-
const {
|
|
27
|
-
current: defaultValue
|
|
28
|
-
} = React.useRef(inDefaultValue);
|
|
29
|
-
const {
|
|
30
|
-
current: isControlled
|
|
31
|
-
} = React.useRef(inValueWithoutRenderTimezone !== undefined);
|
|
32
|
-
const [previousTimezoneProp, setPreviousTimezoneProp] = React.useState(timezoneProp);
|
|
33
|
-
|
|
34
|
-
/* eslint-disable react-hooks/rules-of-hooks, react-hooks/exhaustive-deps */
|
|
35
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
36
|
-
React.useEffect(() => {
|
|
37
|
-
if (isControlled !== (inValueWithoutRenderTimezone !== undefined)) {
|
|
38
|
-
console.error([`MUI X: A component is changing the ${isControlled ? '' : 'un'}controlled value of a picker to be ${isControlled ? 'un' : ''}controlled.`, 'Elements should not switch from uncontrolled to controlled (or vice versa).', `Decide between using a controlled or uncontrolled value` + 'for the lifetime of the component.', "The nature of the state is determined during the first render. It's considered controlled if the value is not `undefined`.", 'More info: https://fb.me/react-controlled-components'].join('\n'));
|
|
39
|
-
}
|
|
40
|
-
}, [inValueWithoutRenderTimezone]);
|
|
41
|
-
React.useEffect(() => {
|
|
42
|
-
if (!isControlled && defaultValue !== inDefaultValue) {
|
|
43
|
-
console.error([`MUI X: A component is changing the defaultValue of an uncontrolled picker after being initialized. ` + `To suppress this warning opt to use a controlled value.`].join('\n'));
|
|
44
|
-
}
|
|
45
|
-
}, [JSON.stringify(defaultValue)]);
|
|
46
|
-
}
|
|
47
|
-
/* eslint-enable react-hooks/rules-of-hooks, react-hooks/exhaustive-deps */
|
|
48
|
-
|
|
49
|
-
const utils = useUtils();
|
|
50
|
-
const adapter = useLocalizationContext();
|
|
51
|
-
const {
|
|
52
|
-
open,
|
|
53
|
-
setOpen
|
|
54
|
-
} = useOpenState(props);
|
|
55
|
-
const {
|
|
56
|
-
timezone,
|
|
57
|
-
value: inValueWithTimezoneToRender,
|
|
58
|
-
handleValueChange
|
|
59
|
-
} = useValueWithTimezone({
|
|
60
|
-
timezone: timezoneProp,
|
|
61
|
-
value: inValueWithoutRenderTimezone,
|
|
62
|
-
defaultValue,
|
|
63
|
-
referenceDate,
|
|
64
|
-
onChange,
|
|
65
|
-
valueManager
|
|
66
|
-
});
|
|
67
|
-
const [dateState, setDateState] = React.useState(() => {
|
|
68
|
-
let initialValue;
|
|
69
|
-
if (inValueWithTimezoneToRender !== undefined) {
|
|
70
|
-
initialValue = inValueWithTimezoneToRender;
|
|
71
|
-
} else if (defaultValue !== undefined) {
|
|
72
|
-
initialValue = defaultValue;
|
|
73
|
-
} else {
|
|
74
|
-
initialValue = valueManager.emptyValue;
|
|
75
|
-
}
|
|
76
|
-
return {
|
|
77
|
-
draft: initialValue,
|
|
78
|
-
lastPublishedValue: initialValue,
|
|
79
|
-
lastCommittedValue: initialValue,
|
|
80
|
-
lastControlledValue: inValueWithoutRenderTimezone,
|
|
81
|
-
hasBeenModifiedSinceMount: false
|
|
82
|
-
};
|
|
83
|
-
});
|
|
84
|
-
const timezoneFromDraftValue = valueManager.getTimezone(utils, dateState.draft);
|
|
85
|
-
if (previousTimezoneProp !== timezoneProp) {
|
|
86
|
-
setPreviousTimezoneProp(timezoneProp);
|
|
87
|
-
if (timezoneProp && timezoneFromDraftValue && timezoneProp !== timezoneFromDraftValue) {
|
|
88
|
-
setDateState(prev => _extends({}, prev, {
|
|
89
|
-
draft: valueManager.setTimezone(utils, timezoneProp, prev.draft)
|
|
90
|
-
}));
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
const {
|
|
94
|
-
getValidationErrorForNewValue
|
|
95
|
-
} = useValidation({
|
|
96
|
-
props,
|
|
97
|
-
validator,
|
|
98
|
-
timezone,
|
|
99
|
-
value: dateState.draft,
|
|
100
|
-
onError: props.onError
|
|
101
|
-
});
|
|
102
|
-
const setValue = useEventCallback((newValue, options) => {
|
|
103
|
-
const {
|
|
104
|
-
changeImportance = 'accept',
|
|
105
|
-
skipPublicationIfPristine = false,
|
|
106
|
-
validationError,
|
|
107
|
-
shortcut,
|
|
108
|
-
shouldClose = changeImportance === 'accept'
|
|
109
|
-
} = options ?? {};
|
|
110
|
-
let shouldPublish;
|
|
111
|
-
let shouldCommit;
|
|
112
|
-
if (!skipPublicationIfPristine && !isControlled && !dateState.hasBeenModifiedSinceMount) {
|
|
113
|
-
// If the value is not controlled and the value has never been modified before,
|
|
114
|
-
// Then clicking on any value (including the one equal to `defaultValue`) should call `onChange` and `onAccept`
|
|
115
|
-
shouldPublish = true;
|
|
116
|
-
shouldCommit = changeImportance === 'accept';
|
|
117
|
-
} else {
|
|
118
|
-
shouldPublish = !valueManager.areValuesEqual(utils, newValue, dateState.lastPublishedValue);
|
|
119
|
-
shouldCommit = changeImportance === 'accept' && !valueManager.areValuesEqual(utils, newValue, dateState.lastCommittedValue);
|
|
120
|
-
}
|
|
121
|
-
setDateState(prev => _extends({}, prev, {
|
|
122
|
-
draft: newValue,
|
|
123
|
-
lastPublishedValue: shouldPublish ? newValue : prev.lastPublishedValue,
|
|
124
|
-
lastCommittedValue: shouldCommit ? newValue : prev.lastCommittedValue,
|
|
125
|
-
hasBeenModifiedSinceMount: true
|
|
126
|
-
}));
|
|
127
|
-
let cachedContext = null;
|
|
128
|
-
const getContext = () => {
|
|
129
|
-
if (!cachedContext) {
|
|
130
|
-
cachedContext = {
|
|
131
|
-
validationError: validationError == null ? getValidationErrorForNewValue(newValue) : validationError
|
|
132
|
-
};
|
|
133
|
-
if (shortcut) {
|
|
134
|
-
cachedContext.shortcut = shortcut;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return cachedContext;
|
|
138
|
-
};
|
|
139
|
-
if (shouldPublish) {
|
|
140
|
-
handleValueChange(newValue, getContext());
|
|
141
|
-
}
|
|
142
|
-
if (shouldCommit && onAccept) {
|
|
143
|
-
onAccept(newValue, getContext());
|
|
144
|
-
}
|
|
145
|
-
if (shouldClose) {
|
|
146
|
-
setOpen(false);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
if (dateState.lastControlledValue !== inValueWithoutRenderTimezone) {
|
|
150
|
-
const isUpdateComingFromPicker = valueManager.areValuesEqual(utils, dateState.draft, inValueWithTimezoneToRender);
|
|
151
|
-
setDateState(prev => _extends({}, prev, {
|
|
152
|
-
lastControlledValue: inValueWithoutRenderTimezone
|
|
153
|
-
}, isUpdateComingFromPicker ? {} : {
|
|
154
|
-
lastCommittedValue: inValueWithTimezoneToRender,
|
|
155
|
-
lastPublishedValue: inValueWithTimezoneToRender,
|
|
156
|
-
draft: inValueWithTimezoneToRender,
|
|
157
|
-
hasBeenModifiedSinceMount: true
|
|
158
|
-
}));
|
|
159
|
-
}
|
|
160
|
-
const isValid = testedValue => {
|
|
161
|
-
const error = validator({
|
|
162
|
-
adapter,
|
|
163
|
-
value: testedValue,
|
|
164
|
-
timezone,
|
|
165
|
-
props
|
|
166
|
-
});
|
|
167
|
-
return !valueManager.hasError(error);
|
|
168
|
-
};
|
|
169
|
-
const clearValue = useEventCallback(() => setValue(valueManager.emptyValue));
|
|
170
|
-
const setValueToToday = useEventCallback(() => setValue(valueManager.getTodayValue(utils, timezone, valueType)));
|
|
171
|
-
const acceptValueChanges = useEventCallback(() => setValue(dateState.lastPublishedValue));
|
|
172
|
-
const cancelValueChanges = useEventCallback(() => setValue(dateState.lastCommittedValue, {
|
|
173
|
-
skipPublicationIfPristine: true
|
|
174
|
-
}));
|
|
175
|
-
const dismissViews = useEventCallback(() => {
|
|
176
|
-
setValue(dateState.lastPublishedValue, {
|
|
177
|
-
skipPublicationIfPristine: true
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
const setValueFromView = useEventCallback((newValue, selectionState = 'partial') => {
|
|
181
|
-
// TODO: Expose a new method (private?) like `setView` that only updates the draft value.
|
|
182
|
-
if (selectionState === 'shallow') {
|
|
183
|
-
setDateState(prev => _extends({}, prev, {
|
|
184
|
-
draft: newValue,
|
|
185
|
-
hasBeenModifiedSinceMount: true
|
|
186
|
-
}));
|
|
187
|
-
}
|
|
188
|
-
setValue(newValue, {
|
|
189
|
-
changeImportance: selectionState === 'finish' && closeOnSelect ? 'accept' : 'set'
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
const valueWithoutError = React.useMemo(() => valueManager.cleanValue(utils, dateState.draft), [utils, valueManager, dateState.draft]);
|
|
193
|
-
const viewResponse = {
|
|
194
|
-
value: valueWithoutError,
|
|
195
|
-
onChange: setValueFromView,
|
|
196
|
-
open,
|
|
197
|
-
setOpen
|
|
198
|
-
};
|
|
199
|
-
const actionsContextValue = React.useMemo(() => ({
|
|
200
|
-
setValue,
|
|
201
|
-
setOpen,
|
|
202
|
-
clearValue,
|
|
203
|
-
setValueToToday,
|
|
204
|
-
acceptValueChanges,
|
|
205
|
-
cancelValueChanges
|
|
206
|
-
}), [setValue, setOpen, clearValue, setValueToToday, acceptValueChanges, cancelValueChanges]);
|
|
207
|
-
const contextValue = React.useMemo(() => _extends({}, actionsContextValue, {
|
|
208
|
-
value: dateState.draft,
|
|
209
|
-
timezone,
|
|
210
|
-
open
|
|
211
|
-
}), [actionsContextValue, timezone, open, dateState.draft]);
|
|
212
|
-
const privateContextValue = React.useMemo(() => ({
|
|
213
|
-
dismissViews
|
|
214
|
-
}), [dismissViews]);
|
|
215
|
-
const providerParams = {
|
|
216
|
-
value: dateState.draft,
|
|
217
|
-
contextValue,
|
|
218
|
-
actionsContextValue,
|
|
219
|
-
privateContextValue,
|
|
220
|
-
isValidContextValue: isValid
|
|
221
|
-
};
|
|
222
|
-
return {
|
|
223
|
-
viewProps: viewResponse,
|
|
224
|
-
provider: providerParams
|
|
225
|
-
};
|
|
226
|
-
};
|