-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
renderer.js
67 lines (62 loc) · 1.93 KB
/
renderer.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* eslint import/prefer-default-export: 0 */
import classNames from 'classnames';
import escapeHTML from 'escape-html';
import tag from 'html5-tag';
const defaultRowRenderer = (node, treeOptions) => {
const { id, name, loadOnDemand = false, children, state } = node;
const droppable = treeOptions.droppable;
const { depth, open, path, total, selected = false, filtered } = state;
const childrenLength = Object.keys(children).length;
const more = node.hasChildren();
if (filtered === false) {
return '';
}
let togglerContent = '';
if (!more && loadOnDemand) {
togglerContent = '►';
}
if (more && open) {
togglerContent = '▼';
}
if (more && !open) {
togglerContent = '►';
}
const toggler = tag('a', {
'class': (() => {
if (!more && loadOnDemand) {
return classNames(treeOptions.togglerClass, 'infinite-tree-closed');
}
if (more && open) {
return classNames(treeOptions.togglerClass);
}
if (more && !open) {
return classNames(treeOptions.togglerClass, 'infinite-tree-closed');
}
return '';
})()
}, togglerContent);
const title = tag('span', {
'class': classNames('infinite-tree-title')
}, escapeHTML(name));
const treeNode = tag('div', {
'class': 'infinite-tree-node',
'style': `margin-left: ${depth * 18}px`
}, toggler + title);
return tag('div', {
'data-id': id,
'data-expanded': more && open,
'data-depth': depth,
'data-path': path,
'data-selected': selected,
'data-children': childrenLength,
'data-total': total,
'class': classNames(
'infinite-tree-item',
{ 'infinite-tree-selected': selected }
),
'droppable': droppable
}, treeNode);
};
export {
defaultRowRenderer
};