-
Notifications
You must be signed in to change notification settings - Fork 78
/
lrn-button-old-ported.js
282 lines (274 loc) · 6.41 KB
/
lrn-button-old-ported.js
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
import { html, Polymer } from "@polymer/polymer/polymer-legacy.js";
import "@polymer/paper-button/paper-button.js";
import "@polymer/iron-icons/iron-icons.js";
import "@polymer/iron-icon/iron-icon.js";
import "@lrnwebcomponents/materializecss-styles";
import "@polymer/paper-tooltip/paper-tooltip.js";
/**
`lrnsys-button`
A LRN element
* @demo demo/index.html
*/
let LrnsysButton = Polymer({
_template: html`
<style include="materializecss-styles-colors">
:host {
display: block;
@apply --paper-font-common-base;
@apply --paper-button;
--lrnsys-button-height: 48px;
}
:host(.center) {
text-align: center;
}
a {
text-decoration: none;
display: block;
color: #000000;
}
paper-button {
transition: 0.3s;
margin: 0;
max-width: 50%;
height: inherit;
-webkit-justify-content: flex-start;
justify-content: flex-start;
align-items: center;
border-radius: unset;
}
paper-button iron-icon {
height: var(--lrnsys-button-height);
margin: 0 12px;
}
paper-button div.inner {
height: var(--lrnsys-button-height);
line-height: var(--lrnsys-button-height);
padding: 0 12px;
}
paper-button span.label {
height: var(--lrnsys-button-height);
line-height: var(--lrnsys-button-height);
}
.no-margin {
margin: 0 !important;
}
.no-right-padding {
padding-right: 0 !important;
}
.no-left-padding {
padding-left: 0 !important;
}
.center {
text-align: center;
margin: 0 auto;
}
</style>
<a
tabindex="-1"
id="lrnsys-button-link"
href\$="[[showHref]]"
data-prefetch-hover\$="[[prefetch]]"
target\$="[[target]]"
>
<paper-button
id="button"
raised="[[raised]]"
class\$="[[class]] [[color]] [[textColor]]"
disabled\$="[[disabled]]"
>
<div class\$="inner [[innerClass]]">
<iron-icon
icon\$="[[icon]]"
id="icon"
class\$="[[iconClass]]"
hidden\$="[[!icon]]"
></iron-icon>
<span class="label" hidden\$="[[!label]]"> [[label]] </span>
<slot></slot>
</div>
</paper-button>
</a>
<paper-tooltip for="lrnsys-button-link" animation-delay="0"
>[[alt]]</paper-tooltip
>
`,
is: "lrn-button",
/**
* Detect when hovering on our off the element and provide color switching
*/
listeners: {
mousedown: "tapEventOn",
mouseover: "tapEventOn",
mouseout: "tapEventOff",
"button.focused-changed": "focusToggle"
},
properties: {
/**
* Standard href pass down
*/
href: {
type: String,
value: "#"
},
showHref: {
type: String,
value: false
},
/**
* If the button should be visually lifted off the UI.
*/
raised: {
type: Boolean
},
/**
* Label to place in the text area
*/
label: {
type: String,
value: ""
},
target: {
type: String,
value: ""
},
/**
* iron-icon to use (with iconset if needed)
*/
icon: {
type: String,
value: false
},
/**
* Classes to add / subtract based on the item being hovered.
*/
hoverClass: {
type: String
},
/**
* Icon class in the event you want it to look different from the text.
*/
iconClass: {
type: String
},
/**
* Inner container classes.
*/
innerClass: {
type: String
},
/**
* materializeCSS color class
*/
color: {
type: String
},
/**
* materializeCSS color class for text
*/
textColor: {
type: String
},
/**
* Allow for prefetch data on hover
*/
prefetch: {
type: String
},
/**
* Alt via tooltip.
*/
alt: {
type: String
},
/**
* Disabled state.
*/
disabled: {
type: Boolean,
value: false
},
/**
* Tracks if focus state is applied
*/
focusState: {
type: Boolean,
value: false
}
},
/**
* Go to the href if the button isn't disabled
*/
ready: function(e) {
if (!this.disabled) {
this.showHref = this.href;
}
},
/**
* Class processing on un-tap / hover
*/
tapEventOn: function(e) {
let root = this;
if (typeof root.hoverClass !== typeof undefined && !root.disabled) {
// break class into array
var classes = root.hoverClass.split(" ");
// run through each and add or remove classes
classes.forEach(function(item, index) {
if (item != "") {
root.$.button.classList.add(item);
if (item.indexOf("-") != -1) {
root.$.icon.classList.add(item);
}
}
});
}
},
/**
* Undo class processing on un-tap / hover
*/
tapEventOff: function(e) {
let root = this;
if (typeof root.hoverClass !== typeof undefined && !root.disabled) {
// break class into array
var classes = root.hoverClass.split(" ");
// run through each and add or remove classes
classes.forEach(function(item, index) {
if (item != "") {
root.$.button.classList.remove(item);
if (item.indexOf("-") != -1) {
root.$.icon.classList.remove(item);
}
}
});
}
},
/**
* Handle toggle for mouse class and manage classList array for paper-button.
*/
focusToggle: function(e) {
let root = this;
this.fire("focus-changed", { focus: root.focusState });
// see if it has hover classes
if (typeof root.hoverClass !== typeof undefined && !root.disabled) {
// break class into array
var classes = root.hoverClass.split(" ");
// run through each and add or remove classes
classes.forEach(function(item, index) {
if (item != "") {
if (root.focusState) {
root.$.button.classList.add(item);
if (item.indexOf("-") != -1) {
root.$.icon.classList.add(item);
}
} else {
root.$.button.classList.remove(item);
if (item.indexOf("-") != -1) {
root.$.icon.classList.remove(item);
}
}
}
});
}
root.focusState = !root.focusState;
}
});
export { LrnsysButton };