import { FC, useContext, useEffect, useRef, useState } from "react"; import { Button, Stack } from "../../../../components"; import { NavContext, NavItemRow } from "./"; import Scrollbars from "react-scrollbars-custom"; import { backButtonHeader, navPanelColumn, scrollbarsWrapper, } from "../Nav.styles"; import { useDimensions } from "../../../../hooks"; const NavPanelColumn: FC = ({ currTier, data, panelNum, updatePanels, offset, }) => { const columnWrapperRef = useRef(null); const scrollWrapper = useRef(null); const [isHeightTruncated, setIsHeightTruncated] = useState(false); const { menuWidth, navSettings, panelWidth, setPanelWidth } = useContext(NavContext); const { icon, attachTo, motion, scrollable } = navSettings[panelNum + offset]; const { items, back } = data; const { width } = useDimensions(columnWrapperRef); const { height: scrollHeight, y: scrollTop, screenHeight, } = useDimensions(scrollWrapper); useEffect(() => { if (panelNum === 0) { setPanelWidth(width); } }, [width, panelNum]); useEffect(() => { if (scrollTop && scrollHeight && screenHeight) { const availableHeight = screenHeight - scrollTop; setIsHeightTruncated(availableHeight < scrollHeight); } }, [scrollTop, scrollHeight, screenHeight]); if (!Array.isArray(items)) return null; let backButton; if (back && attachTo === "slide") { backButton = (