Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions docs/pages/x/api/date-pickers/date-range-picker-day.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"disableMargin": { "type": { "name": "bool" }, "default": "false" },
"disableRipple": { "type": { "name": "bool" }, "default": "false" },
"disableTouchRipple": { "type": { "name": "bool" }, "default": "false" },
"draggable": { "type": { "name": "bool" }, "default": "false" },
"focusRipple": { "type": { "name": "bool" }, "default": "false" },
"focusVisibleClassName": { "type": { "name": "string" } },
"isVisuallySelected": { "type": { "name": "bool" } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
"disableTouchRipple": {
"description": "If <code>true</code>, the touch ripple effect is disabled."
},
"draggable": {
"description": "If <code>true</code>, the day can be dragged to change the current date range."
},
"focusRipple": {
"description": "If <code>true</code>, the base button will have a keyboard focus ripple."
},
Expand Down
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,44 @@ 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: ({
ownerState: { isHiddenDayFiller, isStartOfHighlighting, isFirstVisibleCell },
}: {
ownerState: OwnerState;
}) => !isHiddenDayFiller && (isStartOfHighlighting || isFirstVisibleCell),
style: {
...startBorderStyle,
paddingLeft: 0,
},
},
{
props: ({
ownerState: { isHiddenDayFiller, isEndOfHighlighting, isLastVisibleCell },
}: {
ownerState: OwnerState;
}) => !isHiddenDayFiller && (isEndOfHighlighting || isLastVisibleCell),
style: {
...endBorderStyle,
paddingRight: 0,
},
},
],
}));

