From 0a7b6e520450f5eafad9782860e2f4feb552e9e7 Mon Sep 17 00:00:00 2001 From: Siklos Date: Mon, 1 Aug 2022 01:01:52 +0200 Subject: [PATCH] SVGSidebar: Improve style with depth --- src/Components/SVGSidebar/SVGSidebar.tsx | 37 +++++++++++++++--------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/Components/SVGSidebar/SVGSidebar.tsx b/src/Components/SVGSidebar/SVGSidebar.tsx index 5e7399d..a40adf8 100644 --- a/src/Components/SVGSidebar/SVGSidebar.tsx +++ b/src/Components/SVGSidebar/SVGSidebar.tsx @@ -8,7 +8,7 @@ interface ISVGSidebarProps { } export class SVGSidebar extends React.Component { - public iterateChilds(handleContainer: (container: Container) => void): React.ReactNode { + public iterateChilds(handleContainer: (container: Container, depth: number) => void): React.ReactNode { const root = this.props.MainContainer; if (!root) { return null; @@ -16,18 +16,24 @@ export class SVGSidebar extends React.Component { const queue = [root]; const visited = new Set([root]); + let depth = 0; while (queue.length > 0) { - const container = queue.shift() as Container; + let size = queue.length; - handleContainer(container); + while (size-- > 0) { + const container = queue.shift() as Container; - container.props.children.forEach((child) => { - if (visited.has(child)) { - return; - } - visited.add(child); - queue.push(child); - }); + handleContainer(container, depth); + + container.props.children.forEach((child) => { + if (visited.has(child)) { + return; + } + visited.add(child); + queue.push(child); + }); + } + depth++; } } @@ -35,11 +41,12 @@ export class SVGSidebar extends React.Component { const isOpenClasses = this.props.isOpen ? 'right-0' : '-right-64'; const containerRows: React.ReactNode[] = []; - this.iterateChilds((container: Container) => { + this.iterateChilds((container: Container, depth: number) => { const key = container.props.id.toString(); + const text = '\t\t'.repeat(depth) + key; containerRows.push( - ); }); @@ -52,7 +59,9 @@ export class SVGSidebar extends React.Component {
Liste des éléments
- { containerRows } +
+ { containerRows } +
); }