@mui/x-date-pickers 8.0.0-alpha.0 → 8.0.0-alpha.1

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 (115) hide show
  1. package/CHANGELOG.md +429 -5
  2. package/DateCalendar/DateCalendar.js +1 -0
  3. package/DatePicker/DatePickerToolbar.js +0 -12
  4. package/DateTimePicker/DateTimePickerToolbar.d.ts +2 -2
  5. package/DateTimePicker/DateTimePickerToolbar.js +6 -15
  6. package/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +0 -12
  7. package/DigitalClock/DigitalClock.js +1 -0
  8. package/MonthCalendar/MonthCalendar.js +1 -0
  9. package/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
  10. package/PickersLayout/PickersLayout.js +0 -12
  11. package/PickersLayout/PickersLayout.types.d.ts +2 -2
  12. package/PickersLayout/usePickerLayout.js +1 -5
  13. package/PickersTextField/PickersInputBase/PickersInputBase.js +10 -9
  14. package/PickersTextField/PickersTextField.js +2 -2
  15. package/README.md +2 -2
  16. package/TimeClock/Clock.js +1 -0
  17. package/TimeClock/TimeClock.js +1 -0
  18. package/TimePicker/TimePickerToolbar.js +6 -15
  19. package/YearCalendar/YearCalendar.js +1 -0
  20. package/hooks/useSplitFieldProps.d.ts +3 -3
  21. package/index.js +1 -1
  22. package/internals/components/PickerProvider.d.ts +26 -0
  23. package/internals/components/PickerProvider.js +3 -1
  24. package/internals/components/PickersToolbar.js +2 -4
  25. package/internals/hooks/useDesktopPicker/useDesktopPicker.js +1 -1
  26. package/internals/hooks/useField/useField.types.d.ts +2 -2
  27. package/internals/hooks/useField/useField.utils.d.ts +2 -2
  28. package/internals/hooks/useField/useFieldState.js +1 -0
  29. package/internals/hooks/useField/useFieldV7TextField.js +2 -1
  30. package/internals/hooks/useMobilePicker/useMobilePicker.js +1 -1
  31. package/internals/hooks/usePicker/usePicker.d.ts +1 -1
  32. package/internals/hooks/usePicker/usePicker.js +9 -12
  33. package/internals/hooks/usePicker/usePicker.types.d.ts +6 -6
  34. package/internals/hooks/usePicker/usePickerLayoutProps.d.ts +6 -7
  35. package/internals/hooks/usePicker/usePickerLayoutProps.js +2 -5
  36. package/internals/hooks/usePicker/usePickerProvider.d.ts +20 -4
  37. package/internals/hooks/usePicker/usePickerProvider.js +61 -5
  38. package/internals/hooks/usePicker/usePickerValue.d.ts +1 -1
  39. package/internals/hooks/usePicker/usePickerValue.js +18 -6
  40. package/internals/hooks/usePicker/usePickerValue.types.d.ts +8 -7
  41. package/internals/hooks/usePicker/usePickerViews.d.ts +1 -0
  42. package/internals/hooks/usePicker/usePickerViews.js +1 -0
  43. package/internals/hooks/useStaticPicker/useStaticPicker.js +1 -1
  44. package/internals/hooks/useValueWithTimezone.d.ts +19 -15
  45. package/internals/hooks/useValueWithTimezone.js +13 -1
  46. package/internals/index.d.ts +1 -1
  47. package/internals/models/common.d.ts +2 -1
  48. package/internals/models/props/toolbar.d.ts +1 -2
  49. package/internals/utils/date-utils.d.ts +2 -2
  50. package/models/common.d.ts +1 -0
  51. package/models/fields.d.ts +0 -1
  52. package/models/pickers.d.ts +18 -0
  53. package/modern/DateCalendar/DateCalendar.js +1 -0
  54. package/modern/DatePicker/DatePickerToolbar.js +0 -12
  55. package/modern/DateTimePicker/DateTimePickerToolbar.js +6 -15
  56. package/modern/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +0 -12
  57. package/modern/DigitalClock/DigitalClock.js +1 -0
  58. package/modern/MonthCalendar/MonthCalendar.js +1 -0
  59. package/modern/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
  60. package/modern/PickersLayout/PickersLayout.js +0 -12
  61. package/modern/PickersLayout/usePickerLayout.js +1 -5
  62. package/modern/PickersTextField/PickersInputBase/PickersInputBase.js +10 -9
  63. package/modern/PickersTextField/PickersTextField.js +2 -2
  64. package/modern/TimeClock/Clock.js +1 -0
  65. package/modern/TimeClock/TimeClock.js +1 -0
  66. package/modern/TimePicker/TimePickerToolbar.js +6 -15
  67. package/modern/YearCalendar/YearCalendar.js +1 -0
  68. package/modern/index.js +1 -1
  69. package/modern/internals/components/PickerProvider.js +3 -1
  70. package/modern/internals/components/PickersToolbar.js +2 -4
  71. package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.js +1 -1
  72. package/modern/internals/hooks/useField/useFieldState.js +1 -0
  73. package/modern/internals/hooks/useField/useFieldV7TextField.js +2 -1
  74. package/modern/internals/hooks/useMobilePicker/useMobilePicker.js +1 -1
  75. package/modern/internals/hooks/usePicker/usePicker.js +9 -12
  76. package/modern/internals/hooks/usePicker/usePickerLayoutProps.js +2 -5
  77. package/modern/internals/hooks/usePicker/usePickerProvider.js +61 -5
  78. package/modern/internals/hooks/usePicker/usePickerValue.js +18 -6
  79. package/modern/internals/hooks/usePicker/usePickerViews.js +1 -0
  80. package/modern/internals/hooks/useStaticPicker/useStaticPicker.js +1 -1
  81. package/modern/internals/hooks/useValueWithTimezone.js +13 -1
  82. package/node/DateCalendar/DateCalendar.js +1 -0
  83. package/node/DatePicker/DatePickerToolbar.js +0 -12
  84. package/node/DateTimePicker/DateTimePickerToolbar.js +6 -15
  85. package/node/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +0 -12
  86. package/node/DigitalClock/DigitalClock.js +1 -0
  87. package/node/MonthCalendar/MonthCalendar.js +1 -0
  88. package/node/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
  89. package/node/PickersLayout/PickersLayout.js +0 -12
  90. package/node/PickersLayout/usePickerLayout.js +1 -5
  91. package/node/PickersTextField/PickersInputBase/PickersInputBase.js +10 -9
  92. package/node/PickersTextField/PickersTextField.js +2 -2
  93. package/node/TimeClock/Clock.js +1 -0
  94. package/node/TimeClock/TimeClock.js +1 -0
  95. package/node/TimePicker/TimePickerToolbar.js +6 -15
  96. package/node/YearCalendar/YearCalendar.js +1 -0
  97. package/node/index.js +1 -1
  98. package/node/internals/components/PickerProvider.js +3 -1
  99. package/node/internals/components/PickersToolbar.js +2 -4
  100. package/node/internals/hooks/useDesktopPicker/useDesktopPicker.js +1 -1
  101. package/node/internals/hooks/useField/useFieldState.js +1 -0
  102. package/node/internals/hooks/useField/useFieldV7TextField.js +2 -1
  103. package/node/internals/hooks/useMobilePicker/useMobilePicker.js +1 -1
  104. package/node/internals/hooks/usePicker/usePicker.js +9 -12
  105. package/node/internals/hooks/usePicker/usePickerLayoutProps.js +2 -5
  106. package/node/internals/hooks/usePicker/usePickerProvider.js +64 -5
  107. package/node/internals/hooks/usePicker/usePickerValue.js +18 -6
  108. package/node/internals/hooks/usePicker/usePickerViews.js +1 -0
  109. package/node/internals/hooks/useStaticPicker/useStaticPicker.js +1 -1
  110. package/node/internals/hooks/useValueWithTimezone.js +13 -1
  111. package/package.json +4 -4
  112. package/internals/hooks/usePicker/usePickerOwnerState.d.ts +0 -10
  113. package/internals/hooks/usePicker/usePickerOwnerState.js +0 -16
  114. package/modern/internals/hooks/usePicker/usePickerOwnerState.js +0 -16
  115. package/node/internals/hooks/usePicker/usePickerOwnerState.js +0 -23
