From ee5d547f1728d87331cb3e8def517b93793627dc Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 26 Mar 2021 23:06:24 +0100 Subject: more chapter hierarchy but better --- components/chapters.tsx | 31 +++++++++++++++++++++++++++---- components/navbar.tsx | 19 ++++++++----------- styles/navbar.css | 10 ++++++++++ 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/components/chapters.tsx b/components/chapters.tsx index 73c1630..e90f91c 100644 --- a/components/chapters.tsx +++ b/components/chapters.tsx @@ -1,3 +1,5 @@ +import { ReactNode, useState } from 'react'; + import { NavbarItem } from '../components/navbar'; import RemoveRoundedIcon from '@material-ui/icons/RemoveRounded'; @@ -10,16 +12,37 @@ interface chapter { children?: Array; } +function NavbarChapter(props: { + level: number; + chapter: chapter; + children?: ReactNode; +}) { + var [ collapsed, setCollapsed ] = useState(true); + + var icon = props.chapter.children?.length > 0 ? + collapsed ? : : + + + var classes: Array = []; + classes.push("chapter") + classes.push(`indentLevel${props.level}`) + + return + {props.children} + +} + class Chapter { constructor(public chapters: Array, public level: number) {} render() { - console.log(this) - return
+ return
{ this.chapters?.map(chapter => { - return } chapterIndent={this.level} title={chapter.name}> + return { new Chapter(chapter.children, this.level + 1).render() } - + }) }
diff --git a/components/navbar.tsx b/components/navbar.tsx index 9286120..318d673 100644 --- a/components/navbar.tsx +++ b/components/navbar.tsx @@ -1,4 +1,4 @@ -import { ReactNode } from 'react'; +import { ReactNode, CSSProperties } from 'react'; import HomeRoundedIcon from '@material-ui/icons/HomeRounded'; import SearchRoundedIcon from '@material-ui/icons/SearchRounded'; @@ -8,18 +8,15 @@ export function NavbarItem(props: { title: string; href?: string; active?: boolean; - chapterIndent?: number; children?: ReactNode; + classList?: Array; + style?: CSSProperties; }) { - return -