import { ReactNode, useState, CSSProperties } from 'react'; import { NavbarItem } from '../components/navbar'; import RemoveRoundedIcon from '@material-ui/icons/RemoveRounded'; import KeyboardArrowDownRoundedIcon from '@material-ui/icons/KeyboardArrowDownRounded'; export interface chapter { name: string; sectionLink?: string; children?: Array; } function NavbarChapter(props: { level: number; chapter: chapter; children?: ReactNode; }) { var [ collapsed, setCollapsed ] = useState(true); var icon =
{ props.chapter.children?.length > 0 ? : }
var classes = [ "chapter", `indentLevel${props.level}` ] !collapsed && classes.push("childrenCollapsed"); var outercss = /* { "--children-height": 0 + "px" } */ {} as CSSProperties; return props.chapter.children?.length > 0 && setCollapsed(!collapsed)} href={"#" + props.chapter.sectionLink} key={(() => Math.round(Math.random() * 1e12))()} style={{ marginLeft: 12 * props.level, }} outerStyle={outercss}> {props.children} } class Chapter { constructor(public chapters: Array, public level: number) {} render() { return
{ this.chapters?.map(chapter => { return { new Chapter(chapter.children, this.level + 1).render() } }) }
} } export default function Chapters(props: { chapters: Array; }) { return new Chapter(props.chapters, 0).render(); }