forked from winhowes/file-tree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file-folder.html
executable file
·142 lines (113 loc) · 2.87 KB
/
file-folder.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!--
@license
Copyright (c) 2015 Winston Howes. All rights reserved.
This code may only be used under the MIT license found at https://github.com/winhowes/file-tree/blob/master/LICENSE
-->
<link rel="import" href="../polymer/polymer.html">
<!--
An element acting as a folder with other folders inside of it.
Example:
<file-folder></file-folder>
@demo
-->
<link rel="import" href="../iron-icons/iron-icons.html">
<dom-module id="file-folder">
<style>
:host.selected > .thisFolder > .folderTitle{
background-color: rgba(31, 141, 214, 0.4);
border: 1px solid rgba(31, 141, 214, 0.7);
border-radius: 5px;
}
.parent.collapsed:before {
content: '+ ';
padding: 5px;
}
.parent.expanded:before {
content: '- ';
padding: 5px;
}
.parent, .name {
cursor: pointer;
}
ul {
margin: 0;
}
li {
list-style-type: none;
}
iron-icon {
cursor: pointer;
width: 24px;
height: 24px;
}
[hidden] {
display: none;
}
</style>
<template>
<div class="thisFolder">
<div class="folderTitle">
<span class$="{{_determineClass(data.open, data.children)}}" on-click="toggleChildren">
<iron-icon icon$="{{_determineIcon(data.shared)}}"></iron-icon>
</span>
<span class="name" on-click="selectFolder">{{data.name}}</span>
</div>
<ul hidden$={{!data.open}}>
<template is="dom-repeat" items="{{data.children}}">
<li>
<file-folder data="{{item}}"></file-folder>
</li>
</template>
</ul>
</div>
</template>
</dom-module>
<script>
Polymer({
is: 'file-folder',
properties: {
/**
* `data` is the data to be used for the tree.
*/
data: {
type: Object,
value: function() {
return {};
}
},
},
/**
* The `folderSelected` event is fired whenever `selectFolder` is called.
*
* @event folderSelected
*/
/**
* Returns the necessary classes.
*
* @param {boolean}, whether or not the folder is open
*/
_determineClass: function(open, children) {
return 'parent ' + ((open && children && children.length) ? 'expanded' : children && children.length ? 'collapsed' : '');
},
/**
* Returns the necessary folder icon.
*
* @param {boolean}, whether or not the folder is shared
*/
_determineIcon: function(shared) {
return shared ? 'folder-shared' : 'folder';
},
/**
* Highlights folder as the selected folder.
*/
selectFolder: function(e) {
this.fire("folderSelected", this);
},
/**
* Toggles the children nodes on or off.
*/
toggleChildren: function(e) {
this.set("data.open", !this.data.open && this.data.children && this.data.children.length);
}
});
</script>