Skip to content

Instantly share code, notes, and snippets.

@newbornfrontender
Created October 1, 2018 07:23
Show Gist options
  • Save newbornfrontender/2cdc4a1db0ee6ba9054618f813102c61 to your computer and use it in GitHub Desktop.
Save newbornfrontender/2cdc4a1db0ee6ba9054618f813102c61 to your computer and use it in GitHub Desktop.
Polymer slots and fallback
<!doctype html>
<html>
<head>
<script src="https://unpkg.com/@webcomponents/webcomponentsjs@latest/webcomponents-loader.js"></script>
<title>App</title>
</head>
<body>
<script type="module">
import { LitElement, html } from 'https://unpkg.com/@polymer/lit-element@latest/lit-element.js?module';
class MyApp extends LitElement {
constructor () {
super();
};
static get properties () { return {
msg: {
type: String,
},
color: {
type: String,
},
}};
render () {
const { color } = this;
return html`
<style>
span {
color: ${this.color};
}
</style>
<h1><slot name="greeting">Hi</slot> <span>${this.msg}</span>!</h1>
<slot><slot>
`;
};
};
window.customElements.define('my-app', MyApp);
</script>
<my-app msg="world" color="red">
<span slot="greeting">Hello</span>
<p>Lorem ipsum dolor sit amet consectetur adipisicing.</p>
</my-app>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment