wojtekmaj / react-daterange-picker

A date range picker for your React app.
https://projects.wojtekmaj.pl/react-daterange-picker
MIT License
524 stars 64 forks source link

Styling specific dates #345

Open Valent1nn opened 1 month ago

Valent1nn commented 1 month ago

Missing support for applying specific CSS styles to dates that match a specific given set of dates.

The styling logic is simple but I did not find a workaround for this specific component to apply a certain styling logic like the one present in react-calendar or react-date-picker for the property tileClassName.

Here would be an example: highlighted-date is a simple CSS class .highlighted-date { background-color: #38a169 !important; color: white !important; border-radius: 20% !important; opacity: 70% !important; padding: 6px !important; }

Here is the matching and styling logic:

const tileClassName = ({ date }: { date: Date }): string => { if (highlightedDates && Array.isArray(highlightedDates)) { if ( highlightedDates.some( (highlighted) => highlighted && date.toDateString() === highlighted.toDateString() ) ) { return "highlighted-date"; } } return ""; };

Usage within the component:

return ( <DatePicker onChange={handleDateChange} value={value} // closeCalendar={false} // shouldCloseCalendar={false} tileClassName={tileClassName} /> );