-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: basic CalendarCourseMeeting component laid out - missing Text a…
…nd Right Icon
- Loading branch information
1 parent
3568b8e
commit da9e7aa
Showing
3 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { Course, Status } from 'src/shared/types/Course'; | ||
import { CourseMeeting, DAY_MAP } from 'src/shared/types/CourseMeeting'; | ||
import { CourseSchedule } from 'src/shared/types/CourseSchedule'; | ||
import Instructor from 'src/shared/types/Instructor'; | ||
import CalendarCourse from 'src/views/components/common/CalendarCourseMeeting/CalendarCourseMeeting'; | ||
|
||
const meta = { | ||
title: 'Components/Common/CalendarCourseMeeting', | ||
component: CalendarCourse, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
tags: ['autodocs'], | ||
argTypes: { | ||
course: { control: 'object' }, | ||
meetingIdx: { control: 'number' }, | ||
color: { control: 'color' }, | ||
rightIcon: { control: 'object' }, | ||
}, | ||
} satisfies Meta<typeof CalendarCourse>; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
course: new Course({ | ||
uniqueId: 123, | ||
number: '101', | ||
fullName: 'Course 101', | ||
courseName: 'Course', | ||
department: 'BVO', | ||
creditHours: 3, | ||
status: Status.OPEN, | ||
instructors: [new Instructor({ firstName: '', lastName: 'Bevo', fullName: 'Bevo' })], | ||
isReserved: false, | ||
url: '', | ||
flags: [], | ||
schedule: new CourseSchedule({ | ||
meetings: [ | ||
new CourseMeeting({ | ||
days: [DAY_MAP.M, DAY_MAP.W, DAY_MAP.F], | ||
startTime: 480, | ||
endTime: 570, | ||
location: { | ||
building: 'UTC', | ||
room: '123', | ||
}, | ||
}), | ||
], | ||
}), | ||
instructionMode: 'In Person', | ||
semester: { | ||
year: 2024, | ||
season: 'Spring', | ||
}, | ||
}), | ||
meetingIdx: 0, | ||
color: 'red', | ||
}, | ||
}; |
11 changes: 11 additions & 0 deletions
11
src/views/components/common/CalendarCourseMeeting/CalendarCourseMeeting.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.calendar-course { | ||
display: flex; | ||
padding: 7px 7px 9px 7px; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
gap: 5px; | ||
flex: 1 0 0; | ||
align-self: stretch; | ||
border-radius: 4px; | ||
background: #cbd5e1; | ||
} |
47 changes: 47 additions & 0 deletions
47
src/views/components/common/CalendarCourseMeeting/CalendarCourseMeeting.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import { Course } from 'src/shared/types/Course'; | ||
import { CourseMeeting } from 'src/shared/types/CourseMeeting'; | ||
import styles from './CalendarCourseMeeting.module.scss'; | ||
|
||
/** | ||
* Props for the CalendarCourseMeeting component. | ||
*/ | ||
export interface CalendarCourseMeetingProps { | ||
/** The Course that the meeting is for. */ | ||
course: Course; | ||
/* index into course meeting array to display */ | ||
meetingIdx?: number; | ||
/** The background color for the course. */ | ||
color: string; | ||
/** The icon to display on the right side of the course. This is optional. */ | ||
rightIcon?: React.ReactNode; | ||
} | ||
|
||
/** | ||
* `CalendarCourseMeeting` is a functional component that displays a course meeting. | ||
* | ||
* @example | ||
* <CalendarCourseMeeting course={course} meeting={meeting} color="red" rightIcon={<Icon />} /> | ||
*/ | ||
const CalendarCourseMeeting: React.FC<CalendarCourseMeetingProps> = ({ | ||
course, | ||
meetingIdx, | ||
}: CalendarCourseMeetingProps) => { | ||
let meeting: CourseMeeting | null = meetingIdx !== undefined ? course.schedule.meetings[meetingIdx] : null; | ||
return ( | ||
<div className={styles['calendar-course']}> | ||
<div> | ||
{course.department} {course.number} - {course.instructors[0].lastName} | ||
</div> | ||
{meeting && ( | ||
<div> | ||
{`${meeting.getTimeString({ separator: '-', capitalize: true })}${ | ||
meeting.location ? ` - ${meeting.location.building}` : '' | ||
}`} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default CalendarCourseMeeting; |