-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile-uploader-progress-overlay.html
210 lines (174 loc) · 5.25 KB
/
file-uploader-progress-overlay.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../app-localize-mixin/app-localize-mixin.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../offthread-image/offthread-image.html">
<link rel="import" href="../overlay-container/animated-overlay-mixin.html">
<link rel="import" href="../paper-progress/paper-progress.html">
<!--
`file-uploader-progress-overlay`
@demo demo/index.html
-->
<dom-module id="file-uploader-progress-overlay">
<template>
<style>
:host {
background: white;
border-radius: 4px;
bottom: 30px;
box-shadow: 0 16px 24px 2px rgba(0,0,0,0.14), 0 6px 30px 5px rgba(0,0,0,0.12), 0 8px 10px -5px rgba(0,0,0,0.2);
display: inline-block;
height: 100px;
left: 30px;
overflow: hidden;
position: fixed;
right: 30px;
z-index: 9999;
}
@media(min-width: 642px) {
:host {
bottom: 50px;
left: 30px;
right: auto;
width: 320px;
}
}
#paperProgress {
bottom: 0;
height: 4px;
left: 0;
position: absolute;
width: 100%;
--paper-progress-active-color: var(--file-uploader-progress-overlay-color, #2196f3);
}
#container {
@apply --layout-horizontal;
height: 100%;
}
offthread-image {
width: 100px;
height: 100%;
}
.detail {
@apply --layout-vertical;
@apply --layout-flex;
box-sizing: border-box;
color: #666;
font-size: 13px;
padding: 12px 25px 16px;
position: relative;
}
.detail__destination {
@apply --layout-flex;
color: initial;
font-size: 16px;
margin: 2px 0;
}
.detail__button {
background: none;
border-radius: 3px;
border: none;
bottom: 12px;
color: var(--file-uploader-progress-overlay-color, #2196f3);
cursor: pointer;
font-size: 13px;
font-weight: 600;
outline: 0;
padding: 6px 10px;
position: absolute;
right: 20px;
text-transform: uppercase;
}
.detail__button:hover {
background: #f2f2f2;
}
</style>
<div id="container">
<offthread-image sizing="cover" src="[[_computeImageUrl(currentFile)]]"></offthread-image>
<div class="detail">
<div>[[_computeUploadingTitle(destinationText, localize)]]</div>
<div class="detail__destination">[[destinationText]]</div>
<div>[[_computeLoadedDetail(currentFile, uploadingFiles.size, localize)]]</div>
<button class="detail__button" on-click="_stopClicked">[[localize('stop')]]</button>
<paper-progress id="paperProgress" indeterminate></paper-progress>
</div>
</div>
</template>
<script>
class FileUploaderProgressOverlay extends AnimatedOverlayMixin(AppLocalizeMixin(Polymer.Element)) {
static get is() {return 'file-uploader-progress-overlay';}
static get properties() {
return {
// @override AnimatedOverlayBehavior
noCancelOnEscKey: {
type: Boolean,
value: true
},
// @override AnimatedOverlayBehavior
noCancelOnPopState: {
type: Boolean,
value: true
},
uploadingFiles: Map,
// The file that is being currently uploaded.
currentFile: Object,
destinationText: {
type: String,
value: null
},
language: {
type: String,
value: 'en'
},
// localize resources
resources: {
value: _ => {
return {
'en': {
'UploadingTo': 'Uploading to',
'Uploading': 'Uploading...',
'LoadedDetail': '{current} of {total}',
'stop': 'Stop'
},
'es': {
'UploadingTo': 'Subiendo a',
'Uploading': 'Subiendo...',
'LoadedDetail': '{current} de {total}',
'stop': 'Detener'
}
};
}
}
};
}
_stopClicked() {
this.dispatchEvent(new CustomEvent('stop'));
}
_computeImageUrl(currentFile) {
if (currentFile) {
const isImage = /image\/.*/.exec(currentFile.type);
if (isImage) {
return URL.createObjectURL(currentFile);
}
}
}
_computeUploadingTitle(destinationText) {
if (destinationText) {
return this.localize('UploadingTo');
}
return this.localize('Uploading');
}
_computeLoadedDetail(currentFile, uploadingFilesSize) {
let current = 1;
for (let [file, detail] of this.uploadingFiles) {
if (detail.state !== 'queued') {
current += 1;
}
}
return this.localize('LoadedDetail',
'current', String(current),
'total', uploadingFilesSize);
}
}
customElements.define(FileUploaderProgressOverlay.is, FileUploaderProgressOverlay);
</script>
</dom-module>