@@ -44,6 +44,8 @@ class ArrowExpander extends Component {
4444 }
4545}
4646
47+ const treeIndent = dom . span ( { className : "tree-indent" } , "\u200B" ) ;
48+
4749class TreeNode extends Component {
4850 static get propTypes ( ) {
4951 return {
@@ -83,38 +85,6 @@ class TreeNode extends Component {
8385 } )
8486 : null ;
8587
86- const treeIndentWidthVar = "var(--tree-indent-width)" ;
87- const treeBorderColorVar = "var(--tree-indent-border-color, black)" ;
88- const treeBorderWidthVar = "var(--tree-indent-border-width, 1px)" ;
89-
90- const paddingInlineStart = `calc(
91- (${ treeIndentWidthVar } * ${ depth } )
92- ${ ( isExpandable ? "" : "+ var(--arrow-total-width)" ) }
93- )` ;
94-
95- // This is the computed border that will mimic a border on tree nodes.
96- // This allow us to have as many "borders" as we need without adding
97- // specific elements for that purpose only.
98- // it's a gradient with "hard stops" which will give us as much plain
99- // lines as we need given the depth of the node.
100- // The gradient uses CSS custom properties so everything is customizable
101- // by consumers if needed.
102- const backgroundBorder = depth === 0
103- ? null
104- : "linear-gradient(90deg, " +
105- Array . from ( { length : depth } ) . map ( ( _ , i ) => {
106- const indentWidth = `(${ i } * ${ treeIndentWidthVar } )` ;
107- const alignIndent = `(var(--arrow-width) / 2)` ;
108- const start = `calc(${ indentWidth } + ${ alignIndent } )` ;
109- const end = `calc(${ indentWidth } + ${ alignIndent } + ${ treeBorderWidthVar } )` ;
110-
111- return `transparent ${ start } ,
112- ${ treeBorderColorVar } ${ start } ,
113- ${ treeBorderColorVar } ${ end } ,
114- transparent ${ end } ` ;
115- } ) . join ( "," ) +
116- ")" ;
117-
11888 let ariaExpanded ;
11989 if ( this . props . isExpandable ) {
12090 ariaExpanded = false ;
@@ -123,21 +93,20 @@ class TreeNode extends Component {
12393 ariaExpanded = true ;
12494 }
12595
96+ const indents = Array . from ( { length : depth } ) . fill ( treeIndent ) ;
97+ let items = indents . concat ( renderItem ( item , depth , focused , arrow , expanded ) ) ;
98+
12699 return dom . div (
127100 {
128101 id,
129102 className : "tree-node" + ( focused ? " focused" : "" ) ,
130- style : {
131- paddingInlineStart,
132- backgroundImage : backgroundBorder ,
133- } ,
134103 onClick : this . props . onClick ,
135104 role : "treeitem" ,
136105 "aria-level" : depth ,
137106 "aria-expanded" : ariaExpanded ,
138- "data-expandable" : this . props . isExpandable ,
107+ "data-expandable" : this . props . isExpandable
139108 } ,
140- renderItem ( item , depth , focused , arrow , expanded )
109+ ... items
141110 ) ;
142111 }
143112}
@@ -189,19 +158,7 @@ function oncePerAnimationFrame(fn) {
189158 * restrict you to only one certain kind of tree.
190159 *
191160 * The tree comes with basic styling for the indent, the arrow, as well as hovered
192- * and focused styles.
193- * All of this can be customize on the customer end, by overriding the following
194- * CSS custom properties :
195- * --arrow-width: the width of the arrow.
196- * --arrow-single-margin: the end margin between the arrow and the item that follows.
197- * --arrow-fill-color: the fill-color of the arrow.
198- * --tree-indent-width: the width of a 1-level-deep item.
199- * --tree-indent-border-color: the color of the indent border.
200- * --tree-indent-border-width: the width of the indent border.
201- * --tree-node-hover-background-color: the background color of a hovered node.
202- * --tree-node-focus-color: the color of a focused node.
203- * --tree-node-focus-background-color: the background color of a focused node.
204- *
161+ * and focused styles which can be override in CSS.
205162 *
206163 * ### Example Usage
207164 *
0 commit comments