Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/components/ha-date-input.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { mdiCalendar } from "@mdi/js";
import "@polymer/paper-input/paper-input";
import { css, CSSResultGroup, html, LitElement } from "lit";
import { customElement, property } from "lit/decorators";
import { formatDateNumeric } from "../common/datetime/format_date";
import { fireEvent } from "../common/dom/fire_event";
import { HomeAssistant } from "../types";
import "./ha-svg-icon";
import "./ha-textfield";

const loadDatePickerDialog = () => import("./ha-dialog-date-picker");

Expand Down Expand Up @@ -38,17 +38,17 @@ export class HaDateInput extends LitElement {
@property() public label?: string;

render() {
return html`<paper-input
return html`<ha-textfield
.label=${this.label}
.disabled=${this.disabled}
no-label-float
iconTrailing="calendar"
@click=${this._openDialog}
.value=${this.value
? formatDateNumeric(new Date(this.value), this.locale)
: ""}
>
<ha-svg-icon slot="suffix" .path=${mdiCalendar}></ha-svg-icon>
</paper-input>`;
<ha-svg-icon slot="trailingIcon" .path=${mdiCalendar}></ha-svg-icon>
</ha-textfield>`;
}

private _openDialog() {
Expand All @@ -73,9 +73,6 @@ export class HaDateInput extends LitElement {

static get styles(): CSSResultGroup {
return css`
paper-input {
width: 110px;
}
ha-svg-icon {
color: var(--secondary-text-color);
}
Expand Down
20 changes: 13 additions & 7 deletions src/panels/lovelace/cards/hui-alarm-panel-card.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import "@polymer/paper-input/paper-input";
import type { PaperInputElement } from "@polymer/paper-input/paper-input";
import {
css,
CSSResultGroup,
Expand All @@ -15,6 +13,8 @@ import { fireEvent } from "../../../common/dom/fire_event";
import { alarmPanelIcon } from "../../../common/entity/alarm_panel_icon";
import "../../../components/ha-card";
import "../../../components/ha-chip";
import type { HaTextField } from "../../../components/ha-textfield";
import "../../../components/ha-textfield";
import {
callAlarmAction,
FORMAT_NUMBER,
Expand Down Expand Up @@ -61,7 +61,7 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard {

@state() private _config?: AlarmPanelCardConfig;

@query("#alarmCode") private _input?: PaperInputElement;
@query("#alarmCode") private _input?: HaTextField;

public async getCardSize(): Promise<number> {
if (!this._config || !this.hass) {
Expand Down Expand Up @@ -182,14 +182,14 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard {
${!stateObj.attributes.code_format
? html``
: html`
<paper-input
<ha-textfield
id="alarmCode"
.label=${this.hass.localize("ui.card.alarm_control_panel.code")}
type="password"
.inputmode=${stateObj.attributes.code_format === FORMAT_NUMBER
? "numeric"
: "text"}
></paper-input>
></ha-textfield>
`}
${stateObj.attributes.code_format !== FORMAT_NUMBER
? html``
Expand Down Expand Up @@ -263,6 +263,9 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard {
padding-bottom: 16px;
position: relative;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
box-sizing: border-box;
--alarm-color-disarmed: var(--label-badge-green);
--alarm-color-pending: var(--label-badge-yellow);
Expand All @@ -282,6 +285,8 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
box-sizing: border-box;
}

.unavailable {
Expand Down Expand Up @@ -319,8 +324,9 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard {
}
}

paper-input {
margin: 0 auto 8px;
ha-textfield {
display: block;
margin: 8px;
max-width: 150px;
text-align: center;
}
Expand Down
32 changes: 18 additions & 14 deletions src/panels/lovelace/cards/hui-shopping-list-card.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { mdiDrag, mdiNotificationClearAll, mdiPlus, mdiSort } from "@mdi/js";
import { PaperInputElement } from "@polymer/paper-input/paper-input";
import { UnsubscribeFunc } from "home-assistant-js-websocket";
import {
css,
Expand All @@ -17,6 +16,7 @@ import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_elemen
import "../../../components/ha-card";
import "../../../components/ha-svg-icon";
import "../../../components/ha-checkbox";
import "../../../components/ha-textfield";
import {
addItem,
clearItems,
Expand All @@ -29,6 +29,7 @@ import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
import { HomeAssistant } from "../../../types";
import { LovelaceCard, LovelaceCardEditor } from "../types";
import { SensorCardConfig, ShoppingListCardConfig } from "./types";
import type { HaTextField } from "../../../components/ha-textfield";

let Sortable;

Expand Down Expand Up @@ -123,14 +124,13 @@ class HuiShoppingListCard
@click=${this._addItem}
>
</ha-svg-icon>
<paper-input
no-label-float
<ha-textfield
class="addBox"
placeholder=${this.hass!.localize(
.placeholder=${this.hass!.localize(
"ui.panel.lovelace.cards.shopping-list.add_item"
)}
@keydown=${this._addKeyPress}
></paper-input>
></ha-textfield>
<ha-svg-icon
class="reorderButton"
.path=${mdiSort}
Expand Down Expand Up @@ -184,12 +184,12 @@ class HuiShoppingListCard
.itemId=${item.id}
@change=${this._completeItem}
></ha-checkbox>
<paper-input
no-label-float
<ha-textfield
class="item"
.value=${item.name}
.itemId=${item.id}
@change=${this._saveEdit}
></paper-input>
></ha-textfield>
</div>
`
)}
Expand All @@ -213,12 +213,12 @@ class HuiShoppingListCard
.itemId=${item.id}
@change=${this._completeItem}
></ha-checkbox>
<paper-input
no-label-float
<ha-textfield
class="item"
.value=${item.name}
.itemId=${item.id}
@change=${this._saveEdit}
></paper-input>
></ha-textfield>
${this._reordering
? html`
<ha-svg-icon
Expand Down Expand Up @@ -275,8 +275,8 @@ class HuiShoppingListCard
}
}

private get _newItem(): PaperInputElement {
return this.shadowRoot!.querySelector(".addBox") as PaperInputElement;
private get _newItem(): HaTextField {
return this.shadowRoot!.querySelector(".addBox") as HaTextField;
}

private _addItem(ev): void {
Expand Down Expand Up @@ -366,6 +366,10 @@ class HuiShoppingListCard
align-items: center;
}

.item {
margin-top: 8px;
}

.addButton {
padding-right: 16px;
cursor: pointer;
Expand All @@ -380,7 +384,7 @@ class HuiShoppingListCard
margin-left: -12px;
}

paper-input {
ha-textfield {
flex-grow: 1;
}

Expand Down
34 changes: 10 additions & 24 deletions src/panels/lovelace/entity-rows/hui-input-number-entity-row.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "@polymer/paper-input/paper-input";
import {
css,
CSSResultGroup,
Expand All @@ -12,6 +11,7 @@ import { computeStateDisplay } from "../../../common/entity/compute_state_displa
import { computeRTLDirection } from "../../../common/util/compute_rtl";
import { debounce } from "../../../common/util/debounce";
import "../../../components/ha-slider";
import "../../../components/ha-textfield";
import { UNAVAILABLE_STATES } from "../../../data/entity";
import { setValue } from "../../../data/input_text";
import { HomeAssistant } from "../../../types";
Expand Down Expand Up @@ -90,11 +90,10 @@ class HuiInputNumberEntityRow extends LitElement implements LovelaceRow {
.step=${Number(stateObj.attributes.step)}
.min=${Number(stateObj.attributes.min)}
.max=${Number(stateObj.attributes.max)}
.value=${Number(stateObj.state)}
.value=${stateObj.state}
pin
@change=${this._selectedValueChanged}
ignore-bar-touch
id="input"
></ha-slider>
<span class="state">
${computeStateDisplay(
Expand All @@ -108,23 +107,18 @@ class HuiInputNumberEntityRow extends LitElement implements LovelaceRow {
`
: html`
<div class="flex state">
<paper-input
no-label-float
auto-validate
<ha-textfield
.disabled=${UNAVAILABLE_STATES.includes(stateObj.state)}
pattern="[0-9]+([\\.][0-9]+)?"
.step=${Number(stateObj.attributes.step)}
.min=${Number(stateObj.attributes.min)}
.max=${Number(stateObj.attributes.max)}
.value=${Number(stateObj.state)}
.value=${stateObj.state}
.suffix=${stateObj.attributes.unit_of_measurement}
type="number"
@change=${this._selectedValueChanged}
id="input"
>
<span slot="suffix">
${stateObj.attributes.unit_of_measurement}
</span>
</paper-input>
</ha-textfield>
</div>
`}
</hui-generic-entity-row>
Expand All @@ -146,7 +140,7 @@ class HuiInputNumberEntityRow extends LitElement implements LovelaceRow {
min-width: 45px;
text-align: end;
}
paper-input {
ha-textfield {
text-align: end;
}
ha-slider {
Expand Down Expand Up @@ -185,19 +179,11 @@ class HuiInputNumberEntityRow extends LitElement implements LovelaceRow {
}
}

private get _inputElement(): { value: string } {
// linter recommended the following syntax
return this.shadowRoot!.getElementById("input") as unknown as {
value: string;
};
}

private _selectedValueChanged(): void {
const element = this._inputElement;
private _selectedValueChanged(ev): void {
const stateObj = this.hass!.states[this._config!.entity];

if (element.value !== stateObj.state) {
setValue(this.hass!, stateObj.entity_id, element.value!);
if (ev.target.value !== stateObj.state) {
setValue(this.hass!, stateObj.entity_id, ev.target.value);
}
}
}
Expand Down
22 changes: 9 additions & 13 deletions src/panels/lovelace/entity-rows/hui-input-text-entity-row.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PaperInputElement } from "@polymer/paper-input/paper-input";
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators";
import { UNAVAILABLE, UNAVAILABLE_STATES } from "../../../data/entity";
Expand All @@ -8,6 +7,7 @@ import { hasConfigOrEntityChanged } from "../common/has-changed";
import "../components/hui-generic-entity-row";
import { createEntityNotFoundWarning } from "../components/hui-warning";
import { EntityConfig, LovelaceRow } from "./types";
import "../../../components/ha-textfield";

@customElement("hui-input-text-entity-row")
class HuiInputTextEntityRow extends LitElement implements LovelaceRow {
Expand Down Expand Up @@ -43,8 +43,7 @@ class HuiInputTextEntityRow extends LitElement implements LovelaceRow {

return html`
<hui-generic-entity-row .hass=${this.hass} .config=${this._config}>
<paper-input
no-label-float
<ha-textfield
.disabled=${stateObj.state === UNAVAILABLE}
.value=${stateObj.state}
.minlength=${stateObj.attributes.min}
Expand All @@ -54,27 +53,24 @@ class HuiInputTextEntityRow extends LitElement implements LovelaceRow {
.type=${stateObj.attributes.mode}
@change=${this._selectedValueChanged}
placeholder="(empty value)"
></paper-input>
></ha-textfield>
</hui-generic-entity-row>
`;
}

private get _inputEl(): PaperInputElement {
return this.shadowRoot!.querySelector("paper-input") as PaperInputElement;
}

private _selectedValueChanged(ev): void {
const element = this._inputEl;
const stateObj = this.hass!.states[this._config!.entity];

const newValue = ev.target.value;

// Filter out invalid text states
if (element.value && UNAVAILABLE_STATES.includes(element.value)) {
element.value = stateObj.state;
if (newValue && UNAVAILABLE_STATES.includes(newValue)) {
ev.target.value = stateObj.state;
return;
}

if (element.value !== stateObj.state) {
setValue(this.hass!, stateObj.entity_id, element.value!);
if (newValue !== stateObj.state) {
setValue(this.hass!, stateObj.entity_id, newValue);
}

ev.target.blur();
Expand Down
Loading