2021-07-14 12:59:08 +03:00
|
|
|
class AutonomousCustomElement extends HTMLElement {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
const shadow = this.attachShadow({mode: 'open'});
|
|
|
|
const wrapper = document.createElement('span');
|
|
|
|
wrapper.setAttribute('class', 'wrapper');
|
|
|
|
|
|
|
|
const info = document.createElement('span');
|
|
|
|
info.setAttribute('class', 'info');
|
|
|
|
|
|
|
|
info.textContent = this.getAttribute('text');
|
|
|
|
|
|
|
|
const img = document.createElement('img');
|
|
|
|
img.src = this.getAttribute('img');
|
|
|
|
|
|
|
|
// Create some CSS to apply to the shadow dom
|
|
|
|
const style = document.createElement('style');
|
|
|
|
|
|
|
|
style.textContent = `
|
|
|
|
.wrapper {
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
.info {
|
|
|
|
font-size: 0.8rem;
|
|
|
|
width: 200px;
|
|
|
|
display: inline-block;
|
|
|
|
border: 1px solid black;
|
|
|
|
padding: 10px;
|
|
|
|
background: white;
|
|
|
|
border-radius: 10px;
|
|
|
|
}
|
|
|
|
img {
|
|
|
|
width: 100px;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
shadow.appendChild(style);
|
|
|
|
shadow.appendChild(wrapper);
|
|
|
|
wrapper.appendChild(img);
|
|
|
|
wrapper.appendChild(info);
|
|
|
|
}
|
2021-12-31 20:57:17 +03:00
|
|
|
|
|
|
|
connectedCallback() {
|
|
|
|
this.shadowRoot.adoptedStyleSheets = [sheet];
|
|
|
|
}
|
2021-07-14 12:59:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define('autonomous-custom-element', AutonomousCustomElement);
|