-
Notifications
You must be signed in to change notification settings - Fork 0
/
ee-status-button.html
295 lines (248 loc) · 7.79 KB
/
ee-status-button.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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../paper-behaviors/paper-button-behavior.html">
<link rel="import" href="../paper-material/paper-material-shared-styles.html">
<link rel="import" href="../iron-icon/iron-icon.html">
<link rel="import" href="../iron-icons/iron-icons.html">
<!--
`ee-status-button` is a button which displays different icons and titles for fail states = true/false
Example:
<ee-status-button></ee-status-button>
Button titles:
<ee-status-button raised fail
title="Edit emergency profile"
fail-title="Emergency profile missing">
</ee-status-button>
### Styling
The following custom properties and mixins are also available for styling:
Custom property | Description | Default
----------------|-------------|----------
`--ee-status-button-ink-color` | Background color of the ripple | `Based on the button's color`
`--ee-status-button-icon` | Mixin applied to the icon | `{}`
`--ee-status-button-icon-fail` | Mixin applied to the icon when fail=true | `{}`
`--ee-status-button` | Mixin applied to the button | `{}`
`--ee-status-button-icon-container-color` | icon container when fail=false| `{}`
`--ee-status-button-icon-container-color-fail` | Icon color when fail=true | `{}`
`--ee-status-button-icon-container` | Mixin applied to the icon container when fail=false | `{}`
`--ee-status-button-icon-container-fail` | Mixin applied to the icon container when fail=true | `{}`
`--ee-status-button-disabled` | Mixin applied to the disabled button. Note that you can also use the `ee-status-button[disabled]` selector | `{}`
`--ee-status-button-flat-keyboard-focus` | Mixin applied to a flat button after it's been focused using the keyboard | `{}`
`--ee-status-button-raised-keyboard-focus` | Mixin applied to a raised button after it's been focused using the keyboard | `{}`
@demo demo/index.html
-->
<dom-module id="ee-status-button">
<template strip-whitespace>
<style include="paper-material-shared-styles">
:host {
@apply(--layout-inline);
@apply(--layout-center-center);
position: relative;
box-sizing: border-box;
min-width: 5.14em;
margin: 0 0.29em;
background: transparent;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
-webkit-tap-highlight-color: transparent;
font: inherit;
outline-width: 0;
border-radius: 3px;
-moz-user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
user-select: none;
cursor: pointer;
z-index: 0;
padding: 0.7em 0.57em;
opacity: 1;
transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-webkit-transition: opacity 1s ease-in-out;
@apply(--paper-font-common-base);
@apply(--ee-status-button);
}
:host([hidden]) {
display: none !important;
}
:host([raised].keyboard-focus) {
font-weight: bold;
@apply(--ee-status-button-raised-keyboard-focus);
}
:host(:not([raised]).keyboard-focus) {
font-weight: bold;
@apply(--ee-status-button-flat-keyboard-focus);
}
:host([disabled]) {
background: #eaeaea;
color: #a8a8a8;
cursor: auto;
pointer-events: none;
@apply(--ee-status-button-disabled);
}
:host([animated]) {
@apply(--shadow-transition);
}
paper-ripple {
color: var(--ee-status-button-ink-color);
}
.space {
@apply(--layout-flex);
}
#iconContainer {
position: relative;
top: -6px;
right: -6px;
margin-left: 12px;
padding: 2px;
border-radius: 50%;
background-color: var(--ee-status-button-icon-container-color, #72d572);
height: 4.5vw;
width: 4.5vw;
max-width: 26px;
max-height: 26px;
text-align: center;
@apply(--layout-horizontal);
@apply(--layout-center);
@apply(--ee-status-button-icon-container);
}
#iconContainer.fail {
top: 0;
right: 0;
background-color: var(--ee-status-button-icon-container-color-fail, #f46f5a);
@apply(--ee-status-button-icon-container-fail);
}
.icon {
color: #fff;
margin: 0 auto;
--iron-icon-height: 18px;
--iron-icon-width: 18px;
@apply(--ee-status-button-icon);
}
.icon.fail {
--iron-icon-height: 24px;
--iron-icon-width: 24px;
@apply(--ee-status-button-icon-fail);
}
#title {
@apply(--ee-status-button-title);
}
#title.fail {
@apply(--ee-status-button-title-fail);
}
</style>
<content></content>
<span id="title">[[_title]]</span>
<span class="space"></span>
<span id="iconContainer">
<template is="dom-if" if=[[fail]]>
<iron-icon id="icon" class="icon fail" icon$="[[_icon]]"></iron-icon>
</template>
<template is="dom-if" if=[[!fail]]>
<iron-icon id="icon" class="icon" icon$="[[_icon]]"></iron-icon>
</template>
</span>
</template>
<script>
Polymer({
is: 'ee-status-button',
behaviors: [
Polymer.PaperButtonBehavior
],
properties: {
/**
* The button title which should be displayed if fail=false.
*/
icon: {
type: String,
value: 'icons:check',
notify: true
},
/**
* The button icon which should be displayed if fail=true.
*/
failIcon: {
type: String,
value: 'icons:close',
notify: true
},
_icon: {
type: String,
computed: '_computeIconName(icon, failIcon, fail)'
},
/**
* If the fail status should be active.
*/
fail: {
type: Boolean,
value: false,
observer: '_failChanged'
},
/**
* Hides the button if fail=false.
*/
hideIfNotFail: {
type: Boolean,
value: false
},
/**
* The button title which should be displayed if fail=true.
*/
failTitle: {
type: String,
value: '',
notify: true
},
/**
* The button title which should be displayed if fail=false.
*/
title: {
type: String,
value: '',
notify: true
},
_title: {
type: String,
computed: '_computeTitle(title, failTitle, fail)',
notify: true
},
/**
* If true, the button should be styled with a shadow.
*/
raised: {
type: Boolean,
reflectToAttribute: true,
value: false,
observer: '_calculateElevation'
}
},
attached: function() {
this._failChanged();
},
_computeIconName(icon, failIcon, fail) {
return fail ? failIcon : icon;
},
_computeTitle: function(title, failTitle, fail) {
return fail ? failTitle : title;
},
_calculateElevation: function() {
if (!this.raised) {
this._setElevation(0);
} else {
Polymer.PaperButtonBehaviorImpl._calculateElevation.apply(this);
}
},
_failChanged: function() {
if (this.fail) {
this.hidden = false;
this.$.iconContainer.classList.add('fail');
this.$.title.classList.add('fail');
} else {
if (this.hideIfNotFail) {
this.hidden = true;
}
this.$.iconContainer.classList.remove('fail');
this.$.title.classList.remove('fail');
}
},
});
</script>
</dom-module>