A Pen by Joel Alejandro Villarreal Bertoldi on CodePen.
Created
September 5, 2020 00:11
-
-
Save joelalejandro/11ca9d83c2b4e112cafb98f64a272a9a to your computer and use it in GitHub Desktop.
Web Components: Usando <slot>
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
<template id="tabifit-boton"> | |
<button> | |
<slot name="icono-izquierdo"></slot> | |
<slot name="etiqueta">Botón</slot> | |
<slot name="icono-derecho"></slot> | |
</button> | |
</template> | |
<tabifit-boton> | |
<span slot="icono-izquierdo">🦜</span> | |
<label slot="etiqueta">Adoptar un loro</label> | |
</tabifit-boton> | |
<tabifit-boton> | |
<span slot="icono-derecho">🦜</span> | |
<label slot="etiqueta">Adoptar un loro</label> | |
</tabifit-boton> |
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 cargarTemplate(referenciaTemplate, instanciaComponente) { | |
const template = document.querySelector(referenciaTemplate); | |
const templateContent = template.content; | |
instanciaComponente.attachShadow({ mode: "open" }) | |
.appendChild(templateContent.cloneNode(true)); | |
} | |
class TabifitBoton extends HTMLElement { | |
constructor() { | |
super(); | |
cargarTemplate('#tabifit-boton', this); | |
} | |
} | |
customElements.define('tabifit-boton', TabifitBoton); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment