Skip to content

Instantly share code, notes, and snippets.

@lleitep3
Last active May 2, 2018 13:26
Show Gist options
  • Save lleitep3/7814ad9d26efa977ee31a6476f6b28a5 to your computer and use it in GitHub Desktop.
Save lleitep3/7814ad9d26efa977ee31a6476f6b28a5 to your computer and use it in GitHub Desktop.
exemplo attachShadow
(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