Last active
May 2, 2018 13:26
-
-
Save lleitep3/7814ad9d26efa977ee31a6476f6b28a5 to your computer and use it in GitHub Desktop.
exemplo attachShadow
This file contains 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 characters
(function() { | |
const style = ` | |
:host { | |
display: inline-block; | |
margin: 0 5px; | |
contain: content; | |
} | |
` | |
// usage <display-date format="DD/MM/YYYY"></display-date> | |
class DisplayDate extends HTMLElement { | |
constructor() { | |
super() | |
const shadow = this.attachShadow({mode: 'closed'}) | |
shadow.innerHTML = ` | |
<style>${style}</style> | |
<span>${date}</span> | |
` | |
} | |
} | |
function formatDate(format) { | |
const d = new Date() | |
return format | |
.replace('DD', d.getDate()) | |
.replace('MM', (d.getMonth()+1)) | |
.replace('YYYY', d.getFullYear()) | |
} | |
customElements.define('display-date', DisplayDate) | |
}).call(this) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment