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] Prepare compatibility with @mui/zero-runtime (stop using ownerState in styled) #12003

Merged
merged 34 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e5aa92b
[pickers] Explore usage of the new variants styling API
flaviendelangle Feb 8, 2024
3e0c277
Fi
flaviendelangle Feb 8, 2024
12e3395
Review: Brijesh
flaviendelangle Feb 8, 2024
b026e73
Migrate more components
flaviendelangle Feb 9, 2024
56bf1ab
Fix
flaviendelangle Feb 9, 2024
399c385
Fix
flaviendelangle Feb 9, 2024
a486d69
Migrate more components
flaviendelangle Feb 9, 2024
9ef8017
Fix
flaviendelangle Feb 9, 2024
413dfc1
Merge branch 'next' into poc-variants
flaviendelangle Feb 20, 2024
5630924
Code review: Jun
flaviendelangle Feb 20, 2024
481abb5
Work
flaviendelangle Feb 20, 2024
c625f01
Fix
flaviendelangle Feb 20, 2024
3b9665b
Fix
flaviendelangle Feb 20, 2024
d484bf7
Merge branch 'next' into poc-variants
flaviendelangle Feb 21, 2024
6bb160a
Fix
flaviendelangle Feb 21, 2024
d9f6f3e
Work
flaviendelangle Feb 21, 2024
9bdb32b
Fix PickersLayout
flaviendelangle Feb 21, 2024
c8f0f6b
Merge branch 'next' into poc-variants
flaviendelangle Feb 23, 2024
07560fc
Migrate inputs
flaviendelangle Feb 23, 2024
aeee6c4
Fix ts
flaviendelangle Feb 23, 2024
59dba00
Merge branch 'next' into poc-variants
flaviendelangle Mar 13, 2024
201a84f
Code review: Lukas
flaviendelangle Mar 13, 2024
96aae27
Merge branch 'next' into poc-variants
flaviendelangle Mar 18, 2024
4160f43
Fix
flaviendelangle Mar 18, 2024
5b61ce3
Fix
flaviendelangle Mar 18, 2024
8909a74
Merge branch 'master' into poc-variants
flaviendelangle Mar 21, 2024
02a177c
Use new DX
flaviendelangle Mar 21, 2024
e5cdbdd
Improve
flaviendelangle Mar 21, 2024
43346fa
Try to fix specificity issue
flaviendelangle Mar 21, 2024
48b8026
Code review: Lukas
flaviendelangle Mar 21, 2024
d518d2a
Merge branch 'master' into poc-variants
flaviendelangle Mar 22, 2024
5c2ef51
Merge branch 'master' into poc-variants
flaviendelangle Mar 25, 2024
79bac3d
Review: Jun
flaviendelangle Mar 25, 2024
db6bd2d
Merge branch 'master' into poc-variants
flaviendelangle Mar 26, 2024
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 @@ -50,6 +50,11 @@ export interface DateRangePickerDayProps<TDate extends PickerValidDate>
* Indicates if the day should be visually selected.
*/
isVisuallySelected?: boolean;
/**
* If `true`, the day can be dragged to change the current date range.
* @default false
*/
draggable?: boolean;
Copy link
Member Author

Choose a reason for hiding this comment

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

Right now the typing comes from the DOM element which also accepts "true" and "false"
But we are only passing true of undefined so I restricted the typing so that our check in the styled component and the typing are coherent

}

