-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtamas.branch.jsx
66 lines (63 loc) · 3.28 KB
/
tamas.branch.jsx
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
import { useState, useEffect } from 'react';
import '../css/tamas.branch.css';
import $ from 'jquery';
export default ({columns}) => {
const [activeLeaf, setActiveLeaf] = useState('0-0');
return (
<div className='tamas-branch-wrapper'>
{
columns.map((column, columnIndex) =>
<div className='tamas-branch-column'>
{
column.leafs.map((leaf, leafIndex) => {
let leafId = columnIndex+'-'+leafIndex;
let joinToRight =
!leaf.dontJointToRight
&& columns[columnIndex+1]?.leafs?.length >= (leafIndex + 1); // has horizontal pair..?
return (
<div
className={
'tamas-branch-leaf'
+(leafIndex > 0 ? ' has-top-leaf' : '')
+(joinToRight ? ' has-right-leaf' : '')
}
>
<div className='tamas-branch-name'>
{leaf.name || <div> </div>}
</div>
<div
className={
'tamas-branch-icon'
+(leaf.color ? ' '+leaf.color : '')
+(leafId == activeLeaf ? ' active-leaf' : '')
}
onClick={
(e) => {
setActiveLeaf(columnIndex+'-'+leafIndex);
if (typeof leaf.onClick === 'function') {
leaf.onClick(e);
}
}
}
onMouseEnter={
leaf.tooltip ? (e)=> {
let icon = e.target;
if ($(icon).hasClass('tamas-branch-icon') == false) { // children..
icon = $(icon).closest('.tamas-branch-icon');
}
$(icon).showTooltip(leaf.tooltip)
} : null
}
>
{leaf.icon}
</div>
</div>
);
})
}
</div>
)
}
</div>
);
};