-
Notifications
You must be signed in to change notification settings - Fork 93
/
tree-node-renderer.js
82 lines (74 loc) · 2.05 KB
/
tree-node-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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import React, { Component, Children, cloneElement } from 'react';
import PropTypes from 'prop-types';
import styles from './tree-node-renderer.scss';
class FileThemeTreeNodeRenderer extends Component {
render() {
const {
children,
listIndex,
swapFrom,
swapLength,
swapDepth,
scaffoldBlockPxWidth,
lowerSiblingCounts,
connectDropTarget,
isOver,
draggedNode,
canDrop,
treeIndex,
treeId, // Delete from otherProps
getPrevRow, // Delete from otherProps
node, // Delete from otherProps
path, // Delete from otherProps
rowDirection,
...otherProps
} = this.props;
return connectDropTarget(
<div {...otherProps} className={styles.node}>
{Children.map(children, child =>
cloneElement(child, {
isOver,
canDrop,
draggedNode,
lowerSiblingCounts,
listIndex,
swapFrom,
swapLength,
swapDepth,
})
)}
</div>
);
}
}
FileThemeTreeNodeRenderer.defaultProps = {
swapFrom: null,
swapDepth: null,
swapLength: null,
canDrop: false,
draggedNode: null,
};
FileThemeTreeNodeRenderer.propTypes = {
treeIndex: PropTypes.number.isRequired,
treeId: PropTypes.string.isRequired,
swapFrom: PropTypes.number,
swapDepth: PropTypes.number,
swapLength: PropTypes.number,
scaffoldBlockPxWidth: PropTypes.number.isRequired,
lowerSiblingCounts: PropTypes.arrayOf(PropTypes.number).isRequired,
listIndex: PropTypes.number.isRequired,
children: PropTypes.node.isRequired,
// Drop target
connectDropTarget: PropTypes.func.isRequired,
isOver: PropTypes.bool.isRequired,
canDrop: PropTypes.bool,
draggedNode: PropTypes.shape({}),
// used in dndManager
getPrevRow: PropTypes.func.isRequired,
node: PropTypes.shape({}).isRequired,
path: PropTypes.arrayOf(
PropTypes.oneOfType([PropTypes.string, PropTypes.number])
).isRequired,
rowDirection: PropTypes.string.isRequired,
};
export default FileThemeTreeNodeRenderer;