@@ -1,15 +1,66 @@
1
1
  import * as React from 'react';
2
+ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
3
+ import { useUtils } from "../useUtils.js";
4
+ import { arrayIncludes } from "../../utils/utils.js";
5
+ function getOrientation() {
6
+ if (typeof window === 'undefined') {
7
+ return 'portrait';
8
+ }
9
+ if (window.screen && window.screen.orientation && window.screen.orientation.angle) {
10
+ return Math.abs(window.screen.orientation.angle) === 90 ? 'landscape' : 'portrait';
11
+ }
12
+
13
+ // Support IOS safari
14
+ if (window.orientation) {
15
+ return Math.abs(Number(window.orientation)) === 90 ? 'landscape' : 'portrait';
16
+ }
17
+ return 'portrait';
18
+ }
19
+ export const usePickerOrientation = (views, customOrientation) => {
20
+ const [orientation, setOrientation] = React.useState(getOrientation);
21
+ useEnhancedEffect(() => {
22
+ const eventHandler = () => {
23
+ setOrientation(getOrientation());
24
+ };
25
+ window.addEventListener('orientationchange', eventHandler);
26
+ return () => {
27
+ window.removeEventListener('orientationchange', eventHandler);
28
+ };
29
+ }, []);
30
+ if (arrayIncludes(views, ['hours', 'minutes', 'seconds'])) {
31
+ // could not display 13:34:44 in landscape mode
32
+ return 'portrait';
33
+ }
34
+ return customOrientation ?? orientation;
35
+ };
2
36
  export function usePickerProvider(parameters) {
3
37
  const {
38
+ props,
4
39
  pickerValueResponse,
5
- ownerState,
6
- localeText
40
+ valueManager,
41
+ localeText,
42
+ variant,
43
+ views
7
44
  } = parameters;
45
+ const utils = useUtils();
46
+ const orientation = usePickerOrientation(views, props.orientation);
47
+ const ownerState = React.useMemo(() => ({
48
+ isPickerValueEmpty: valueManager.areValuesEqual(utils, pickerValueResponse.viewProps.value, valueManager.emptyValue),
49
+ isPickerOpen: pickerValueResponse.open,
50
+ isPickerDisabled: props.disabled ?? false,
51
+ isPickerReadOnly: props.readOnly ?? false,
52
+ pickerOrientation: orientation,
53
+ pickerVariant: variant
54
+ }), [utils, valueManager, pickerValueResponse.viewProps.value, pickerValueResponse.open, orientation, variant, props.disabled, props.readOnly]);
8
55
  const contextValue = React.useMemo(() => ({
9
56
  onOpen: pickerValueResponse.actions.onOpen,
10
57
  onClose: pickerValueResponse.actions.onClose,
11
- open: pickerValueResponse.open
12
- }), [pickerValueResponse.actions.onOpen, pickerValueResponse.actions.onClose, pickerValueResponse.open]);
58
+ open: pickerValueResponse.open,
59
+ disabled: props.disabled ?? false,
60
+ readOnly: props.readOnly ?? false,
61
+ variant,
62
+ orientation
63
+ }), [pickerValueResponse.actions.onOpen, pickerValueResponse.actions.onClose, pickerValueResponse.open, variant, orientation, props.disabled, props.readOnly]);
13
64
  const privateContextValue = React.useMemo(() => ({
14
65
  ownerState
15
66
  }), [ownerState]);
