Skip to content

Commit 0af69d2

Browse files
committed
Add default row renderer
1 parent 76c97f7 commit 0af69d2

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/renderer.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react';
2+
import classNames from 'classnames';
3+
4+
const defaultRowRenderer = (node, treeOptions) => {
5+
const { id, name, loadOnDemand = false, children, state } = node;
6+
const droppable = treeOptions.droppable;
7+
const { depth, open, path, total, selected = false } = state;
8+
const childrenLength = Object.keys(children).length;
9+
const more = node.hasChildren();
10+
11+
return (
12+
<div
13+
className={classNames(
14+
'infinite-tree-item',
15+
{ 'infinite-tree-selected': selected }
16+
)}
17+
data-id={id}
18+
data-expanded={more && open}
19+
data-depth={depth}
20+
data-path={path}
21+
data-selected={selected}
22+
data-children={childrenLength}
23+
data-total={total}
24+
droppable={droppable}
25+
>
26+
<div
27+
className="infinite-tree-node"
28+
style={{ marginLeft: depth * 18 }}
29+
>
30+
{!more && loadOnDemand &&
31+
<a className={classNames(treeOptions.togglerClass, 'infinite-tree-closed')}></a>
32+
}
33+
{more && open &&
34+
<a className={classNames(treeOptions.togglerClass)}></a>
35+
}
36+
{more && !open &&
37+
<a className={classNames(treeOptions.togglerClass, 'infinite-tree-closed')}></a>
38+
}
39+
<span className="infinite-tree-title">{name}</span>
40+
</div>
41+
</div>
42+
);
43+
};
44+
45+
export {
46+
defaultRowRenderer
47+
};

0 commit comments

Comments
 (0)