From fee0469e1265122eafcdae6cd92c8c9e1b250826 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sat, 27 Mar 2021 09:52:07 +0100 Subject: foldable chapters :tada: --- components/chapters.tsx | 34 +++++++++++++++++++++++----------- components/navbar.tsx | 9 ++++++--- 2 files changed, 29 insertions(+), 14 deletions(-) (limited to 'components') diff --git a/components/chapters.tsx b/components/chapters.tsx index e90f91c..27116ee 100644 --- a/components/chapters.tsx +++ b/components/chapters.tsx @@ -1,9 +1,8 @@ -import { ReactNode, useState } from 'react'; +import { ReactNode, useState, CSSProperties } from 'react'; import { NavbarItem } from '../components/navbar'; import RemoveRoundedIcon from '@material-ui/icons/RemoveRounded'; -import KeyboardArrowRightRoundedIcon from '@material-ui/icons/KeyboardArrowRightRounded'; import KeyboardArrowDownRoundedIcon from '@material-ui/icons/KeyboardArrowDownRounded'; interface chapter { @@ -19,17 +18,30 @@ function NavbarChapter(props: { }) { var [ collapsed, setCollapsed ] = useState(true); - var icon = props.chapter.children?.length > 0 ? - collapsed ? : : - + var icon =
+ { + props.chapter.children?.length > 0 ? + : + + } +
- var classes: Array = []; - classes.push("chapter") - classes.push(`indentLevel${props.level}`) + var classes = [ + "chapter", + `indentLevel${props.level}` + ] + !collapsed && classes.push("childrenCollapsed"); - return + var outercss = /* { "--children-height": 0 + "px" } */ {} as CSSProperties; + + return props.chapter.children?.length > 0 && setCollapsed(!collapsed)} + style={{ + marginLeft: 12 * props.level, + }} outerStyle={outercss}> {props.children} } diff --git a/components/navbar.tsx b/components/navbar.tsx index cbbd164..9183b3b 100644 --- a/components/navbar.tsx +++ b/components/navbar.tsx @@ -11,14 +11,17 @@ export function NavbarItem(props: { children?: ReactNode; classList?: Array; style?: CSSProperties; + outerStyle?: CSSProperties; + onIconClick?: () => void; + onClick?: () => void; }) { var classes = props.classList || []; classes.push("navbarItem"); props.active && classes.push("active"); - return + return
- {props.icon} - {props.title} +
{props.icon}
+ {props.title}
{props.children}
-- cgit v1.2.3