Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. customElements.define('my-element', class extends HTMLElement {
  2. constructor() {
  3. super();
  4. const shadow = this.attachShadow({mode: 'open'});
  5. shadow.innerHTML = `
  6. <style> #custom-shadow { color: red; } ::slotted(h1) { font-size: 38px; } :host { width: 600px; }</style>
  7. <slot id="headerSlot" name="header"></slot>
  8. <div id="custom-shadow">My custom shadow element</div>
  9. <slot id="footerSlot" name="footer"></slot>
  10. `;
  11. this.addEventListener('click', e => {
  12. this.toggleSomething();
  13. });
  14. }
  15.  
  16. toggleSomething() {
  17. //...
  18. }
  19.  
  20. get disabled() {
  21. return this.hasAttribute('disabled');
  22. }
  23.  
  24. set disabled(val) {
  25. if (val) {
  26. this.setAttribute('disabled', '');
  27. } else {
  28. this.removeAttribute('disabled');
  29. }
  30. }
  31. });
  32.  
  33. // <my-element>
  34. // <h1 slot="header">My Header Slot</h1>
  35. // <button slot="footer">Logout</button>
  36. // <a slot="footer">Copyright info</a>
  37. // </my-element>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement