frontend/src/components/SchedulerRow.tsx

70 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-08-12 04:13:14 +02:00
import React from 'react';
import { Group } from '../types';
2020-08-12 04:13:14 +02:00
import styled from 'styled-components';
interface SchedulerEventProps {
eventIndex: number;
cellTop: number;
cellWidth: number;
cellHeight: number;
2020-08-12 04:13:14 +02:00
}
const SchedulerEvent = styled.div<SchedulerEventProps>`
position: absolute;
top: ${({ cellTop }) => cellTop}px;
left: ${({ cellWidth, eventIndex }) => cellWidth + 5 + cellWidth * eventIndex}px;
2020-09-11 18:56:14 +02:00
z-index: 2;
`;
const ClassDiv = styled.div<SchedulerEventProps>`
2020-08-30 10:42:52 +02:00
width: ${({ cellWidth }) => (cellWidth * 2.5) / 3}px;
height: ${({ cellHeight }) => (cellHeight * 2 * 3) / 4}px;
2020-08-12 04:13:14 +02:00
z-index: 2;
2020-09-11 18:56:14 +02:00
border-radius: 10px;
padding-left:5px;
background-color: rgb(100, 181, 246);
2020-08-12 04:13:14 +02:00
`;
2020-08-09 20:44:35 +02:00
interface SchedulerRowProps {
groups: Array<Group>;
indexRow: number;
cellTop: number;
cellWidth: number;
cellHeight: number;
2020-09-11 18:56:14 +02:00
onClick: (e: React.MouseEvent) => void;
2020-08-09 20:44:35 +02:00
}
2020-09-11 08:08:49 +02:00
export const SchedulerRow = ({ groups, indexRow, cellTop, cellWidth, cellHeight, onClick }: SchedulerRowProps) => {
2020-08-09 20:44:35 +02:00
return (
2020-08-12 04:13:14 +02:00
<>
2020-08-18 00:21:21 +02:00
{[...Array(5)].map((_, eventIndex) => (
2020-08-12 04:13:14 +02:00
<SchedulerEvent
2020-09-11 08:08:49 +02:00
onClick={onClick}
2020-08-12 04:13:14 +02:00
eventIndex={eventIndex}
cellTop={cellTop}
cellWidth={cellWidth}
cellHeight={cellHeight}
2020-08-18 00:21:21 +02:00
key={eventIndex}
2020-08-09 21:41:52 +02:00
id={`eventRow${indexRow}eventCol${eventIndex}`}
2020-08-09 20:44:35 +02:00
>
2020-09-11 18:56:14 +02:00
{groups.map(
(group, index) =>
group.day === eventIndex && (
<ClassDiv
eventIndex={eventIndex}
cellTop={cellTop}
cellWidth={cellWidth}
cellHeight={cellHeight}
id={`eventRow${indexRow}eventCol${eventIndex}`}
key={index}
>
{groups[index]?.lecturer}
</ClassDiv>
),
)}
2020-08-12 04:13:14 +02:00
</SchedulerEvent>
2020-08-09 20:44:35 +02:00
))}
2020-08-12 04:13:14 +02:00
</>
2020-08-09 20:44:35 +02:00
);
};