-
Notifications
You must be signed in to change notification settings - Fork 480
/
actions.component.ts
89 lines (86 loc) · 1.91 KB
/
actions.component.ts
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
83
84
85
86
87
88
89
import { Component, Input } from '@angular/core';
import { TreeNode, TreeModel, TREE_ACTIONS, KEYS, IActionMapping, ITreeOptions } from 'angular-tree-component';
const actionMapping:IActionMapping = {
mouse: {
contextMenu: (tree, node, $event) => {
$event.preventDefault();
alert(`context menu for ${node.data.name}`);
},
dblClick: (tree, node, $event) => {
if (node.hasChildren) {
TREE_ACTIONS.TOGGLE_EXPANDED(tree, node, $event);
}
},
click: (tree, node, $event) => {
$event.shiftKey
? TREE_ACTIONS.TOGGLE_ACTIVE_MULTI(tree, node, $event)
: TREE_ACTIONS.TOGGLE_ACTIVE(tree, node, $event);
},
mouseOver: (tree, node, $event) => {
$event.preventDefault();
console.log(`mouseOver ${node.data.name}`);
},
mouseOut: (tree, node, $event) => {
$event.preventDefault();
console.log(`mouseOut ${node.data.name}`);
}
},
keys: {
[KEYS.ENTER]: (tree, node, $event) => alert(`This is ${node.data.name}`)
}
};
@Component({
selector: 'app-actions',
styles: [
],
template: `
<tree-root
#tree
[nodes]="nodes"
[options]="options"
[focused]="true"
>
</tree-root>
<br>
<b>Custom Keys:</b><br>
enter - show alert<br>
<br>
<b>Custom Mouse Actions:</b><br>
shift+click - select multi<br>
double click - expand / collapse<br>
right-click - show alert
`
})
export class ActionsComponent {
nodes = [
{
name: 'root1',
children: [
{
name: 'child1'
}, {
name: 'child2'
}
]
},
{
name: 'root2',
children: [
{
name: 'child2.1'
}, {
name: 'child2.2',
children: [
{
id: 1001,
name: 'subsub'
}
]
}
]
}
];
options: ITreeOptions = {
actionMapping
};
}