forked from home-assistant/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate-card-input_text.js
85 lines (73 loc) · 1.96 KB
/
state-card-input_text.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import "@polymer/iron-flex-layout/iron-flex-layout-classes";
import "@polymer/paper-input/paper-input";
import { html } from "@polymer/polymer/lib/utils/html-tag";
import { PolymerElement } from "@polymer/polymer/polymer-element";
import "../components/entity/state-info";
class StateCardInputText extends PolymerElement {
static get template() {
return html`
<style include="iron-flex iron-flex-alignment"></style>
<style>
paper-input {
margin-left: 16px;
}
</style>
<div class="horizontal justified layout">
${this.stateInfoTemplate}
<paper-input
no-label-float=""
minlength="[[stateObj.attributes.min]]"
maxlength="[[stateObj.attributes.max]]"
value="{{value}}"
auto-validate="[[stateObj.attributes.pattern]]"
pattern="[[stateObj.attributes.pattern]]"
type="[[stateObj.attributes.mode]]"
on-change="selectedValueChanged"
on-click="stopPropagation"
placeholder="(empty value)"
>
</paper-input>
</div>
`;
}
static get stateInfoTemplate() {
return html`
<state-info
hass="[[hass]]"
state-obj="[[stateObj]]"
in-dialog="[[inDialog]]"
></state-info>
`;
}
static get properties() {
return {
hass: Object,
inDialog: {
type: Boolean,
value: false,
},
stateObj: {
type: Object,
observer: "stateObjectChanged",
},
pattern: String,
value: String,
};
}
stateObjectChanged(newVal) {
this.value = newVal.state;
}
selectedValueChanged() {
if (this.value === this.stateObj.state) {
return;
}
this.hass.callService("input_text", "set_value", {
value: this.value,
entity_id: this.stateObj.entity_id,
});
}
stopPropagation(ev) {
ev.stopPropagation();
}
}
customElements.define("state-card-input_text", StateCardInputText);