import * as React from "react"; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faChevronDown } from '@fortawesome/free-solid-svg-icons'; import { DataStorage } from '../dataStorage'; interface ILineContainerComponentProps { title: string; children: any[] | any; closed?: boolean; } export class LineContainerComponent extends React.Component { constructor(props: ILineContainerComponentProps) { super(props); let initialState = DataStorage.ReadBoolean(this.props.title, !this.props.closed); this.state = { isExpanded: initialState }; } switchExpandedState(): void { const newState = !this.state.isExpanded; DataStorage.StoreBoolean(this.props.title, newState); this.setState({ isExpanded: newState }); } renderHeader() { const className = this.state.isExpanded ? "collapse" : "collapse closed"; return (
this.switchExpandedState()}>
{this.props.title}
); } render() { if (!this.state.isExpanded) { return (
{ this.renderHeader() }
); } return (
{ this.renderHeader() }
{this.props.children}
); } }