mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-17 14:26:35 +00:00
Introduce Lit Element (#1738)
This commit is contained in:
parent
c90e13d35e
commit
1b70b6e88c
@ -34,6 +34,7 @@
|
|||||||
"@polymer/iron-media-query": "^3.0.1",
|
"@polymer/iron-media-query": "^3.0.1",
|
||||||
"@polymer/iron-pages": "^3.0.1",
|
"@polymer/iron-pages": "^3.0.1",
|
||||||
"@polymer/iron-resizable-behavior": "^3.0.1",
|
"@polymer/iron-resizable-behavior": "^3.0.1",
|
||||||
|
"@polymer/lit-element": "^0.6.1",
|
||||||
"@polymer/neon-animation": "^3.0.1",
|
"@polymer/neon-animation": "^3.0.1",
|
||||||
"@polymer/paper-button": "^3.0.1",
|
"@polymer/paper-button": "^3.0.1",
|
||||||
"@polymer/paper-card": "^3.0.1",
|
"@polymer/paper-card": "^3.0.1",
|
||||||
|
@ -1,70 +1,67 @@
|
|||||||
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
|
import { LitElement, html } from '@polymer/lit-element';
|
||||||
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
||||||
|
|
||||||
|
|
||||||
import './ha-progress-button.js';
|
import './ha-progress-button.js';
|
||||||
import EventsMixin from '../../mixins/events-mixin.js';
|
import fireEvent from '../../common/dom/fire_event.js';
|
||||||
|
|
||||||
/*
|
class HaCallApiButton extends LitElement {
|
||||||
* @appliesMixin EventsMixin
|
render() {
|
||||||
*/
|
|
||||||
class HaCallApiButton extends EventsMixin(PolymerElement) {
|
|
||||||
static get template() {
|
|
||||||
return html`
|
return html`
|
||||||
<ha-progress-button id="progress" progress="[[progress]]" on-click="buttonTapped" disabled="[[disabled]]"><slot></slot></ha-progress-button>
|
<ha-progress-button
|
||||||
`;
|
.progress="${this.progress}"
|
||||||
|
@click="${this._buttonTapped}"
|
||||||
|
?disabled="${this.disabled}"
|
||||||
|
><slot></slot></ha-progress-button>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.method = 'POST';
|
||||||
|
this.data = {};
|
||||||
|
this.disabled = false;
|
||||||
|
this.progress = false;
|
||||||
|
// Can be removed once this is merged:
|
||||||
|
// https://github.com/Polymer/lit-element/pull/244
|
||||||
|
this._buttonTapped = this._buttonTapped.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
static get properties() {
|
static get properties() {
|
||||||
return {
|
return {
|
||||||
hass: Object,
|
hass: { },
|
||||||
|
progress: Boolean,
|
||||||
progress: {
|
|
||||||
type: Boolean,
|
|
||||||
value: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
path: String,
|
path: String,
|
||||||
|
method: String,
|
||||||
method: {
|
data: { },
|
||||||
type: String,
|
disabled: Boolean
|
||||||
value: 'POST',
|
|
||||||
},
|
|
||||||
|
|
||||||
data: {
|
|
||||||
type: Object,
|
|
||||||
value: {},
|
|
||||||
},
|
|
||||||
|
|
||||||
disabled: {
|
|
||||||
type: Boolean,
|
|
||||||
value: false,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
buttonTapped() {
|
get progressButton() {
|
||||||
|
return this.renderRoot.querySelector('ha-progress-button');
|
||||||
|
}
|
||||||
|
|
||||||
|
async _buttonTapped() {
|
||||||
this.progress = true;
|
this.progress = true;
|
||||||
const eventData = {
|
const eventData = {
|
||||||
method: this.method,
|
method: this.method,
|
||||||
path: this.path,
|
path: this.path,
|
||||||
data: this.data,
|
data: this.data
|
||||||
};
|
};
|
||||||
|
|
||||||
this.hass.callApi(this.method, this.path, this.data)
|
try {
|
||||||
.then((resp) => {
|
const resp = await this.hass.callApi(this.method, this.path, this.data);
|
||||||
this.progress = false;
|
this.progress = false;
|
||||||
this.$.progress.actionSuccess();
|
this.progressButton.actionSuccess();
|
||||||
eventData.success = true;
|
eventData.success = true;
|
||||||
eventData.response = resp;
|
eventData.response = resp;
|
||||||
}, (resp) => {
|
} catch (err) {
|
||||||
this.progress = false;
|
this.progress = false;
|
||||||
this.$.progress.actionError();
|
this.progressButton.actionError();
|
||||||
eventData.success = false;
|
eventData.success = false;
|
||||||
eventData.response = resp;
|
eventData.response = err;
|
||||||
}).then(() => {
|
}
|
||||||
this.fire('hass-api-called', eventData);
|
|
||||||
});
|
fireEvent(this, 'hass-api-called', eventData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
yarn.lock
10
yarn.lock
@ -835,6 +835,12 @@
|
|||||||
"@polymer/iron-meta" "^3.0.0-pre.26"
|
"@polymer/iron-meta" "^3.0.0-pre.26"
|
||||||
"@polymer/polymer" "^3.0.0"
|
"@polymer/polymer" "^3.0.0"
|
||||||
|
|
||||||
|
"@polymer/lit-element@^0.6.1":
|
||||||
|
version "0.6.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/@polymer/lit-element/-/lit-element-0.6.1.tgz#56772f8fb0c6d3d73a20a6d17f3bc82ec648664b"
|
||||||
|
dependencies:
|
||||||
|
lit-html "^0.11.4"
|
||||||
|
|
||||||
"@polymer/neon-animation@^3.0.0-pre.26", "@polymer/neon-animation@^3.0.1":
|
"@polymer/neon-animation@^3.0.0-pre.26", "@polymer/neon-animation@^3.0.1":
|
||||||
version "3.0.1"
|
version "3.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/@polymer/neon-animation/-/neon-animation-3.0.1.tgz#6658e4b524abc057477772a7473292493d366c24"
|
resolved "https://registry.yarnpkg.com/@polymer/neon-animation/-/neon-animation-3.0.1.tgz#6658e4b524abc057477772a7473292493d366c24"
|
||||||
@ -7829,6 +7835,10 @@ liftoff@^2.1.0:
|
|||||||
rechoir "^0.6.2"
|
rechoir "^0.6.2"
|
||||||
resolve "^1.1.7"
|
resolve "^1.1.7"
|
||||||
|
|
||||||
|
lit-html@^0.11.4:
|
||||||
|
version "0.11.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/lit-html/-/lit-html-0.11.4.tgz#fa397d2b2f2d0523ebc136e5a1699aa4e9346152"
|
||||||
|
|
||||||
load-json-file@^1.0.0:
|
load-json-file@^1.0.0:
|
||||||
version "1.1.0"
|
version "1.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-1.1.0.tgz#956905708d58b4bab4c2261b04f59f31c99374c0"
|
resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-1.1.0.tgz#956905708d58b4bab4c2261b04f59f31c99374c0"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user