forked from LRNWebComponents/hax-body
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hax-app-picker.html
170 lines (162 loc) · 5.54 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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-dialog/paper-dialog.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">
<!--
`hax-app-picker`
An app registered with HAX. This provides all the information needed for HAX
to understand how to talk to this backend as well as represent it in listings.
It also expresses how to take that data and wire it up to gizmos making it able to
utilize multiple display methods.
@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 include="materializecss-styles">
:host {
display: block;
};
#dialog {
max-width: 480px;
@apply --hax-app-picker-dialog;
background-color: var(--hax-app-picker-dialog-background-color, white);
}
#title, .hax-element-button > div {
color: var(--hax-app-picker-dialog-text-color, black);
}
#title {
padding: 16px;
margin: 0;
@apply --paper-font-title;
@apply --hax-app-picker-dialog-title;
}
#buttonlist {
border-top: 1px solid rgba(128, 128, 128, .5);
display: block;
text-align: center;
margin: auto;
padding: 8px;
overflow-x: hidden;
overflow-y: auto;
max-height: calc(100vh - 126px);
}
@media (orientation: landscape) {
#buttonlist {
max-height: 50vh;
}
}
@media (orientation: portrait) {
#buttonlist {
max-height: 60vh;
}
}
.hax-element-button {
display: inline-block;
width: 72px;
margin: 8px 4px;
text-align: center;
}
.hax-element-button > div {
@apply --paper-font-caption;
margin-top: 8px;
color: black;
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
@apply --hax-app-picker-hax-element-text;
}
.icon {
cursor: pointer;
width: 64px;
height: 64px;
padding: 16px;
color: white;
border-radius: 50%;
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12), 0 3px 1px -2px rgba(0, 0, 0, 0.2);
-webkit-transition: box-shadow .2s;
-moz-transition: box-shadow .2s;
-ms-transition: box-shadow .2s;
-o-transition: box-shadow .2s;
transition: box-shadow .2s;
@apply --hax-app-picker-hax-element--icon;
}
.icon:hover, .icon:focus {
box-shadow: 0 4px 4px 0 rgba(0, 0, 0, 0.14), 0 2px 10px 0 rgba(0, 0, 0, 0.12), 0 6px 2px -4px rgba(0, 0, 0, 0.2);
}
.icon:active {
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12), 0 3px 1px -2px rgba(0, 0, 0, 0.2);
}
</style>
<paper-dialog id="dialog" entry-animation="scale-up-animation" exit-animation="scale-down-animation" modal>
<h2 id="title">[[title]]</h2>
<paper-dialog-scrollable id="buttonlist">
<template is="dom-repeat" items="[[haxElements]]" as="element">
<div class="hax-element-button" on-tap="_appSelected" data-selected$="[[index]]" title="[[element.gizmo.title]]">
<paper-icon-button on-tap="_appSelected" data-selected$="[[index]]" class$="icon [[element.gizmo.color]]" icon="[[element.gizmo.icon]]"></paper-icon-button>
<div>[[element.gizmo.title]]</div>
</div>
</template>
</paper-dialog-scrollable>
</paper-dialog>
</template>
<script>
Polymer({
is: 'hax-app-picker',
properties: {
/**
* hax elements to select between
*/
haxElements: {
type: Array,
value: [],
},
/**
* Title for the dialog
*/
title: {
type: String,
value: "Pick an options",
},
},
/**
* Attached life cycle
*/
attached: function() {
this.fire('hax-register-app-picker', this);
},
/**
* Present options to the user with a modal and selection method that
* shifts itself to be above everything (stack order)
* @param [array] haxElements a list of haxElements for presenting to the user
* to select between.
*/
presentOptions: function(haxElements, type) {
// wipe existing
this.set('haxElements', []);
this.set('haxElements', haxElements);
this.title = 'Pick how to present the ' + type;
this.$.dialog.open();
},
/**
* Handle the user selecting an app.
*/
_appSelected: function(e) {
var normalizedEvent = Polymer.dom(event);
let key = normalizedEvent.localTarget.getAttribute('data-selected');
if (typeof this.haxElements[key] !== typeof undefined) {
Polymer.HaxStore.write('activeHaxElement', this.haxElements[key], this);
}
this.$.dialog.close();
},
});
</script>
</dom-module>