@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.
Files changed (197) hide show
  1. package/CHANGELOG.md +131 -0
  2. package/DatePicker/shared.d.ts +1 -1
  3. package/DateTimePicker/DateTimePicker.types.d.ts +2 -2
  4. package/DateTimePicker/DateTimePickerToolbar.d.ts +1 -1
  5. package/DateTimePicker/DateTimePickerToolbar.js +1 -1
  6. package/DateTimePicker/shared.d.ts +18 -10
  7. package/DateTimePicker/shared.js +23 -2
  8. package/DesktopDateTimePicker/DesktopDateTimePicker.js +2 -11
  9. package/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +4 -7
  10. package/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
  11. package/MobileDateTimePicker/MobileDateTimePicker.d.ts +1 -2
  12. package/MobileDateTimePicker/MobileDateTimePicker.js +61 -6
  13. package/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +1 -3
  14. package/PickersTextField/PickersTextField.js +3 -1
  15. package/StaticDateTimePicker/StaticDateTimePicker.js +60 -6
  16. package/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +1 -2
  17. package/TimePicker/shared.d.ts +1 -1
  18. package/esm/DatePicker/shared.d.ts +1 -1
  19. package/esm/DateTimePicker/DateTimePicker.types.d.ts +2 -2
  20. package/esm/DateTimePicker/DateTimePickerToolbar.d.ts +1 -1
  21. package/esm/DateTimePicker/DateTimePickerToolbar.js +1 -1
  22. package/esm/DateTimePicker/shared.d.ts +18 -10
  23. package/esm/DateTimePicker/shared.js +23 -2
  24. package/esm/DesktopDateTimePicker/DesktopDateTimePicker.js +3 -12
  25. package/esm/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +4 -7
  26. package/esm/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
  27. package/esm/MobileDateTimePicker/MobileDateTimePicker.d.ts +1 -2
  28. package/esm/MobileDateTimePicker/MobileDateTimePicker.js +62 -7
  29. package/esm/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +1 -3
  30. package/esm/PickersTextField/PickersTextField.js +3 -1
  31. package/esm/StaticDateTimePicker/StaticDateTimePicker.js +61 -7
  32. package/esm/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +1 -2
  33. package/esm/TimePicker/shared.d.ts +1 -1
  34. package/esm/index.js +1 -1
  35. package/esm/internals/components/PickerFieldUI.js +6 -2
  36. package/esm/internals/components/PickerPopper/PickerPopper.js +3 -3
  37. package/esm/internals/components/PickerProvider.d.ts +137 -6
  38. package/esm/internals/components/PickerProvider.js +1 -1
  39. package/esm/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +4 -7
  40. package/esm/internals/hooks/useField/useField.js +7 -8
  41. package/esm/internals/hooks/useField/useField.types.d.ts +46 -43
  42. package/esm/internals/hooks/useField/useField.utils.js +4 -1
  43. package/esm/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
  44. package/esm/internals/hooks/useField/useFieldState.d.ts +2 -1
  45. package/esm/internals/hooks/useField/useFieldState.js +136 -83
  46. package/esm/internals/hooks/useField/useFieldV6TextField.js +1 -1
  47. package/esm/internals/hooks/useField/useFieldV7TextField.js +2 -1
  48. package/esm/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +4 -7
  49. package/esm/internals/hooks/useNullableFieldPrivateContext.d.ts +5 -2
  50. package/esm/internals/hooks/usePicker/hooks/useOrientation.d.ts +2 -0
  51. package/esm/internals/hooks/usePicker/hooks/useOrientation.js +34 -0
  52. package/esm/internals/hooks/usePicker/hooks/useValueAndOpenStates.d.ts +19 -0
  53. package/esm/internals/hooks/usePicker/hooks/useValueAndOpenStates.js +210 -0
  54. package/esm/internals/hooks/usePicker/index.d.ts +1 -3
  55. package/esm/internals/hooks/usePicker/usePicker.d.ts +5 -5
  56. package/esm/internals/hooks/usePicker/usePicker.js +276 -34
  57. package/esm/internals/hooks/usePicker/usePicker.types.d.ts +181 -9
  58. package/esm/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +3 -4
  59. package/esm/internals/hooks/useValueWithTimezone.d.ts +1 -1
  60. package/esm/internals/index.d.ts +3 -6
  61. package/esm/internals/models/manager.d.ts +108 -4
  62. package/esm/internals/models/props/basePickerProps.d.ts +2 -2
  63. package/esm/internals/models/props/time.d.ts +1 -1
  64. package/esm/internals/utils/date-time-utils.d.ts +2 -2
  65. package/esm/internals/utils/valueManagers.d.ts +1 -1
  66. package/esm/internals/utils/valueManagers.js +10 -18
  67. package/esm/managers/useDateManager.d.ts +3 -4
  68. package/esm/managers/useDateTimeManager.d.ts +3 -4
  69. package/esm/managers/useTimeManager.d.ts +3 -4
  70. package/esm/models/adapters.d.ts +2 -1
  71. package/esm/models/manager.d.ts +4 -5
  72. package/esm/validation/useValidation.d.ts +1 -1
  73. package/index.js +1 -1
  74. package/internals/components/PickerFieldUI.js +6 -2
  75. package/internals/components/PickerPopper/PickerPopper.js +3 -3
  76. package/internals/components/PickerProvider.d.ts +137 -6
  77. package/internals/components/PickerProvider.js +1 -1
  78. package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +4 -7
  79. package/internals/hooks/useField/useField.js +7 -8
  80. package/internals/hooks/useField/useField.types.d.ts +46 -43
  81. package/internals/hooks/useField/useField.utils.js +4 -1
  82. package/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
  83. package/internals/hooks/useField/useFieldState.d.ts +2 -1
  84. package/internals/hooks/useField/useFieldState.js +135 -82
  85. package/internals/hooks/useField/useFieldV6TextField.js +1 -1
  86. package/internals/hooks/useField/useFieldV7TextField.js +2 -1
  87. package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +4 -7
  88. package/internals/hooks/useNullableFieldPrivateContext.d.ts +5 -2
  89. package/internals/hooks/usePicker/hooks/useOrientation.d.ts +2 -0
  90. package/internals/hooks/usePicker/hooks/useOrientation.js +42 -0
  91. package/internals/hooks/usePicker/hooks/useValueAndOpenStates.d.ts +19 -0
  92. package/internals/hooks/usePicker/{usePickerValue.js → hooks/useValueAndOpenStates.js} +97 -114
  93. package/internals/hooks/usePicker/index.d.ts +1 -3
  94. package/internals/hooks/usePicker/usePicker.d.ts +5 -5
  95. package/internals/hooks/usePicker/usePicker.js +278 -34
  96. package/internals/hooks/usePicker/usePicker.types.d.ts +181 -9
  97. package/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +3 -4
  98. package/internals/hooks/useValueWithTimezone.d.ts +1 -1
  99. package/internals/index.d.ts +3 -6
  100. package/internals/models/manager.d.ts +108 -4
  101. package/internals/models/props/basePickerProps.d.ts +2 -2
  102. package/internals/models/props/time.d.ts +1 -1
  103. package/internals/utils/date-time-utils.d.ts +2 -2
  104. package/internals/utils/valueManagers.d.ts +1 -1
  105. package/internals/utils/valueManagers.js +10 -18
  106. package/managers/useDateManager.d.ts +3 -4
  107. package/managers/useDateTimeManager.d.ts +3 -4
  108. package/managers/useTimeManager.d.ts +3 -4
  109. package/models/adapters.d.ts +2 -1
  110. package/models/manager.d.ts +4 -5
  111. package/modern/DatePicker/shared.d.ts +1 -1
  112. package/modern/DateTimePicker/DateTimePicker.types.d.ts +2 -2
  113. package/modern/DateTimePicker/DateTimePickerToolbar.d.ts +1 -1
  114. package/modern/DateTimePicker/DateTimePickerToolbar.js +1 -1
  115. package/modern/DateTimePicker/shared.d.ts +18 -10
  116. package/modern/DateTimePicker/shared.js +23 -2
  117. package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +3 -12
  118. package/modern/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +4 -7
  119. package/modern/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
  120. package/modern/MobileDateTimePicker/MobileDateTimePicker.d.ts +1 -2
  121. package/modern/MobileDateTimePicker/MobileDateTimePicker.js +62 -7
  122. package/modern/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +1 -3
  123. package/modern/PickersTextField/PickersTextField.js +3 -1
  124. package/modern/StaticDateTimePicker/StaticDateTimePicker.js +61 -7
  125. package/modern/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +1 -2
  126. package/modern/TimePicker/shared.d.ts +1 -1
  127. package/modern/index.js +1 -1
  128. package/modern/internals/components/PickerFieldUI.js +6 -2
  129. package/modern/internals/components/PickerPopper/PickerPopper.js +3 -3
  130. package/modern/internals/components/PickerProvider.d.ts +137 -6
  131. package/modern/internals/components/PickerProvider.js +1 -1
  132. package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +4 -7
  133. package/modern/internals/hooks/useField/useField.js +7 -8
  134. package/modern/internals/hooks/useField/useField.types.d.ts +46 -43
  135. package/modern/internals/hooks/useField/useField.utils.js +4 -1
  136. package/modern/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
  137. package/modern/internals/hooks/useField/useFieldState.d.ts +2 -1
  138. package/modern/internals/hooks/useField/useFieldState.js +136 -83
  139. package/modern/internals/hooks/useField/useFieldV6TextField.js +1 -1
  140. package/modern/internals/hooks/useField/useFieldV7TextField.js +2 -1
  141. package/modern/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +4 -7
  142. package/modern/internals/hooks/useNullableFieldPrivateContext.d.ts +5 -2
  143. package/modern/internals/hooks/usePicker/hooks/useOrientation.d.ts +2 -0
  144. package/modern/internals/hooks/usePicker/hooks/useOrientation.js +34 -0
  145. package/modern/internals/hooks/usePicker/hooks/useValueAndOpenStates.d.ts +19 -0
  146. package/modern/internals/hooks/usePicker/hooks/useValueAndOpenStates.js +210 -0
  147. package/modern/internals/hooks/usePicker/index.d.ts +1 -3
  148. package/modern/internals/hooks/usePicker/usePicker.d.ts +5 -5
  149. package/modern/internals/hooks/usePicker/usePicker.js +276 -34
  150. package/modern/internals/hooks/usePicker/usePicker.types.d.ts +181 -9
  151. package/modern/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +3 -4
  152. package/modern/internals/hooks/useValueWithTimezone.d.ts +1 -1
  153. package/modern/internals/index.d.ts +3 -6
  154. package/modern/internals/models/manager.d.ts +108 -4
  155. package/modern/internals/models/props/basePickerProps.d.ts +2 -2
  156. package/modern/internals/models/props/time.d.ts +1 -1
  157. package/modern/internals/utils/date-time-utils.d.ts +2 -2
  158. package/modern/internals/utils/valueManagers.d.ts +1 -1
  159. package/modern/internals/utils/valueManagers.js +10 -18
  160. package/modern/managers/useDateManager.d.ts +3 -4
  161. package/modern/managers/useDateTimeManager.d.ts +3 -4
  162. package/modern/managers/useTimeManager.d.ts +3 -4
  163. package/modern/models/adapters.d.ts +2 -1
  164. package/modern/models/manager.d.ts +4 -5
  165. package/modern/validation/useValidation.d.ts +1 -1
  166. package/package.json +1 -1
  167. package/tsconfig.build.tsbuildinfo +1 -1
  168. package/validation/useValidation.d.ts +1 -1
  169. package/esm/internals/hooks/useOpenState.d.ts +0 -14
  170. package/esm/internals/hooks/useOpenState.js +0 -37
  171. package/esm/internals/hooks/usePicker/usePickerProvider.d.ts +0 -65
  172. package/esm/internals/hooks/usePicker/usePickerProvider.js +0 -125
  173. package/esm/internals/hooks/usePicker/usePickerValue.d.ts +0 -12
  174. package/esm/internals/hooks/usePicker/usePickerValue.js +0 -226
  175. package/esm/internals/hooks/usePicker/usePickerValue.types.d.ts +0 -327
  176. package/esm/internals/hooks/usePicker/usePickerValue.types.js +0 -1
  177. package/esm/internals/hooks/usePicker/usePickerViews.d.ts +0 -137
  178. package/esm/internals/hooks/usePicker/usePickerViews.js +0 -188
  179. package/internals/hooks/useOpenState.d.ts +0 -14
  180. package/internals/hooks/useOpenState.js +0 -46
  181. package/internals/hooks/usePicker/usePickerProvider.d.ts +0 -65
  182. package/internals/hooks/usePicker/usePickerProvider.js +0 -135
  183. package/internals/hooks/usePicker/usePickerValue.d.ts +0 -12
  184. package/internals/hooks/usePicker/usePickerValue.types.d.ts +0 -327
  185. package/internals/hooks/usePicker/usePickerValue.types.js +0 -5
  186. package/internals/hooks/usePicker/usePickerViews.d.ts +0 -137
  187. package/internals/hooks/usePicker/usePickerViews.js +0 -195
  188. package/modern/internals/hooks/useOpenState.d.ts +0 -14
  189. package/modern/internals/hooks/useOpenState.js +0 -37
  190. package/modern/internals/hooks/usePicker/usePickerProvider.d.ts +0 -65
  191. package/modern/internals/hooks/usePicker/usePickerProvider.js +0 -125
  192. package/modern/internals/hooks/usePicker/usePickerValue.d.ts +0 -12
  193. package/modern/internals/hooks/usePicker/usePickerValue.js +0 -226
  194. package/modern/internals/hooks/usePicker/usePickerValue.types.d.ts +0 -327
  195. package/modern/internals/hooks/usePicker/usePickerValue.types.js +0 -1
  196. package/modern/internals/hooks/usePicker/usePickerViews.d.ts +0 -137
  197. 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/hooks/usePicker';
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
- };