fix coloring of selected and hovered

This commit is contained in:
Thomas Ruoff
2020-10-10 22:11:00 +02:00
parent 36226a7fa9
commit 9d69225d46
2 changed files with 16 additions and 4 deletions

View File

@@ -29,11 +29,15 @@ export default function MyCalendar({ ...props }) {
const prevBooked = inSelection && getNextSmaller(daysBooked, start) const prevBooked = inSelection && getNextSmaller(daysBooked, start)
const nextBooked = inSelection && getNextBigger(daysBooked, start) const nextBooked = inSelection && getNextBigger(daysBooked, start)
function isSelected(date: Date) { function isDateSelected(date: Date) {
if (!startDate) { if (!startDate) {
return false return false
} }
if (isSameDay(date, startDate)) {
return true
}
// if end is before start, it is not within // if end is before start, it is not within
if (endDate && !isAfter(endDate, startDate)) { if (endDate && !isAfter(endDate, startDate)) {
return false return false
@@ -50,18 +54,22 @@ export default function MyCalendar({ ...props }) {
const isDaysBookedLoaded = !!daysBooked const isDaysBookedLoaded = !!daysBooked
const isInPast = isPast(endOfDay(date)) const isInPast = isPast(endOfDay(date))
const isBooked = daysBooked?.includes(dateFormatBackend(date)) const isBooked = daysBooked?.includes(dateFormatBackend(date))
const isSelected = isDateSelected(date)
return classnames({ return classnames({
'react-calendar__tile--past': isMonthView && isInPast, 'react-calendar__tile--past': isMonthView && isInPast,
'react-calendar__tile--booked': 'react-calendar__tile--booked':
isMonthView && isDaysBookedLoaded && isBooked && !isInPast, isMonthView && isDaysBookedLoaded && isBooked && !isInPast,
'react-calendar__tile--free': 'react-calendar__tile--free':
isMonthView && isDaysBookedLoaded && !isBooked && !isInPast, isMonthView &&
isDaysBookedLoaded &&
!isBooked &&
!isInPast &&
!isSelected,
'react-calendar__tile--selected-start': 'react-calendar__tile--selected-start':
isMonthView && isSameDay(date, startDate), isMonthView && isSameDay(date, startDate),
'react-calendar__tile--selected-end': 'react-calendar__tile--selected-end':
isMonthView && isSameDay(date, endDate), isMonthView && isSameDay(date, endDate),
'react-calendar__tile--selected': 'react-calendar__tile--selected': isSelected,
isSelected(date) || isSameDay(date, startDate),
'react-calendar__tile--unselectable': 'react-calendar__tile--unselectable':
inSelection && inSelection &&
((prevBooked && date < new Date(prevBooked)) || ((prevBooked && date < new Date(prevBooked)) ||

View File

@@ -205,6 +205,10 @@
@apply bg-blue-400; @apply bg-blue-400;
} }
.react-calendar__tile--selected:hover {
@apply bg-blue-600;
}
.react-calendar__tile--unselectable { .react-calendar__tile--unselectable {
@apply cursor-not-allowed; @apply cursor-not-allowed;
} }