Skip to content

Commit b2a7b81

Browse files
committed
Add rct-node-leaf and rct-node-parent classes to TreeNode element
Resolves #27.
1 parent adfbe16 commit b2a7b81

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"webpack-stream": "^3.2.0"
5656
},
5757
"dependencies": {
58+
"classnames": "^2.2.5",
5859
"shortid": "^2.2.6"
5960
}
6061
}

src/js/TreeNode.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import classNames from 'classnames';
12
import React from 'react';
23

34
import 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

Comments
 (0)