From 13fdbda63528574e6747d5d76cb8cf722e05e387 Mon Sep 17 00:00:00 2001 From: Nam Anh Dang Date: Wed, 1 May 2024 23:36:16 -0400 Subject: [PATCH] Grayed out weekends and holidays --- frontend/src/components/MiniCal/MiniCal.tsx | 40 ++++++++++++++++++- .../MiniCal/datepicker_override.css | 4 +- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/MiniCal/MiniCal.tsx b/frontend/src/components/MiniCal/MiniCal.tsx index 19ff68b94..e32d1ac0e 100644 --- a/frontend/src/components/MiniCal/MiniCal.tsx +++ b/frontend/src/components/MiniCal/MiniCal.tsx @@ -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() && @@ -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 (
} + filterDate={filterDate} highlightDates={[{ 'custom--today': [new Date()] }]} renderCustomHeader={({ date, diff --git a/frontend/src/components/MiniCal/datepicker_override.css b/frontend/src/components/MiniCal/datepicker_override.css index f100f495f..3d2d4e3d3 100644 --- a/frontend/src/components/MiniCal/datepicker_override.css +++ b/frontend/src/components/MiniCal/datepicker_override.css @@ -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; } @@ -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; }