I'm learning Polymer/lit-element and trying to build a really simple demo project. I'm trying to use es6 arrow function inside the class (getButtonStyle function), but it returns me this error
SyntaxError: This experimental syntax requires enabling the parser plugin: 'classProperties'
How to use arrow function in lit-element project? What am I missing? Thanks!
I've tried install some babel extension packages and setup plugins in .babelrc, but it didn't work (for sure, because it's not using babel). also tried to Google it, but didn't see anyone has the same issue.
import { html, LitElement } from "lit-element";
class ButtonDemo extends LitElement {
constructor() {
super();
this.text = "Button";
this.disabled = false;
this.ready = false;
}
static get properties() {
return {
disabled: {
type: Boolean
},
ready: {
type: Boolean
}
};
}
getButtonStyle = (disabled, ready) => {
if (!disabled) return "";
var styles = "disabled ";
styles += ready ? "saving" : "incomplete";
return styles;
};
render() {
return html`
<style>
button {
//some style
}
button.disabled.saving {
//some style
}
button.disabled.incomplete {
//some style
}
</style>
<button
class="${this.getButtonStyle(this.disabled, this.ready)}"
?disabled="${this.disabled}"
>
My Button
</button>
`;
}
}
window.customElements.define("button-demo", ButtonDemo);
any thoughts will be appreciated. Thank you.