This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhax-app-picker.html
319 lines (313 loc) · 9.85 KB
/
hax-app-picker.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-list/iron-list.html">
<link rel="import" href="../paper-dialog/paper-dialog.html">
<link rel="import" href="../paper-dialog-scrollable/paper-dialog-scrollable.html">
<link rel="import" href="../paper-ripple/paper-ripple.html">
<link rel="import" href="../paper-toast/paper-toast.html">
<link rel="import" href="../paper-icon-button/paper-icon-button.html">
<link rel="import" href="../neon-animation/web-animations.html">
<link rel="import" href="../neon-animation/neon-animation.html">
<link rel="import" href="../neon-animation/animations/scale-up-animation.html">
<link rel="import" href="../neon-animation/animations/scale-down-animation.html">
<link rel="import" href="../materializecss-styles/materializecss-styles.html">
<link rel="import" href="../simple-colors/simple-colors.html">
<link rel="import" href="./hax-app-picker-item.html">
<!--
`hax-app-picker`
A picker for selecting an item from a list of apps / hax gizmos which require
a decision to be made. This is used when multiple things match either on upload
in the add operation of the app or in the gizmo selection to render through,
such as having multiple ways of presenting an image.
@demo demo/index.html
@microcopy - the mental model for this element
- data - this is the app data model for an element which expresses itself to hax
-->
<dom-module id="hax-app-picker">
<template>
<style is="custom-style" include="materializecss-styles">
:host {
display: block;
--hax-app-picker-dialog-background-color: var(--simple-colors-light-green-background1);
};
hax-app-picker-item {
-webkit-transition: .3s all linear;
transition: .3s all linear;
display: inline-flex;
}
paper-icon-button.close {
float: right;
top: 0;
right: 0;
position: absolute;
padding: 4px;
margin: 0;
color: var(--simple-colors-light-green-background1);
}
#ironlist {
width: 100%;
height: 30vh;
}
#dialog {
min-width: 30vw;
min-height: 30vh;
height: 30vw;
width: 30vh;
padding: 8px;
overflow: hidden;
background-color: rgba(0,0,0,.9);
border-radius: 16px;
z-index: 1000000;
border: 2px solid var(--simple-colors-light-green-background1);
@apply --hax-app-picker-dialog;
}
#title, .element-button > div {
color: var(--hax-app-picker-dialog-text-color, #FFFFFF);
}
#title {
padding: 16px;
border-bottom: 2px solid var(--simple-colors-light-green-background1);
margin: 0;
width: calc(100% - 32px);
color: var(--hax-app-picker-dialog-text-color, #FFFFFF);
@apply --paper-font-title;
@apply --hax-app-picker-dialog-title;
}
#buttonlist {
display: block;
text-align: left;
margin: auto;
padding: 8px;
overflow-x: hidden;
overflow-y: auto;
--paper-dialog-scrollable: {
padding: 0 0 78px 0;
}
}
@media (orientation: landscape) {
#buttonlist,
#ironlist,
#dialog {
width: 40vw;
height: 50vh;
}
}
@media (orientation: portrait) {
#buttonlist,
#ironlist,
#dialog {
width: 50vw;
height: 60vh;
}
}
.element-button {
display: inline-block;
width: 72px;
margin: 8px 4px;
text-align: center;
}
@media screen and (max-width: 550px) {
#buttonlist,
#ironlist,
#dialog {
max-width: 80%;
overflow: auto;
}
.element-button {
width: 54px;
margin: 0px;
}
}
</style>
<paper-dialog id="dialog" with-backdrop always-on-top>
<h3 id="title">[[title]]</h3>
<paper-dialog-scrollable id="buttonlist">
<iron-list id="ironlist" items="[[selectionList]]" as="element" grid>
<template>
<div>
<hax-app-picker-item
id$="picker-item-[[index]]"
class="element-button"
on-tap="_selected"
data-selected$="[[index]]"
label="[[element.title]]"
icon="[[element.icon]]"
color="[[element.color]]"></hax-app-picker-item></div>
</template>
</iron-list>
</paper-dialog-scrollable>
<paper-icon-button dialog-dismiss icon="icons:cancel" class="close" title="Close dialog"></paper-icon-button>
</paper-dialog>
</template>
<script>
Polymer({
is: 'hax-app-picker',
listeners: {
'dialog.iron-overlay-canceled': 'close',
'dialog.iron-overlay-closed': 'close',
},
behaviors: [
simpleColorsBehaviors,
],
properties: {
/**
* raw element set
*/
_elements: {
type: Array,
value: [],
},
/**
* Refactored list for selection purposes
*/
selectionList: {
type: Array,
value: [],
},
/**
* Title for the dialog
*/
title: {
type: String,
value: "Pick an options",
},
/**
* Allow multiple uses
*/
pickerType: {
type: String,
value: "gizmo",
},
/**
* Opened status to bind to the dialog box being open
*/
opened: {
type: Boolean,
value: false,
observer: '_openedChanged',
},
},
/**
* Attached life cycle
*/
attached: function() {
this.fire('hax-register-app-picker', this);
},
/**
* Attached life cycle
*/
ready: function() {
document.body.appendChild(this);
},
/**
* Close the picker and ensure body locking is off.
*/
close: function() {
this.opened = false;
},
/**
* Open status changed
*/
_openedChanged: function(newValue, oldValue) {
if (typeof newValue !== typeof undefined) {
if (newValue) {
this.$.dialog.open();
setTimeout(() => {
this.$.ironlist.fire('iron-resize');
window.dispatchEvent(new Event('resize'));
}, 100);
// lock the background
document.body.style.overflow = 'hidden';
}
else {
this.$.dialog.close();
document.body.style.overflow = null;
}
}
},
/**
* Present options to the user with a modal and selection method that
* shifts itself to be above everything (stack order)
* @param [array] elements a list of elements for presenting to the user
* to select between.
*/
presentOptions: function(elements, type, title = 'Select an option', pickerType = 'gizmo') {
// wipe existing
this.title = title;
this.pickerType = pickerType;
var tmp = [];
switch (pickerType) {
// hax gizmo selector
case 'gizmo':
for (var i in elements) {
elements[i].__type = type;
tmp[i] = {
"icon" : elements[i].gizmo.icon,
"title" : elements[i].gizmo.title,
"color" : elements[i].gizmo.color
}
}
break;
// app selector
case 'app':
for (var i in elements) {
tmp[i] = {
"icon" : elements[i].details.icon,
"title" : elements[i].details.title,
"color" : elements[i].details.color,
}
}
break;
// we don't know what to do with this
default:
tmp = elements;
break;
}
this._elements = elements;
this.set('selectionList', []);
this.set('selectionList', tmp);
this.opened = true;
// try to focus on option 0
setTimeout( () => {
this.$$('#picker-item-0').focus();
}, 100);
},
/**
* Handle the user selecting an app.
*/
_selected: function(e) {
var normalizedEvent = Polymer.dom(e);
let key = normalizedEvent.localTarget.getAttribute('data-selected');
e.preventDefault();
e.stopPropagation();
if (typeof this._elements[key] !== typeof undefined) {
// haxElement is a unique case
if (this.pickerType == 'gizmo') {
Polymer.HaxStore.write('activeHaxElement', this._elements[key], this);
if (this._elements[key].__type === '__convert') {
Polymer.HaxStore.instance.haxManager.editExistingNode = true;
}
// ensure this is open even though it should be
Polymer.HaxStore.instance.haxManager.selectStep('configure');
Polymer.HaxStore.instance.haxManager.open();
}
else if (this.pickerType == 'delete') {
if (this._elements[key]['title'] === 'Yes') {
if (Polymer.HaxStore.instance.activeHaxBody.activeNode !== Polymer.HaxStore.instance.activeHaxBody.activeContainerNode) {
Polymer.HaxStore.instance.activeHaxBody.haxDeleteNode(Polymer.HaxStore.instance.activeHaxBody.activeNode, Polymer.HaxStore.instance.activeHaxBody.activeContainerNode);
}
else {
Polymer.HaxStore.instance.activeHaxBody.haxDeleteNode(Polymer.HaxStore.instance.activeHaxBody.activeNode);
}
Polymer.HaxStore.toast('Element deleted', 2000);
}
}
else {
// bubble this up
this.fire('hax-app-picker-selection', this._elements[key]);
}
}
this.opened = false;
},
});
</script>
</dom-module>