-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathpaper-tree.html
executable file
·116 lines (94 loc) · 3.12 KB
/
paper-tree.html
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="paper-tree-node.html">
<!--
`<paper-tree>` display a browsable tree of nodes (`<paper-tree-node>`) with expandable/collapsible capabilities and actions menu for each node.
Example:
<paper-tree></paper-tree>
@demo
-->
<link rel="import" href="paper-tree-node.html">
<dom-module id="paper-tree">
<template>
<div>
<paper-tree-node id="root" data="[[data]]" actions="[[actions]]"></paper-tree-node>
</div>
</template>
</dom-module>
<script>
Polymer({
is: 'paper-tree',
properties: {
/**
* Data hold by the root node (contains the children).
*
* Specific data:
*
* - `data.name`: string representing the node name.
* - `data.icon`: string telling which icon to use (default to 'folder' icon).
* - `data.open`: boolean telling whether the node is expanded or not.
* - `data.children` array containing the children of the node.
*/
data: {
type: Object,
value: function() {
return null;
},
observer: "_dataChanged"
},
/**
* `selected` is the current selected `<paper-tree-node>` in the tree.
*/
selected: {
type: Object,
value: null,
notify: true
},
/**
* `actions` available for all nodes. Each action object has the following fields:
*
* - `action.label`: string representing the display name of the menu item.
* - `action.event`: string which is the event name to dispatch whenever the item is clicked.
*
*/
actions: {
type: Array,
value: function() {
return null;
},
observer: "_actionsChanged"
}
},
listeners: {
"select": "_selectNode"
},
/**
* Called whenever the data is changed to notify the lower nodes.
*/
_dataChanged: function() {
this.$.root.data = this.data;
},
/**
* Called whenever the actions list is changed to notify the lower nodes.
*/
_actionsChanged: function() {
this.$.root.actions = this.actions;
},
/**
* Called when the `select` event is fired from an internal node.
*
* @param {object} e An event object.
*/
_selectNode: function(e) {
if(this.selected) {
this.toggleClass("selected", false, this.selected);
}
// Only selects `<paper-tree-node>`.
if (e.detail && e.detail.tagName === 'PAPER-TREE-NODE') {
this.selected = e.detail;
this.toggleClass("selected", true, this.selected);
} else {
this.selected = null;
}
}
});
</script>