@@ -18,4 +69,9 @@ export function usePickerProvider(parameters) {
18
69
  contextValue,
19
70
  privateContextValue
20
71
  };
21
- }
72
+ }
73
+
74
+ /**
75
+ * Props used to create the private context.
76
+ * Those props are exposed on all the pickers.
77
+ */
@@ -3,4 +3,4 @@ import { UsePickerValueProps, UsePickerValueParams, UsePickerValueResponse } fro
3
3
  /**
4
4
  * Manage the value lifecycle of all the pickers.
5
5
  */
6
- export declare const usePickerValue: <TValue, TSection extends FieldSection, TExternalProps extends UsePickerValueProps<TValue, any>>({ props, valueManager, valueType, wrapperVariant, validator, }: UsePickerValueParams<TValue, TExternalProps>) => UsePickerValueResponse<TValue, TSection, InferError<TExternalProps>>;
6
+ export declare const usePickerValue: <TValue, TSection extends FieldSection, TExternalProps extends UsePickerValueProps<TValue, any>>({ props, valueManager, valueType, variant, validator, }: UsePickerValueParams<TValue, TExternalProps>) => UsePickerValueResponse<TValue, TSection, InferError<TExternalProps>>;
@@ -113,7 +113,7 @@ export const usePickerValue = ({
113
113
  props,
114
114
  valueManager,
115
115
  valueType,
116
- wrapperVariant,
116
+ variant,
117
117
  validator
118
118
  }) => {
119
119
  const {
@@ -121,8 +121,9 @@ export const usePickerValue = ({
121
121
  onChange,
122
122
  value: inValueWithoutRenderTimezone,
123
123
  defaultValue: inDefaultValue,
124
- closeOnSelect = wrapperVariant === 'desktop',
125
- timezone: timezoneProp
124
+ closeOnSelect = variant === 'desktop',
125
+ timezone: timezoneProp,
126
+ referenceDate
126
127
  } = props;
127
128
  const {
128
129
  current: defaultValue
@@ -130,6 +131,7 @@ export const usePickerValue = ({
130
131
  const {
131
132
  current: isControlled
132
133
  } = React.useRef(inValueWithoutRenderTimezone !== undefined);
134
+ const [previousTimezoneProp, setPreviousTimezoneProp] = React.useState(timezoneProp);
133
135
 
134
136
  /* eslint-disable react-hooks/rules-of-hooks, react-hooks/exhaustive-deps */
135
137
  if (process.env.NODE_ENV !== 'production') {
@@ -160,6 +162,7 @@ export const usePickerValue = ({
160
162
  timezone: timezoneProp,
161
163
  value: inValueWithoutRenderTimezone,
162
164
  defaultValue,
165
+ referenceDate,
163
166
  onChange,
164
167
  valueManager
165
168
  });
@@ -176,10 +179,19 @@ export const usePickerValue = ({
176
179
  draft: initialValue,
177
180
  lastPublishedValue: initialValue,
178
181
  lastCommittedValue: initialValue,
179
- lastControlledValue: inValueWithTimezoneToRender,
182
+ lastControlledValue: inValueWithoutRenderTimezone,
180
183
  hasBeenModifiedSinceMount: false
181
184
  };
182
185
  });
186
+ const timezoneFromDraftValue = valueManager.getTimezone(utils, dateState.draft);
187
+ if (previousTimezoneProp !== timezoneProp) {
188
+ setPreviousTimezoneProp(timezoneProp);
189
+ if (timezoneProp && timezoneFromDraftValue && timezoneProp !== timezoneFromDraftValue) {
190
+ setDateState(prev => _extends({}, prev, {
191
+ draft: valueManager.setTimezone(utils, timezoneProp, prev.draft)
192
+ }));
193
+ }
194
+ }
183
195
  const {
184
196
  getValidationErrorForNewValue
185
197
  } = useValidation({
@@ -229,10 +241,10 @@ export const usePickerValue = ({
229
241
  setIsOpen(false);
230
242
  }
231
243
  });
232
- if (inValueWithTimezoneToRender !== undefined && (dateState.lastControlledValue === undefined || !valueManager.areValuesEqual(utils, dateState.lastControlledValue, inValueWithTimezoneToRender))) {
244
+ if (dateState.lastControlledValue !== inValueWithoutRenderTimezone) {
233
245
  const isUpdateComingFromPicker = valueManager.areValuesEqual(utils, dateState.draft, inValueWithTimezoneToRender);
234
246
  setDateState(prev => _extends({}, prev, {
235
- lastControlledValue: inValueWithTimezoneToRender
247
+ lastControlledValue: inValueWithoutRenderTimezone
236
248
  }, isUpdateComingFromPicker ? {} : {
237
249
  lastCommittedValue: inValueWithTimezoneToRender,
238
250
  lastPublishedValue: inValueWithTimezoneToRender,
@@ -1,7 +1,7 @@
1
1
  import { FieldChangeHandlerContext, UseFieldInternalProps } from '../useField';
2
2
  import { Validator } from '../../../validation';
3
- import { WrapperVariant } from '../../models/common';
4
- import { FieldSection, FieldValueType, TimezoneProps, MuiPickersAdapter, PickersTimezone, PickerChangeHandlerContext, PickerValidDate, OnErrorProps, InferError } from '../../../models';
3
+ import { PickerVariant } from '../../models/common';
4
+ import { FieldSection, TimezoneProps, MuiPickersAdapter, PickersTimezone, PickerChangeHandlerContext, PickerValidDate, OnErrorProps, InferError, PickerValueType } from '../../../models';
5
5
  import { GetDefaultReferenceDateProps } from '../../utils/getDefaultReferenceDate';
6
6
  import { PickerShortcutChangeImportance, PickersShortcutsItemContext } from '../../../PickersShortcuts';
7
7
  export interface PickerValueManager<TValue, TError> {
@@ -23,10 +23,10 @@ export interface PickerValueManager<TValue, TError> {
23
23
  * @template TValue
24
24
  * @param {MuiPickersAdapter} utils The adapter.
25
25
  * @param {PickersTimezone} timezone The current timezone.
26
- * @param {FieldValueType} valueType The type of the value being edited.
26
+ * @param {PickerValueType} valueType The type of the value being edited.
27
27
  * @returns {TValue} The value to set when clicking the "Today" button.
28
28
  */
29
- getTodayValue: (utils: MuiPickersAdapter, timezone: PickersTimezone, valueType: FieldValueType) => TValue;
29
+ getTodayValue: (utils: MuiPickersAdapter, timezone: PickersTimezone, valueType: PickerValueType) => TValue;
30
30
  /**
31
31
  * @template TValue
32
32
  * Method returning the reference value to use when mounting the component.
@@ -122,7 +122,7 @@ export interface UsePickerValueState<TValue> {
122
122
  */
123
123
  lastCommittedValue: TValue;
124
124
  /**
125
- * Last value passed with `props.value`.
125
+ * Last value passed to `props.value`.
126
126
  * Used to update the `draft` value whenever the `value` prop changes.
127
127
  */
128
128
  lastControlledValue: TValue | undefined;
@@ -226,12 +226,13 @@ export interface UsePickerValueNonStaticProps {
226
226
  * Props used to handle the value of the pickers.
227
227
  */
228
228
  export interface UsePickerValueProps<TValue, TError> extends UsePickerValueBaseProps<TValue, TError>, UsePickerValueNonStaticProps, TimezoneProps {
229
+ referenceDate?: PickerValidDate;
229
230
  }
230
231
  export interface UsePickerValueParams<TValue, TExternalProps extends UsePickerValueProps<TValue, any>> {
231
232
  props: TExternalProps;
232
233
  valueManager: PickerValueManager<TValue, InferError<TExternalProps>>;
233
- valueType: FieldValueType;
234
- wrapperVariant: WrapperVariant;
234
+ valueType: PickerValueType;
235
+ variant: PickerVariant;
235
236
  validator: Validator<TValue, InferError<TExternalProps>, TExternalProps>;
236
237
  }
237
238
  export interface UsePickerValueActions {
@@ -77,6 +77,7 @@ export interface UsePickerViewsResponse<TView extends DateOrTimeViewWithMeridiem
77
77
  * Indicates if the the picker has at least one view that should be rendered in UI.
78
78
  */
79
79
  hasUIView: boolean;
80
+ views: readonly TView[];
80
81
  renderCurrentView: () => React.ReactNode;
81
82
  shouldRestoreFocus: () => boolean;
82
83
  layoutProps: UsePickerViewsLayoutResponse<TView>;
@@ -134,6 +134,7 @@ export const usePickerViews = ({
134
134
  };
135
135
  return {
136
136
  hasUIView,
137
+ views,
137
138
  shouldRestoreFocus,
138
139
  layoutProps,
139
140
  renderCurrentView: () => {
@@ -48,7 +48,7 @@ export const useStaticPicker = _ref => {
48
48
  fieldRef: undefined,
49
49
  localeText,
50
50
  additionalViewProps: {},
51
- wrapperVariant: displayStaticWrapperAs
51
+ variant: displayStaticWrapperAs
52
52
  }));
53
53
  const Layout = slots?.layout ?? PickerStaticLayout;
54
54
  const renderPicker = () => /*#__PURE__*/_jsx(PickerProvider, _extends({}, providerProps, {
@@ -1,17 +1,11 @@
1
1
  import type { PickerValueManager } from './usePicker';
2
- import { PickersTimezone } from '../../models';
2
+ import { PickersTimezone, PickerValidDate } from '../../models';
3
3
  /**
4
4
  * Hooks making sure that:
5
5
  * - The value returned by `onChange` always have the timezone of `props.value` or `props.defaultValue` if defined
6
6
  * - The value rendered is always the one from `props.timezone` if defined
7
7
  */
8
- export declare const useValueWithTimezone: <TValue, TChange extends (...params: any[]) => void>({ timezone: timezoneProp, value: valueProp, defaultValue, onChange, valueManager, }: {
9
- timezone: PickersTimezone | undefined;
10
- value: TValue | undefined;
11
- defaultValue: TValue | undefined;
12
- onChange: TChange | undefined;
13
- valueManager: PickerValueManager<TValue, any>;
14
- }) => {
8
+ export declare const useValueWithTimezone: <TValue, TChange extends (...params: any[]) => void>({ timezone: timezoneProp, value: valueProp, defaultValue, referenceDate, onChange, valueManager, }: UseValueWithTimezoneParameters<TValue, TChange>) => {
15
9
  value: TValue;
16
10
  handleValueChange: TChange;
17
11
  timezone: string;
@@ -19,15 +13,25 @@ export declare const useValueWithTimezone: <TValue, TChange extends (...params:
19
13
  /**
20
14
  * Wrapper around `useControlled` and `useValueWithTimezone`
21
15
  */
22
- export declare const useControlledValueWithTimezone: <TValue, TChange extends (...params: any[]) => void>({ name, timezone: timezoneProp, value: valueProp, defaultValue, onChange: onChangeProp, valueManager, }: {
23
- name: string;
16
+ export declare const useControlledValueWithTimezone: <TValue, TChange extends (...params: any[]) => void>({ name, timezone: timezoneProp, value: valueProp, defaultValue, referenceDate, onChange: onChangeProp, valueManager, }: UseControlledValueWithTimezoneParameters<TValue, TChange>) => {
17
+ value: TValue;
18
+ handleValueChange: TChange;
19
+ timezone: string;
20
+ };
21
+ interface UseValueWithTimezoneParameters<TValue, TChange extends (...params: any[]) => void> {
24
22
  timezone: PickersTimezone | undefined;
25
23
  value: TValue | undefined;
26
24
  defaultValue: TValue | undefined;
25
+ /**
26
+ * The reference date as passed to `props.referenceDate`.
27
+ * It does not need to have its default value.
28
+ * This is only used to determine the timezone to use when `props.value` and `props.defaultValue` are not defined.
29
+ */
30
+ referenceDate: PickerValidDate | undefined;
27
31
  onChange: TChange | undefined;
28
32
  valueManager: PickerValueManager<TValue, any>;
29
- }) => {
30
- value: TValue;
31
- handleValueChange: TChange;
32
- timezone: string;
33
- };
33
+ }
34
+ interface UseControlledValueWithTimezoneParameters<TValue, TChange extends (...params: any[]) => void> extends UseValueWithTimezoneParameters<TValue, TChange> {
35
+ name: string;
36
+ }
37
+ export {};
@@ -11,6 +11,7 @@ export const useValueWithTimezone = ({
11
11
  timezone: timezoneProp,
12
12
  value: valueProp,
13
13
  defaultValue,
14
+ referenceDate,
14
15
  onChange,
15
16
  valueManager
16
17
  }) => {
@@ -24,7 +25,16 @@ export const useValueWithTimezone = ({
24
25
  }
25
26
  return valueManager.setTimezone(utils, inputTimezone, newValue);
26
27
  });
27
- const timezoneToRender = timezoneProp ?? inputTimezone ?? 'default';
28
+ let timezoneToRender;
29
+ if (timezoneProp) {
30
+ timezoneToRender = timezoneProp;
31
+ } else if (inputTimezone) {
32
+ timezoneToRender = inputTimezone;
33
+ } else if (referenceDate) {
34
+ timezoneToRender = utils.getTimezone(referenceDate);
35
+ } else {
36
+ timezoneToRender = 'default';
37
+ }
28
38
  const valueWithTimezoneToRender = React.useMemo(() => valueManager.setTimezone(utils, timezoneToRender, inputValue), [valueManager, utils, timezoneToRender, inputValue]);
29
39
  const handleValueChange = useEventCallback((newValue, ...otherParams) => {
30
40
  const newValueWithInputTimezone = setInputTimezone(newValue);
@@ -45,6 +55,7 @@ export const useControlledValueWithTimezone = ({
45
55
  timezone: timezoneProp,
46
56
  value: valueProp,
47
57
  defaultValue,
58
+ referenceDate,
48
59
  onChange: onChangeProp,
49
60
  valueManager
50
61
  }) => {
@@ -62,6 +73,7 @@ export const useControlledValueWithTimezone = ({
62
73
  timezone: timezoneProp,
63
74
  value: valueWithInputTimezone,
64
75
  defaultValue: undefined,
76
+ referenceDate,
65
77
  onChange,
66
78
  valueManager
67
79
  });
@@ -44,7 +44,7 @@ export type { BaseClockProps, DesktopOnlyTimePickerProps, AmPmProps } from './mo
44
44
  export type { BaseTabsProps, ExportedBaseTabsProps } from './models/props/tabs';
45
45
  export type { BaseToolbarProps, ExportedBaseToolbarProps } from './models/props/toolbar';
46
46
  export type { FormProps } from './models/formProps';
47
- export type { WrapperVariant, TimeViewWithMeridiem, DateOrTimeViewWithMeridiem, } from './models/common';
47
+ export type { PickerVariant, TimeViewWithMeridiem, DateOrTimeViewWithMeridiem, } from './models/common';
48
48
  export type { BaseDateValidationProps, BaseTimeValidationProps, TimeValidationProps, MonthValidationProps, YearValidationProps, DayValidationProps, DateTimeValidationProps, } from './models/validation';
49
49
  export type { PickerRangeValue } from './models/value';
50
50
  export { convertFieldResponseIntoMuiTextFieldProps } from './utils/convertFieldResponseIntoMuiTextFieldProps';
@@ -1,4 +1,5 @@
1
1
  import { DateView, TimeView } from '../../models/views';
2
- export type WrapperVariant = 'mobile' | 'desktop' | null;
2
+ export type PickerOrientation = 'portrait' | 'landscape';
3
+ export type PickerVariant = 'mobile' | 'desktop' | null;
3
4
  export type TimeViewWithMeridiem = TimeView | 'meridiem';
4
5
  export type DateOrTimeViewWithMeridiem = DateView | TimeViewWithMeridiem;
@@ -2,8 +2,7 @@ import * as React from 'react';
2
2
  import { SxProps } from '@mui/system';
3
3
  import { Theme } from '@mui/material/styles';
4
4
  import { DateOrTimeViewWithMeridiem } from '../common';
5
- import { FormProps } from '../formProps';
6
- export interface BaseToolbarProps<TValue, TView extends DateOrTimeViewWithMeridiem> extends ExportedBaseToolbarProps, FormProps {
5
+ export interface BaseToolbarProps<TValue, TView extends DateOrTimeViewWithMeridiem> extends ExportedBaseToolbarProps {
7
6
  isLandscape: boolean;
8
7
  onChange: (newValue: TValue) => void;
9
8
  value: TValue;
@@ -1,4 +1,4 @@
1
- import { DateView, FieldValueType, MuiPickersAdapter, PickersTimezone, PickerValidDate } from '../../models';
1
+ import { DateView, MuiPickersAdapter, PickersTimezone, PickerValidDate, PickerValueType } from '../../models';
2
2
  import { DateOrTimeViewWithMeridiem } from '../models';
3
3
  export declare const mergeDateAndTime: (utils: MuiPickersAdapter, dateParam: PickerValidDate, timeParam: PickerValidDate) => PickerValidDate;
4
4
  interface FindClosestDateParams {
@@ -16,7 +16,7 @@ export declare const replaceInvalidDateByNull: (utils: MuiPickersAdapter, value:
16
16
  export declare const applyDefaultDate: (utils: MuiPickersAdapter, value: PickerValidDate | null | undefined, defaultValue: PickerValidDate) => PickerValidDate;
17
17
  export declare const areDatesEqual: (utils: MuiPickersAdapter, a: PickerValidDate, b: PickerValidDate) => boolean;
18
18
  export declare const getMonthsInYear: (utils: MuiPickersAdapter, year: PickerValidDate) => PickerValidDate[];
19
- export declare const getTodayDate: (utils: MuiPickersAdapter, timezone: PickersTimezone, valueType?: FieldValueType) => PickerValidDate;
19
+ export declare const getTodayDate: (utils: MuiPickersAdapter, timezone: PickersTimezone, valueType?: PickerValueType) => PickerValidDate;
20
20
  export declare const formatMeridiem: (utils: MuiPickersAdapter, meridiem: "am" | "pm") => string;
21
21
  export declare const isDatePickerView: (view: DateOrTimeViewWithMeridiem) => view is DateView;
22
22
  export declare const resolveDateFormat: (utils: MuiPickersAdapter, { format, views }: {
@@ -3,3 +3,4 @@ export interface TimeStepOptions {
3
3
  minutes?: number;
4
4
  seconds?: number;
5
5
  }
6
+ export type PickerValueType = 'date' | 'time' | 'date-time';
@@ -7,7 +7,6 @@ import type { PickersTextFieldProps } from '../PickersTextField';
7
7
  import { BaseForwardedSingleInputFieldProps } from '../internals/models';
8
8
  export type FieldSectionType = 'year' | 'month' | 'day' | 'weekDay' | 'hours' | 'minutes' | 'seconds' | 'meridiem' | 'empty';
9
9
  export type FieldSectionContentType = 'digit' | 'digit-with-letter' | 'letter';
10
- export type FieldValueType = 'date' | 'time' | 'date-time';
11
10
  export interface FieldSection {
12
11
  /**
13
12
  * Value of the section, as rendered inside the input.
@@ -1,3 +1,4 @@
1
+ import { PickerOrientation, PickerVariant } from '../internals/models/common';
1
2
  import type { PickersShortcutsItemContext } from '../PickersShortcuts';
2
3
  export interface PickerChangeHandlerContext<TError> {
3
4
  validationError: TError;
@@ -31,4 +32,21 @@ export interface PickerOwnerState {
31
32
  * Is always `false` if the component you are accessing the ownerState from is not wrapped by a picker.
32
33
  */
33
34
  isPickerReadOnly: boolean;
35
+ /**
36
+ * The responsive variant of the picker.
37
+ * Is equal to "desktop" when using a desktop picker (like <DesktopDatePicker />).
38
+ * Is equal to "mobile" when using a mobile picker (like <MobileDatePicker />).
39
+ * Is equal to "mobile" or "desktop" when using a responsive picker (like <DatePicker />) depending on the `desktopModeMediaQuery` prop.
40
+ * Is equal to "mobile" or "desktop" when using a static picker (like <StaticDatePicker />) depending on the `displayStaticWrapperAs` prop.
41
+ * Is always equal to "desktop" if the component you are accessing the ownerState from is not wrapped by a picker.
42
+ */
43
+ pickerVariant: PickerVariant;
44
+ /**
45
+ * The orientation of the picker.
46
+ * Is equal to "landscape" when the picker is in landscape orientation.
47
+ * Is equal to "portrait" when the picker is in portrait orientation.
48
+ * You can use the "orientation" on any picker component to force the orientation.
49
+ * Is always equal to "portrait" if the component you are accessing the ownerState from is not wrapped by a picker.
50
+ */
51
+ pickerOrientation: PickerOrientation;
34
52
  }
@@ -137,6 +137,7 @@ export const DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(
137
137
  timezone: timezoneProp,
138
138
  value: valueProp,
139
139
  defaultValue,
140
+ referenceDate: referenceDateProp,
140
141
  onChange,
141
142
  valueManager: singleItemValueManager
142
143
  });
@@ -107,12 +107,6 @@ process.env.NODE_ENV !== "production" ? DatePickerToolbar.propTypes = {
107
107
  */
108
108
  classes: PropTypes.object,
109
109
  className: PropTypes.string,
110
- /**
111
- * If `true`, the component is disabled.
112
- * When disabled, the value cannot be changed and no interaction is possible.
113
- * @default false
114
- */
115
- disabled: PropTypes.bool,
116
110
  /**
117
111
  * If `true`, show the toolbar even in desktop mode.
118
112
  * @default `true` for Desktop, `false` for Mobile.
@@ -126,12 +120,6 @@ process.env.NODE_ENV !== "production" ? DatePickerToolbar.propTypes = {
126
120
  * @param {TView} view The view to open
127
121
  */
128
122
  onViewChange: PropTypes.func.isRequired,
129
- /**
130
- * If `true`, the component is read-only.
131
- * When read-only, the value cannot be changed but the user can interact with the interface.
132
- * @default false
133
- */
134
- readOnly: PropTypes.bool,
135
123
  /**
136
124
  * The system prop that allows defining system overrides as well as additional CSS styles.
137
125
  */
@@ -2,7 +2,7 @@
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- const _excluded = ["ampm", "ampmInClock", "value", "onChange", "view", "isLandscape", "onViewChange", "toolbarFormat", "toolbarPlaceholder", "views", "disabled", "readOnly", "toolbarVariant", "toolbarTitle", "className"];
5
+ const _excluded = ["ampm", "ampmInClock", "value", "onChange", "view", "isLandscape", "onViewChange", "toolbarFormat", "toolbarPlaceholder", "views", "toolbarVariant", "toolbarTitle", "className"];
6
6
  import * as React from 'react';
7
7
  import PropTypes from 'prop-types';
8
8
  import { useRtl } from '@mui/system/RtlProvider';
@@ -20,6 +20,7 @@ import { MULTI_SECTION_CLOCK_SECTION_WIDTH } from "../internals/constants/dimens
20
20
  import { formatMeridiem } from "../internals/utils/date-utils.js";
21
21
  import { pickersToolbarTextClasses } from "../internals/components/pickersToolbarTextClasses.js";
22
22
  import { pickersToolbarClasses } from "../internals/components/pickersToolbarClasses.js";
23
+ import { usePickerContext } from "../hooks/usePickerContext.js";
23
24
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
25
  const useUtilityClasses = ownerState => {
25
26
  const {
@@ -226,14 +227,16 @@ function DateTimePickerToolbar(inProps) {
226
227
  toolbarFormat,
227
228
  toolbarPlaceholder = '––',
228
229
  views,
229
- disabled,
230
- readOnly,
231
230
  toolbarVariant = 'mobile',
232
231
  toolbarTitle: inToolbarTitle,
233
232
  className
234
233
  } = props,
235
234
  other = _objectWithoutPropertiesLoose(props, _excluded);
236
235
  const isRtl = useRtl();
236
+ const {
237
+ disabled,
238
+ readOnly
239
+ } = usePickerContext();
237
240
  const ownerState = _extends({}, props, {
238
241
  isRtl
239
242
  });
@@ -359,12 +362,6 @@ process.env.NODE_ENV !== "production" ? DateTimePickerToolbar.propTypes = {
359
362
  */
360
363
  classes: PropTypes.object,
361
364
  className: PropTypes.string,
362
- /**
363
- * If `true`, the component is disabled.
364
- * When disabled, the value cannot be changed and no interaction is possible.
365
- * @default false
366
- */
367
- disabled: PropTypes.bool,
368
365
  /**
369
366
  * If `true`, show the toolbar even in desktop mode.
370
367
  * @default `true` for Desktop, `false` for Mobile.
@@ -378,12 +375,6 @@ process.env.NODE_ENV !== "production" ? DateTimePickerToolbar.propTypes = {
378
375
  * @param {TView} view The view to open
379
376
  */
380
377
  onViewChange: PropTypes.func.isRequired,
381
- /**
382
- * If `true`, the component is read-only.
383
- * When read-only, the value cannot be changed but the user can interact with the interface.
384
- * @default false
385
- */
386
- readOnly: PropTypes.bool,
387
378
  /**
388
379
  * The system prop that allows defining system overrides as well as additional CSS styles.
389
380
  */
@@ -66,12 +66,6 @@ process.env.NODE_ENV !== "production" ? DesktopDateTimePickerLayout.propTypes =
66
66
  */
67
67
  classes: PropTypes.object,
68
68
  className: PropTypes.string,
69
- /**
70
- * If `true`, the component is disabled.
71
- * When disabled, the value cannot be changed and no interaction is possible.
72
- * @default false
73
- */
74
- disabled: PropTypes.bool,
75
69
  isLandscape: PropTypes.bool.isRequired,
76
70
  /**
77
71
  * `true` if the application is in right-to-left direction.
@@ -92,12 +86,6 @@ process.env.NODE_ENV !== "production" ? DesktopDateTimePickerLayout.propTypes =
92
86
  * Force rendering in particular orientation.
93
87
  */
94
88
  orientation: PropTypes.oneOf(['landscape', 'portrait']),
95
- /**
96
- * If `true`, the component is read-only.
97
- * When read-only, the value cannot be changed but the user can interact with the interface.
98
- * @default false
99
- */
100
- readOnly: PropTypes.bool,
101
89
  /**
102
90
  * The props used for each component slot.
103
91
  * @default {}
@@ -149,6 +149,7 @@ export const DigitalClock = /*#__PURE__*/React.forwardRef(function DigitalClock(
149
149
  timezone: timezoneProp,
150
150
  value: valueProp,
151
151
  defaultValue,
152
+ referenceDate: referenceDateProp,
152
153
  onChange,
153
154
  valueManager: singleItemValueManager
154
155
  });
@@ -98,6 +98,7 @@ export const MonthCalendar = /*#__PURE__*/React.forwardRef(function MonthCalenda
98
98
  timezone: timezoneProp,
99
99
  value: valueProp,
100
100
  defaultValue,
101
+ referenceDate: referenceDateProp,
101
102
  onChange,
102
103
  valueManager: singleItemValueManager
103
104
  });
@@ -101,6 +101,7 @@ export const MultiSectionDigitalClock = /*#__PURE__*/React.forwardRef(function M
101
101
  timezone: timezoneProp,
102
102
  value: valueProp,
103
103
  defaultValue,
104
+ referenceDate: referenceDateProp,
104
105
  onChange,
105
106
  valueManager: singleItemValueManager
106
107
  });
@@ -145,12 +145,6 @@ process.env.NODE_ENV !== "production" ? PickersLayout.propTypes = {
145
145
  */
146
146
  classes: PropTypes.object,
147
147
  className: PropTypes.string,
148
- /**
149
- * If `true`, the component is disabled.
150
- * When disabled, the value cannot be changed and no interaction is possible.
151
- * @default false
152
- */
153
- disabled: PropTypes.bool,
154
148
  isLandscape: PropTypes.bool.isRequired,
155
149
  /**
156
150
  * `true` if the application is in right-to-left direction.
@@ -171,12 +165,6 @@ process.env.NODE_ENV !== "production" ? PickersLayout.propTypes = {
171
165
  * Force rendering in particular orientation.
172
166
  */
173
167
  orientation: PropTypes.oneOf(['landscape', 'portrait']),
174
- /**
175
- * If `true`, the component is read-only.
176
- * When read-only, the value cannot be changed but the user can interact with the interface.
177
- * @default false
178
- */
179
- readOnly: PropTypes.bool,
180
168
  /**
181
169
  * The props used for each component slot.
182
170
  * @default {}
@@ -45,8 +45,6 @@ const usePickerLayout = props => {
45
45
  onSelectShortcut,
46
46
  isValid,
47
47
  isLandscape,
48
- disabled,
49
- readOnly,
50
48
  children,
51
49
  slots,
52
50
  slotProps,
@@ -90,9 +88,7 @@ const usePickerLayout = props => {
90
88
  value,
91
89
  view,
92
90
  onViewChange,
93
- views,
94
- disabled,
95
- readOnly
91
+ views
96
92
  },
97
93
  className: classes.toolbar,
98
94
  ownerState