1
+ import classNames from 'classnames' ;
1
2
import React from 'react' ;
2
3
3
4
import nodeShape from './nodeShape' ;
@@ -58,6 +59,10 @@ class TreeNode extends React.Component {
58
59
} ) ;
59
60
}
60
61
62
+ hasChildren ( ) {
63
+ return this . props . rawChildren !== null ;
64
+ }
65
+
61
66
renderCollapseIcon ( ) {
62
67
if ( ! this . props . expanded ) {
63
68
return < i className = "rct-icon rct-icon-expand-close" /> ;
@@ -67,7 +72,7 @@ class TreeNode extends React.Component {
67
72
}
68
73
69
74
renderCollapseButton ( ) {
70
- if ( this . props . rawChildren === null ) {
75
+ if ( ! this . hasChildren ( ) ) {
71
76
return (
72
77
< span className = "rct-collapse" >
73
78
< i className = "rct-icon" />
@@ -99,7 +104,7 @@ class TreeNode extends React.Component {
99
104
return this . props . icon ;
100
105
}
101
106
102
- if ( this . props . rawChildren === null ) {
107
+ if ( ! this . hasChildren ( ) ) {
103
108
return < i className = "rct-icon rct-icon-leaf" /> ;
104
109
}
105
110
@@ -121,9 +126,14 @@ class TreeNode extends React.Component {
121
126
render ( ) {
122
127
const { checked, treeId, label, value } = this . props ;
123
128
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
+ } ) ;
124
134
125
135
return (
126
- < li className = "rct-node" >
136
+ < li className = { nodeClass } >
127
137
< span className = "rct-text" >
128
138
{ this . renderCollapseButton ( ) }
129
139
< label htmlFor = { inputId } >
0 commit comments