type OwnerState = DateRangePickerDayProps<any> & {
Expand Down Expand Up @@ -154,10 +159,11 @@ const DateRangePickerDayRoot = styled('div', {
},
styles.root,
],
})<{ ownerState: OwnerState }>(({ theme, ownerState }) =>
ownerState.isHiddenDayFiller
? {}
: {
})<{ ownerState: OwnerState }>(({ theme }) => ({
variants: [
{
props: { isHiddenDayFiller: false },
style: {
[`&:first-of-type .${dateRangePickerDayClasses.rangeIntervalDayPreview}`]: {
...startBorderStyle,
borderLeftColor: (theme.vars || theme).palette.divider,
Expand All @@ -166,25 +172,38 @@ const DateRangePickerDayRoot = styled('div', {
...endBorderStyle,
borderRightColor: (theme.vars || theme).palette.divider,
},
...(ownerState.isHighlighting && {
borderRadius: 0,
color: (theme.vars || theme).palette.primary.contrastText,
backgroundColor: theme.vars
? `rgba(${theme.vars.palette.primary.mainChannel} / ${theme.vars.palette.action.focusOpacity})`
: alpha(theme.palette.primary.main, theme.palette.action.focusOpacity),
'&:first-of-type': startBorderStyle,
'&:last-of-type': endBorderStyle,
}),
...((ownerState.isStartOfHighlighting || ownerState.isFirstVisibleCell) && {
...startBorderStyle,
paddingLeft: 0,
}),
...((ownerState.isEndOfHighlighting || ownerState.isLastVisibleCell) && {
...endBorderStyle,
paddingRight: 0,
}),
},
);
},
{
props: { isHiddenDayFiller: false, isHighlighting: true },
style: {
borderRadius: 0,
color: (theme.vars || theme).palette.primary.contrastText,
backgroundColor: theme.vars
? `rgba(${theme.vars.palette.primary.mainChannel} / ${theme.vars.palette.action.focusOpacity})`
: alpha(theme.palette.primary.main, theme.palette.action.focusOpacity),
'&:first-of-type': startBorderStyle,
'&:last-of-type': endBorderStyle,
},
},
{
props: ({ isHiddenDayFiller, isStartOfHighlighting, isFirstVisibleCell }: OwnerState) =>
!isHiddenDayFiller && (isStartOfHighlighting || isFirstVisibleCell),
style: {
...startBorderStyle,
paddingLeft: 0,
},
},
{
props: ({ isHiddenDayFiller, isEndOfHighlighting, isLastVisibleCell }: OwnerState) =>
!isHiddenDayFiller && (isEndOfHighlighting || isLastVisibleCell),
style: {
...endBorderStyle,
paddingRight: 0,
},
},
],
}));

DateRangePickerDayRoot.propTypes = {
// ----------------------------- Warning --------------------------------
Expand Down Expand Up @@ -248,19 +267,22 @@ const DateRangePickerDayDay = styled(PickersDay, {
],
})<{
ownerState: OwnerState;
}>(({ ownerState }) => ({
}>({
// Required to overlap preview border
transform: 'scale(1.1)',
'& > *': {
transform: 'scale(0.9)',
},
...(ownerState.draggable && {
cursor: 'grab',
}),
...(ownerState.draggable && {
touchAction: 'none',
}),
})) as unknown as <TDate extends PickerValidDate>(
variants: [
{
props: { draggable: true },
style: {
cursor: 'grab',
touchAction: 'none',
},
},
],
}) as unknown as <TDate extends PickerValidDate>(
props: PickersDayProps<TDate> & { ownerState: OwnerState },
) => React.JSX.Element;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ const DayCalendarSkeletonDay = styled(Skeleton, {
name: 'MuiDayCalendarSkeleton',
slot: 'DaySkeleton',
overridesResolver: (props, styles) => styles.daySkeleton,
})<{ ownerState: { day: number } }>(({ ownerState }) => ({
})<{ ownerState: { day: number } }>({
margin: `0 ${DAY_MARGIN}px`,
...(ownerState.day === 0 && {
visibility: 'hidden',
}),
}));
variants: [
{
props: { day: 0 },
style: { visibility: 'hidden' },
},
],
});

