forked from ToolJet/ToolJet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSONNodeIndicator.jsx
More file actions
55 lines (46 loc) · 1.45 KB
/
JSONNodeIndicator.jsx
File metadata and controls
55 lines (46 loc) · 1.45 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
49
50
51
52
53
54
55
import React from 'react';
const JSONTreeNodeIndicator = ({ toExpand, toShowNodeIndicator, handleToggle, ...restProps }) => {
const {
renderCustomIndicator,
typeofCurrentNode,
currentNode,
isSelected,
toExpandNode,
data,
path,
toExpandWithLabels,
toggleWithLabels,
} = restProps;
const defaultStyles = {
transform: toExpandNode && toExpand ? 'rotate(90deg)' : 'rotate(0deg)',
transition: '0.2s all',
display: 'inline-block',
cursor: 'pointer',
};
const handleToggleForNode = () => {
if (!toExpandNode) return;
if (toExpandWithLabels) {
return toggleWithLabels(data, currentNode, path);
}
return handleToggle(currentNode);
};
const renderDefaultIndicator = () => (
<svg width="6" height="10" viewBox="0 0 6 10" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M1.02063 1L5.01032 5.01028L1.00003 8.99997"
stroke={`${toExpand && isSelected ? '#4D72FA' : '#61656F'}`}
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
);
if (!toShowNodeIndicator && (typeofCurrentNode !== 'Object' || typeofCurrentNode !== 'Array')) return null;
return (
<React.Fragment>
<span className="json-tree-node-icon" onClick={handleToggleForNode} style={defaultStyles}>
{renderCustomIndicator ? renderCustomIndicator() : renderDefaultIndicator()}
</span>
</React.Fragment>
);
};
export default JSONTreeNodeIndicator;