Skip to content

Commit 1a5c9d7

Browse files
experimenal layout refactor
1 parent eb2cae5 commit 1a5c9d7

File tree

6 files changed

+26
-7
lines changed

6 files changed

+26
-7
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ DesktopDateTimePickerLayout.propTypes = {
115115
PropTypes.object,
116116
]),
117117
value: PropTypes.any,
118+
valueType: PropTypes.oneOf(['date-time', 'date', 'time']).isRequired,
118119
view: PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']),
119120
views: PropTypes.arrayOf(
120121
PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']).isRequired,

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

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const MultiSectionDigitalClockRoot = styled(PickerViewRoot, {
4545
flexDirection: 'row',
4646
width: '100%',
4747
borderBottom: `1px solid ${(theme.vars || theme).palette.divider}`,
48+
justifyContent: 'space-evenly',
4849
}));
4950

5051
type MultiSectionDigitalClockComponent = (<TDate extends PickerValidDate>(

packages/x-date-pickers/src/MultiSectionDigitalClock/MultiSectionDigitalClockSection.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ const MultiSectionDigitalClockSectionRoot = styled(MenuList, {
5656
})<{ ownerState: MultiSectionDigitalClockSectionProps<any> & { alreadyRendered: boolean } }>(
5757
({ theme }) => ({
5858
maxHeight: DIGITAL_CLOCK_VIEW_HEIGHT,
59-
width: 56,
59+
width: '100%',
6060
padding: 0,
6161
overflow: 'hidden',
62+
borderLeft: `1px solid ${(theme.vars || theme).palette.divider}`,
63+
scrollbarGutter: 'stable',
6264
'@media (prefers-reduced-motion: no-preference)': {
6365
scrollBehavior: 'auto',
6466
},
@@ -70,8 +72,8 @@ const MultiSectionDigitalClockSectionRoot = styled(MenuList, {
7072
'@media (pointer: none), (pointer: coarse)': {
7173
overflowY: 'auto',
7274
},
73-
'&:not(:first-of-type)': {
74-
borderLeft: `1px solid ${(theme.vars || theme).palette.divider}`,
75+
'&:first-of-type': {
76+
borderColor: 'transparent',
7577
},
7678
'&::after': {
7779
display: 'block',

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

+13-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { PickersLayoutProps } from './PickersLayout.types';
88
import { pickersLayoutClasses, getPickersLayoutUtilityClass } from './pickersLayoutClasses';
99
import usePickerLayout from './usePickerLayout';
1010
import { DateOrTimeViewWithMeridiem } from '../internals/models';
11-
import { PickerValidDate } from '../models';
11+
import { FieldValueType, PickerValidDate } from '../models';
1212

1313
const useUtilityClasses = (ownerState: PickersLayoutProps<any, any, any>) => {
1414
const { isLandscape, classes } = ownerState;
@@ -73,11 +73,19 @@ export const PickersLayoutContentWrapper = styled('div', {
7373
name: 'MuiPickersLayout',
7474
slot: 'ContentWrapper',
7575
overridesResolver: (props, styles) => styles.contentWrapper,
76-
})({
76+
})<{ ownerState?: { valueType: FieldValueType } }>({
7777
gridColumn: 2,
7878
gridRow: 2,
7979
display: 'flex',
8080
flexDirection: 'column',
81+
variants: [
82+
{
83+
props: { valueType: 'time' },
84+
style: {
85+
gridColumn: '1/4',
86+
},
87+
},
88+
],
8189
});
8290

8391
type PickersLayoutComponent = (<
@@ -105,7 +113,7 @@ const PickersLayout = React.forwardRef(function PickersLayout<
105113
const props = useThemeProps({ props: inProps, name: 'MuiPickersLayout' });
106114

107115
const { toolbar, content, tabs, actionBar, shortcuts } = usePickerLayout(props);
108-
const { sx, className, isLandscape, wrapperVariant } = props;
116+
const { sx, className, isLandscape, wrapperVariant, valueType } = props;
109117

110118
const classes = useUtilityClasses(props);
111119

@@ -118,7 +126,7 @@ const PickersLayout = React.forwardRef(function PickersLayout<
118126
>
119127
{isLandscape ? shortcuts : toolbar}
120128
{isLandscape ? toolbar : shortcuts}
121-
<PickersLayoutContentWrapper className={classes.contentWrapper}>
129+
<PickersLayoutContentWrapper ownerState={{ valueType }} className={classes.contentWrapper}>
122130
{wrapperVariant === 'desktop' ? (
123131
<React.Fragment>
124132
{content}
@@ -188,6 +196,7 @@ PickersLayout.propTypes = {
188196
PropTypes.object,
189197
]),
190198
value: PropTypes.any,
199+
valueType: PropTypes.oneOf(['date-time', 'date', 'time']).isRequired,
191200
view: PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']),
192201
views: PropTypes.arrayOf(
193202
PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']).isRequired,

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

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export const usePicker = <
7070
const pickerLayoutResponse = usePickerLayoutProps({
7171
props,
7272
wrapperVariant,
73+
valueType,
7374
propsFromPickerValue: pickerValueResponse.layoutProps,
7475
propsFromPickerViews: pickerViewsResponse.layoutProps,
7576
});

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

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useRtl } from '@mui/system/RtlProvider';
2+
import { FieldValueType } from '../../../models';
23
import { useIsLandscape } from '../useIsLandscape';
34
import { UsePickerValueLayoutResponse } from './usePickerValue.types';
45
import { UsePickerViewsLayoutResponse } from './usePickerViews';
@@ -26,6 +27,7 @@ export interface UsePickerLayoutPropsResponseLayoutProps<
2627
isLandscape: boolean;
2728
isRtl: boolean;
2829
wrapperVariant: WrapperVariant;
30+
valueType: FieldValueType;
2931
isValid: (value: TValue) => boolean;
3032
}
3133

@@ -38,6 +40,7 @@ export interface UsePickerLayoutPropsParams<TValue, TView extends DateOrTimeView
3840
propsFromPickerValue: UsePickerValueLayoutResponse<TValue>;
3941
propsFromPickerViews: UsePickerViewsLayoutResponse<TView>;
4042
wrapperVariant: WrapperVariant;
43+
valueType: FieldValueType;
4144
}
4245

4346
/**
@@ -48,6 +51,7 @@ export const usePickerLayoutProps = <TValue, TView extends DateOrTimeViewWithMer
4851
propsFromPickerValue,
4952
propsFromPickerViews,
5053
wrapperVariant,
54+
valueType,
5155
}: UsePickerLayoutPropsParams<TValue, TView>): UsePickerLayoutPropsResponse<TValue, TView> => {
5256
const { orientation } = props;
5357
const isLandscape = useIsLandscape(propsFromPickerViews.views, orientation);
@@ -59,6 +63,7 @@ export const usePickerLayoutProps = <TValue, TView extends DateOrTimeViewWithMer
5963
isLandscape,
6064
isRtl,
6165
wrapperVariant,
66+
valueType,
6267
disabled: props.disabled,
6368
readOnly: props.readOnly,
6469
};

0 commit comments

Comments
 (0)