@mui/x-date-pickers-pro 8.0.0-alpha.5 → 8.0.0-alpha.7

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 (148) hide show
  1. package/{AdapterDateFnsJalaliV3 → AdapterDateFnsJalaliV2}/index.d.ts +1 -1
  2. package/{AdapterDateFnsJalaliV3 → AdapterDateFnsJalaliV2}/index.js +1 -1
  3. package/{AdapterDateFnsJalaliV3 → AdapterDateFnsJalaliV2}/package.json +1 -1
  4. package/{AdapterDateFnsV3 → AdapterDateFnsV2}/index.d.ts +1 -1
  5. package/{AdapterDateFnsV3 → AdapterDateFnsV2}/index.js +1 -1
  6. package/{AdapterDateFnsV3 → AdapterDateFnsV2}/package.json +1 -1
  7. package/CHANGELOG.md +206 -1
  8. package/DateRangeCalendar/DateRangeCalendar.js +9 -7
  9. package/DateRangePicker/DateRangePicker.js +1 -1
  10. package/DateRangePicker/DateRangePicker.types.d.ts +5 -0
  11. package/DateRangePicker/DateRangePickerToolbar.d.ts +2 -3
  12. package/DateRangePicker/DateRangePickerToolbar.js +25 -31
  13. package/DateRangePicker/shared.d.ts +1 -1
  14. package/DateTimeRangePicker/DateTimeRangePicker.js +2 -2
  15. package/DateTimeRangePicker/DateTimeRangePickerTabs.d.ts +4 -5
  16. package/DateTimeRangePicker/DateTimeRangePickerTabs.js +25 -24
  17. package/DateTimeRangePicker/DateTimeRangePickerTimeWrapper.d.ts +8 -10
  18. package/DateTimeRangePicker/DateTimeRangePickerTimeWrapper.js +7 -5
  19. package/DateTimeRangePicker/DateTimeRangePickerToolbar.d.ts +2 -4
  20. package/DateTimeRangePicker/DateTimeRangePickerToolbar.js +66 -69
  21. package/DateTimeRangePicker/shared.d.ts +2 -2
  22. package/DesktopDateRangePicker/DesktopDateRangePicker.js +9 -3
  23. package/DesktopDateRangePicker/DesktopDateRangePicker.types.d.ts +7 -2
  24. package/DesktopDateTimeRangePicker/DesktopDateTimeRangePicker.js +17 -14
  25. package/DesktopDateTimeRangePicker/DesktopDateTimeRangePicker.types.d.ts +2 -3
  26. package/MobileDateRangePicker/MobileDateRangePicker.js +2 -2
  27. package/MobileDateRangePicker/MobileDateRangePicker.types.d.ts +2 -2
  28. package/MobileDateTimeRangePicker/MobileDateTimeRangePicker.js +15 -8
  29. package/MobileDateTimeRangePicker/MobileDateTimeRangePicker.types.d.ts +2 -3
  30. package/SingleInputDateRangeField/useSingleInputDateRangeField.d.ts +1 -1
  31. package/SingleInputDateRangeField/useSingleInputDateRangeField.js +13 -14
  32. package/SingleInputDateTimeRangeField/useSingleInputDateTimeRangeField.d.ts +1 -1
  33. package/SingleInputDateTimeRangeField/useSingleInputDateTimeRangeField.js +13 -14
  34. package/SingleInputTimeRangeField/useSingleInputTimeRangeField.d.ts +1 -1
  35. package/SingleInputTimeRangeField/useSingleInputTimeRangeField.js +13 -14
  36. package/StaticDateRangePicker/StaticDateRangePicker.types.d.ts +2 -2
  37. package/dateRangeViewRenderers/dateRangeViewRenderers.d.ts +2 -2
  38. package/dateRangeViewRenderers/dateRangeViewRenderers.js +0 -6
  39. package/hooks/index.d.ts +1 -0
  40. package/hooks/index.js +1 -0
  41. package/hooks/package.json +6 -0
  42. package/hooks/usePickerRangePositionContext.d.ts +7 -0
  43. package/hooks/usePickerRangePositionContext.js +15 -0
  44. package/index.d.ts +2 -0
  45. package/index.js +4 -2
  46. package/internals/hooks/models/useRangePicker.d.ts +4 -4
  47. package/internals/hooks/useDesktopRangePicker/useDesktopRangePicker.js +35 -53
  48. package/internals/hooks/useDesktopRangePicker/useDesktopRangePicker.types.d.ts +7 -9
  49. package/internals/hooks/useEnrichedRangePickerFieldProps.d.ts +6 -6
  50. package/internals/hooks/useEnrichedRangePickerFieldProps.js +11 -8
  51. package/internals/hooks/useMobileRangePicker/useMobileRangePicker.js +24 -40
  52. package/internals/hooks/useMobileRangePicker/useMobileRangePicker.types.d.ts +7 -9
  53. package/internals/hooks/useMultiInputFieldSelectedSections.d.ts +10 -12
  54. package/internals/hooks/useMultiInputRangeField/useMultiInputDateRangeField.d.ts +1 -1
  55. package/internals/hooks/useMultiInputRangeField/useMultiInputDateRangeField.js +11 -6
  56. package/internals/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField.d.ts +2 -2
  57. package/internals/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField.js +12 -7
  58. package/internals/hooks/useMultiInputRangeField/useMultiInputTimeRangeField.d.ts +2 -2
  59. package/internals/hooks/useMultiInputRangeField/useMultiInputTimeRangeField.js +13 -8
  60. package/internals/hooks/useNullablePickerRangePositionContext.d.ts +5 -0
  61. package/internals/hooks/useNullablePickerRangePositionContext.js +10 -0
  62. package/internals/hooks/useRangePosition.d.ts +1 -1
  63. package/internals/hooks/useStaticRangePicker/useStaticRangePicker.js +14 -24
  64. package/internals/hooks/useStaticRangePicker/useStaticRangePicker.types.d.ts +6 -6
  65. package/internals/utils/date-range-manager.js +2 -1
  66. package/internals/utils/releaseInfo.js +1 -1
  67. package/internals/utils/valueManagers.js +7 -7
  68. package/managers/index.d.ts +6 -0
  69. package/managers/index.js +3 -0
  70. package/managers/package.json +6 -0
  71. package/managers/useDateRangeManager.d.ts +15 -0
  72. package/managers/useDateRangeManager.js +31 -0
  73. package/managers/useDateTimeRangeManager.d.ts +15 -0
  74. package/managers/useDateTimeRangeManager.js +31 -0
  75. package/managers/useTimeRangeManager.d.ts +15 -0
  76. package/managers/useTimeRangeManager.js +29 -0
  77. package/models/range.d.ts +0 -1
  78. package/modern/{AdapterDateFnsJalaliV3 → AdapterDateFnsJalaliV2}/index.js +1 -1
  79. package/modern/{AdapterDateFnsV3 → AdapterDateFnsV2}/index.js +1 -1
  80. package/modern/DateRangeCalendar/DateRangeCalendar.js +9 -7
  81. package/modern/DateRangePicker/DateRangePicker.js +1 -1
  82. package/modern/DateRangePicker/DateRangePickerToolbar.js +25 -31
  83. package/modern/DateTimeRangePicker/DateTimeRangePicker.js +2 -2
  84. package/modern/DateTimeRangePicker/DateTimeRangePickerTabs.js +25 -24
  85. package/modern/DateTimeRangePicker/DateTimeRangePickerTimeWrapper.js +7 -5
  86. package/modern/DateTimeRangePicker/DateTimeRangePickerToolbar.js +66 -69
  87. package/modern/DesktopDateRangePicker/DesktopDateRangePicker.js +9 -3
  88. package/modern/DesktopDateTimeRangePicker/DesktopDateTimeRangePicker.js +17 -14
  89. package/modern/MobileDateRangePicker/MobileDateRangePicker.js +2 -2
  90. package/modern/MobileDateTimeRangePicker/MobileDateTimeRangePicker.js +15 -8
  91. package/modern/SingleInputDateRangeField/useSingleInputDateRangeField.js +13 -14
  92. package/modern/SingleInputDateTimeRangeField/useSingleInputDateTimeRangeField.js +13 -14
  93. package/modern/SingleInputTimeRangeField/useSingleInputTimeRangeField.js +13 -14
  94. package/modern/dateRangeViewRenderers/dateRangeViewRenderers.js +0 -6
  95. package/modern/hooks/index.js +1 -0
  96. package/modern/hooks/usePickerRangePositionContext.js +15 -0
  97. package/modern/index.js +4 -2
  98. package/modern/internals/hooks/useDesktopRangePicker/useDesktopRangePicker.js +35 -53
  99. package/modern/internals/hooks/useEnrichedRangePickerFieldProps.js +11 -8
  100. package/modern/internals/hooks/useMobileRangePicker/useMobileRangePicker.js +24 -40
  101. package/modern/internals/hooks/useMultiInputRangeField/useMultiInputDateRangeField.js +11 -6
  102. package/modern/internals/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField.js +12 -7
  103. package/modern/internals/hooks/useMultiInputRangeField/useMultiInputTimeRangeField.js +13 -8
  104. package/modern/internals/hooks/useNullablePickerRangePositionContext.js +10 -0
  105. package/modern/internals/hooks/useStaticRangePicker/useStaticRangePicker.js +14 -24
  106. package/modern/internals/utils/date-range-manager.js +2 -1
  107. package/modern/internals/utils/releaseInfo.js +1 -1
  108. package/modern/internals/utils/valueManagers.js +7 -7
  109. package/modern/managers/index.js +3 -0
  110. package/modern/managers/useDateRangeManager.js +31 -0
  111. package/modern/managers/useDateTimeRangeManager.js +31 -0
  112. package/modern/managers/useTimeRangeManager.js +29 -0
  113. package/node/{AdapterDateFnsJalaliV3 → AdapterDateFnsJalaliV2}/index.js +1 -1
  114. package/node/{AdapterDateFnsV3 → AdapterDateFnsV2}/index.js +1 -1
  115. package/node/DateRangeCalendar/DateRangeCalendar.js +9 -7
  116. package/node/DateRangePicker/DateRangePicker.js +1 -1
  117. package/node/DateRangePicker/DateRangePickerToolbar.js +24 -30
  118. package/node/DateTimeRangePicker/DateTimeRangePicker.js +2 -2
  119. package/node/DateTimeRangePicker/DateTimeRangePickerTabs.js +24 -23
  120. package/node/DateTimeRangePicker/DateTimeRangePickerTimeWrapper.js +7 -5
  121. package/node/DateTimeRangePicker/DateTimeRangePickerToolbar.js +65 -68
  122. package/node/DesktopDateRangePicker/DesktopDateRangePicker.js +9 -3
  123. package/node/DesktopDateTimeRangePicker/DesktopDateTimeRangePicker.js +17 -14
  124. package/node/MobileDateRangePicker/MobileDateRangePicker.js +2 -2
  125. package/node/MobileDateTimeRangePicker/MobileDateTimeRangePicker.js +15 -8
  126. package/node/SingleInputDateRangeField/useSingleInputDateRangeField.js +12 -14
  127. package/node/SingleInputDateTimeRangeField/useSingleInputDateTimeRangeField.js +12 -14
  128. package/node/SingleInputTimeRangeField/useSingleInputTimeRangeField.js +12 -14
  129. package/node/dateRangeViewRenderers/dateRangeViewRenderers.js +0 -6
  130. package/node/hooks/index.js +12 -0
  131. package/node/hooks/usePickerRangePositionContext.js +22 -0
  132. package/node/index.js +23 -1
  133. package/node/internals/hooks/useDesktopRangePicker/useDesktopRangePicker.js +35 -53
  134. package/node/internals/hooks/useEnrichedRangePickerFieldProps.js +11 -8
  135. package/node/internals/hooks/useMobileRangePicker/useMobileRangePicker.js +24 -40
  136. package/node/internals/hooks/useMultiInputRangeField/useMultiInputDateRangeField.js +10 -5
  137. package/node/internals/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField.js +11 -6
  138. package/node/internals/hooks/useMultiInputRangeField/useMultiInputTimeRangeField.js +12 -7
  139. package/node/internals/hooks/useNullablePickerRangePositionContext.js +16 -0
  140. package/node/internals/hooks/useStaticRangePicker/useStaticRangePicker.js +14 -24
  141. package/node/internals/utils/date-range-manager.js +2 -1
  142. package/node/internals/utils/releaseInfo.js +1 -1
  143. package/node/internals/utils/valueManagers.js +7 -7
  144. package/node/managers/index.js +26 -0
  145. package/node/managers/useDateRangeManager.js +38 -0
  146. package/node/managers/useDateTimeRangeManager.js +38 -0
  147. package/node/managers/useTimeRangeManager.js +36 -0
  148. package/package.json +5 -5
@@ -27,6 +27,7 @@ import { useDragRange } from "./useDragRange.js";
27
27
  import { useRangePosition } from "../internals/hooks/useRangePosition.js";
28
28
  import { DAY_RANGE_SIZE, DAY_MARGIN } from "../internals/constants/dimensions.js";
29
29
  import { PickersRangeCalendarHeader } from "../PickersRangeCalendarHeader/index.js";
30
+ import { useNullablePickerRangePositionContext } from "../internals/hooks/useNullablePickerRangePositionContext.js";
30
31
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
31
32
  const releaseInfo = getReleaseInfo();
32
33
  const DateRangeCalendarRoot = styled('div', {
@@ -135,8 +136,8 @@ const DateRangeCalendar = /*#__PURE__*/React.forwardRef(function DateRangeCalend
135
136
  reduceAnimations,
136
137
  onMonthChange,
137
138
  rangePosition: rangePositionProp,
138
- defaultRangePosition: inDefaultRangePosition,
139
- onRangePositionChange: inOnRangePositionChange,
139
+ defaultRangePosition: defaultRangePositionProp,
140
+ onRangePositionChange: onRangePositionChangeProp,
140
141
  calendars,
141
142
  currentMonthCalendarPosition = 1,
142
143
  slots,
@@ -161,6 +162,7 @@ const DateRangeCalendar = /*#__PURE__*/React.forwardRef(function DateRangeCalend
161
162
  onViewChange
162
163
  } = props,
163
164
  other = _objectWithoutPropertiesLoose(props, _excluded);
165
+ const rangePositionContext = useNullablePickerRangePositionContext();
164
166
  const {
165
167
  value,
166
168
  handleValueChange,
@@ -192,9 +194,9 @@ const DateRangeCalendar = /*#__PURE__*/React.forwardRef(function DateRangeCalend
192
194
  rangePosition,
193
195
  onRangePositionChange
194
196
  } = useRangePosition({
195
- rangePosition: rangePositionProp,
196
- defaultRangePosition: inDefaultRangePosition,
197
- onRangePositionChange: inOnRangePositionChange
197
+ rangePosition: rangePositionProp ?? rangePositionContext?.rangePosition,
198
+ defaultRangePosition: defaultRangePositionProp,
199
+ onRangePositionChange: onRangePositionChangeProp ?? rangePositionContext?.onRangePositionChange
198
200
  });
199
201
  const handleDatePositionChange = useEventCallback(position => {
200
202
  if (rangePosition !== position) {
@@ -228,7 +230,7 @@ const DateRangeCalendar = /*#__PURE__*/React.forwardRef(function DateRangeCalend
228
230
 
229
231
  // Range going for the start of the start day to the end of the end day.
230
232
  // This makes sure that `isWithinRange` works with any time in the start and end day.
231
- const valueDayRange = React.useMemo(() => [value[0] == null || !utils.isValid(value[0]) ? value[0] : utils.startOfDay(value[0]), value[1] == null || !utils.isValid(value[1]) ? value[1] : utils.endOfDay(value[1])], [value, utils]);
233
+ const valueDayRange = React.useMemo(() => [!utils.isValid(value[0]) ? value[0] : utils.startOfDay(value[0]), !utils.isValid(value[1]) ? value[1] : utils.endOfDay(value[1])], [value, utils]);
232
234
  const _useDragRange = useDragRange({
233
235
  disableDragEditing: shouldDisableDragEditing,
234
236
  onDrop: handleDrop,
@@ -316,7 +318,7 @@ const DateRangeCalendar = /*#__PURE__*/React.forwardRef(function DateRangeCalend
316
318
  const prevValue = React.useRef(null);
317
319
  React.useEffect(() => {
318
320
  const date = rangePosition === 'start' ? value[0] : value[1];
319
- if (!date || !utils.isValid(date)) {
321
+ if (!utils.isValid(date)) {
320
322
  return;
321
323
  }
322
324
  const prevDate = rangePosition === 'start' ? prevValue.current?.[0] : prevValue.current?.[1];
@@ -63,7 +63,7 @@ process.env.NODE_ENV !== "production" ? DateRangePicker.propTypes = {
63
63
  calendars: PropTypes.oneOf([1, 2, 3]),
64
64
  className: PropTypes.string,
65
65
  /**
66
- * If `true`, the popover or modal will close after submitting the full date.
66
+ * If `true`, the Picker will close after submitting the full date.
67
67
  * @default `true` for desktop, `false` for mobile (based on the chosen wrapper and `desktopModeMediaQuery` prop).
68
68
  */
69
69
  closeOnSelect: PropTypes.bool,
@@ -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 = ["value", "rangePosition", "onRangePositionChange", "toolbarFormat", "className", "classes", "onViewChange", "view", "views"];
5
+ const _excluded = ["toolbarFormat", "className", "classes"];
6
6
  import * as React from 'react';
7
7
  import PropTypes from 'prop-types';
8
8
  import clsx from 'clsx';
@@ -10,8 +10,9 @@ import Typography from '@mui/material/Typography';
10
10
  import { styled, useThemeProps } from '@mui/material/styles';
11
11
  import composeClasses from '@mui/utils/composeClasses';
12
12
  import { PickersToolbar, PickersToolbarButton, useUtils, useToolbarOwnerState } from '@mui/x-date-pickers/internals';
13
- import { usePickerTranslations } from '@mui/x-date-pickers/hooks';
13
+ import { usePickerContext, usePickerTranslations } from '@mui/x-date-pickers/hooks';
14
14
  import { getDateRangePickerToolbarUtilityClass } from "./dateRangePickerToolbarClasses.js";
15
+ import { usePickerRangePositionContext } from "../hooks/index.js";
15
16
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
16
17
  const useUtilityClasses = classes => {
17
18
  const slots = {
@@ -49,38 +50,48 @@ const DateRangePickerToolbar = /*#__PURE__*/React.forwardRef(function DateRangeP
49
50
  name: 'MuiDateRangePickerToolbar'
50
51
  });
51
52
  const {
52
- value: [start, end],
53
- rangePosition,
54
- onRangePositionChange,
55
- toolbarFormat,
53
+ toolbarFormat: toolbarFormatProp,
56
54
  className,
57
55
  classes: classesProp
58
56
  } = props,
59
57
  other = _objectWithoutPropertiesLoose(props, _excluded);
58
+ const {
59
+ value
60
+ } = usePickerContext();
60
61
  const translations = usePickerTranslations();
61
62
  const ownerState = useToolbarOwnerState();
63
+ const {
64
+ rangePosition,
65
+ onRangePositionChange
66
+ } = usePickerRangePositionContext();
62
67
  const classes = useUtilityClasses(classesProp);
63
- const startDateValue = start ? utils.formatByString(start, toolbarFormat || utils.formats.shortDate) : translations.start;
64
- const endDateValue = end ? utils.formatByString(end, toolbarFormat || utils.formats.shortDate) : translations.end;
68
+
69
+ // This can't be a default value when spreading because it breaks the API generation.
70
+ const toolbarFormat = toolbarFormatProp ?? utils.formats.shortDate;
71
+ const formatDate = (date, fallback) => {
72
+ if (!utils.isValid(date)) {
73
+ return fallback;
74
+ }
75
+ return utils.formatByString(date, toolbarFormat);
76
+ };
65
77
  return /*#__PURE__*/_jsx(DateRangePickerToolbarRoot, _extends({}, other, {
66
78
  toolbarTitle: translations.dateRangePickerToolbarTitle,
67
- isLandscape: false,
68
79
  className: clsx(classes.root, className),
69
80
  ownerState: ownerState,
70
81
  ref: ref,
71
82
  children: /*#__PURE__*/_jsxs(DateRangePickerToolbarContainer, {
72
83
  className: classes.container,
73
84
  children: [/*#__PURE__*/_jsx(PickersToolbarButton, {
74
- variant: start !== null ? 'h5' : 'h6',
75
- value: startDateValue,
85
+ variant: value[0] == null ? 'h6' : 'h5',
86
+ value: formatDate(value[0], translations.start),
76
87
  selected: rangePosition === 'start',
77
88
  onClick: () => onRangePositionChange('start')
78
89
  }), /*#__PURE__*/_jsxs(Typography, {
79
90
  variant: "h5",
80
91
  children: ["\xA0", '–', "\xA0"]
81
92
  }), /*#__PURE__*/_jsx(PickersToolbarButton, {
82
- variant: end !== null ? 'h5' : 'h6',
83
- value: endDateValue,
93
+ variant: value[1] == null ? 'h6' : 'h5',
94
+ value: formatDate(value[1], translations.end),
84
95
  selected: rangePosition === 'end',
85
96
  onClick: () => onRangePositionChange('end')
86
97
  })]
@@ -102,14 +113,6 @@ process.env.NODE_ENV !== "production" ? DateRangePickerToolbar.propTypes = {
102
113
  * @default `true` for Desktop, `false` for Mobile.
103
114
  */
104
115
  hidden: PropTypes.bool,
105
- onRangePositionChange: PropTypes.func.isRequired,
106
- /**
107
- * Callback called when a toolbar is clicked
108
- * @template TView
109
- * @param {TView} view The view to open
110
- */
111
- onViewChange: PropTypes.func.isRequired,
112
- rangePosition: PropTypes.oneOf(['end', 'start']).isRequired,
113
116
  /**
114
117
  * The system prop that allows defining system overrides as well as additional CSS styles.
115
118
  */
@@ -123,15 +126,6 @@ process.env.NODE_ENV !== "production" ? DateRangePickerToolbar.propTypes = {
123
126
  * Toolbar value placeholder—it is displayed when the value is empty.
124
127
  * @default "––"
125
128
  */
126
- toolbarPlaceholder: PropTypes.node,
127
- value: PropTypes.arrayOf(PropTypes.object).isRequired,
128
- /**
129
- * Currently visible picker view.
130
- */
131
- view: PropTypes.oneOf(['day']).isRequired,
132
- /**
133
- * Available views.
134
- */
135
- views: PropTypes.arrayOf(PropTypes.oneOf(['day'])).isRequired
129
+ toolbarPlaceholder: PropTypes.node
136
130
  } : void 0;
137
131
  export { DateRangePickerToolbar };
@@ -68,8 +68,8 @@ process.env.NODE_ENV !== "production" ? DateTimeRangePicker.propTypes = {
68
68
  calendars: PropTypes.oneOf([1, 2, 3]),
69
69
  className: PropTypes.string,
70
70
  /**
71
- * If `true`, the popover or modal will close after submitting the full date.
72
- * @default `true` for desktop, `false` for mobile (based on the chosen wrapper and `desktopModeMediaQuery` prop).
71
+ * If `true`, the Picker will close after submitting the full date.
72
+ * @default false
73
73
  */
74
74
  closeOnSelect: PropTypes.bool,
75
75
  /**
@@ -8,10 +8,11 @@ import composeClasses from '@mui/utils/composeClasses';
8
8
  import useEventCallback from '@mui/utils/useEventCallback';
9
9
  import { TimeIcon, DateRangeIcon, ArrowLeftIcon, ArrowRightIcon } from '@mui/x-date-pickers/icons';
10
10
  import { isDatePickerView, usePickerPrivateContext } from '@mui/x-date-pickers/internals';
11
- import { usePickerTranslations } from '@mui/x-date-pickers/hooks';
11
+ import { usePickerContext, usePickerTranslations } from '@mui/x-date-pickers/hooks';
12
12
  import IconButton from '@mui/material/IconButton';
13
13
  import Button from '@mui/material/Button';
14
14
  import { getDateTimeRangePickerTabsUtilityClass } from "./dateTimeRangePickerTabsClasses.js";
15
+ import { usePickerRangePositionContext } from "../hooks/index.js";
15
16
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
16
17
  const viewToTab = (view, rangePosition) => {
17
18
  if (isDatePickerView(view)) {
@@ -69,12 +70,8 @@ const DateTimeRangePickerTabs = function DateTimeRangePickerTabs(inProps) {
69
70
  });
70
71
  const {
71
72
  dateIcon = /*#__PURE__*/_jsx(DateRangeIcon, {}),
72
- onViewChange,
73
73
  timeIcon = /*#__PURE__*/_jsx(TimeIcon, {}),
74
- view,
75
74
  hidden = typeof window === 'undefined' || window.innerHeight < 667,
76
- rangePosition,
77
- onRangePositionChange,
78
75
  className,
79
76
  classes: classesProp,
80
77
  sx
@@ -83,8 +80,16 @@ const DateTimeRangePickerTabs = function DateTimeRangePickerTabs(inProps) {
83
80
  const {
84
81
  ownerState
85
82
  } = usePickerPrivateContext();
83
+ const {
84
+ view,
85
+ setView
86
+ } = usePickerContext();
86
87
  const classes = useUtilityClasses(classesProp);
87
- const value = React.useMemo(() => viewToTab(view, rangePosition), [view, rangePosition]);
88
+ const {
89
+ rangePosition,
90
+ onRangePositionChange
91
+ } = usePickerRangePositionContext();
92
+ const value = React.useMemo(() => view == null ? null : viewToTab(view, rangePosition), [view, rangePosition]);
88
93
  const isPreviousHidden = value === 'start-date';
89
94
  const isNextHidden = value === 'end-time';
90
95
  const tabLabel = React.useMemo(() => {
@@ -109,18 +114,26 @@ const DateTimeRangePickerTabs = function DateTimeRangePickerTabs(inProps) {
109
114
  }
110
115
  });
111
116
  const changeToPreviousTab = useEventCallback(() => {
112
- const previousTab = tabOptions[tabOptions.indexOf(value) - 1];
113
- onViewChange(tabToView(previousTab));
117
+ const previousTab = value == null ? tabOptions[0] : tabOptions[tabOptions.indexOf(value) - 1];
118
+ setView(tabToView(previousTab));
114
119
  handleRangePositionChange(previousTab);
115
120
  });
116
121
  const changeToNextTab = useEventCallback(() => {
117
- const nextTab = tabOptions[tabOptions.indexOf(value) + 1];
118
- onViewChange(tabToView(nextTab));
122
+ const nextTab = value == null ? tabOptions[0] : tabOptions[tabOptions.indexOf(value) + 1];
123
+ setView(tabToView(nextTab));
119
124
  handleRangePositionChange(nextTab);
120
125
  });
121
126
  if (hidden) {
122
127
  return null;
123
128
  }
129
+ let startIcon;
130
+ if (view == null) {
131
+ startIcon = null;
132
+ } else if (isDatePickerView(view)) {
133
+ startIcon = dateIcon;
134
+ } else {
135
+ startIcon = timeIcon;
136
+ }
124
137
  return /*#__PURE__*/_jsxs(DateTimeRangePickerTabsRoot, {
125
138
  ownerState: ownerState,
126
139
  className: clsx(classes.root, className),
@@ -133,7 +146,7 @@ const DateTimeRangePickerTabs = function DateTimeRangePickerTabs(inProps) {
133
146
  }) : /*#__PURE__*/_jsx(DateTimeRangePickerTabFiller, {
134
147
  className: classes.filler
135
148
  }), /*#__PURE__*/_jsx(DateTimeRangePickerTab, {
136
- startIcon: isDatePickerView(view) ? dateIcon : timeIcon,
149
+ startIcon: startIcon,
137
150
  className: classes.tabButton,
138
151
  size: "large",
139
152
  children: tabLabel
@@ -167,14 +180,6 @@ process.env.NODE_ENV !== "production" ? DateTimeRangePickerTabs.propTypes = {
167
180
  * @default `window.innerHeight < 667` for `DesktopDateTimeRangePicker` and `MobileDateTimeRangePicker`
168
181
  */
169
182
  hidden: PropTypes.bool,
170
- onRangePositionChange: PropTypes.func.isRequired,
171
- /**
172
- * Callback called when a tab is clicked.
173
- * @template TView
174
- * @param {TView} view The view to open
175
- */
176
- onViewChange: PropTypes.func.isRequired,
177
- rangePosition: PropTypes.oneOf(['end', 'start']).isRequired,
178
183
  /**
179
184
  * The system prop that allows defining system overrides as well as additional CSS styles.
180
185
  */
@@ -183,10 +188,6 @@ process.env.NODE_ENV !== "production" ? DateTimeRangePickerTabs.propTypes = {
183
188
  * Time tab icon.
184
189
  * @default TimeIcon
185
190
  */
186
- timeIcon: PropTypes.element,
187
- /**
188
- * Currently visible picker view.
189
- */
190
- view: PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']).isRequired
191
+ timeIcon: PropTypes.element
191
192
  } : void 0;
192
193
  export { DateTimeRangePickerTabs };
@@ -1,17 +1,16 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["rangePosition", "onRangePositionChange", "viewRenderer", "value", "onChange", "defaultValue", "onViewChange", "views", "className"];
3
+ const _excluded = ["viewRenderer", "value", "onChange", "defaultValue", "onViewChange", "views", "className"];
4
4
  import { isInternalTimeView, useUtils } from '@mui/x-date-pickers/internals';
5
5
  import { isRangeValid } from "../internals/utils/date-utils.js";
6
6
  import { calculateRangeChange } from "../internals/utils/date-range-manager.js";
7
+ import { usePickerRangePositionContext } from "../hooks/index.js";
7
8
  /**
8
9
  * @ignore - internal component.
9
10
  */
10
- function DateTimeRangePickerTimeWrapper(props, ref) {
11
+ function DateTimeRangePickerTimeWrapper(props) {
11
12
  const utils = useUtils();
12
13
  const {
13
- rangePosition,
14
- onRangePositionChange,
15
14
  viewRenderer,
16
15
  value,
17
16
  onChange,
@@ -20,6 +19,10 @@ function DateTimeRangePickerTimeWrapper(props, ref) {
20
19
  views
21
20
  } = props,
22
21
  other = _objectWithoutPropertiesLoose(props, _excluded);
22
+ const {
23
+ rangePosition,
24
+ onRangePositionChange
25
+ } = usePickerRangePositionContext();
23
26
  if (!viewRenderer) {
24
27
  return null;
25
28
  }
@@ -47,7 +50,6 @@ function DateTimeRangePickerTimeWrapper(props, ref) {
47
50
  onChange(newRange, isFullRangeSelected ? 'finish' : 'partial', selectedView);
48
51
  };
49
52
  return viewRenderer(_extends({}, other, {
50
- ref,
51
53
  views,
52
54
  onViewChange,
53
55
  value: currentValue,
@@ -2,17 +2,18 @@
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 = ["value", "rangePosition", "onRangePositionChange", "className", "classes", "onViewChange", "onChange", "classes", "view", "isLandscape", "views", "ampm", "hidden", "toolbarFormat", "toolbarPlaceholder", "titleId", "sx"];
5
+ const _excluded = ["className", "classes", "classes", "ampm", "hidden", "toolbarFormat", "toolbarPlaceholder", "titleId", "sx"];
6
6
  import * as React from 'react';
7
7
  import PropTypes from 'prop-types';
8
8
  import clsx from 'clsx';
9
9
  import { styled, useThemeProps } from '@mui/material/styles';
10
10
  import composeClasses from '@mui/utils/composeClasses';
11
- import { useUtils, useToolbarOwnerState, DateTimePickerToolbarForceDesktopVariant } from '@mui/x-date-pickers/internals';
11
+ import { useUtils, useToolbarOwnerState, DateTimePickerToolbarOverrideContext } from '@mui/x-date-pickers/internals';
12
12
  import { usePickerContext, usePickerTranslations } from '@mui/x-date-pickers/hooks';
13
13
  import { DateTimePickerToolbar } from '@mui/x-date-pickers/DateTimePicker';
14
14
  import { getDateTimeRangePickerToolbarUtilityClass } from "./dateTimeRangePickerToolbarClasses.js";
15
15
  import { calculateRangeChange } from "../internals/utils/date-range-manager.js";
16
+ import { usePickerRangePositionContext } from "../hooks/index.js";
16
17
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
17
18
  const useUtilityClasses = classes => {
18
19
  const slots = {
@@ -50,16 +51,8 @@ const DateTimeRangePickerToolbar = /*#__PURE__*/React.forwardRef(function DateTi
50
51
  });
51
52
  const utils = useUtils();
52
53
  const {
53
- value: [start, end],
54
- rangePosition,
55
- onRangePositionChange,
56
54
  className,
57
55
  classes: classesProp,
58
- onViewChange,
59
- onChange,
60
- view,
61
- isLandscape,
62
- views,
63
56
  ampm,
64
57
  hidden,
65
58
  toolbarFormat,
@@ -69,14 +62,22 @@ const DateTimeRangePickerToolbar = /*#__PURE__*/React.forwardRef(function DateTi
69
62
  } = props,
70
63
  other = _objectWithoutPropertiesLoose(props, _excluded);
71
64
  const {
65
+ value,
66
+ setValue,
72
67
  disabled,
73
- readOnly
68
+ readOnly,
69
+ view,
70
+ setView,
71
+ views
74
72
  } = usePickerContext();
75
73
  const translations = usePickerTranslations();
76
74
  const ownerState = useToolbarOwnerState();
75
+ const {
76
+ rangePosition,
77
+ onRangePositionChange
78
+ } = usePickerRangePositionContext();
77
79
  const classes = useUtilityClasses(classesProp);
78
80
  const commonToolbarProps = {
79
- isLandscape,
80
81
  views,
81
82
  ampm,
82
83
  disabled,
@@ -85,69 +86,84 @@ const DateTimeRangePickerToolbar = /*#__PURE__*/React.forwardRef(function DateTi
85
86
  toolbarFormat,
86
87
  toolbarPlaceholder
87
88
  };
88
- const handleStartRangeViewChange = React.useCallback(newView => {
89
- if (newView === 'year' || newView === 'month') {
90
- return;
91
- }
92
- if (rangePosition !== 'start') {
93
- onRangePositionChange('start');
94
- }
95
- onViewChange(newView);
96
- }, [onRangePositionChange, onViewChange, rangePosition]);
97
- const handleEndRangeViewChange = React.useCallback(newView => {
98
- if (newView === 'year' || newView === 'month') {
99
- return;
100
- }
101
- if (rangePosition !== 'end') {
102
- onRangePositionChange('end');
103
- }
104
- onViewChange(newView);
105
- }, [onRangePositionChange, onViewChange, rangePosition]);
106
- const handleOnChange = React.useCallback(newDate => {
89
+ const wrappedSetValue = React.useCallback(newDate => {
107
90
  const {
108
91
  nextSelection,
109
92
  newRange
110
93
  } = calculateRangeChange({
111
94
  newDate,
112
95
  utils,
113
- range: props.value,
96
+ range: value,
114
97
  rangePosition,
115
98
  allowRangeFlip: true
116
99
  });
117
100
  onRangePositionChange(nextSelection);
118
- onChange(newRange);
119
- }, [onChange, onRangePositionChange, props.value, rangePosition, utils]);
101
+ setValue(newRange, {
102
+ changeImportance: 'set'
103
+ });
104
+ }, [setValue, onRangePositionChange, value, rangePosition, utils]);
105
+ const startOverrides = React.useMemo(() => {
106
+ const handleStartRangeViewChange = newView => {
107
+ if (newView === 'year' || newView === 'month') {
108
+ return;
109
+ }
110
+ if (rangePosition !== 'start') {
111
+ onRangePositionChange('start');
112
+ }
113
+ setView(newView);
114
+ };
115
+ return {
116
+ value: value[0],
117
+ setValue: wrappedSetValue,
118
+ forceDesktopVariant: true,
119
+ setView: handleStartRangeViewChange,
120
+ view: rangePosition === 'start' ? view : null
121
+ };
122
+ }, [value, wrappedSetValue, rangePosition, view, onRangePositionChange, setView]);
123
+ const endOverrides = React.useMemo(() => {
124
+ const handleEndRangeViewChange = newView => {
125
+ if (newView === 'year' || newView === 'month') {
126
+ return;
127
+ }
128
+ if (rangePosition !== 'end') {
129
+ onRangePositionChange('end');
130
+ }
131
+ setView(newView);
132
+ };
133
+ return {
134
+ value: value[1],
135
+ setValue: wrappedSetValue,
136
+ forceDesktopVariant: true,
137
+ setView: handleEndRangeViewChange,
138
+ view: rangePosition === 'end' ? view : null
139
+ };
140
+ }, [value, wrappedSetValue, rangePosition, view, onRangePositionChange, setView]);
120
141
  if (hidden) {
121
142
  return null;
122
143
  }
123
- return /*#__PURE__*/_jsx(DateTimeRangePickerToolbarRoot, _extends({
144
+ return /*#__PURE__*/_jsxs(DateTimeRangePickerToolbarRoot, _extends({
124
145
  className: clsx(classes.root, className),
125
146
  ownerState: ownerState,
126
147
  ref: ref,
127
148
  sx: sx
128
149
  }, other, {
129
- children: /*#__PURE__*/_jsxs(DateTimePickerToolbarForceDesktopVariant.Provider, {
130
- value: true,
131
- children: [/*#__PURE__*/_jsx(DateTimeRangePickerToolbarStart, _extends({
132
- value: start,
133
- onViewChange: handleStartRangeViewChange,
150
+ children: [/*#__PURE__*/_jsx(DateTimePickerToolbarOverrideContext.Provider, {
151
+ value: startOverrides,
152
+ children: /*#__PURE__*/_jsx(DateTimeRangePickerToolbarStart, _extends({
134
153
  toolbarTitle: translations.start,
135
154
  ownerState: ownerState,
136
- view: rangePosition === 'start' ? view : undefined,
137
155
  className: classes.startToolbar,
138
- onChange: handleOnChange,
139
156
  titleId: titleId ? `${titleId}-start-toolbar` : undefined
140
- }, commonToolbarProps)), /*#__PURE__*/_jsx(DateTimeRangePickerToolbarEnd, _extends({
141
- value: end,
142
- onViewChange: handleEndRangeViewChange,
157
+ }, commonToolbarProps))
158
+ }), /*#__PURE__*/_jsx(DateTimePickerToolbarOverrideContext.Provider, {
159
+ value: endOverrides,
160
+ children: /*#__PURE__*/_jsx(DateTimeRangePickerToolbarEnd, _extends({
143
161
  toolbarTitle: translations.end,
144
162
  ownerState: ownerState,
145
- view: rangePosition === 'end' ? view : undefined,
146
163
  className: classes.endToolbar,
147
- onChange: handleOnChange,
148
164
  titleId: titleId ? `${titleId}-end-toolbar` : undefined
149
- }, commonToolbarProps))]
150
- })
165
+ }, commonToolbarProps))
166
+ })]
151
167
  }));
152
168
  });
153
169
  process.env.NODE_ENV !== "production" ? DateTimeRangePickerToolbar.propTypes = {
@@ -166,16 +182,6 @@ process.env.NODE_ENV !== "production" ? DateTimeRangePickerToolbar.propTypes = {
166
182
  * @default `true` for Desktop, `false` for Mobile.
167
183
  */
168
184
  hidden: PropTypes.bool,
169
- isLandscape: PropTypes.bool.isRequired,
170
- onChange: PropTypes.func.isRequired,
171
- onRangePositionChange: PropTypes.func.isRequired,
172
- /**
173
- * Callback called when a toolbar is clicked
174
- * @template TView
175
- * @param {TView} view The view to open
176
- */
177
- onViewChange: PropTypes.func.isRequired,
178
- rangePosition: PropTypes.oneOf(['end', 'start']).isRequired,
179
185
  /**
180
186
  * The system prop that allows defining system overrides as well as additional CSS styles.
181
187
  */
@@ -189,15 +195,6 @@ process.env.NODE_ENV !== "production" ? DateTimeRangePickerToolbar.propTypes = {
189
195
  * Toolbar value placeholder—it is displayed when the value is empty.
190
196
  * @default "––"
191
197
  */
192
- toolbarPlaceholder: PropTypes.node,
193
- value: PropTypes.arrayOf(PropTypes.object).isRequired,
194
- /**
195
- * Currently visible picker view.
196
- */
197
- view: PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'seconds']).isRequired,
198
- /**
199
- * Available views.
200
- */
201
- views: PropTypes.arrayOf(PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'seconds']).isRequired).isRequired
198
+ toolbarPlaceholder: PropTypes.node
202
199
  } : void 0;
203
200
  export { DateTimeRangePickerToolbar };
@@ -13,6 +13,8 @@ import { renderDateRangeViewCalendar } from "../dateRangeViewRenderers/index.js"
13
13
  import { MultiInputDateRangeField } from "../MultiInputDateRangeField/index.js";
14
14
  import { useDesktopRangePicker } from "../internals/hooks/useDesktopRangePicker/index.js";
15
15
  import { validateDateRange } from "../validation/index.js";
16
+ const emptyActions = [];
17
+
16
18
  /**
17
19
  * Demos:
18
20
  *
@@ -32,6 +34,7 @@ const DesktopDateRangePicker = /*#__PURE__*/React.forwardRef(function DesktopDat
32
34
  day: renderDateRangeViewCalendar
33
35
  }, defaultizedProps.viewRenderers);
34
36
  const props = _extends({}, defaultizedProps, {
37
+ closeOnSelect: defaultizedProps.closeOnSelect ?? true,
35
38
  viewRenderers,
36
39
  format: utils.formats.keyboardDate,
37
40
  calendars: defaultizedProps.calendars ?? 2,
@@ -46,7 +49,10 @@ const DesktopDateRangePicker = /*#__PURE__*/React.forwardRef(function DesktopDat
46
49
  }),
47
50
  toolbar: _extends({
48
51
  hidden: true
49
- }, defaultizedProps.slotProps?.toolbar)
52
+ }, defaultizedProps.slotProps?.toolbar),
53
+ actionBar: ownerState => _extends({
54
+ actions: emptyActions
55
+ }, resolveComponentProps(defaultizedProps.slotProps?.actionBar, ownerState))
50
56
  })
51
57
  });
52
58
  const {
@@ -78,8 +84,8 @@ DesktopDateRangePicker.propTypes = {
78
84
  calendars: PropTypes.oneOf([1, 2, 3]),
79
85
  className: PropTypes.string,
80
86
  /**
81
- * If `true`, the popover or modal will close after submitting the full date.
82
- * @default `true` for desktop, `false` for mobile (based on the chosen wrapper and `desktopModeMediaQuery` prop).
87
+ * If `true`, the Picker will close after submitting the full date.
88
+ * @default true
83
89
  */
84
90
  closeOnSelect: PropTypes.bool,
85
91
  /**