From fa9f78b46e3a2270a44d4cc0691195a7c695cb93 Mon Sep 17 00:00:00 2001 From: Samuel Gunter <29130894+Samathingamajig@users.noreply.github.com> Date: Sun, 23 Mar 2025 19:49:11 -0500 Subject: [PATCH] feat: sticky calendar header and days (#568) * feat: sticky calendar days * feat: partial height borders for day labels * feat: make calendar header actually sticky * fix: remove unneeded gap * refactor: add preston as co-author Co-authored-by: Preston-Cook * fix: z-index issues with export sub-buttons --------- Co-authored-by: Preston-Cook Co-authored-by: doprz <52579214+doprz@users.noreply.github.com> --- src/views/components/calendar/Calendar.tsx | 4 +- .../components/calendar/CalendarGrid.tsx | 41 +++++++++++++------ .../components/calendar/CalendarGridCell.tsx | 4 +- .../CalendarHeader/CalendarHeader.tsx | 4 +- .../tests/useFlattenedCourseSchedule.test.ts | 2 +- src/views/hooks/useFlattenedCourseSchedule.ts | 4 +- 6 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/views/components/calendar/Calendar.tsx b/src/views/components/calendar/Calendar.tsx index 0715cf75..f2402e9c 100644 --- a/src/views/components/calendar/Calendar.tsx +++ b/src/views/components/calendar/Calendar.tsx @@ -140,7 +140,7 @@ export default function Calendar(): JSX.Element { // scrollbarGutter: 'stable', } } - className='h-full flex flex-grow flex-col overflow-x-scroll px-spacing-5' + className='z-1 h-full flex flex-grow flex-col overflow-x-scroll [&>*]:px-spacing-5' > -
+
diff --git a/src/views/components/calendar/CalendarGrid.tsx b/src/views/components/calendar/CalendarGrid.tsx index fd97ba6b..938e188e 100644 --- a/src/views/components/calendar/CalendarGrid.tsx +++ b/src/views/components/calendar/CalendarGrid.tsx @@ -3,7 +3,7 @@ import CalendarCourseCell from '@views/components/calendar/CalendarCourseCell'; import Text from '@views/components/common/Text/Text'; import { ColorPickerProvider } from '@views/contexts/ColorPickerContext'; import type { CalendarGridCourse } from '@views/hooks/useFlattenedCourseSchedule'; -import React from 'react'; +import React, { Fragment } from 'react'; import CalendarCell from './CalendarGridCell'; @@ -30,13 +30,13 @@ function makeGridRow(row: number, cols: number): JSX.Element { const hour = hoursOfDay[row]!; return ( - <> +
{[...Array(cols).keys()].map(col => ( ))} - + ); } @@ -56,23 +56,40 @@ export default function CalendarGrid({ setCourse, }: React.PropsWithChildren): JSX.Element { return ( -
+
+ {/* Cover top left corner of grid, so time gets cut off at the top of the partial border */} +
{/* Displaying day labels */} -
-
{daysOfWeek.map(day => ( -
- - {day} - +
+ {/* Partial border height because that's what Isaiah wants */} +
+ {/* Alignment for text */} +
+ + {day} + +
+
))} + {/* empty slot, for alignment */} +
+ {/* time tick for the first hour */} +
{[...Array(13).keys()].map(i => makeGridRow(i, 5))} {Array(6) .fill(1) - .map(() => ( -
+ .map((_, i) => ( + // Key suppresses warning about duplicate keys, + // and index is fine because it doesn't change between renders + // eslint-disable-next-line react/no-array-index-key +
))} {courseCells && } diff --git a/src/views/components/calendar/CalendarGridCell.tsx b/src/views/components/calendar/CalendarGridCell.tsx index 334e0151..a010872a 100644 --- a/src/views/components/calendar/CalendarGridCell.tsx +++ b/src/views/components/calendar/CalendarGridCell.tsx @@ -17,8 +17,8 @@ function CalendarCell({ row, col }: Props): JSX.Element {
diff --git a/src/views/components/calendar/CalendarHeader/CalendarHeader.tsx b/src/views/components/calendar/CalendarHeader/CalendarHeader.tsx index b4e7f314..8990cb56 100644 --- a/src/views/components/calendar/CalendarHeader/CalendarHeader.tsx +++ b/src/views/components/calendar/CalendarHeader/CalendarHeader.tsx @@ -27,7 +27,7 @@ export default function CalendarHeader({ sidebarOpen, onSidebarToggle }: Calenda return (
{!sidebarOpen && (