Skip to content

Commit

Permalink
Grayed out weekends and holidays
Browse files Browse the repository at this point in the history
  • Loading branch information
namanhboi committed May 2, 2024
1 parent bb23040 commit 13fdbda
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
40 changes: 39 additions & 1 deletion frontend/src/components/MiniCal/MiniCal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,35 @@ import './datepicker_override.css';
import styles from './minical.module.css';
import { useDate } from '../../context/date';

/**startDate is inclusive, endDate is exclusive */
type Holiday = {
startDate: Date;
endDate: Date;
holidayName: string;
};

const holidays: Holiday[] = [
{
startDate: new Date('2024-2-24'),
endDate: new Date('2024-2-28'),
holidayName: 'Febuaray Break',
},
{
startDate: new Date('2024-3-30'),
endDate: new Date('2024-4-8'),
holidayName: 'Spring Break',
},
];

const isHoliday = (date: Date) => {
for (const holiday of holidays) {
if (holiday.startDate <= date && date < holiday.endDate) {
return true;
}
}
return false;
};

const currentDate = new Date();
const isToday = (date: Date) =>
date.getDate() === currentDate.getDate() &&
Expand Down Expand Up @@ -77,17 +106,26 @@ const MiniCal = () => {
window.scroll(x + 1, y);
window.scroll(x, y);
};
const isWeekday = (date: Date) => {
const day = date.getDay();
return day !== 0 && day !== 6;
};

const filterDate = (date: Date) => {
return isWeekday(date) && !isHoliday(date);
};

return (
<div className={styles.root}>
<DatePicker
adjustDateOnChange
//adjustDateOnChange
selected={curDate}
onChange={updateDate}
closeOnScroll={true}
dateFormat="MMM dd, yyyy"
showPopperArrow={false}
customInput={<CustomInput />}
filterDate={filterDate}
highlightDates={[{ 'custom--today': [new Date()] }]}
renderCustomHeader={({
date,
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/MiniCal/datepicker_override.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
.react-datepicker__year-text--in-selecting-range,
.react-datepicker__year-text--in-range {
border-radius: 0.3rem;
background-color: #000000;
background-color: black;
color: #fff;
}

Expand All @@ -78,7 +78,7 @@
.react-datepicker__quarter-text--keyboard-selected,
.react-datepicker__year-text--keyboard-selected {
border-radius: 0.3rem;
background-color: #000000;
background-color: rgba(0, 0, 0, 0.25);
color: #fff;
}

Expand Down

0 comments on commit 13fdbda

Please sign in to comment.