Web component using slots
HTML
<script src="https://cdn.rawgit.com/webcomponents/webcomponentsjs/3b3bd26f/webcomponents-lite.js"></script>
<my-components>
<p slot="header">
header
</p>
<p slot="footer">
footer
</p>
</my-components>
JavaScript
/*
// src code
customElements.define('my-components', class extends HTMLElement {
constructor() {
super()
var root = this.attachShadow({mode: 'open'});
root.innerHTML = `
<slot name="footer"></slot>
<slot name="header"></slot>
`
}
});
*/
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
// src code
customElements.define('my-components', function (_HTMLElement) {
_inherits(_class, _HTMLElement);
function _class() {
_classCallCheck(this, _class);
var _this = _possibleConstructorReturn(this, _HTMLElement.call(this));
function connectedCallback() {
console.log("connected");
}
var root = _this.attachShadow({ mode: 'open' });
root.innerHTML = '\n <slot name="footer"></slot>\n <slot name="header"></slot>\n ';
return _this;
}
return _class;
}(HTMLElement));