Closed tpeek closed 3 years ago
@tpeek This is already possible with the rangeIntervalDayHighlightStart
and rangeIntervalDayHighlightEnd
classes keys. However, it seems that there is a couple of changes we can perform to make the customization experience much more enjoyable. Please confirm or infirm any of my observations:
.MuiPickersDateRangeDay-rangeIntervalDayHighlightStart
to .MuiPickersDateRangeDay-highlightStart
.diff --git a/lib/src/DateRangePicker/DateRangePickerDay.tsx b/lib/src/DateRangePicker/DateRangePickerDay.tsx
index f4bdabf6..ae6e4607 100644
--- a/lib/src/DateRangePicker/DateRangePickerDay.tsx
+++ b/lib/src/DateRangePicker/DateRangePickerDay.tsx
@@ -43,7 +43,7 @@ const useStyles = makeStyles(
'&:first-child': startBorderStyle,
'&:last-child': endBorderStyle,
},
- rangeIntervalDayHighlightStart: {
+ highlightStart: {
...startBorderStyle,
paddingLeft: 0,
marginLeft: DAY_MARGIN / 2,
@@ -124,7 +124,7 @@ export const PureDateRangeDay = ({
className={clsx(classes.root, {
[classes.rangeIntervalDayHighlight]: shouldRenderHighlight,
[classes.rangeIntervalDayHighlightEnd]: isEndOfHighlighting || isEndOfMonth,
- [classes.rangeIntervalDayHighlightStart]: isStartOfHighlighting || isStartOfMonth,
+ [classes.highlightStart]: isStartOfHighlighting || isStartOfMonth,
})}
>
<div
diff --git a/lib/src/DateRangePicker/DateRangePickerDay.tsx b/lib/src/DateRangePicker/DateRangePickerDay.tsx
index 48094361..37d58e44 100644
--- a/lib/src/DateRangePicker/DateRangePickerDay.tsx
+++ b/lib/src/DateRangePicker/DateRangePickerDay.tsx
@@ -43,6 +43,7 @@ const useStyles = makeStyles(
'&:first-child': startBorderStyle,
'&:last-child': endBorderStyle,
},
+ /* Styles applied to the root element when the highlight starts on this day. */
highlightStart: {
...startBorderStyle,
paddingLeft: 0,
DateRangePickerDay.tsx
-> DateRangeDay.tsx
. Diverging from the naming convention makes it harder to navigate the source. (used by people to figure out what's going on as a last resort)PickersDay
component, I would suggest a shorter name for this component: PickersRangeDay
instead of DateRangePickerDay
.import { PickersRangeDay, DateRangePicker } from '@material-ui/pickers';
function MyPickersRangeDay(props) {
return <PickersRangeDay {...props} />
}
<DateRangePicker slotComponents={{ PickersRangeDay: MyPickersRangeDay }} />
I'm 💯 for exploring these 7 changes further, the ease of customization is important.
@oliviertassinari
This is already possible with the
rangeIntervalDayHighlightStart
andrangeIntervalDayHighlightEnd
classes keys.
The rangeIntervalDayHighlightStart
and rangeIntervalDayHighlightEnd
classes aren't just applied to the beginning and end of a selected range- they are also applied to the end and beginning of months and weeks within a selected range:
[classes.rangeIntervalDayHighlightEnd]: isEndOfHighlighting || isEndOfMonth,
DateRangePickerDay L126
@tpeek Ok, so we would need an item 8: differentiate these two states.
Summary 💡
Right now, the classes are the same for a highlighted day at the beginning (or end) of a week, a month, or a selected range. It would be great if we had the ability to style a day highlight differently if it was at the beginning (or end) of a selected range.
Examples 🌈
Here's a visual:
The beginning and end of weeks and months are squared, while the beginning and end of the preview/highlighted range are rounded.
Motivation 🔦
I'm able to get most of the way with some creative and complicated css, but being able to target the divs at the beginning and end of a range would allow me to simplify the css greatly and match the design completely.