-
Notifications
You must be signed in to change notification settings - Fork 2
/
transburger-icon.html
executable file
·127 lines (112 loc) · 3.57 KB
/
transburger-icon.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
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="transburger-icon-styles.html">
<dom-module id="transburger-icon">
<template>
<style include="transburger-icon-styles"></style>
<button type$="[[type]]" disabled$="[[disabled]]" on-click="_onClick">
<div class="t-icon-wrapper">
<div class$="t-icon t-icon--{{transformTo}}" id="icon">
<div class="t-icon__middle"></div>
</div>
<div class="t-icon-content">
<slot></slot>
</div>
</div>
</button>
</template>
<script>
{
/**
* `<transburger-icon>` is a custom element to display a hamburger icon that is transformed into a back or close icon after clicking on it or programmatically using its `toggleIcon()` method.
*
* By default the hamburger icon is transformed into a close icon. Other posible transformations are `arrow-left` and `arrow-right`.
* To prevent changing the icon when the button is clicked, add `no-transform` attribute.
*
* Check out component's README.md for information about available custom CSS properties.
*
* @customElement
* @polymer
* @demo demo/index.html
*/
class TransburgerIcon extends Polymer.Element {
static get is() {
return 'transburger-icon';
}
static get properties() {
return {
/**
* Hamburger icon transformation.
* Possible values: `close`, `arrow-left`, `arrow-right`.
*/
transformTo: {
type: String,
value: 'close'
},
/**
* Where to place the hamburger icon when the button has text
* or other contents inside it.
* Possible values: `left`, `right`.
*/
iconPosition: {
type: String,
value: 'left',
reflectToAttribute: true
},
/**
* If true, the second icon will be shown initially.
*/
active: {
type: Boolean,
value: false,
observer: '_activeObserver'
},
/**
* If true, the icon won't be changed after clicking the button.
* Use this attribute if you need to change the icon programmatically.
*/
noTransform: {
type: Boolean,
value: false
},
/**
* Button type (button, submit, etc.)
*/
type: String,
/**
* Disabled button.
*/
disabled: {
type: Boolean,
value: false
}
};
}
/**
* Changes the icon.
*/
toggleIcon() {
this.active = !this.active;
}
/**
* Fired when the icon is changed.
* @event transburger-icon-changed
* @param {{icon: String}} detail Icon displayed.
*/
_activeObserver(active) {
this.$.icon.classList.toggle('is-active', active);
this.dispatchEvent(new CustomEvent('transburger-icon-changed', {
detail: { icon: active ? this.transformTo : 'menu' },
bubbles: true, composed: true
}));
}
_onClick() {
if (this.noTransform) {
return;
}
this.toggleIcon();
}
}
customElements.define(TransburgerIcon.is, TransburgerIcon);
}
</script>
</dom-module>