Last active
March 14, 2025 21:01
-
-
Save henriquegogo/ea84886e9d98a97332b70d578a36fc8c to your computer and use it in GitHub Desktop.
Revisions
-
henriquegogo revised this gist
Mar 14, 2025 . 2 changed files with 10 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ document.querySelectorAll('template[id]').forEach(({id, content}) => customElements.define(id, class extends HTMLElement { constructor() { super().attachShadow({mode: 'open'}).appendChild(content.cloneNode(true)); [...this.attributes].forEach(({name, value}) => { @@ -10,7 +10,4 @@ document.addEventListener('DOMContentLoaded', () => { !el.getAttribute(name) && el.setAttribute(name, value)); }); } })); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,12 @@ <script defer src="./script.js"></script> <x-button onclick="console.log('here')" label="Button 1">Click here</x-button> <x-button onclick="console.log('now')" label="Button 2">Click now!</x-button> <template id="x-button"> <style>label { display: block; }</style> <label><slot name="label"></slot> <button onclick><slot></slot></button> </label> </template> -
henriquegogo revised this gist
Mar 14, 2025 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ <template id="x-button"> <style>label { display: block; }</style> <label><slot name="label"></slot> <button onclick><slot></slot></button> </label> </template> <x-button onclick="console.log('here')" label="Button 1">Click here</x-button> <x-button onclick="console.log('now')" label="Button 2">Click now!</x-button> -
henriquegogo revised this gist
Mar 14, 2025 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,9 +6,11 @@ document.addEventListener('DOMContentLoaded', () => { const span = document.createElement('span'); this.appendChild(Object.assign(span, {slot: name})).textContent = value; this.removeAttribute(name) this.shadowRoot.querySelectorAll(`[${name}]`).forEach(el => !el.getAttribute(name) && el.setAttribute(name, value)); }); } }; document.querySelectorAll('template[id]').forEach(({id, content}) => customElements.define(id, createCustomElement(content))); }); -
henriquegogo revised this gist
Mar 14, 2025 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,9 +2,11 @@ document.addEventListener('DOMContentLoaded', () => { const createCustomElement = content => class extends HTMLElement { constructor() { super().attachShadow({mode: 'open'}).appendChild(content.cloneNode(true)); [...this.attributes].forEach(({name, value}) => { const span = document.createElement('span'); this.appendChild(Object.assign(span, {slot: name})).textContent = value; this.removeAttribute(name) }); } }; document.querySelectorAll('template[id]').forEach(({id, content}) => -
henriquegogo revised this gist
Mar 14, 2025 . 1 changed file with 11 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,12 @@ document.addEventListener('DOMContentLoaded', () => { const createCustomElement = content => class extends HTMLElement { constructor() { super().attachShadow({mode: 'open'}).appendChild(content.cloneNode(true)); [...this.attributes].forEach(({name, value}) => this.appendChild( Object.assign(document.createElement('span'), {slot: name}) ).textContent = value); } }; document.querySelectorAll('template[id]').forEach(({id, content}) => customElements.define(id, createCustomElement(content))); }); -
henriquegogo created this gist
Mar 14, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ document.addEventListener('DOMContentLoaded', () => { document.querySelectorAll('template[id]').forEach(({id, content}) => { customElements.define(id, class extends HTMLElement { constructor() { super().attachShadow({mode: 'open'}).appendChild(content.cloneNode(true)); [...this.attributes].forEach(({name, value}) => this.appendChild( Object.assign(document.createElement('span'), {slot: name}) ).textContent = value); } }); }); });