Files
UT-Registration-Plus/src/views/components/calendar/CalendarCourseCell/CalendarCourseCell.tsx
Casey Charleston 0dff12232c feat: async text hiding on Calendar's Bottom Bar when there are no async courses (#152)
* feat: async text not visible when no async courses

* refactor: converted useState to boolean

* fix: remove unused import

* fix: maintain component height when hiding is enabled

* refactor: match stylings to figma

* refactor: padding change to match when there are courses to display

---------

Co-authored-by: Razboy20 <razboy20@gmail.com>
2024-03-12 23:13:27 -05:00

94 lines
3.2 KiB
TypeScript

import type { StatusType } from '@shared/types/Course';
import { Status } from '@shared/types/Course';
import type { CourseColors } from '@shared/util/colors';
import { pickFontColor } from '@shared/util/colors';
import Text from '@views/components/common/Text/Text';
import clsx from 'clsx';
import React from 'react';
import ClosedIcon from '~icons/material-symbols/lock';
import WaitlistIcon from '~icons/material-symbols/timelapse';
import CancelledIcon from '~icons/material-symbols/warning';
/**
* Props for the CalendarCourseCell component.
*/
export interface CalendarCourseCellProps {
courseDeptAndInstr: string;
timeAndLocation?: string;
status: StatusType;
colors: CourseColors;
className?: string;
onClick?: React.MouseEventHandler<HTMLDivElement>;
}
/**
* Renders a cell for a calendar course.
*
* @component
* @param {CalendarCourseCellProps} props - The component props.
* @param {string} props.courseDeptAndInstr - The course department and instructor.
* @param {string} props.timeAndLocation - The time and location of the course.
* @param {StatusType} props.status - The status of the course.
* @param {Colors} props.colors - The colors for styling the cell.
* @param {string} props.className - Additional CSS class name for the cell.
* @returns {JSX.Element} The rendered component.
*/
export default function CalendarCourseCell({
courseDeptAndInstr,
timeAndLocation,
status,
colors,
className,
onClick,
}: CalendarCourseCellProps): JSX.Element {
let rightIcon: React.ReactNode | null = null;
if (status === Status.WAITLISTED) {
rightIcon = <WaitlistIcon className='h-5 w-5' />;
} else if (status === Status.CLOSED) {
rightIcon = <ClosedIcon className='h-5 w-5' />;
} else if (status === Status.CANCELLED) {
rightIcon = <CancelledIcon className='h-5 w-5' />;
}
// whiteText based on secondaryColor
const fontColor = pickFontColor(colors.primaryColor);
return (
<div
className={clsx('h-full w-full flex justify-center rounded p-2 cursor-pointer', fontColor, className)}
style={{
backgroundColor: colors.primaryColor,
}}
onClick={onClick}
>
<div
className={clsx('flex flex-1 flex-col gap-0.25 overflow-hidden max-h-full', {
'self-center': !timeAndLocation,
})}
>
<Text
variant='h1-course'
className={clsx('leading-tight truncate', {
'-my-0.8': timeAndLocation,
'text-wrap': !timeAndLocation,
})}
>
{courseDeptAndInstr}
</Text>
{timeAndLocation && <Text variant='h3-course'>{timeAndLocation}</Text>}
</div>
{rightIcon && (
<div
className='h-fit flex items-center justify-center justify-self-start rounded p-0.5 text-white'
style={{
backgroundColor: colors.secondaryColor,
}}
>
{rightIcon}
</div>
)}
</div>
);
}