DayCalendarSkeletonDay.propTypes = {
// ----------------------------- Warning --------------------------------
Expand Down
16 changes: 13 additions & 3 deletions packages/x-date-pickers/src/DigitalClock/DigitalClock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,24 @@ const DigitalClockRoot = styled(PickerViewRoot, {
name: 'MuiDigitalClock',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})<{ ownerState: DigitalClockProps<any> & { alreadyRendered: boolean } }>(({ ownerState }) => ({
})<{ ownerState: DigitalClockProps<any> & { alreadyRendered: boolean } }>({
overflowY: 'auto',
width: '100%',
'@media (prefers-reduced-motion: no-preference)': {
scrollBehavior: ownerState.alreadyRendered ? 'smooth' : 'auto',
scrollBehavior: 'auto',
},
maxHeight: DIGITAL_CLOCK_VIEW_HEIGHT,
}));
variants: [
{
props: { alreadyRendered: true },
style: {
'@media (prefers-reduced-motion: no-preference)': {
scrollBehavior: 'smooth',
},
},
},
],
});

const DigitalClockList = styled(MenuList, {
name: 'MuiDigitalClock',
Expand Down
11 changes: 8 additions & 3 deletions packages/x-date-pickers/src/MonthCalendar/PickersMonth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,17 @@ const PickersMonthRoot = styled('div', {
overridesResolver: (_, styles) => [styles.root],
})<{
ownerState: PickersMonthProps;
}>(({ ownerState }) => ({
flexBasis: ownerState.monthsPerRow === 3 ? '33.3%' : '25%',
}>({
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}));
variants: [3, 4].map((monthsPerRow) => ({
props: { monthsPerRow },
style: {
flexBasis: `${Math.round((1 / monthsPerRow) * 1000) / 10}%`,
},
})),
});

const PickersMonthButton = styled('button', {
name: 'MuiPickersMonth',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ const MultiSectionDigitalClockSectionRoot = styled(MenuList, {
slot: 'Root',
overridesResolver: (_, styles) => styles.root,
})<{ ownerState: MultiSectionDigitalClockSectionProps<any> & { alreadyRendered: boolean } }>(
({ theme, ownerState }) => ({
({ theme }) => ({
maxHeight: DIGITAL_CLOCK_VIEW_HEIGHT,
width: 56,
padding: 0,
overflow: 'hidden',
'@media (prefers-reduced-motion: no-preference)': {
scrollBehavior: ownerState.alreadyRendered ? 'smooth' : 'auto',
scrollBehavior: 'auto',
},
'@media (pointer: fine)': {
'&:hover': {
Expand All @@ -78,6 +78,16 @@ const MultiSectionDigitalClockSectionRoot = styled(MenuList, {
// subtracting the height of one item, extra margin and borders to make sure the max height is correct
height: 'calc(100% - 40px - 6px)',
},
variants: [
{
props: { alreadyRendered: true },
style: {
'@media (prefers-reduced-motion: no-preference)': {
scrollBehavior: 'smooth',
},
},
},
],
}),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,19 @@ const PickersCalendarHeaderSwitchViewButton = styled(IconButton, {
overridesResolver: (_, styles) => styles.switchViewButton,
})<{
ownerState: PickersCalendarHeaderOwnerState<any>;
}>(({ ownerState }) => ({
}>({
marginRight: 'auto',
...(ownerState.view === 'year' && {
[`.${pickersCalendarHeaderClasses.switchViewIcon}`]: {
transform: 'rotate(180deg)',
variants: [
{
props: { view: 'year' },
style: {
[`.${pickersCalendarHeaderClasses.switchViewIcon}`]: {
transform: 'rotate(180deg)',
},
},
},
}),
}));
],
});

const PickersCalendarHeaderSwitchViewIcon = styled(ArrowDropDownIcon, {
name: 'MuiPickersCalendarHeader',
Expand Down
39 changes: 24 additions & 15 deletions packages/x-date-pickers/src/PickersDay/PickersDay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const useUtilityClasses = (ownerState: PickersDayProps<any>) => {
return composeClasses(slots, getPickersDayUtilityClass, classes);
};

const styleArg = ({ theme, ownerState }: { theme: Theme; ownerState: OwnerState }) => ({
const styleArg = ({ theme }: { theme: Theme }) => ({
...theme.typography.caption,
width: DAY_SIZE,
height: DAY_SIZE,
Expand Down Expand Up @@ -170,19 +170,28 @@ const styleArg = ({ theme, ownerState }: { theme: Theme; ownerState: OwnerState
[`&.${pickersDayClasses.disabled}&.${pickersDayClasses.selected}`]: {
opacity: 0.6,
},
...(!ownerState.disableMargin && {
margin: `0 ${DAY_MARGIN}px`,
}),
...(ownerState.outsideCurrentMonth &&
ownerState.showDaysOutsideCurrentMonth && {
color: (theme.vars || theme).palette.text.secondary,
}),
...(!ownerState.disableHighlightToday &&
ownerState.today && {
[`&:not(.${pickersDayClasses.selected})`]: {
border: `1px solid ${(theme.vars || theme).palette.text.secondary}`,
variants: [
{
props: { disableMargin: false },
style: {
margin: `0 ${DAY_MARGIN}px`,
},
}),
},
{
props: { outsideCurrentMonth: true, showDaysOutsideCurrentMonth: true },
style: {
color: (theme.vars || theme).palette.text.secondary,
},
},
{
props: { disableHighlightToday: false, today: true },
style: {
[`&:not(.${pickersDayClasses.selected})`]: {
border: `1px solid ${(theme.vars || theme).palette.text.secondary}`,
},
},
},
],
});

const overridesResolver = (
Expand Down Expand Up @@ -213,8 +222,8 @@ const PickersDayFiller = styled('div', {
name: 'MuiPickersDay',
slot: 'Root',
overridesResolver,
})<{ ownerState: OwnerState }>(({ theme, ownerState }) => ({
...styleArg({ theme, ownerState }),
})<{ ownerState: OwnerState }>(({ theme }) => ({
...styleArg({ theme }),
// visibility: 'hidden' does not work here as it hides the element from screen readers as well
opacity: 0,
pointerEvents: 'none',
Expand Down
31 changes: 18 additions & 13 deletions packages/x-date-pickers/src/PickersLayout/PickersLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,28 @@ const PickersLayoutRoot = styled('div', {
name: 'MuiPickersLayout',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})<{ ownerState: { isLandscape: boolean } }>(({ theme, ownerState }) => ({
})<{ ownerState: { isLandscape: boolean } }>(({ theme }) => ({
display: 'grid',
gridAutoColumns: 'max-content auto max-content',
gridAutoRows: 'max-content auto max-content',
[`& .${pickersLayoutClasses.toolbar}`]: ownerState.isLandscape
? {
gridColumn: theme.direction === 'rtl' ? 3 : 1,
gridRow: '2 / 3',
}
: { gridColumn: '2 / 4', gridRow: 1 },
[`.${pickersLayoutClasses.shortcuts}`]: ownerState.isLandscape
? { gridColumn: '2 / 4', gridRow: 1 }
: {
gridColumn: theme.direction === 'rtl' ? 3 : 1,
gridRow: '2 / 3',
},
[`& .${pickersLayoutClasses.actionBar}`]: { gridColumn: '1 / 4', gridRow: 3 },
variants: [true, false].map((isLandscape) => ({
props: { isLandscape },
style: {
[`& .${pickersLayoutClasses.toolbar}`]: isLandscape
? {
gridColumn: theme.direction === 'rtl' ? 3 : 1,
gridRow: '2 / 3',
}
: { gridColumn: '2 / 4', gridRow: 1 },
[`.${pickersLayoutClasses.shortcuts}`]: isLandscape
? { gridColumn: '2 / 4', gridRow: 1 }
: {
gridColumn: theme.direction === 'rtl' ? 3 : 1,
gridRow: '2 / 3',
},
},
})),
}));

PickersLayoutRoot.propTypes = {
Expand Down
Loading
Loading