Skip to content

DateRangePickerDay: selected class on wrapping divs #2006

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

Closed
1 task done
tpeek opened this issue Jul 18, 2020 · 3 comments
Closed
1 task done

DateRangePickerDay: selected class on wrapping divs #2006

tpeek opened this issue Jul 18, 2020 · 3 comments
Labels

Comments

@tpeek
Copy link

tpeek commented Jul 18, 2020

  • I have searched the issues of this repository and believe that this is not a duplicate.

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:

Screen Shot 2020-07-18 at 4 11 22 PM

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.

@tpeek tpeek added the status: needs triage These issues haven't been looked at yet by a maintainer. label Jul 18, 2020
@oliviertassinari
Copy link
Member

oliviertassinari commented Jul 19, 2020

@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:

  1. The name of the style rule is long. We can shrink it from .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
  1. We can add the description on each of the style rules:
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,
  1. The name of the file is wrong. It doesn't match the name of the component:
    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)
  2. Considering the existing public PickersDay component, I would suggest a shorter name for this component: PickersRangeDay instead of DateRangePickerDay.
  3. We could make this component public, allowing easier overrides using it. For instance, leveraging this RFC: [RFC] What's the best API to override deep/nested elements? material-ui#21453.
import { PickersRangeDay, DateRangePicker } from '@material-ui/pickers';

function MyPickersRangeDay(props) {
  return <PickersRangeDay {...props} />
}

<DateRangePicker slotComponents={{ PickersRangeDay: MyPickersRangeDay }} />
  1. We could document the CSS API as in https://material-ui.com/api/autocomplete/#css. This requires updating the folder structure to match the convention of the main repository and moving the source to the main repo afterward.
  2. We could explore how to flatten the DOM:

Capture d’écran 2020-07-19 à 01 58 57

  • Do we need a span inside the button? -1
  • Do we need a DOM node for the highlight? Why not leverage the button? -1
  • Do we need a DOM node for the preview effect? Why not leverage the button? -1

I'm 💯 for exploring these 7 changes further, the ease of customization is important.

@oliviertassinari oliviertassinari added enhancement New feature or request good to take Help wanted and removed status: needs triage These issues haven't been looked at yet by a maintainer. labels Jul 19, 2020
@tpeek
Copy link
Author

tpeek commented Jul 19, 2020

@oliviertassinari

This is already possible with the rangeIntervalDayHighlightStart and rangeIntervalDayHighlightEnd 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

@oliviertassinari
Copy link
Member

@tpeek Ok, so we would need an item 8: differentiate these two states.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants