import React, { Children, useEffect, useState } from 'react'; import { Form, 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 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; } } }; const [active, setActive] = useState(sections[0]); useEffect(() => { window.addEventListener('scroll', () => { const active = getCurrentSection(); if (active) { setActive(active); } }); }, [active]); const Nav = () => (