import React, { useEffect, MouseEvent, useRef, useCallback, useLayoutEffect } from 'react'; import { useState } from 'react'; import { SchedulerEvents } from './SchedulerEvents'; import { days, hours } from '../constants/index'; import styled from 'styled-components/macro'; const SchedulerWrapper = styled.div` border-collapse: collapse; flex: 1; background-color: white; padding: 5px 15px 5px 5px; border-radius: 5px; margin-right: 20px; flex-direction: column; justify-content: center; align-items: center; box-shadow: 3px 3px 3px -2px rgba(0, 0, 0, 0.59); `; const TableBody = styled.div` width: 100%; display: flex; flex-direction: column; `; const TableRow = styled.div` display: flex; `; const TableHead = styled.div` display: flex; width: 100%; `; interface TableCellProps { height: number; isHourColumn?: boolean; } const TableCell = styled.div` height: ${({ height }) => height}px; border-width: ${({ isHourColumn }) => !isHourColumn && '2px'}; border-style: ${({ isHourColumn }) => !isHourColumn && 'none solid dotted none'}; border-color: rgb(242, 243, 245); margin-top: ${({ isHourColumn, height }) => isHourColumn ? -(height / 2) : 0}px; display: flex; align-items: center; justify-content: ${({ isHourColumn }) => isHourColumn ? 'flex-end' : 'center'}; flex: ${({ isHourColumn }) => isHourColumn ? '1' : '5'}; margin-right: ${({ isHourColumn }) => isHourColumn ? '10px' : '0px'}; font-size: 0.75vw; user-select: none; border-collapse:collapse; :nth-child(2) { border-left: 2px solid rgb(242, 243, 245); } font-weight: bold; `; export const Scheduler = () => { const cellRef = useRef(null); const [cellWidth, setCellWidth] = useState(0); const [cellTop, setCellTop] = useState(0); const wrapperRef = useRef(null); const [wrapperHeight, setWrapperHeight] = useState(0); const [, updateState] = useState(); const forceUpdate = useCallback(() => updateState({}), []); useEffect(() => { const handleResize = () => { if (cellRef.current) { setCellWidth(cellRef.current.getBoundingClientRect().width); setCellTop(cellRef.current.getBoundingClientRect().top); cellRef.current.style.backgroundColor = "blue"; console.log("XDDD") } }; handleResize(); }, []); useEffect(() => { const handleWrapperResize = () => { if (wrapperRef.current) { setWrapperHeight(wrapperRef.current.getBoundingClientRect().height); } } window.addEventListener('resize', handleWrapperResize); return () => window.removeEventListener('resize', handleWrapperResize); }, []) return ( <> {days.map((day, indexCell) => indexCell === 0 ? ( {day} ) : ( {day} ), )} {hours.map((hour, indexRow) => ( {[hour, '', '', '', '', ''].map((value, indexCell) => indexCell === 0 ? ( {value} ) : (indexRow === 0 && indexCell === 1) ? ( {value} ) : indexRow === 23 ? ( {value} ) : indexCell === 5 ? ( {value} ) : indexRow % 2 !== 0 ? ( {value} ) : {value} )} ))} ); };