Skip to content

Commit a9649f8

Browse files
Merge
2 parents 7b2bf84 + 13975ee commit a9649f8

File tree

10 files changed

+43
-180
lines changed

10 files changed

+43
-180
lines changed

docs/data/date-pickers/custom-components/custom-components.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ You can override the actions displayed by passing the `actions` prop to the `act
3434
actions: ['clear'],
3535
},
3636
// The actions will be different between desktop and mobile
37-
actionBar: ({ wrapperVariant }) => ({
38-
actions: wrapperVariant === 'desktop' ? [] : ['clear'],
37+
actionBar: ({ variant }) => ({
38+
actions: variant === 'desktop' ? [] : ['clear'],
3939
}),
4040
}}
4141
/>

docs/data/date-pickers/custom-layout/custom-layout.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ import {
8686
} from '@mui/x-date-pickers/PickersLayout';
8787

8888
function MyCustomLayout(props) {
89-
const { toolbar, tabs, content, actionBar } = usePickerLayout(props);
89+
const { toolbar, tabs, content, actionBar, ownerState } = usePickerLayout(props);
9090

9191
// Put the action bar before the content
9292
return (
93-
<PickersLayoutRoot className={pickersLayoutClasses.root} ownerState={props}>
93+
<PickersLayoutRoot className={pickersLayoutClasses.root} ownerState={ownerState}>
9494
{toolbar}
9595
{actionBar}
9696
<PickersLayoutContentWrapper className={pickersLayoutClasses.contentWrapper}>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from 'react';
2+
3+
export default function MobileKeyboardView() {
4+
return (
5+
<iframe
6+
title="codesandbox"
7+
src="https://codesandbox.io/embed/https-mui-com-x-migration-migration-pickers-v7-forked-9fz6f6?hidenavigation=1&fontsize=14&view=preview"
8+
style={{
9+
width: '100%',
10+
height: 520,
11+
border: 0,
12+
}}
13+
sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"
14+
/>
15+
);
16+
}

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

+1-112
Original file line numberDiff line numberDiff line change
@@ -171,118 +171,7 @@ The picker components no longer have a keyboard view to render the input inside
171171

172172
- If you want to keep the old keyboard view, you can pass a custom `Layout` component slot to re-introduce the keyboard view.
173173

174-
```tsx
175-
import * as React from 'react';
176-
import { Dayjs } from 'dayjs';
177-
import Box from '@mui/material/Box';
178-
import Stack from '@mui/material/Stack';
179-
import IconButton from '@mui/material/IconButton';
180-
import ModeEditIcon from '@mui/icons-material/ModeEdit';
181-
import CalendarMonthIcon from '@mui/icons-material/CalendarMonth';
182-
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
183-
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
184-
import { DateView } from '@mui/x-date-pickers/models';
185-
import {
186-
pickersLayoutClasses,
187-
PickersLayoutContentWrapper,
188-
PickersLayoutRoot,
189-
PickersLayoutProps,
190-
usePickerLayout,
191-
} from '@mui/x-date-pickers/PickersLayout';
192-
import { MobileDatePicker } from '@mui/x-date-pickers/MobileDatePicker';
193-
import { DateField } from '@mui/x-date-pickers/DateField';
194-
import {
195-
DatePickerToolbar,
196-
DatePickerToolbarProps,
197-
} from '@mui/x-date-pickers/DatePicker';
198-
199-
function LayoutWithKeyboardView(props: PickersLayoutProps<Dayjs | null, DateView>) {
200-
const { value, onChange } = props;
201-
const [showKeyboardView, setShowKeyboardView] = React.useState(false);
202-
203-
const { toolbar, tabs, content, actionBar } = usePickerLayout({
204-
...props,
205-
slotProps: {
206-
...props.slotProps,
207-
toolbar: {
208-
...props.slotProps?.toolbar,
209-
// @ts-ignore
210-
showKeyboardViewSwitch: props.wrapperVariant === 'mobile',
211-
showKeyboardView,
212-
setShowKeyboardView,
213-
},
214-
},
215-
});
216-
217-
return (
218-
<PickersLayoutRoot ownerState={props}>
219-
{toolbar}
220-
{actionBar}
221-
<PickersLayoutContentWrapper className={pickersLayoutClasses.contentWrapper}>
222-
{tabs}
223-
{showKeyboardView ? (
224-
<Box sx={{ mx: 3, my: 2, width: 272 }}>
225-
<DateField value={value} onChange={onChange} sx={{ width: '100%' }} />
226-
</Box>
227-
) : (
228-
content
229-
)}
230-
</PickersLayoutContentWrapper>
231-
</PickersLayoutRoot>
232-
);
233-
}
234-
235-
function ToolbarWithKeyboardViewSwitch(
236-
props: DatePickerToolbarProps & {
237-
showKeyboardViewSwitch?: boolean;
238-
showKeyboardView?: boolean;
239-
setShowKeyboardView?: React.Dispatch<React.SetStateAction<boolean>>;
240-
},
241-
) {
242-
const { showKeyboardViewSwitch, showKeyboardView, setShowKeyboardView, ...other } =
243-
props;
244-
245-
if (showKeyboardViewSwitch) {
246-
return (
247-
<Stack
248-
spacing={2}
249-
direction={other.isLandscape ? 'column' : 'row'}
250-
alignItems="center"
251-
sx={
252-
other.isLandscape
253-
? {
254-
gridColumn: 1,
255-
gridRow: '1 / 3',
256-
}
257-
: { gridColumn: '1 / 4', gridRow: 1, mr: 1 }
258-
}
259-
>
260-
<DatePickerToolbar {...other} sx={{ flex: '1 1 100%' }} />
261-
<IconButton
262-
color="inherit"
263-
onClick={() => setShowKeyboardView!((prev) => !prev)}
264-
>
265-
{showKeyboardView ? <CalendarMonthIcon /> : <ModeEditIcon />}
266-
</IconButton>
267-
</Stack>
268-
);
269-
}
270-
271-
return <DatePickerToolbar {...other} />;
272-
}
273-
export default function MobileKeyboardView() {
274-
return (
275-
<LocalizationProvider dateAdapter={AdapterDayjs}>
276-
<MobileDatePicker
277-
slots={{
278-
layout: LayoutWithKeyboardView,
279-
toolbar: ToolbarWithKeyboardViewSwitch,
280-
}}
281-
/>
282-
</LocalizationProvider>
283-
);
284-
}
285-
```
174+
{{"demo": "MobileKeyboardView.js", "hideToolbar": true, "bg": true}}
286175

287176
:::info
288177
At some point, the mobile pickers should have a prop allowing to have an editable field without opening the modal.

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

-4
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ const theme = createTheme({
262262
```diff
263263
-const { toolbar, tabs, content, actionBar } = usePickerLayout(props);
264264
+const { toolbar, tabs, content, actionBar, ownerState } = usePickerLayout(props);
265-
266265
return (
267266
- <PickersLayoutRoot ownerState={props}>
268267
+ <PickersLayoutRoot ownerState={ownerState}>
@@ -295,7 +294,6 @@ const theme = createTheme({
295294

296295
```diff
297296
+import { useRtl } from '@mui/system/RtlProvider';
298-
299297
function CustomLayout(props) {
300298
- console.log(props.isRtl);
301299
+ const isRtl = useRtl();
@@ -310,7 +308,6 @@ const theme = createTheme({
310308
+import { usePickersContext } from '@mui/x-date-pickers/hooks';
311309
+const { orientation } = usePickersContext();
312310
+console.log(orientation);
313-
314311
-console.log(props.isLandscape);
315312
+import { usePickersContext } from '@mui/x-date-pickers/hooks';
316313
+const { orientation } = usePickersContext();
@@ -321,7 +318,6 @@ const theme = createTheme({
321318

322319
```diff
323320
-console.log(props.wrapperVariant);
324-
325321
+import { usePickersContext } from '@mui/x-date-pickers/hooks';
326322
+const { variant } = usePickersContext();
327323
+console.log(variant);

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@ import PropTypes from 'prop-types';
44
import clsx from 'clsx';
55
import { styled, useThemeProps } from '@mui/material/styles';
66
import composeClasses from '@mui/utils/composeClasses';
7-
import { PickersLayoutProps } from './PickersLayout.types';
7+
import { PickerLayoutOwnerState, PickersLayoutProps } from './PickersLayout.types';
88
import {
99
pickersLayoutClasses,
1010
getPickersLayoutUtilityClass,
1111
PickersLayoutClasses,
1212
} from './pickersLayoutClasses';
1313
import usePickerLayout from './usePickerLayout';
1414
import { DateOrTimeViewWithMeridiem } from '../internals/models';
15-
import { PickerOwnerState } from '../models/pickers';
1615
import { usePickerContext } from '../hooks/usePickerContext';
1716

1817
const useUtilityClasses = (
1918
classes: Partial<PickersLayoutClasses> | undefined,
20-
ownerState: PickerOwnerState,
19+
ownerState: PickerLayoutOwnerState,
2120
) => {
2221
const { pickerOrientation } = ownerState;
2322
const slots = {
@@ -32,7 +31,7 @@ export const PickersLayoutRoot = styled('div', {
3231
name: 'MuiPickersLayout',
3332
slot: 'Root',
3433
overridesResolver: (props, styles) => styles.root,
35-
})<{ ownerState: PickerOwnerState }>({
34+
})<{ ownerState: PickerLayoutOwnerState }>({
3635
display: 'grid',
3736
gridAutoColumns: 'max-content auto max-content',
3837
gridAutoRows: 'max-content auto max-content',

packages/x-date-pickers/src/PickersLayout/PickersLayout.types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ export interface ExportedPickersLayoutSlots<TValue, TView extends DateOrTimeView
3636
}
3737

3838
export interface PickerLayoutOwnerState extends PickerOwnerState {
39+
// isRTL cannot be part of PickerOwnerState because we need to have the correct isRTL value even when there is not picker above for some components.
40+
/**
41+
* `true` if the application is in right-to-left direction.
42+
*/
3943
isRtl: boolean;
4044
}
4145

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

+11-9
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
import * as React from 'react';
33
import useSlotProps from '@mui/utils/useSlotProps';
44
import composeClasses from '@mui/utils/composeClasses';
5+
import { useRtl } from '@mui/system/RtlProvider';
56
import { PickersActionBar, PickersActionBarAction } from '../PickersActionBar';
6-
import { PickersLayoutProps, SubComponents } from './PickersLayout.types';
7+
import { PickerLayoutOwnerState, PickersLayoutProps, SubComponents } from './PickersLayout.types';
78
import { getPickersLayoutUtilityClass, PickersLayoutClasses } from './pickersLayoutClasses';
89
import { PickersShortcuts } from '../PickersShortcuts';
910
import { BaseToolbarProps } from '../internals/models/props/toolbar';
1011
import { DateOrTimeViewWithMeridiem } from '../internals/models';
1112
import { usePickerPrivateContext } from '../internals/hooks/usePickerPrivateContext';
12-
import { PickerPrivateContextValue } from '../internals/components/PickerProvider';
13-
import { PickerOwnerState } from '../models/pickers';
1413
import { usePickerContext } from '../hooks';
1514

1615
function toolbarHasView<TValue, TView extends DateOrTimeViewWithMeridiem>(
@@ -21,7 +20,7 @@ function toolbarHasView<TValue, TView extends DateOrTimeViewWithMeridiem>(
2120

2221
const useUtilityClasses = (
2322
classes: Partial<PickersLayoutClasses> | undefined,
24-
ownerState: PickerOwnerState,
23+
ownerState: PickerLayoutOwnerState,
2524
) => {
2625
const { pickerOrientation } = ownerState;
2726
const slots = {
@@ -41,15 +40,17 @@ interface PickersLayoutPropsWithValueRequired<TValue, TView extends DateOrTimeVi
4140
extends PickersLayoutProps<TValue, TView> {
4241
value: TValue;
4342
}
44-
interface UsePickerLayoutResponse<TValue>
45-
extends SubComponents<TValue>,
46-
Pick<PickerPrivateContextValue, 'ownerState'> {}
43+
44+
interface UsePickerLayoutResponse<TValue> extends SubComponents<TValue> {
45+
ownerState: PickerLayoutOwnerState;
46+
}
4747

4848
const usePickerLayout = <TValue, TView extends DateOrTimeViewWithMeridiem>(
4949
props: PickersLayoutProps<TValue, TView>,
5050
): UsePickerLayoutResponse<TValue> => {
51-
const { ownerState } = usePickerPrivateContext();
52-
const { variant } = usePickerContext();
51+
const { ownerState: pickerOwnerState } = usePickerPrivateContext();
52+
const { variant, orientation } = usePickerContext();
53+
const isRtl = useRtl();
5354

5455
const {
5556
onAccept,
@@ -73,6 +74,7 @@ const usePickerLayout = <TValue, TView extends DateOrTimeViewWithMeridiem>(
7374
// - For range pickers value: [PickerValidDate | null, PickerValidDate | null]
7475
} = props as PickersLayoutPropsWithValueRequired<TValue, TView>;
7576

77+
const ownerState: PickerLayoutOwnerState = { ...pickerOwnerState, isRtl };
7678
const classes = useUtilityClasses(classesProp, ownerState);
7779

7880
// Action bar

packages/x-date-pickers/src/internals/hooks/useIsLandscape.tsx

-46
This file was deleted.

packages/x-date-pickers/src/internals/hooks/usePicker/usePicker.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ export const usePicker = <
8282
shouldRestoreFocus: pickerViewsResponse.shouldRestoreFocus,
8383

8484
// Picker layout
85-
layoutProps: { ...pickerValueResponse.layoutProps, ...pickerViewsResponse.layoutProps },
85+
layoutProps: {
86+
...pickerViewsResponse.layoutProps,
87+
...pickerValueResponse.layoutProps,
88+
},
8689

8790
// Picker provider
8891
providerProps,

0 commit comments

Comments
 (0)