Skip to content

Commit ecc98e2

Browse files
authored
Merge pull request #43 from rackerlabs/update-HxIcon-api
feat(HxIcon): react to attr change, pass type to constructor
2 parents f2d4168 + cb7a97b commit ecc98e2

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

source/components/icons/_HxIcon.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,33 @@ window.addEventListener('WebComponentsReady', function () {
4343
return 'hx-icon';
4444
}
4545

46+
static get observedAttributes() {
47+
return ['type'];
48+
}
49+
4650
static get icons () {
4751
return icons;
4852
}
4953

54+
constructor (type) {
55+
super();
56+
57+
if (type) {
58+
this.setAttribute('type', type);
59+
}
60+
}
61+
5062
connectedCallback () {
63+
this._render();
64+
}
65+
66+
attributeChangedCallback (attr, oldValue, newValue) {
67+
if (attr === 'type') {
68+
this._render();
69+
}
70+
}
71+
72+
_render () {
5173
const type = this.getAttribute('type');
5274

5375
// erase previously injected markup
@@ -63,7 +85,7 @@ window.addEventListener('WebComponentsReady', function () {
6385
// inject SVG into Light DOM
6486
this.appendChild(svg);
6587
}
66-
}//connectedCallback
88+
}//_render()
6789
}//HxIcon
6890

6991
customElements.define(HxIcon.is, HxIcon);

0 commit comments

Comments
 (0)