From 777e6c4c72c8a4e819b9be9a5113050ea0f5d90c Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Tue, 19 Oct 2021 22:42:30 +0200 Subject: [PATCH] Migrate all paper-radio elements to mwc-radio (#10327) --- package.json | 2 - src/onboarding/onboarding-core-config.ts | 78 ++++++++----- .../types/ha-automation-condition-sun.ts | 104 +++++++++++------- .../ha-automation-trigger-geo_location.ts | 53 +++++---- .../ha-automation-trigger-homeassistant.ts | 53 +++++---- .../types/ha-automation-trigger-sun.ts | 61 ++++++---- .../types/ha-automation-trigger-zone.ts | 54 +++++---- src/panels/config/core/ha-config-core-form.ts | 77 ++++++++----- src/panels/config/core/ha-config-name-form.ts | 2 - .../helpers/forms/ha-input_datetime-form.ts | 62 +++++++---- .../helpers/forms/ha-input_number-form.ts | 44 +++++--- .../helpers/forms/ha-input_text-form.ts | 44 +++++--- yarn.lock | 27 ----- 13 files changed, 398 insertions(+), 263 deletions(-) diff --git a/package.json b/package.json index 2329f6e87..16c2a47c0 100644 --- a/package.json +++ b/package.json @@ -84,8 +84,6 @@ "@polymer/paper-listbox": "^3.0.1", "@polymer/paper-menu-button": "^3.1.0", "@polymer/paper-progress": "^3.0.1", - "@polymer/paper-radio-button": "^3.0.1", - "@polymer/paper-radio-group": "^3.0.1", "@polymer/paper-ripple": "^3.0.2", "@polymer/paper-slider": "^3.0.1", "@polymer/paper-styles": "^3.0.1", diff --git a/src/onboarding/onboarding-core-config.ts b/src/onboarding/onboarding-core-config.ts index 83a1e0628..d0f61cfbb 100644 --- a/src/onboarding/onboarding-core-config.ts +++ b/src/onboarding/onboarding-core-config.ts @@ -1,8 +1,6 @@ import "@material/mwc-button/mwc-button"; import "@polymer/paper-input/paper-input"; import type { PaperInputElement } from "@polymer/paper-input/paper-input"; -import "@polymer/paper-radio-button/paper-radio-button"; -import "@polymer/paper-radio-group/paper-radio-group"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators"; import memoizeOne from "memoize-one"; @@ -21,6 +19,9 @@ import { SYMBOL_TO_ISO } from "../data/currency"; import { onboardCoreConfigStep } from "../data/onboarding"; import type { PolymerChangedEvent } from "../polymer-types"; import type { HomeAssistant } from "../types"; +import "../components/ha-radio"; +import "../components/ha-formfield"; +import type { HaRadio } from "../components/ha-radio"; const amsterdam: [number, number] = [52.3731339, 4.8903147]; const mql = matchMedia("(prefers-color-scheme: dark)"); @@ -135,32 +136,44 @@ class OnboardingCoreConfig extends LitElement { "ui.panel.config.core.section.core.core_config.unit_system" )} - - - ${this.hass.localize( - "ui.panel.config.core.section.core.core_config.unit_system_metric" - )} -
- ${this.hass.localize( - "ui.panel.config.core.section.core.core_config.metric_example" +
+ - - - ${this.hass.localize( - "ui.panel.config.core.section.core.core_config.unit_system_imperial" - )} -
- ${this.hass.localize( - "ui.panel.config.core.section.core.core_config.imperial_example" +
+ ${this.hass.localize( + "ui.panel.config.core.section.core.core_config.metric_example" + )} +
`} + > + + + - - +
+ ${this.hass.localize( + "ui.panel.config.core.section.core.core_config.imperial_example" + )} +
`} + > + +
+
@@ -281,10 +294,8 @@ class OnboardingCoreConfig extends LitElement { this._location = ev.detail.location; } - private _unitSystemChanged( - ev: PolymerChangedEvent - ) { - this._unitSystem = ev.detail.value; + private _unitSystemChanged(ev: CustomEvent) { + this._unitSystem = (ev.target as HaRadio).value as "metric" | "imperial"; } private async _detect() { @@ -363,6 +374,13 @@ class OnboardingCoreConfig extends LitElement { .row > * { margin: 0 8px; } + + .radio-group { + display: flex; + flex-direction: column; + flex: 1; + } + .footer { margin-top: 16px; text-align: right; diff --git a/src/panels/config/automation/condition/types/ha-automation-condition-sun.ts b/src/panels/config/automation/condition/types/ha-automation-condition-sun.ts index bda939953..0cbf5a339 100644 --- a/src/panels/config/automation/condition/types/ha-automation-condition-sun.ts +++ b/src/panels/config/automation/condition/types/ha-automation-condition-sun.ts @@ -1,8 +1,5 @@ import "@polymer/paper-input/paper-input"; -import "@polymer/paper-radio-button/paper-radio-button"; -import "@polymer/paper-radio-group/paper-radio-group"; -import type { PaperRadioGroupElement } from "@polymer/paper-radio-group/paper-radio-group"; -import { html, LitElement } from "lit"; +import { css, html, LitElement } from "lit"; import { customElement, property } from "lit/decorators"; import { fireEvent } from "../../../../../common/dom/fire_event"; import type { SunCondition } from "../../../../../data/automation"; @@ -11,12 +8,15 @@ import { ConditionElement, handleChangeEvent, } from "../ha-automation-condition-row"; +import "../../../../../components/ha-radio"; +import "../../../../../components/ha-formfield"; +import type { HaRadio } from "../../../../../components/ha-radio"; @customElement("ha-automation-condition-sun") export class HaSunCondition extends LitElement implements ConditionElement { @property({ attribute: false }) public hass!: HomeAssistant; - @property() public condition!: SunCondition; + @property({ attribute: false }) public condition!: SunCondition; public static get defaultConfig() { return {}; @@ -25,28 +25,35 @@ export class HaSunCondition extends LitElement implements ConditionElement { protected render() { const { after, after_offset, before, before_offset } = this.condition; return html` - - - `; } @@ -87,10 +93,17 @@ export default class HaGeolocationTrigger extends LitElement { fireEvent(this, "value-changed", { value: { ...this.trigger, - event: (ev.target as PaperRadioGroupElement).selected, + event: (ev.target as HaRadio).value, }, }); } + + static styles = css` + label { + display: flex; + align-items: center; + } + `; } declare global { diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-homeassistant.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-homeassistant.ts index f4464a4b3..5e64f7fd4 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-homeassistant.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-homeassistant.ts @@ -1,17 +1,17 @@ -import "@polymer/paper-radio-button/paper-radio-button"; -import "@polymer/paper-radio-group/paper-radio-group"; -import type { PaperRadioGroupElement } from "@polymer/paper-radio-group/paper-radio-group"; -import { html, LitElement } from "lit"; +import { css, html, LitElement } from "lit"; import { customElement, property } from "lit/decorators"; import { fireEvent } from "../../../../../common/dom/fire_event"; +import type { HaRadio } from "../../../../../components/ha-radio"; import type { HassTrigger } from "../../../../../data/automation"; import type { HomeAssistant } from "../../../../../types"; +import "../../../../../components/ha-formfield"; +import "../../../../../components/ha-radio"; @customElement("ha-automation-trigger-homeassistant") export default class HaHassTrigger extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; - @property() public trigger!: HassTrigger; + @property({ attribute: false }) public trigger!: HassTrigger; public static get defaultConfig() { return { @@ -26,23 +26,31 @@ export default class HaHassTrigger extends LitElement { ${this.hass.localize( "ui.panel.config.automation.editor.triggers.type.homeassistant.event" )} - - - - ${this.hass.localize( + - - ${this.hass.localize( + > + + + - + > + + + `; } @@ -51,10 +59,17 @@ export default class HaHassTrigger extends LitElement { fireEvent(this, "value-changed", { value: { ...this.trigger, - event: (ev.target as PaperRadioGroupElement).selected, + event: (ev.target as HaRadio).value, }, }); } + + static styles = css` + label { + display: flex; + align-items: center; + } + `; } declare global { diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-sun.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-sun.ts index d940a3e1c..0d6bf9798 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-sun.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-sun.ts @@ -1,10 +1,10 @@ import "@polymer/paper-input/paper-input"; -import "@polymer/paper-radio-button/paper-radio-button"; -import "@polymer/paper-radio-group/paper-radio-group"; -import type { PaperRadioGroupElement } from "@polymer/paper-radio-group/paper-radio-group"; -import { html, LitElement } from "lit"; +import { css, html, LitElement } from "lit"; import { customElement, property } from "lit/decorators"; import { fireEvent } from "../../../../../common/dom/fire_event"; +import "../../../../../components/ha-radio"; +import "../../../../../components/ha-formfield"; +import type { HaRadio } from "../../../../../components/ha-radio"; import type { SunTrigger } from "../../../../../data/automation"; import type { HomeAssistant } from "../../../../../types"; import { @@ -16,7 +16,7 @@ import { export class HaSunTrigger extends LitElement implements TriggerElement { @property({ attribute: false }) public hass!: HomeAssistant; - @property() public trigger!: SunTrigger; + @property({ attribute: false }) public trigger!: SunTrigger; public static get defaultConfig() { return { @@ -27,27 +27,35 @@ export class HaSunTrigger extends LitElement implements TriggerElement { protected render() { const { offset, event } = this.trigger; return html` - - `; } @@ -97,10 +106,17 @@ export class HaZoneTrigger extends LitElement { fireEvent(this, "value-changed", { value: { ...this.trigger, - event: (ev.target as PaperRadioGroupElement).selected, + event: (ev.target as HaRadio).value, }, }); } + + static styles = css` + label { + display: flex; + align-items: center; + } + `; } declare global { diff --git a/src/panels/config/core/ha-config-core-form.ts b/src/panels/config/core/ha-config-core-form.ts index 4e4809867..495b96312 100644 --- a/src/panels/config/core/ha-config-core-form.ts +++ b/src/panels/config/core/ha-config-core-form.ts @@ -1,8 +1,6 @@ import "@material/mwc-button/mwc-button"; import "@polymer/paper-input/paper-input"; import type { PaperInputElement } from "@polymer/paper-input/paper-input"; -import "@polymer/paper-radio-button/paper-radio-button"; -import "@polymer/paper-radio-group/paper-radio-group"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators"; import memoizeOne from "memoize-one"; @@ -16,6 +14,9 @@ import { ConfigUpdateValues, saveCoreConfig } from "../../../data/core"; import { SYMBOL_TO_ISO } from "../../../data/currency"; import type { PolymerChangedEvent } from "../../../polymer-types"; import type { HomeAssistant } from "../../../types"; +import "../../../components/ha-formfield"; +import "../../../components/ha-radio"; +import type { HaRadio } from "../../../components/ha-radio"; @customElement("ha-config-core-form") class ConfigCoreForm extends LitElement { @@ -120,32 +121,44 @@ class ConfigCoreForm extends LitElement { "ui.panel.config.core.section.core.core_config.unit_system" )}
- - - ${this.hass.localize( - "ui.panel.config.core.section.core.core_config.unit_system_metric" - )} -
- ${this.hass.localize( - "ui.panel.config.core.section.core.core_config.metric_example" +
+ - - - ${this.hass.localize( - "ui.panel.config.core.section.core.core_config.unit_system_imperial" - )} -
- ${this.hass.localize( - "ui.panel.config.core.section.core.core_config.imperial_example" +
+ ${this.hass.localize( + "ui.panel.config.core.section.core.core_config.metric_example" + )} +
`} + > + + + - - +
+ ${this.hass.localize( + "ui.panel.config.core.section.core.core_config.imperial_example" + )} +
`} + > + +
+
@@ -258,10 +271,8 @@ class ConfigCoreForm extends LitElement { this._location = ev.detail.location; } - private _unitSystemChanged( - ev: PolymerChangedEvent - ) { - this._unitSystem = ev.detail.value; + private _unitSystemChanged(ev: CustomEvent) { + this._unitSystem = (ev.target as HaRadio).value as "metric" | "imperial"; } private async _save() { @@ -307,6 +318,12 @@ class ConfigCoreForm extends LitElement { margin: 0 8px; } + .radio-group { + display: flex; + flex-direction: column; + flex: 1; + } + .card-actions { text-align: right; } diff --git a/src/panels/config/core/ha-config-name-form.ts b/src/panels/config/core/ha-config-name-form.ts index 3edc3be6d..7dc775272 100644 --- a/src/panels/config/core/ha-config-name-form.ts +++ b/src/panels/config/core/ha-config-name-form.ts @@ -1,8 +1,6 @@ import "@material/mwc-button/mwc-button"; import "@polymer/paper-input/paper-input"; import type { PaperInputElement } from "@polymer/paper-input/paper-input"; -import "@polymer/paper-radio-button/paper-radio-button"; -import "@polymer/paper-radio-group/paper-radio-group"; import { css, html, LitElement, TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators"; import "../../../components/ha-card"; diff --git a/src/panels/config/helpers/forms/ha-input_datetime-form.ts b/src/panels/config/helpers/forms/ha-input_datetime-form.ts index 87c6931c8..8f9f89c08 100644 --- a/src/panels/config/helpers/forms/ha-input_datetime-form.ts +++ b/src/panels/config/helpers/forms/ha-input_datetime-form.ts @@ -1,6 +1,4 @@ import "@polymer/paper-input/paper-input"; -import "@polymer/paper-radio-button/paper-radio-button"; -import "@polymer/paper-radio-group/paper-radio-group"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators"; import { fireEvent } from "../../../../common/dom/fire_event"; @@ -8,6 +6,9 @@ import "../../../../components/ha-icon-picker"; import { InputDateTime } from "../../../../data/input_datetime"; import { haStyle } from "../../../../resources/styles"; import { HomeAssistant } from "../../../../types"; +import "../../../../components/ha-formfield"; +import "../../../../components/ha-radio"; +import type { HaRadio } from "../../../../components/ha-radio"; @customElement("ha-input_datetime-form") class HaInputDateTimeForm extends LitElement { @@ -81,32 +82,49 @@ class HaInputDateTimeForm extends LitElement {
${this.hass.localize("ui.dialogs.helper_settings.input_datetime.mode")}:
- - - ${this.hass.localize( - "ui.dialogs.helper_settings.input_datetime.date" - )} - - - ${this.hass.localize( - "ui.dialogs.helper_settings.input_datetime.time" - )} - - - ${this.hass.localize( - "ui.dialogs.helper_settings.input_datetime.datetime" - )} - - + + + + + + + +
`; } private _modeChanged(ev: CustomEvent) { - const mode = ev.detail.value; + const mode = (ev.target as HaRadio).value; fireEvent(this, "value-changed", { value: { ...this._item, diff --git a/src/panels/config/helpers/forms/ha-input_number-form.ts b/src/panels/config/helpers/forms/ha-input_number-form.ts index b65e5d1ed..9d6960062 100644 --- a/src/panels/config/helpers/forms/ha-input_number-form.ts +++ b/src/panels/config/helpers/forms/ha-input_number-form.ts @@ -1,6 +1,4 @@ import "@polymer/paper-input/paper-input"; -import "@polymer/paper-radio-button/paper-radio-button"; -import "@polymer/paper-radio-group/paper-radio-group"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators"; import { fireEvent } from "../../../../common/dom/fire_event"; @@ -8,6 +6,9 @@ import "../../../../components/ha-icon-picker"; import { InputNumber } from "../../../../data/input_number"; import { haStyle } from "../../../../resources/styles"; import { HomeAssistant } from "../../../../types"; +import "../../../../components/ha-formfield"; +import "../../../../components/ha-radio"; +import type { HaRadio } from "../../../../components/ha-radio"; @customElement("ha-input_number-form") class HaInputNumberForm extends LitElement { @@ -117,21 +118,30 @@ class HaInputNumberForm extends LitElement { ${this.hass.localize( "ui.dialogs.helper_settings.input_number.mode" )} - - - ${this.hass.localize( - "ui.dialogs.helper_settings.input_number.slider" - )} - - - ${this.hass.localize( - "ui.dialogs.helper_settings.input_number.box" - )} - - + + + + +
- - ${this.hass.localize( - "ui.dialogs.helper_settings.input_text.text" - )} - - - ${this.hass.localize( - "ui.dialogs.helper_settings.input_text.password" - )} - - + + + + +