import { IElement } from "./basic"; import * as React from "react"; import { classes } from "./helpers"; type IFoldable = IElement & { folded?: boolean; closeButton?: React.ReactNode; openButton?: React.ReactNode; }; export class Foldable extends React.Component { constructor(props: IFoldable) { super(props); this.state = { folded: props.folded ?? true }; } toggleFold = () => { this.setState({ folded: !this.state.folded }); }; render() { return (
{this.props.children}
{this.state.folded ? this.props.openButton : this.props.openButton}
); } } export function MaybeFoldable(props: IElement & { foldWhen: boolean }) { if (props.foldWhen) { return {props.children}; } else { return {props.children}; } }