-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfa-awesome.html
285 lines (236 loc) · 6.53 KB
/
fa-awesome.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
<!--
@license
Copyright (c) 2015 Peter Kaske <p.kaske@gmail.com>. All rights reserved.
This code may only be used under the MIT license found at http://opensource.org/licenses/MIT.
Or see the LICENSE file that comes with this code.
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../neon-animation/neon-animation.html">
<link rel="import" href="../polymer-font-awesome-icons/fa-all.html">
<link rel="import" href="../iron-icon/iron-icon.html">
<!--
# fa-awesome
Shows font-awesome icons.
The element as some bonus attributes for things like spinning icons.
Check out the examples below and the demo.
## Examples
```html
Normal icon with label on the right
<fa-awesome icon="fa:chevron-right">Go right</fa-awesome>
Icon with label on the left
<fa-awesome icon="fa:chevron-left" label-left>Go left</fa-awesome>
Spinning icon
<fa-awesome icon="fa:cog" spin>I spinn</fa-awesome>
Pulse icon
<fa-awesome icon="fa:spinner" pulse>Pusing</fa-awesome>
Icon size set directly
<fa-awesome icon="fa:cog" size="50"></fa-awesome>
Rotated icon, support are `90` (default), `180` and `270`
<fa-awesome icon="fa:flag" rotate="180"></fa-awesome>
Flipped icon, support are `horizontal` (default) and `vertical`
<fa-awesome icon="fa:flat" rotate></fa-awesome>
```
@group GUI Elements
@element fa-awesome
@demo demo/index.html
@homepage http://pkaske.github.io/fa-awesome
-->
<dom-module id="fa-awesome">
<style>
:host {
display: inline-block;
}
:host([animated]) {
display: none;
}
#label {
padding-left: 5px;
}
#label.hide {
display: none;
}
#wrap {
@apply(--layout-horizontal);
@apply(--layout-center);
}
#wrap.reverse {
@apply(--layout-horizontal-reverse);
}
#wrap.reverse #label {
padding-left: 0;
padding-right: 5px;
}
#ico {
--iron-icon-width: var(--fa-awesome-icon-width, 24px);
--iron-icon-height: var(--fa-awesome-icon-height, 24px);
}
:host([spin]) #ico {
-webkit-animation: fa-spin 2s infinite linear;
animation: fa-spin 2s infinite linear;
}
:host([pulse]) #ico {
-webkit-animation: fa-spin 1s infinite steps(8);
animation: fa-spin 1s infinite steps(8);
}
@-webkit-keyframes fa-spin {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
@keyframes fa-spin {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
:host([rotate]) #ico {
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);
-webkit-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
}
:host([rotate="180"]) #ico {
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=2);
-webkit-transform: rotate(180deg);
-ms-transform: rotate(180deg);
transform: rotate(180deg);
}
:host([rotate="270"]) #ico {
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
-webkit-transform: rotate(270deg);
-ms-transform: rotate(270deg);
transform: rotate(270deg);
}
:host([flip]) #ico, {
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);
-webkit-transform: scale(-1, 1);
-ms-transform: scale(-1, 1);
transform: scale(-1, 1);
}
:host([flip="vertical"]) #ico {
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=2, mirror=1);
-webkit-transform: scale(1, -1);
-ms-transform: scale(1, -1);
transform: scale(1, -1);
}
iron-icon {
display: inline-block;
}
</style>
<template>
<div id="wrap">
<iron-icon id="ico" icon="[[icon]]" size="[[size]]"></iron-icon>
<span id="label">
<content></content>
</span>
</div>
</template>
</dom-module>
<script>
Polymer({
is: 'fa-awesome',
behaviors: [
Polymer.NeonAnimationRunnerBehavior
],
properties: {
size: {
type: String,
observer: '_sizeChanged'
},
/**
* If the 'label-left' attribute is set the label is placed left (instead of right) from the icon.
*
* @property labelLeft
* @type bool
* @default false
*/
labelLeft: {
type: Boolean,
observer: '_labelLeftChanged'
},
animated: {
type: Boolean,
value: false,
observer: '_animatedChanged'
},
visible: {
type: Boolean
},
animationConfig: {
value: function() {
return {
'entry': [{
name: 'fade-in-animation',
node: this
}, {
name: 'scale-up-animation',
node: this
}],
'exit': [{
name: 'fade-out-animation',
node: this
}, {
name: 'scale-down-animation',
node: this
}]
};
}
}
},
listeners: {
'neon-animation-finish': '_onNeonAnimationFinish'
},
attached: function() {
if (this.$.label.textContent.trim().length == 0) {
this.toggleClass('hide', true, this.$.label);
}
},
ready: function() {
if (this.visible && this.animated) {
this.show();
}
},
show: function() {
if (!this.animated) return;
this.visible = true;
this.style.display = 'inline-block';
this.playAnimation('entry');
},
hide: function() {
if (!this.animated) return;
this.visible = false;
this.playAnimation('exit');
},
_sizeChanged: function() {
if (!this.size || this.size == '') {
this.size = '24';
}
this.$.ico.customStyle['--iron-icon-width'] = this.size + 'px';
this.$.ico.customStyle['--iron-icon-height'] = this.size + 'px';
this.$.ico.updateStyles();
},
_labelLeftChanged: function(newValue) {
this.toggleClass('reverse', newValue, this.$.wrap);
},
_animatedChanged: function(newValue, oldValue) {
if (!oldValue && newValue == true) {
this.playAnimation('exit');
}
},
_onNeonAnimationFinish: function() {
if (!this.visible) {
this.style.display = 'none';
}
}
});
</script>