import React, { Children, useEffect, useState } from "react"; import { Grid, GridItem, Title } from "@patternfly/react-core"; import { FormPanel } from "./FormPanel"; import style from "./scroll-form.module.css"; type ScrollFormProps = { sections: string[]; children: React.ReactNode; }; export const ScrollForm = ({ sections, children }: ScrollFormProps) => { const [active, setActive] = useState(sections[0]); useEffect(() => { const getCurrentSection = () => { for (let sectionName of sections) { const section = document.getElementById(sectionName)!; const startAt = section.offsetTop; const endAt = startAt + section.offsetHeight; const currentPosition = document.documentElement.scrollTop || document.body.scrollTop; const isInView = currentPosition >= startAt && currentPosition < endAt; if (isInView) { return sectionName; } } }; window.addEventListener("scroll", () => { const active = getCurrentSection(); if (active) { setActive(active); } }); }, [active, sections]); const Nav = () => (