From 7aec9ff9436ec3ab73e516489910c715715de0ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciek=20G=C5=82owacki?= Date: Sun, 9 Aug 2020 19:29:03 +0200 Subject: [PATCH] Basic responsivness for table --- src/components/Scheduler/index.scss | 4 -- src/components/Scheduler/index.tsx | 99 ++++++++++++++++------------- 2 files changed, 55 insertions(+), 48 deletions(-) diff --git a/src/components/Scheduler/index.scss b/src/components/Scheduler/index.scss index ef5e92d..8a0764f 100644 --- a/src/components/Scheduler/index.scss +++ b/src/components/Scheduler/index.scss @@ -2,10 +2,6 @@ margin-top: 20px; border-collapse: collapse; - .thead { - display: flex; - width: 100%; - } .tbody { display: flex; diff --git a/src/components/Scheduler/index.tsx b/src/components/Scheduler/index.tsx index 1f14b32..5e082e7 100644 --- a/src/components/Scheduler/index.tsx +++ b/src/components/Scheduler/index.tsx @@ -1,8 +1,6 @@ -import React, { useEffect, useContext } from "react"; +import React, { useEffect, useContext, useRef } from "react"; import { useState } from "react"; import "./index.scss"; -import { SchedulerEvent } from "./SchedulerEvent"; -import { Column } from "./Column"; import { LecturesContext } from "../../businesslogic/LecturesProvider"; const days = ["", "poniedziałek", "wtorek", "środa", "czwartek", "piątek"]; @@ -19,8 +17,6 @@ const hours = [ "17:00", "18:00", "19:00", - "20:00", - "21:00", ]; let events: Array = []; @@ -31,15 +27,12 @@ for (let i = 0; i < hours.length / 2; i++) { let center: "center" = "center"; let row: "row" = "row"; let column: "column" = "column"; -let wrap: "wrap" = "wrap"; +const collapse: "collapse" = "collapse"; const tbodyStyles = { - width: 900, - height: 560, - backgroundColor: "blue", + width: "100%", + height: "100%", display: "flex", flexDirection: column, - // flexWrap: wrap - } const rowStyles = { @@ -54,13 +47,44 @@ const cellStyles = { flex: 1, } -let terms = ["Zawsze", "jest pora", "na kurde", "lody", "koral"]; +const theadStyles = { + display: "flex", + width: "100%" +} + +const scheduler = { + marginTop: "20px", + borderCollapse: collapse + +} + export const Scheduler = () => { const [currentEventsIds, setCurrentEventsIds] = useState>([]); - + const cellRef = useRef(null); + const [cellWidth, setCellWidth] = useState(0); + const [cellTop, setCellTop] = useState(0); const { choosenGroups } = useContext(LecturesContext); + + useEffect(() => { + const handleResize = () => { + console.log(`cellref is:`); + console.log(cellRef); + if (cellRef.current) { + setCellWidth(cellRef.current.getBoundingClientRect().width); + setCellTop(cellRef.current.getBoundingClientRect().top); + console.log(`cellwidth: ${cellWidth}`); + console.log("cell ref:"); + console.log(cellRef.current.getBoundingClientRect()); + } + } + handleResize(); + window.addEventListener('resize', handleResize); + + }, []); + + useEffect(() => { const displayEvents = () => { currentEventsIds.map((eventId: string) => { @@ -85,7 +109,7 @@ export const Scheduler = () => { return ( <>
-
+
{days.map((day, index) => (
{day} @@ -93,66 +117,53 @@ export const Scheduler = () => { ))}
- {hours.map((hour, index) => ( + {hours.map((hour, indexRow) => (
{ - [hour, "", "", "", "", ""].map((value) => ( -
{value}
- ))}
+ [hour, "", "", "", "", ""].map((value, indexCell) => + indexRow === 0 && indexCell === 1 ? (
) : (
{value}
) + + )}
))}
- {["", "", "", "", ""].map((value, index) => ( -
+ {[...Array(5)].map((value, index) => ( +
))}
- {["", "", "", "", ""].map((value, index) => ( -
+ {[...Array(5)].map((value, index) => ( +
))}
- {["", "", "", "", ""].map((value, index) => ( -
+ {[...Array(5)].map((value, index) => ( +
))}
- {["", "", "", "", ""].map((value, index) => ( -
+ {[...Array(5)].map((value, index) => ( +
))}
- {["", "", "", "", ""].map((value, index) => ( -
+ {[...Array(5)].map((value, index) => ( +
))}
- {["", "", "", "", ""].map((value, index) => ( -
+ {[...Array(5)].map((value, index) => ( +
))}
- - {/*
- - {terms.map((_, colIndex) => ( - - - - ))} -
*/}
);