@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,46 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.useOpenState = void 0;
9
- var React = _interopRequireWildcard(require("react"));
10
- var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
11
- const useOpenState = ({
12
- open,
13
- onOpen,
14
- onClose
15
- }) => {
16
- const isControllingOpenProp = React.useRef(typeof open === 'boolean').current;
17
- const [openState, setOpenState] = React.useState(false);
18
-
19
- // It is required to update inner state in useEffect in order to avoid situation when
20
- // Our component is not mounted yet, but `open` state is set to `true` (for example initially opened)
21
- React.useEffect(() => {
22
- if (isControllingOpenProp) {
23
- if (typeof open !== 'boolean') {
24
- throw new Error('You must not mix controlling and uncontrolled mode for `open` prop');
25
- }
26
- setOpenState(open);
27
- }
28
- }, [isControllingOpenProp, open]);
29
- const setOpen = (0, _useEventCallback.default)(action => {
30
- const newOpen = typeof action === 'function' ? action(openState) : action;
31
- if (!isControllingOpenProp) {
32
- setOpenState(newOpen);
33
- }
34
- if (newOpen && onOpen) {
35
- onOpen();
36
- }
37
- if (!newOpen && onClose) {
38
- onClose();
39
- }
40
- });
41
- return {
42
- open: openState,
43
- setOpen
44
- };
45
- };
46
- exports.useOpenState = useOpenState;
@@ -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,135 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.usePickerOrientation = void 0;
9
- exports.usePickerProvider = usePickerProvider;
10
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
- var React = _interopRequireWildcard(require("react"));
12
- var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
13
- var _useForkRef = _interopRequireDefault(require("@mui/utils/useForkRef"));
14
- var _useId = _interopRequireDefault(require("@mui/utils/useId"));
15
- var _useUtils = require("../useUtils");
16
- var _utils = require("../../utils/utils");
17
- var _useReduceAnimations = require("../useReduceAnimations");
18
- function getOrientation() {
19
- if (typeof window === 'undefined') {
20
- return 'portrait';
21
- }
22
- if (window.screen && window.screen.orientation && window.screen.orientation.angle) {
23
- return Math.abs(window.screen.orientation.angle) === 90 ? 'landscape' : 'portrait';
24
- }
25
-
26
- // Support IOS safari
27
- if (window.orientation) {
28
- return Math.abs(Number(window.orientation)) === 90 ? 'landscape' : 'portrait';
29
- }
30
- return 'portrait';
31
- }
32
- const usePickerOrientation = (views, customOrientation) => {
33
- const [orientation, setOrientation] = React.useState(getOrientation);
34
- (0, _useEnhancedEffect.default)(() => {
35
- const eventHandler = () => {
36
- setOrientation(getOrientation());
37
- };
38
- window.addEventListener('orientationchange', eventHandler);
39
- return () => {
40
- window.removeEventListener('orientationchange', eventHandler);
41
- };
42
- }, []);
43
- if ((0, _utils.arrayIncludes)(views, ['hours', 'minutes', 'seconds'])) {
44
- // could not display 13:34:44 in landscape mode
45
- return 'portrait';
46
- }
47
- return customOrientation ?? orientation;
48
- };
49
- exports.usePickerOrientation = usePickerOrientation;
50
- function usePickerProvider(parameters) {
51
- const {
52
- ref,
53
- props,
54
- valueManager,
55
- localeText,
56
- variant,
57
- paramsFromUsePickerValue,
58
- paramsFromUsePickerViews
59
- } = parameters;
60
- const utils = (0, _useUtils.useUtils)();
61
- const orientation = usePickerOrientation(paramsFromUsePickerViews.views, props.orientation);
62
- const reduceAnimations = (0, _useReduceAnimations.useReduceAnimations)(props.reduceAnimations);
63
- const triggerRef = React.useRef(null);
64
- const popupRef = React.useRef(null);
65
- const rootRefObject = React.useRef(null);
66
- const rootRef = (0, _useForkRef.default)(ref, rootRefObject);
67
-
68
- /**
69
- * TODO: Improve how we generate the aria-label and aria-labelledby attributes.
70
- */
71
- const labelId = (0, _useId.default)();
72
- const ownerState = React.useMemo(() => ({
73
- isPickerValueEmpty: valueManager.areValuesEqual(utils, paramsFromUsePickerValue.value, valueManager.emptyValue),
74
- isPickerOpen: paramsFromUsePickerValue.contextValue.open,
75
- isPickerDisabled: props.disabled ?? false,
76
- isPickerReadOnly: props.readOnly ?? false,
77
- pickerOrientation: orientation,
78
- pickerVariant: variant
79
- }), [utils, valueManager, paramsFromUsePickerValue.value, paramsFromUsePickerValue.contextValue.open, orientation, variant, props.disabled, props.readOnly]);
80
- const triggerStatus = React.useMemo(() => {
81
- if (props.disableOpenPicker || !paramsFromUsePickerViews.hasUIView) {
82
- return 'hidden';
83
- }
84
- if (props.disabled || props.readOnly) {
85
- return 'disabled';
86
- }
87
- return 'enabled';
88
- }, [props.disableOpenPicker, paramsFromUsePickerViews.hasUIView, props.disabled, props.readOnly]);
89
- const contextValue = React.useMemo(() => (0, _extends2.default)({}, paramsFromUsePickerValue.contextValue, paramsFromUsePickerViews.contextValue, {
90
- disabled: props.disabled ?? false,
91
- readOnly: props.readOnly ?? false,
92
- autoFocus: props.autoFocus ?? false,
93
- variant,
94
- orientation,
95
- popupRef,
96
- reduceAnimations,
97
- triggerRef,
98
- triggerStatus,
99
- fieldFormat: props.format ?? '',
100
- name: props.name,
101
- label: props.label,
102
- rootSx: props.sx,
103
- rootRef,
104
- rootClassName: props.className
105
- }), [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]);
106
- const privateContextValue = React.useMemo(() => (0, _extends2.default)({}, paramsFromUsePickerValue.privateContextValue, paramsFromUsePickerViews.privateContextValue, {
107
- ownerState,
108
- rootRefObject,
109
- labelId
110
- }), [paramsFromUsePickerValue.privateContextValue, paramsFromUsePickerViews.privateContextValue, ownerState, labelId]);
111
- const actionsContextValue = React.useMemo(() => (0, _extends2.default)({}, paramsFromUsePickerValue.actionsContextValue, paramsFromUsePickerViews.actionsContextValue), [paramsFromUsePickerValue.actionsContextValue, paramsFromUsePickerViews.actionsContextValue]);
112
- const fieldPrivateContextValue = React.useMemo(() => (0, _extends2.default)({}, paramsFromUsePickerViews.fieldPrivateContextValue, {
113
- formatDensity: props.formatDensity,
114
- enableAccessibleFieldDOMStructure: props.enableAccessibleFieldDOMStructure,
115
- selectedSections: props.selectedSections,
116
- onSelectedSectionsChange: props.onSelectedSectionsChange
117
- }), [paramsFromUsePickerViews.fieldPrivateContextValue, props.formatDensity, props.enableAccessibleFieldDOMStructure, props.selectedSections, props.onSelectedSectionsChange]);
118
- return {
119
- localeText,
120
- contextValue,
121
- privateContextValue,
122
- actionsContextValue,
123
- fieldPrivateContextValue,
124
- isValidContextValue: paramsFromUsePickerValue.isValidContextValue
125
- };
126
- }
127
-
128
- /**
129
- * Props used to create the picker's contexts.
130
- * Those props are exposed on all the pickers.
131
- */
132
-
133
- /**
134
- * Props used to create the picker's contexts and that are not available on static pickers.
135
- */
@@ -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,327 +0,0 @@
1
- import * as React from 'react';
2
- import { UseFieldInternalProps } from "../useField/index.js";
3
- import { Validator } from "../../../validation/index.js";
4
- import { TimezoneProps, MuiPickersAdapter, PickersTimezone, PickerChangeHandlerContext, PickerValidDate, OnErrorProps, InferError, PickerValueType, PickerChangeImportance } from "../../../models/index.js";
5
- import { GetDefaultReferenceDateProps } from "../../utils/getDefaultReferenceDate.js";
6
- import type { PickersShortcutsItemContext } from '../../../PickersShortcuts';
7
- import { InferNonNullablePickerValue, PickerValidValue } from "../../models/index.js";
8
- export interface PickerValueManager<TValue extends PickerValidValue, TError> {
9
- /**
10
- * Determines if two values are equal.
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.
12
- * @param {MuiPickersAdapter} utils The adapter.
13
- * @param {TValue} valueLeft The first value to compare.
14
- * @param {TValue} valueRight The second value to compare.
15
- * @returns {boolean} A boolean indicating if the two values are equal.
16
- */
17
- areValuesEqual: (utils: MuiPickersAdapter, valueLeft: TValue, valueRight: TValue) => boolean;
18
- /**
19
- * Value to set when clicking the "Clear" button.
20
- */
21
- emptyValue: TValue;
22
- /**
23
- * Method returning the value to set when clicking the "Today" button
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.
25
- * @param {MuiPickersAdapter} utils The adapter.
26
- * @param {PickersTimezone} timezone The current timezone.
27
- * @param {PickerValueType} valueType The type of the value being edited.
28
- * @returns {TValue} The value to set when clicking the "Today" button.
29
- */
30
- getTodayValue: (utils: MuiPickersAdapter, timezone: PickersTimezone, valueType: PickerValueType) => TValue;
31
- /**
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.
33
- * Method returning the reference value to use when mounting the component.
34
- * @param {object} params The params of the method.
35
- * @param {PickerValidDate | undefined} params.referenceDate The referenceDate provided by the user.
36
- * @param {TValue} params.value The value provided by the user.
37
- * @param {GetDefaultReferenceDateProps} params.props The validation props needed to compute the reference value.
38
- * @param {MuiPickersAdapter} params.utils The adapter.
39
- * @param {number} params.granularity The granularity of the selection possible on this component.
40
- * @param {PickersTimezone} params.timezone The current timezone.
41
- * @param {() => PickerValidDate} params.getTodayDate The reference date to use if no reference date is passed to the component.
42
- * @returns {TValue} The reference value to use for non-provided dates.
43
- */
44
- getInitialReferenceValue: (params: {
45
- referenceDate: PickerValidDate | undefined;
46
- value: TValue;
47
- props: GetDefaultReferenceDateProps;
48
- utils: MuiPickersAdapter;
49
- granularity: number;
50
- timezone: PickersTimezone;
51
- getTodayDate?: () => PickerValidDate;
52
- }) => InferNonNullablePickerValue<TValue>;
53
- /**
54
- * Method parsing the input value to replace all invalid dates by `null`.
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.
56
- * @param {MuiPickersAdapter} utils The adapter.
57
- * @param {TValue} value The value to parse.
58
- * @returns {TValue} The value without invalid date.
59
- */
60
- cleanValue: (utils: MuiPickersAdapter, value: TValue) => TValue;
61
- /**
62
- * Generates the new value, given the previous value and the new proposed value.
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.
64
- * @param {MuiPickersAdapter} utils The adapter.
65
- * @param {TValue} lastValidDateValue The last valid value.
66
- * @param {TValue} value The proposed value.
67
- * @returns {TValue} The new value.
68
- */
69
- valueReducer?: (utils: MuiPickersAdapter, lastValidDateValue: TValue, value: TValue) => TValue;
70
- /**
71
- * Compare two errors to know if they are equal.
72
- * @template TError
73
- * @param {TError} error The new error
74
- * @param {TError | null} prevError The previous error
75
- * @returns {boolean} `true` if the new error is different from the previous one.
76
- */
77
- isSameError: (error: TError, prevError: TError | null) => boolean;
78
- /**
79
- * Checks if the current error is empty or not.
80
- * @template TError
81
- * @param {TError} error The current error.
82
- * @returns {boolean} `true` if the current error is not empty.
83
- */
84
- hasError: (error: TError) => boolean;
85
- /**
86
- * The value identifying no error, used to initialise the error state.
87
- */
88
- defaultErrorState: TError;
89
- /**
90
- * Return the timezone of the date inside a value.
91
- * Throw an error on range picker if both values don't have the same timezone.
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.
93
- @param {MuiPickersAdapter} utils The utils to manipulate the date.
94
- @param {TValue} value The current value.
95
- @returns {string | null} The timezone of the current value.
96
- */
97
- getTimezone: (utils: MuiPickersAdapter, value: TValue) => string | null;
98
- /**
99
- * Change the timezone of the dates inside a value.
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.
101
- @param {MuiPickersAdapter} utils The utils to manipulate the date.
102
- @param {PickersTimezone} timezone The current timezone.
103
- @param {TValue} value The value to convert.
104
- @returns {TValue} The value with the new dates in the new timezone.
105
- */
106
- setTimezone: (utils: MuiPickersAdapter, timezone: PickersTimezone, value: TValue) => TValue;
107
- }
108
- export type PickerSelectionState = 'partial' | 'shallow' | 'finish';
109
- export interface UsePickerValueState<TValue extends PickerValidValue> {
110
- /**
111
- * Date displayed on the views and the field.
112
- * It is updated whenever the user modifies something.
113
- */
114
- draft: TValue;
115
- /**
116
- * Last value published (the last value for which `shouldPublishValue` returned `true`).
117
- * If `onChange` is defined, it's the value that was passed on the last call to this callback.
118
- */
119
- lastPublishedValue: TValue;
120
- /**
121
- * Last value committed (the last value for which `shouldCommitValue` returned `true`).
122
- * If `onAccept` is defined, it's the value that was passed on the last call to this callback.
123
- */
124
- lastCommittedValue: TValue;
125
- /**
126
- * Last value passed to `props.value`.
127
- * Used to update the `draft` value whenever the `value` prop changes.
128
- */
129
- lastControlledValue: TValue | undefined;
130
- /**
131
- * If we never modified the value since the mount of the component,
132
- * Then we might want to apply some custom logic.
133
- *
134
- * For example, when the component is not controlled and `defaultValue` is defined.
135
- * Then clicking on "Accept", "Today" or "Clear" should fire `onAccept` with `defaultValue`, but clicking on "Cancel" or dismissing the picker should not.
136
- */
137
- hasBeenModifiedSinceMount: boolean;
138
- }
139
- /**
140
- * Props used to handle the value that are common to all pickers.
141
- */
142
- export interface UsePickerValueBaseProps<TValue extends PickerValidValue, TError> extends OnErrorProps<TValue, TError> {
143
- /**
144
- * The selected value.
145
- * Used when the component is controlled.
146
- */
147
- value?: TValue;
148
- /**
149
- * The default value.
150
- * Used when the component is not controlled.
151
- */
152
- defaultValue?: TValue;
153
- /**
154
- * Callback fired when the value changes.
155
- * @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.
156
- * @template TError The validation error type. It will be either `string` or a `null`. It can be in `[start, end]` format in case of range value.
157
- * @param {TValue} value The new value.
158
- * @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
159
- */
160
- onChange?: (value: TValue, context: PickerChangeHandlerContext<TError>) => void;
161
- /**
162
- * Callback fired when the value is accepted.
163
- * @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.
164
- * @template TError The validation error type. It will be either `string` or a `null`. It can be in `[start, end]` format in case of range value.
165
- * @param {TValue} value The value that was just accepted.
166
- * @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
167
- */
168
- onAccept?: (value: TValue, context: PickerChangeHandlerContext<TError>) => void;
169
- }
170
- /**
171
- * Props used to handle the value of non-static pickers.
172
- */
173
- export interface UsePickerValueNonStaticProps {
174
- /**
175
- * If `true`, the Picker will close after submitting the full date.
176
- * @default false
177
- */
178
- closeOnSelect?: boolean;
179
- /**
180
- * Control the popup or dialog open state.
181
- * @default false
182
- */
183
- open?: boolean;
184
- /**
185
- * Callback fired when the popup requests to be closed.
186
- * Use in controlled mode (see `open`).
187
- */
188
- onClose?: () => void;
189
- /**
190
- * Callback fired when the popup requests to be opened.
191
- * Use in controlled mode (see `open`).
192
- */
193
- onOpen?: () => void;
194
- }
195
- /**
196
- * Props used to handle the value of the pickers.
197
- */
198
- export interface UsePickerValueProps<TValue extends PickerValidValue, TError> extends UsePickerValueBaseProps<TValue, TError>, UsePickerValueNonStaticProps, TimezoneProps {
199
- referenceDate?: PickerValidDate;
200
- }
201
- export interface UsePickerValueParams<TValue extends PickerValidValue, TExternalProps extends UsePickerValueProps<TValue, any>> {
202
- props: TExternalProps;
203
- valueManager: PickerValueManager<TValue, InferError<TExternalProps>>;
204
- valueType: PickerValueType;
205
- validator: Validator<TValue, InferError<TExternalProps>, TExternalProps>;
206
- }
207
- export type UsePickerValueFieldResponse<TValue extends PickerValidValue, TError> = Required<Pick<UseFieldInternalProps<TValue, any, TError>, 'value' | 'onChange'>>;
208
- /**
209
- * Props passed to `usePickerViews`.
210
- */
211
- export interface UsePickerValueViewsResponse<TValue extends PickerValidValue> {
212
- value: TValue;
213
- onChange: (value: TValue, selectionState?: PickerSelectionState) => void;
214
- open: boolean;
215
- setOpen: React.Dispatch<React.SetStateAction<boolean>>;
216
- }
217
- /**
218
- * Params passed to `usePickerProvider`.
219
- */
220
- export interface UsePickerValueProviderParams<TValue extends PickerValidValue, TError> {
221
- value: TValue;
222
- contextValue: UsePickerValueContextValue<TValue, TError>;
223
- actionsContextValue: UsePickerValueActionsContextValue<TValue, TError>;
224
- privateContextValue: UsePickerValuePrivateContextValue;
225
- isValidContextValue: (value: TValue) => boolean;
226
- }
227
- export interface UsePickerValueResponse<TValue extends PickerValidValue, TError> {
228
- viewProps: UsePickerValueViewsResponse<TValue>;
229
- provider: UsePickerValueProviderParams<TValue, TError>;
230
- }
231
- export interface UsePickerValueContextValue<TValue extends PickerValidValue, TError> extends UsePickerValueActionsContextValue<TValue, TError> {
232
- /**
233
- * The current value of the picker.
234
- */
235
- value: TValue;
236
- /**
237
- * The timezone to use when rendering the dates.
238
- * If a `timezone` prop is provided, it will be used.
239
- * If the `value` prop contains a valid date, its timezone will be used.
240
- * If no `value` prop is provided, but the `defaultValue` contains a valid date, its timezone will be used.
241
- * If no `value` or `defaultValue` is provided, but the `referenceDate` is provided, its timezone will be used.
242
- * Otherwise, the timezone will be the default one of your date library.
243
- */
244
- timezone: PickersTimezone;
245
- /**
246
- * Whether the picker is open.
247
- */
248
- open: boolean;
249
- }
250
- export interface UsePickerValueActionsContextValue<TValue extends PickerValidValue, TError> {
251
- /**
252
- * Set the current value of the picker.
253
- * @param {TValue} value The new value of the picker.
254
- * @param {SetValueActionOptions<TError>} options The options to customize the behavior of this update.
255
- */
256
- setValue: (value: TValue, options?: SetValueActionOptions<TError>) => void;
257
- /**
258
- * Set the current open state of the Picker.
259
- * ```ts
260
- * setOpen(true); // Opens the picker.
261
- * setOpen(false); // Closes the picker.
262
- * setOpen((prevOpen) => !prevOpen); // Toggles the open state.
263
- * ```
264
- * @param {React.SetStateAction<boolean>} action The new open state of the Picker.
265
- * It can be a function that will receive the current open state.
266
- */
267
- setOpen: React.Dispatch<React.SetStateAction<boolean>>;
268
- /**
269
- * Set the current value of the picker to be empty.
270
- * The value will be `null` on single pickers and `[null, null]` on range pickers.
271
- */
272
- clearValue: () => void;
273
- /**
274
- * Set the current value of the picker to be the current date.
275
- * The value will be `today` on single pickers and `[today, today]` on range pickers.
276
- * With `today` being the current date, with its time set to `00:00:00` on Date Pickers and its time set to the current time on Time and Date Pickers.
277
- */
278
- setValueToToday: () => void;
279
- /**
280
- * Accept the current value of the picker.
281
- * Will call `onAccept` if defined.
282
- * If the picker is re-opened, this value will be the one used to initialize the views.
283
- */
284
- acceptValueChanges: () => void;
285
- /**
286
- * Cancel the changes made to the current value of the picker.
287
- * The value will be reset to the last accepted value.
288
- */
289
- cancelValueChanges: () => void;
290
- }
291
- export interface UsePickerValuePrivateContextValue {
292
- /**
293
- * Close the picker and accepts the current value if it is not equal to the last accepted value.
294
- */
295
- dismissViews: () => void;
296
- }
297
- export interface SetValueActionOptions<TError = string | null> {
298
- /**
299
- * The importance of the change when picking a value:
300
- * - "accept": fires `onChange`, fires `onAccept` and closes the picker.
301
- * - "set": fires `onChange` but do not fire `onAccept` and does not close the picker.
302
- * @default "accept"
303
- */
304
- changeImportance?: PickerChangeImportance;
305
- /**
306
- * The validation error associated to the current value.
307
- * If not defined, the validation will be computed by the picker.
308
- */
309
- validationError?: TError;
310
- /**
311
- * The shortcut that triggered this change.
312
- * It should not be defined if the change does not come from a shortcut.
313
- */
314
- shortcut?: PickersShortcutsItemContext;
315
- /**
316
- * Whether the value should call `onChange` and `onAccept` when the value is not controlled and has never been modified.
317
- * If `true`, the `onChange` and `onAccept` callback will only be fired if the value has been modified (and is not equal to the last published value).
318
- * If `false`, the `onChange` and `onAccept` callback will be fired when the value has never been modified (`onAccept` only if `changeImportance` is set to "accept").
319
- * @default false
320
- */
321
- skipPublicationIfPristine?: boolean;
322
- /**
323
- * Whether the picker should close.
324
- * @default changeImportance === "accept"
325
- */
326
- shouldClose?: boolean;
327
- }
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });