import * as React from 'react'; import { motion } from 'framer-motion'; import { Properties } from '../Properties/Properties'; import { IContainerModel } from '../../Interfaces/ContainerModel'; import { getDepth, MakeIterator } from '../../utils/itertools'; interface IElementsSidebarProps { MainContainer: IContainerModel | null isOpen: boolean isHistoryOpen: boolean SelectedContainer: IContainerModel | null onClick: () => void onPropertyChange: (key: string, value: string) => void selectContainer: (container: IContainerModel) => void } export class ElementsSidebar extends React.PureComponent { public iterateChilds(handleContainer: (container: IContainerModel) => void): React.ReactNode { if (this.props.MainContainer == null) { return null; } const it = MakeIterator(this.props.MainContainer); for (const container of it) { handleContainer(container); } } public render(): JSX.Element { let isOpenClasses = '-right-64'; if (this.props.isOpen) { isOpenClasses = this.props.isHistoryOpen ? 'right-64' : 'right-0'; } const containerRows: React.ReactNode[] = []; this.iterateChilds((container: IContainerModel) => { const depth: number = getDepth(container); const key = container.properties.id.toString(); const text = '|\t'.repeat(depth) + key; const selectedClass: string = this.props.SelectedContainer !== undefined && this.props.SelectedContainer !== null && this.props.SelectedContainer.properties.id === container.properties.id ? 'bg-blue-500 hover:bg-blue-600' : 'bg-slate-400 hover:bg-slate-600'; containerRows.push( this.props.selectContainer(container)}> { text } ); }); return (
Elements
{ containerRows }
); } }