import * as React from 'react'; import { motion } from 'framer-motion'; import { Properties } from '../Properties/Properties'; import { IContainerModel, getDepth, MakeIterator } from '../SVG/Elements/ContainerModel'; interface IElementsSidebarProps { MainContainer: IContainerModel | null, isOpen: boolean, SelectedContainer: IContainerModel | null, onClick: () => void, onPropertyChange: (key: string, value: string) => void, selectContainer: (container: IContainerModel) => void } export class ElementsSidebar extends React.Component { public iterateChilds(handleContainer: (container: IContainerModel) => void): React.ReactNode { if (!this.props.MainContainer) { return null; } const it = MakeIterator(this.props.MainContainer); for (const container of it) { handleContainer(container as IContainerModel); } } public render() { const isOpenClasses = this.props.isOpen ? 'right-0' : '-right-64'; 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 !== 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 }
); } }