1+ import classNames from 'classnames' ;
12import React from 'react' ;
23
34import nodeShape from './nodeShape' ;
@@ -58,6 +59,10 @@ class TreeNode extends React.Component {
5859 } ) ;
5960 }
6061
62+ hasChildren ( ) {
63+ return this . props . rawChildren !== null ;
64+ }
65+
6166 renderCollapseIcon ( ) {
6267 if ( ! this . props . expanded ) {
6368 return < i className = "rct-icon rct-icon-expand-close" /> ;
@@ -67,7 +72,7 @@ class TreeNode extends React.Component {
6772 }
6873
6974 renderCollapseButton ( ) {
70- if ( this . props . rawChildren === null ) {
75+ if ( ! this . hasChildren ( ) ) {
7176 return (
7277 < span className = "rct-collapse" >
7378 < i className = "rct-icon" />
@@ -99,7 +104,7 @@ class TreeNode extends React.Component {
99104 return this . props . icon ;
100105 }
101106
102- if ( this . props . rawChildren === null ) {
107+ if ( ! this . hasChildren ( ) ) {
103108 return < i className = "rct-icon rct-icon-leaf" /> ;
104109 }
105110
@@ -121,9 +126,14 @@ class TreeNode extends React.Component {
121126 render ( ) {
122127 const { checked, treeId, label, value } = this . props ;
123128 const inputId = `${ treeId } -${ value } ` ;
129+ const nodeClass = classNames ( {
130+ 'rct-node' : true ,
131+ 'rct-node-parent' : this . hasChildren ( ) ,
132+ 'rct-node-leaf' : ! this . hasChildren ( ) ,
133+ } ) ;
124134
125135 return (
126- < li className = "rct-node" >
136+ < li className = { nodeClass } >
127137 < span className = "rct-text" >
128138 { this . renderCollapseButton ( ) }
129139 < label htmlFor = { inputId } >
0 commit comments