import { Grid, GridItem, GridProps, JumpLinks, JumpLinksItem, PageSection, } from "@patternfly/react-core"; import { Fragment, ReactNode, useMemo } from "react"; import { useTranslation } from "react-i18next"; import { mainPageContentId } from "../../App"; import { FormPanel } from "./FormPanel"; import { ScrollPanel } from "./ScrollPanel"; import "./scroll-form.css"; type ScrollSection = { title: string; panel: ReactNode; isHidden?: boolean; }; type ScrollFormProps = GridProps & { sections: ScrollSection[]; borders?: boolean; }; const spacesToHyphens = (string: string): string => { return string.replace(/\s+/g, "-"); }; export const ScrollForm = ({ sections, borders = false, ...rest }: ScrollFormProps) => { const { t } = useTranslation("common"); const shownSections = useMemo( () => sections.filter(({ isHidden }) => !isHidden), [sections], ); return ( {shownSections.map(({ title, panel }) => { const scrollId = spacesToHyphens(title.toLowerCase()); return ( {borders ? ( {panel} ) : ( {panel} )} ); })} {shownSections.map(({ title }) => { const scrollId = spacesToHyphens(title.toLowerCase()); return ( // note that JumpLinks currently does not work with spaces in the href {title} ); })} ); };