-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathTree.js
More file actions
48 lines (42 loc) · 1.34 KB
/
Tree.js
File metadata and controls
48 lines (42 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import React, { Component, Children, cloneElement } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { cleanProps } from './util';
export default class Tree extends Component {
constructor() {
super();
this.renderTreeNode = this.renderTreeNode.bind(this);
}
renderTreeNode(tnode) {
const { onNodeClick, onNodeToggle, onNodeLabelClick, toggleOnNodeClick } = this.props;
return cloneElement(tnode, {
level: 1, onNodeClick, onNodeToggle, onNodeLabelClick, toggleOnNodeClick,
});
}
render() {
const { className, label, children, ...props } = this.props;
const treeClassNames = classnames(className, 'slds-tree-container');
const pprops = cleanProps(props, Tree.propTypes);
return (
<div className={ treeClassNames } role='application' { ...pprops }>
{
label ?
<h4 className='slds-text-heading--label'>{ label }</h4> :
null
}
<ul className='slds-tree' role='tree'>
{ Children.map(children, this.renderTreeNode) }
</ul>
</div>
);
}
}
Tree.propTypes = {
className: PropTypes.string,
label: PropTypes.string,
onNodeClick: PropTypes.func,
onNodeToggle: PropTypes.func,
onNodeLabelClick: PropTypes.func,
toggleOnNodeClick: PropTypes.bool,
children: PropTypes.node,
};