Skip to content

Instantly share code, notes, and snippets.

@tjmonsi
Created December 15, 2021 06:34
Show Gist options
  • Select an option

  • Save tjmonsi/f5f455e816af59c787cc876a701bc913 to your computer and use it in GitHub Desktop.

Select an option

Save tjmonsi/f5f455e816af59c787cc876a701bc913 to your computer and use it in GitHub Desktop.
import { LitElement, html } from 'lit';
export class Component extends LitElement {
static properties = {
isLoggedIn: {
type: Boolean
}
}
constructor () {
super();
this._boundSetLoggedIn = this.setLoggedIn.bind(this) // this === Component
}
setLoggedIn (value) {
// "this" is equal to Component Class because we have bounded it
this.isLoggedIn = !!value;
}
createRenderRoot () {
return this;
}
render () {
return html`
<header class="header">
<h1>
<a href="/">My Blog</a>
</h1>
<nav>
${this.isLoggedIn
? html`<a href="/logout">Logout</a>`
: html`<a href="/login">Login</a>`}
</nav>
</header>
`
}
}
window.customElements.define('web-header', Component);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment