Skip to content

Commit 02e5152

Browse files
Work
1 parent 9fcc82d commit 02e5152

File tree

14 files changed

+132
-46
lines changed

14 files changed

+132
-46
lines changed

docs/data/migration/migration-pickers-v7/migration-pickers-v7.md

+88-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,94 @@ const theme = createTheme({
259259
});
260260
```
261261

262-
## Removed types
262+
## Slots breaking changes
263+
264+
### Slot: `layout`
265+
266+
- The `PickersLayoutRoot` must now receive the `ownerState` returned by `usePickerLayout` instead of its props:
267+
268+
```diff
269+
-const { toolbar, tabs, content, actionBar } = usePickerLayout(props);
270+
+const { toolbar, tabs, content, actionBar, ownerState } = usePickerLayout(props);
271+
272+
return (
273+
- <PickersLayoutRoot ownerState={props}>
274+
+ <PickersLayoutRoot ownerState={ownerState}>
275+
Layout content
276+
</PickersLayoutRoot>
277+
);
278+
}
279+
```
280+
281+
- The component passed to the `layout` slot no longer receives a `isRtl` prop. If you need to access this information, you can use the `useRtl` hook from `@mui/system`:
282+
283+
```diff
284+
+import { useRtl } from '@mui/system/RtlProvider';
285+
286+
function CustomLayout(props) {
287+
- console.log(props.isRtl);
288+
+ const isRtl = useRtl();
289+
+ console.log(isRtl);
290+
}
291+
```
292+
293+
- The component passed to the `layout` slot no longer receives an `orientation` and the `isLandscape` props, instead you can use the `usePickersContext` hook:
294+
295+
```diff
296+
-console.log(props.orientation);
297+
+const { orientation } = usePickersContext();
298+
+console.log(orientation);
299+
300+
-console.log(props.isLandscape);
301+
+const { orientation } = usePickersContext();
302+
+console.log(orientation === 'landscape');
303+
```
304+
305+
- The component passed to the `layout` slot no longer receives a `wrapperVariant` prop, instead you can use the `usePickersContext` hook:
306+
307+
```diff
308+
-console.log(props.wrapperVariant);
309+
+const { variant } = usePickersContext();
310+
+console.log(variant);
311+
```
312+
313+
### Slot: `toolbar`
314+
315+
- The component passed to the `toolbar` slot no longer receives a `isLandscape` prop. There is currently no way to access this information, if you need it, please [open an issue](https://github.com/mui/mui-x/issues/new/choose).
316+
317+
```diff
318+
-console.log(props.isLandscape);
319+
+const { orientation } = usePickersContext();
320+
+console.log(orientation === 'landscape');
321+
```
322+
323+
- The component passed to the `toolbar` slot no longer receives a `toolbarVariant` prop, instead you can use the `usePickersContext` hook:
324+
325+
```diff
326+
-console.log(props.wrapperVariant);
327+
+const { variant } = usePickersContext();
328+
+console.log(variant);
329+
```
330+
331+
- The component passed to the `toolbar` slot no longer receives a `disabled` prop, instead you can use the `usePickersContext` hook:
332+
333+
```diff
334+
-console.log(props.disabled);
335+
+const { disabled } = usePickersContext();
336+
+console.log(disabled);
337+
```
338+
339+
- The component passed to the `toolbar` slot no longer receives a `readOnly` prop, instead you can use the `usePickersContext` hook:
340+
341+
```diff
342+
-console.log(props.readOnly);
343+
+const { readOnly } = usePickersContext();
344+
+console.log(readOnly);
345+
```
346+
347+
## Typing breaking changes
348+
349+
### Removed types
263350

264351
The following types are no longer exported by `@mui/x-date-pickers` and/or `@mui/x-date-pickers-pro`.
265352
If you were using them, you need to replace them with the following code:

packages/x-date-pickers-pro/src/DateRangePicker/DateRangePickerToolbar.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ DateRangePickerToolbar.propTypes = {
143143
*/
144144
classes: PropTypes.object,
145145
className: PropTypes.string,
146-
disabled: PropTypes.bool,
147146
/**
148147
* If `true`, show the toolbar even in desktop mode.
149148
* @default `true` for Desktop, `false` for Mobile.
@@ -157,7 +156,6 @@ DateRangePickerToolbar.propTypes = {
157156
*/
158157
onViewChange: PropTypes.func.isRequired,
159158
rangePosition: PropTypes.oneOf(['end', 'start']).isRequired,
160-
readOnly: PropTypes.bool,
161159
/**
162160
* The system prop that allows defining system overrides as well as additional CSS styles.
163161
*/

packages/x-date-pickers-pro/src/DateTimeRangePicker/DateTimeRangePickerToolbar.tsx

+6-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
PickerRangeValue,
1313
usePickersPrivateContext,
1414
} from '@mui/x-date-pickers/internals';
15-
import { usePickersTranslations } from '@mui/x-date-pickers/hooks';
15+
import { usePickersContext, usePickersTranslations } from '@mui/x-date-pickers/hooks';
1616
import { PickerOwnerState, PickerValidDate } from '@mui/x-date-pickers/models';
1717
import {
1818
DateTimePickerToolbarProps,
@@ -129,8 +129,6 @@ const DateTimeRangePickerToolbar = React.forwardRef(function DateTimeRangePicker
129129
view,
130130
views,
131131
ampm,
132-
disabled,
133-
readOnly,
134132
hidden,
135133
toolbarFormat,
136134
toolbarPlaceholder,
@@ -139,6 +137,11 @@ const DateTimeRangePickerToolbar = React.forwardRef(function DateTimeRangePicker
139137
...other
140138
} = props;
141139

140+
const translations = usePickersTranslations();
141+
const { ownerState } = usePickersPrivateContext();
142+
const { disabled, readOnly } = usePickersContext();
143+
const classes = useUtilityClasses(classesProp);
144+
142145
const commonToolbarProps = {
143146
views,
144147
ampm,
@@ -149,11 +152,6 @@ const DateTimeRangePickerToolbar = React.forwardRef(function DateTimeRangePicker
149152
toolbarPlaceholder,
150153
};
151154

152-
const translations = usePickersTranslations();
153-
const { ownerState } = usePickersPrivateContext();
154-
155-
const classes = useUtilityClasses(classesProp);
156-
157155
const handleStartRangeViewChange = React.useCallback(
158156
(newView: DateOrTimeViewWithMeridiem) => {
159157
if (newView === 'year' || newView === 'month') {
@@ -244,7 +242,6 @@ DateTimeRangePickerToolbar.propTypes = {
244242
*/
245243
classes: PropTypes.object,
246244
className: PropTypes.string,
247-
disabled: PropTypes.bool,
248245
/**
249246
* If `true`, show the toolbar even in desktop mode.
250247
* @default `true` for Desktop, `false` for Mobile.
@@ -259,7 +256,6 @@ DateTimeRangePickerToolbar.propTypes = {
259256
*/
260257
onViewChange: PropTypes.func.isRequired,
261258
rangePosition: PropTypes.oneOf(['end', 'start']).isRequired,
262-
readOnly: PropTypes.bool,
263259
/**
264260
* The system prop that allows defining system overrides as well as additional CSS styles.
265261
*/

packages/x-date-pickers/src/DatePicker/DatePickerToolbar.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from './datePickerToolbarClasses';
1717
import { resolveDateFormat } from '../internals/utils/date-utils';
1818
import { usePickersPrivateContext } from '../internals/hooks/usePickersPrivateContext';
19+
import { usePickersContext } from '../hooks';
1920

2021
export interface DatePickerToolbarProps
2122
extends BaseToolbarProps<PickerValidDate | null, DateView>,
@@ -92,7 +93,8 @@ export const DatePickerToolbar = React.forwardRef(function DatePickerToolbar(
9293

9394
const utils = useUtils();
9495
const translations = usePickersTranslations();
95-
const { ownerState, orientation } = usePickersPrivateContext();
96+
const { ownerState } = usePickersPrivateContext();
97+
const { orientation } = usePickersContext();
9698
const classes = useUtilityClasses(classesProp);
9799

98100
const dateText = React.useMemo(() => {
@@ -135,7 +137,6 @@ DatePickerToolbar.propTypes = {
135137
*/
136138
classes: PropTypes.object,
137139
className: PropTypes.string,
138-
disabled: PropTypes.bool,
139140
/**
140141
* If `true`, show the toolbar even in desktop mode.
141142
* @default `true` for Desktop, `false` for Mobile.
@@ -148,7 +149,6 @@ DatePickerToolbar.propTypes = {
148149
* @param {TView} view The view to open
149150
*/
150151
onViewChange: PropTypes.func.isRequired,
151-
readOnly: PropTypes.bool,
152152
/**
153153
* The system prop that allows defining system overrides as well as additional CSS styles.
154154
*/

packages/x-date-pickers/src/DateTimePicker/DateTimePickerToolbar.tsx

+3-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { pickersToolbarTextClasses } from '../internals/components/pickersToolba
2525
import { pickersToolbarClasses } from '../internals/components/pickersToolbarClasses';
2626
import { PickerOwnerState, PickerValidDate } from '../models';
2727
import { usePickersPrivateContext } from '../internals/hooks/usePickersPrivateContext';
28+
import { usePickersContext } from '../hooks/usePickersContext';
2829

2930
export interface ExportedDateTimePickerToolbarProps extends ExportedBaseToolbarProps {
3031
/**
@@ -245,16 +246,15 @@ function DateTimePickerToolbar(inProps: DateTimePickerToolbarProps) {
245246
toolbarFormat,
246247
toolbarPlaceholder = '––',
247248
views,
248-
disabled,
249-
readOnly,
250249
toolbarTitle: inToolbarTitle,
251250
className,
252251
classes: classesProp,
253252
...other
254253
} = props;
255254

256255
const isRtl = useRtl();
257-
const { ownerState: pickerOwnerState, variant, orientation } = usePickersPrivateContext();
256+
const { ownerState: pickerOwnerState } = usePickersPrivateContext();
257+
const { orientation, variant, disabled, readOnly } = usePickersContext();
258258
const ownerState: DateTimePickerToolbarOwnerState = { ...pickerOwnerState, isRtl };
259259
const utils = useUtils();
260260
const { meridiemMode, handleMeridiemChange } = useMeridiemMode(value, ampm, onChange);
@@ -425,7 +425,6 @@ DateTimePickerToolbar.propTypes = {
425425
*/
426426
classes: PropTypes.object,
427427
className: PropTypes.string,
428-
disabled: PropTypes.bool,
429428
/**
430429
* If `true`, show the toolbar even in desktop mode.
431430
* @default `true` for Desktop, `false` for Mobile.
@@ -438,7 +437,6 @@ DateTimePickerToolbar.propTypes = {
438437
* @param {TView} view The view to open
439438
*/
440439
onViewChange: PropTypes.func.isRequired,
441-
readOnly: PropTypes.bool,
442440
/**
443441
* The system prop that allows defining system overrides as well as additional CSS styles.
444442
*/

packages/x-date-pickers/src/DesktopDateTimePicker/DesktopDateTimePickerLayout.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
usePickerLayout,
1111
} from '../PickersLayout';
1212
import { DateOrTimeViewWithMeridiem } from '../internals/models/common';
13+
import { usePickersContext } from '../hooks/usePickersContext';
1314

1415
type DesktopDateTimePickerLayoutComponent = (<TValue, TView extends DateOrTimeViewWithMeridiem>(
1516
props: PickersLayoutProps<TValue, TView> & React.RefAttributes<HTMLDivElement>,
@@ -22,8 +23,8 @@ const DesktopDateTimePickerLayout = React.forwardRef(function DesktopDateTimePic
2223
TValue,
2324
TView extends DateOrTimeViewWithMeridiem,
2425
>(props: PickersLayoutProps<TValue, TView>, ref: React.Ref<HTMLDivElement>) {
25-
const { toolbar, tabs, content, actionBar, shortcuts, orientation, ownerState } =
26-
usePickerLayout(props);
26+
const { toolbar, tabs, content, actionBar, shortcuts, ownerState } = usePickerLayout(props);
27+
const { orientation } = usePickersContext();
2728
const { sx, className, classes } = props;
2829
const isActionBarVisible = actionBar && (actionBar.props.actions?.length ?? 0) > 0;
2930

packages/x-date-pickers/src/PickersLayout/PickersLayout.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import usePickerLayout from './usePickerLayout';
1414
import { DateOrTimeViewWithMeridiem } from '../internals/models';
1515
import { PickerOwnerState } from '../models/pickers';
16+
import { usePickersContext } from '../hooks/usePickersContext';
1617

1718
const useUtilityClasses = (
1819
classes: Partial<PickersLayoutClasses> | undefined,
@@ -106,8 +107,8 @@ const PickersLayout = React.forwardRef(function PickersLayout<
106107
>(inProps: PickersLayoutProps<TValue, TView>, ref: React.Ref<HTMLDivElement>) {
107108
const props = useThemeProps({ props: inProps, name: 'MuiPickersLayout' });
108109

109-
const { toolbar, content, tabs, actionBar, shortcuts, orientation, variant, ownerState } =
110-
usePickerLayout(props);
110+
const { toolbar, content, tabs, actionBar, shortcuts, ownerState } = usePickerLayout(props);
111+
const { orientation, variant } = usePickersContext();
111112
const { sx, className, classes: classesProp } = props;
112113

113114
const classes = useUtilityClasses(classesProp, ownerState);

packages/x-date-pickers/src/PickersLayout/usePickerLayout.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { BaseToolbarProps } from '../internals/models/props/toolbar';
1111
import { DateOrTimeViewWithMeridiem } from '../internals/models';
1212
import { usePickersPrivateContext } from '../internals/hooks/usePickersPrivateContext';
1313
import { PickersPrivateContextValue } from '../internals/components/PickersProvider';
14+
import { usePickersContext } from '../hooks/usePickersContext';
1415

1516
function toolbarHasView<TValue, TView extends DateOrTimeViewWithMeridiem>(
1617
toolbarProps: BaseToolbarProps<TValue, TView> | any,
@@ -42,12 +43,13 @@ interface PickersLayoutPropsWithValueRequired<TValue, TView extends DateOrTimeVi
4243
}
4344
interface UsePickerLayoutResponse<TValue>
4445
extends SubComponents<TValue>,
45-
Pick<PickersPrivateContextValue, 'orientation' | 'variant' | 'ownerState'> {}
46+
Pick<PickersPrivateContextValue, 'ownerState'> {}
4647

4748
const usePickerLayout = <TValue, TView extends DateOrTimeViewWithMeridiem>(
4849
props: PickersLayoutProps<TValue, TView>,
4950
): UsePickerLayoutResponse<TValue> => {
50-
const { ownerState: pickerOwnerState, variant, orientation } = usePickersPrivateContext();
51+
const { ownerState: pickerOwnerState } = usePickersPrivateContext();
52+
const { variant } = usePickersContext();
5153

5254
const {
5355
onAccept,
@@ -144,8 +146,6 @@ const usePickerLayout = <TValue, TView extends DateOrTimeViewWithMeridiem>(
144146
tabs,
145147
actionBar,
146148
shortcuts,
147-
orientation,
148-
variant,
149149
ownerState,
150150
};
151151
};

packages/x-date-pickers/src/TimePicker/TimePickerToolbar.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { TimeViewWithMeridiem } from '../internals/models';
2222
import { formatMeridiem } from '../internals/utils/date-utils';
2323
import { PickerOwnerState, PickerValidDate } from '../models';
2424
import { usePickersPrivateContext } from '../internals/hooks/usePickersPrivateContext';
25+
import { usePickersContext } from '../hooks';
2526

2627
export interface TimePickerToolbarProps
2728
extends BaseToolbarProps<PickerValidDate | null, TimeViewWithMeridiem>,
@@ -163,8 +164,6 @@ function TimePickerToolbar(inProps: TimePickerToolbarProps) {
163164
view,
164165
onViewChange,
165166
views,
166-
disabled,
167-
readOnly,
168167
className,
169168
classes: classesProp,
170169
...other
@@ -173,6 +172,7 @@ function TimePickerToolbar(inProps: TimePickerToolbarProps) {
173172
const translations = usePickersTranslations();
174173
const isRtl = useRtl();
175174
const { ownerState: pickerOwnerState } = usePickersPrivateContext();
175+
const { disabled, readOnly } = usePickersContext();
176176

177177
const showAmPmControl = Boolean(ampm && !ampmInClock && views.includes('hours'));
178178
const { meridiemMode, handleMeridiemChange } = useMeridiemMode(value, ampm, onChange);
@@ -276,7 +276,6 @@ TimePickerToolbar.propTypes = {
276276
*/
277277
classes: PropTypes.object,
278278
className: PropTypes.string,
279-
disabled: PropTypes.bool,
280279
/**
281280
* If `true`, show the toolbar even in desktop mode.
282281
* @default `true` for Desktop, `false` for Mobile.
@@ -289,7 +288,6 @@ TimePickerToolbar.propTypes = {
289288
* @param {TView} view The view to open
290289
*/
291290
onViewChange: PropTypes.func.isRequired,
292-
readOnly: PropTypes.bool,
293291
/**
294292
* The system prop that allows defining system overrides as well as additional CSS styles.
295293
*/

packages/x-date-pickers/src/internals/components/PickersProvider.tsx

+12-6
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ export const PickersPrivateContext = React.createContext<PickersPrivateContextVa
1515
pickerVariant: 'desktop',
1616
pickerOrientation: 'portrait',
1717
},
18-
variant: 'desktop',
19-
orientation: 'portrait',
2018
});
2119

2220
/**
@@ -60,12 +58,14 @@ export interface PickersContextValue {
6058
* `true` if the picker is open, `false` otherwise.
6159
*/
6260
open: boolean;
63-
}
64-
export interface PickersPrivateContextValue {
6561
/**
66-
* The ownerState of the picker.
62+
* `true` if the picker is disabled, `false` otherwise.
6763
*/
68-
ownerState: PickerOwnerState;
64+
disabled: boolean;
65+
/**
66+
* `true` if the picker is read-only, `false` otherwise.
67+
*/
68+
readOnly: boolean;
6969
/**
7070
* The responsive variant of the picker.
7171
* Is equal to "desktop" when using a desktop picker (like <DesktopDatePicker />).
@@ -84,3 +84,9 @@ export interface PickersPrivateContextValue {
8484
*/
8585
orientation: PickerOrientation;
8686
}
87+
export interface PickersPrivateContextValue {
88+
/**
89+
* The ownerState of the picker.
90+
*/
91+
ownerState: PickerOwnerState;
92+
}

0 commit comments

Comments
 (0)