diff options
author | lonkaars <l.leblansch@gmail.com> | 2021-03-27 09:52:07 +0100 |
---|---|---|
committer | lonkaars <l.leblansch@gmail.com> | 2021-03-27 09:52:07 +0100 |
commit | fee0469e1265122eafcdae6cd92c8c9e1b250826 (patch) | |
tree | f5db0373444da61c2d9490fdb139e24bc9e80ea7 /components/chapters.tsx | |
parent | f129069cbfcd29f3fd9ba0c8f4ca3b0167489e03 (diff) |
foldable chapters :tada:
Diffstat (limited to 'components/chapters.tsx')
-rw-r--r-- | components/chapters.tsx | 34 |
1 files changed, 23 insertions, 11 deletions
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 ? <KeyboardArrowDownRoundedIcon/> : <KeyboardArrowRightRoundedIcon/> : - <RemoveRoundedIcon/> + var icon = <div className={ "collapseIcon" + (collapsed ? "" : " collapsed") }> + { + props.chapter.children?.length > 0 ? + <KeyboardArrowDownRoundedIcon/> : + <RemoveRoundedIcon/> + } + </div> - var classes: Array<string> = []; - classes.push("chapter") - classes.push(`indentLevel${props.level}`) + var classes = [ + "chapter", + `indentLevel${props.level}` + ] + !collapsed && classes.push("childrenCollapsed"); - return <NavbarItem icon={icon} classList={classes} title={props.chapter.name} style={{ - marginLeft: 12 * props.level - }}> + var outercss = /* { "--children-height": 0 + "px" } */ {} as CSSProperties; + + return <NavbarItem + icon={icon} + classList={classes} + title={props.chapter.name} + onIconClick={() => props.chapter.children?.length > 0 && setCollapsed(!collapsed)} + style={{ + marginLeft: 12 * props.level, + }} outerStyle={outercss}> {props.children} </NavbarItem> } |