DateRangePickerDayRoot.propTypes = {
// ----------------------------- Warning --------------------------------
Expand All @@ -209,24 +234,42 @@ const DateRangePickerDayRangeIntervalPreview = styled('div', {
},
styles.rangeIntervalPreview,
],
})<{ ownerState: OwnerState }>(({ theme, ownerState }) => ({
})<{ ownerState: OwnerState }>(({ theme }) => ({
// replace default day component margin with transparent border to avoid jumping on preview
border: '2px solid transparent',
...(ownerState.isPreviewing &&
!ownerState.isHiddenDayFiller && {
borderRadius: 0,
border: `2px dashed ${(theme.vars || theme).palette.divider}`,
borderLeftColor: 'transparent',
borderRightColor: 'transparent',
...((ownerState.isStartOfPreviewing || ownerState.isFirstVisibleCell) && {
variants: [
{
props: { isPreviewing: true, isHiddenDayFiller: false },
style: {
borderRadius: 0,
border: `2px dashed ${(theme.vars || theme).palette.divider}`,
borderLeftColor: 'transparent',
borderRightColor: 'transparent',
},
},
{
props: ({
ownerState: { isPreviewing, isHiddenDayFiller, isStartOfPreviewing, isFirstVisibleCell },
}: {
ownerState: OwnerState;
}) => isPreviewing && !isHiddenDayFiller && (isStartOfPreviewing || isFirstVisibleCell),
style: {
borderLeftColor: (theme.vars || theme).palette.divider,
...startBorderStyle,
}),
...((ownerState.isEndOfPreviewing || ownerState.isLastVisibleCell) && {
},
},
{
props: ({
ownerState: { isPreviewing, isHiddenDayFiller, isEndOfPreviewing, isLastVisibleCell },
}: {
ownerState: OwnerState;
}) => isPreviewing && !isHiddenDayFiller && (isEndOfPreviewing || isLastVisibleCell),
style: {
borderRightColor: (theme.vars || theme).palette.divider,
...endBorderStyle,
}),
}),
},
},
],
}));

DateRangePickerDayRangeIntervalPreview.propTypes = {
Expand All @@ -248,19 +291,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 Expand Up @@ -405,6 +451,11 @@ DateRangePickerDayRaw.propTypes = {
* @default false
*/
disableTouchRipple: PropTypes.bool,
/**
* If `true`, the day can be dragged to change the current date range.
* @default false
*/
draggable: PropTypes.bool,
/**
* If `true`, the base button will have a keyboard focus ripple.
* @default false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,43 @@ const DateTimeRangePickerToolbarStart = styled(DateTimePickerToolbar, {
name: 'MuiDateTimeRangePickerToolbar',
slot: 'StartToolbar',
overridesResolver: (_, styles) => styles.startToolbar,
})<DateTimeRangePickerStartOrEndToolbarProps<any>>(({ ownerState }) => ({
})<DateTimeRangePickerStartOrEndToolbarProps<any>>({
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
})<DateTimeRangePickerStartOrEndToolbarProps<any>>({
})<DateTimeRangePickerStartOrEndToolbarProps<any> & { ownerState: DateTimeRangePickerStartOrEndToolbarProps<any> }>({

This would make sure that the styled-component receives ownerState.

Copy link
Member Author

@flaviendelangle flaviendelangle Mar 25, 2024

Choose a reason for hiding this comment

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

DateTimeRangePickerStartOrEndToolbarProps already contains it 👍

type DateTimeRangePickerStartOrEndToolbarProps<TDate extends PickerValidDate> =
  DateTimePickerToolbarProps<TDate> & {
    ownerState?: DateTimeRangePickerToolbarProps<TDate>;
  };

Copy link
Member Author

Choose a reason for hiding this comment

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

OK the problem was that ownerState was optional in DateTimeRangePickerStartOrEndToolbarProps

Copy link
Member Author

Choose a reason for hiding this comment

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

But the right API here is :

      props: ({ toolbarVariant }: DateTimeRangePickerStartOrEndToolbarProps<any>) => toolbarVariant !== 'desktop',

In which case I do need the typing because the types equals props and not props & ownerState (it should probably be fixed)

borderBottom: 'none',
...(ownerState?.toolbarVariant !== 'desktop'
? {
variants: [
{
props: ({ toolbarVariant }: DateTimeRangePickerStartOrEndToolbarProps<any>) =>
toolbarVariant !== 'desktop',
style: {
padding: '12px 8px 0 12px',
}
: {
},
},
{
props: { toolbarVariant: 'desktop' },
style: {
paddingBottom: 0,
}),
})) as DateTimeRangePickerStartOrEndToolbarComponent;
},
},
],
}) as DateTimeRangePickerStartOrEndToolbarComponent;

const DateTimeRangePickerToolbarEnd = styled(DateTimePickerToolbar, {
name: 'MuiDateTimeRangePickerToolbar',
slot: 'EndToolbar',
overridesResolver: (_, styles) => styles.endToolbar,
})<DateTimeRangePickerStartOrEndToolbarProps<any>>(({ ownerState }) => ({
padding: ownerState?.toolbarVariant !== 'desktop' ? '12px 8px 12px 12px' : undefined,
})) as DateTimeRangePickerStartOrEndToolbarComponent;
})<DateTimeRangePickerStartOrEndToolbarProps<any>>({
variants: [
{
props: ({
ownerState: { toolbarVariant },
}: {
ownerState: DateTimeRangePickerStartOrEndToolbarProps<any>;
}) => toolbarVariant !== 'desktop',
style: {
padding: '12px 8px 12px 12px',
},
},
],
}) as DateTimeRangePickerStartOrEndToolbarComponent;

const DateTimeRangePickerToolbar = React.forwardRef(function DateTimeRangePickerToolbar<
TDate extends PickerValidDate,
Expand Down
15 changes: 10 additions & 5 deletions packages/x-date-pickers/src/DatePicker/DatePickerToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,16 @@ const DatePickerToolbarTitle = styled(Typography, {
name: 'MuiDatePickerToolbar',
slot: 'Title',
overridesResolver: (_, styles) => styles.title,
})<{ ownerState: DatePickerToolbarProps<any> }>(({ ownerState }) => ({
...(ownerState.isLandscape && {
margin: 'auto 16px auto auto',
}),
}));
})<{ ownerState: DatePickerToolbarProps<any> }>({
variants: [
{
props: { isLandscape: true },
style: {
margin: 'auto 16px auto auto',
},
},
],
});

type DatePickerToolbarComponent = (<TDate extends PickerValidDate>(
props: DatePickerToolbarProps<TDate> & React.RefAttributes<HTMLDivElement>,
Expand Down
Loading