import React, { Fragment, FunctionComponent, ReactNode, useMemo } from "react"; import { useTranslation } from "react-i18next"; import { Grid, GridItem, GridProps, JumpLinks, JumpLinksItem, PageSection, } from "@patternfly/react-core"; import { mainPageContentId } from "../../App"; import { ScrollPanel } from "./ScrollPanel"; import { FormPanel } from "./FormPanel"; 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: FunctionComponent = ({ sections, borders = false, ...rest }) => { 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} ); })} ); };