-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtileElement.js
More file actions
46 lines (38 loc) · 1.09 KB
/
tileElement.js
File metadata and controls
46 lines (38 loc) · 1.09 KB
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
import { defaultImage } from "./staticData.js";
export class TileElement extends HTMLElement {
static get observedAttributes() {
return ['image', 'border', 'data-no-tile']
}
constructor() {
super();
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
:host {
display: block;
width: 64px;
height: 64px;
background-size: cover;
cursor: pointer;
border: 1px solid #333;
image-rendering: pixelated;
background-image: url(${defaultImage});
}
</style>
`;
}
attributeChangedCallback(name, oldValue, newValue) {
if (name === 'image') {
if (newValue)
this.shadowRoot.host.style.backgroundImage = `url(${newValue})`;
}
if (name === 'border') {
this.shadowRoot.host.style.borderColor = newValue;
}
if (name === 'data-no-tile' && newValue) {
delete this.shadowRoot.host.style.backgroundImage;
this.shadowRoot.host.removeAttribute('style');
}
}
}
customElements.define('x-tile-element', TileElement);