2020-09-01 14:51:59 +00:00
|
|
|
import React, { Children, useEffect, useState } from "react";
|
2020-12-07 12:51:38 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import {
|
|
|
|
Grid,
|
|
|
|
GridItem,
|
|
|
|
JumpLinks,
|
|
|
|
JumpLinksItem,
|
|
|
|
Title,
|
|
|
|
} from "@patternfly/react-core";
|
2020-08-28 05:23:39 +00:00
|
|
|
|
2020-09-01 14:51:59 +00:00
|
|
|
import { FormPanel } from "./FormPanel";
|
|
|
|
import style from "./scroll-form.module.css";
|
2020-08-28 05:23:39 +00:00
|
|
|
|
|
|
|
type ScrollFormProps = {
|
|
|
|
sections: string[];
|
|
|
|
children: React.ReactNode;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ScrollForm = ({ sections, children }: ScrollFormProps) => {
|
2020-12-07 12:51:38 +00:00
|
|
|
const { t } = useTranslation("common");
|
2020-08-28 05:23:39 +00:00
|
|
|
const [active, setActive] = useState(sections[0]);
|
|
|
|
|
|
|
|
const Nav = () => (
|
|
|
|
<div className={style.sticky}>
|
|
|
|
<Title headingLevel="h5" size="lg">
|
2020-12-07 12:51:38 +00:00
|
|
|
{t("jumpToSection")}
|
2020-08-28 05:23:39 +00:00
|
|
|
</Title>
|
2020-12-07 12:51:38 +00:00
|
|
|
|
|
|
|
<JumpLinks isVertical>
|
|
|
|
{sections.map((cat) => (
|
|
|
|
<JumpLinksItem
|
|
|
|
isActive={active === cat}
|
|
|
|
key={cat}
|
|
|
|
href={`#${cat}`}
|
|
|
|
onClick={() => setActive(cat)}
|
|
|
|
>
|
|
|
|
{cat}
|
|
|
|
</JumpLinksItem>
|
|
|
|
))}
|
|
|
|
</JumpLinks>
|
2020-08-28 05:23:39 +00:00
|
|
|
</div>
|
|
|
|
);
|
2020-12-07 12:51:38 +00:00
|
|
|
|
2020-08-28 05:23:39 +00:00
|
|
|
const nodes = Children.toArray(children);
|
|
|
|
return (
|
2020-12-07 12:51:38 +00:00
|
|
|
<Grid hasGutter>
|
|
|
|
<GridItem span={8}>
|
|
|
|
{sections.map((cat, index) => (
|
|
|
|
<FormPanel id={cat} key={cat} title={cat}>
|
|
|
|
{nodes[index]}
|
|
|
|
</FormPanel>
|
|
|
|
))}
|
|
|
|
</GridItem>
|
|
|
|
<GridItem span={4}>
|
|
|
|
<Nav />
|
|
|
|
</GridItem>
|
|
|
|
</Grid>
|
2020-08-28 05:23:39 +00:00
|
|
|
);
|
|
|
|
};
|