Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pickers] MultiSectionDigitalClock layout review #15258

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ DesktopDateTimePickerLayout.propTypes = {
PropTypes.object,
]),
value: PropTypes.any,
valueType: PropTypes.oneOf(['date-time', 'date', 'time']).isRequired,
view: PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']),
views: PropTypes.arrayOf(
PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']).isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const MultiSectionDigitalClockRoot = styled(PickerViewRoot, {
flexDirection: 'row',
width: '100%',
borderBottom: `1px solid ${(theme.vars || theme).palette.divider}`,
justifyContent: 'space-evenly',
}));

type MultiSectionDigitalClockComponent = (<TDate extends PickerValidDate>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ const MultiSectionDigitalClockSectionRoot = styled(MenuList, {
})<{ ownerState: MultiSectionDigitalClockSectionProps<any> & { alreadyRendered: boolean } }>(
({ theme }) => ({
maxHeight: DIGITAL_CLOCK_VIEW_HEIGHT,
width: 56,
width: '100%',
padding: 0,
overflow: 'hidden',
borderLeft: `1px solid ${(theme.vars || theme).palette.divider}`,
scrollbarGutter: 'stable',
'@media (prefers-reduced-motion: no-preference)': {
scrollBehavior: 'auto',
},
Expand All @@ -70,8 +72,8 @@ const MultiSectionDigitalClockSectionRoot = styled(MenuList, {
'@media (pointer: none), (pointer: coarse)': {
overflowY: 'auto',
},
'&:not(:first-of-type)': {
borderLeft: `1px solid ${(theme.vars || theme).palette.divider}`,
'&:first-of-type': {
borderColor: 'transparent',
},
'&::after': {
display: 'block',
Expand Down
17 changes: 13 additions & 4 deletions packages/x-date-pickers/src/PickersLayout/PickersLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { PickersLayoutProps } from './PickersLayout.types';
import { pickersLayoutClasses, getPickersLayoutUtilityClass } from './pickersLayoutClasses';
import usePickerLayout from './usePickerLayout';
import { DateOrTimeViewWithMeridiem } from '../internals/models';
import { PickerValidDate } from '../models';
import { FieldValueType, PickerValidDate } from '../models';

const useUtilityClasses = (ownerState: PickersLayoutProps<any, any, any>) => {
const { isLandscape, classes } = ownerState;
Expand Down Expand Up @@ -73,11 +73,19 @@ export const PickersLayoutContentWrapper = styled('div', {
name: 'MuiPickersLayout',
slot: 'ContentWrapper',
overridesResolver: (props, styles) => styles.contentWrapper,
})({
})<{ ownerState?: { valueType: FieldValueType } }>({
gridColumn: 2,
gridRow: 2,
display: 'flex',
flexDirection: 'column',
variants: [
{
props: { valueType: 'time' },
style: {
gridColumn: '1/4',
},
},
],
});

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

const { toolbar, content, tabs, actionBar, shortcuts } = usePickerLayout(props);
const { sx, className, isLandscape, wrapperVariant } = props;
const { sx, className, isLandscape, wrapperVariant, valueType } = props;

const classes = useUtilityClasses(props);

Expand All @@ -118,7 +126,7 @@ const PickersLayout = React.forwardRef(function PickersLayout<
>
{isLandscape ? shortcuts : toolbar}
{isLandscape ? toolbar : shortcuts}
<PickersLayoutContentWrapper className={classes.contentWrapper}>
<PickersLayoutContentWrapper ownerState={{ valueType }} className={classes.contentWrapper}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in the main PR, the ownerState should comme from usePickerLayout.

But overall I have an issue with this BC because PickersLayoutContentWrapper is public so people will need to pass manually the ownerState and it's not a great DX IMHO.
We really need to rework the whole DX at some point to hide those implementation details.

{wrapperVariant === 'desktop' ? (
<React.Fragment>
{content}
Expand Down Expand Up @@ -188,6 +196,7 @@ PickersLayout.propTypes = {
PropTypes.object,
]),
value: PropTypes.any,
valueType: PropTypes.oneOf(['date-time', 'date', 'time']).isRequired,
view: PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']),
views: PropTypes.arrayOf(
PropTypes.oneOf(['day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'year']).isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const usePicker = <
const pickerLayoutResponse = usePickerLayoutProps({
props,
wrapperVariant,
valueType,
propsFromPickerValue: pickerValueResponse.layoutProps,
propsFromPickerViews: pickerViewsResponse.layoutProps,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useRtl } from '@mui/system/RtlProvider';
import { FieldValueType } from '../../../models';
import { useIsLandscape } from '../useIsLandscape';
import { UsePickerValueLayoutResponse } from './usePickerValue.types';
import { UsePickerViewsLayoutResponse } from './usePickerViews';
Expand Down Expand Up @@ -26,6 +27,7 @@ export interface UsePickerLayoutPropsResponseLayoutProps<
isLandscape: boolean;
isRtl: boolean;
wrapperVariant: WrapperVariant;
valueType: FieldValueType;
isValid: (value: TValue) => boolean;
}

Expand All @@ -38,6 +40,7 @@ export interface UsePickerLayoutPropsParams<TValue, TView extends DateOrTimeView
propsFromPickerValue: UsePickerValueLayoutResponse<TValue>;
propsFromPickerViews: UsePickerViewsLayoutResponse<TView>;
wrapperVariant: WrapperVariant;
valueType: FieldValueType;
}

/**
Expand All @@ -48,6 +51,7 @@ export const usePickerLayoutProps = <TValue, TView extends DateOrTimeViewWithMer
propsFromPickerValue,
propsFromPickerViews,
wrapperVariant,
valueType,
}: UsePickerLayoutPropsParams<TValue, TView>): UsePickerLayoutPropsResponse<TValue, TView> => {
const { orientation } = props;
const isLandscape = useIsLandscape(propsFromPickerViews.views, orientation);
Expand All @@ -59,6 +63,7 @@ export const usePickerLayoutProps = <TValue, TView extends DateOrTimeViewWithMer
isLandscape,
isRtl,
wrapperVariant,
valueType,
disabled: props.disabled,
readOnly: props.readOnly,
};
Expand Down
Loading