Use icon button to switch between code and editor (#17294)

This commit is contained in:
Paul Bottein 2023-07-13 16:35:53 +02:00 committed by GitHub
parent 56e82eab03
commit df765515ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 24 deletions

View File

@ -1,7 +1,7 @@
import "@material/mwc-list/mwc-list-item"; import "@material/mwc-list/mwc-list-item";
import "@material/mwc-tab-bar/mwc-tab-bar"; import "@material/mwc-tab-bar/mwc-tab-bar";
import "@material/mwc-tab/mwc-tab"; import "@material/mwc-tab/mwc-tab";
import { mdiContentCopy } from "@mdi/js"; import { mdiCodeBraces, mdiContentCopy, mdiListBoxOutline } from "@mdi/js";
import deepClone from "deep-clone-simple"; import deepClone from "deep-clone-simple";
import type { MDCTabBarActivatedEvent } from "@material/tab-bar"; import type { MDCTabBarActivatedEvent } from "@material/tab-bar";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
@ -92,6 +92,8 @@ export class HuiConditionalCardEditor
return nothing; return nothing;
} }
const isGuiMode = !this._cardEditorEl || this._GUImode;
return html` return html`
<mwc-tab-bar <mwc-tab-bar
.activeIndex=${this._cardTab ? 1 : 0} .activeIndex=${this._cardTab ? 1 : 0}
@ -114,17 +116,17 @@ export class HuiConditionalCardEditor
${this._config.card.type !== undefined ${this._config.card.type !== undefined
? html` ? html`
<div class="card-options"> <div class="card-options">
<mwc-button <ha-icon-button
class="gui-mode-button"
@click=${this._toggleMode} @click=${this._toggleMode}
.disabled=${!this._guiModeAvailable} .disabled=${!this._guiModeAvailable}
class="gui-mode-button" .label=${this.hass!.localize(
> isGuiMode
${this.hass!.localize(
!this._cardEditorEl || this._GUImode
? "ui.panel.lovelace.editor.edit_card.show_code_editor" ? "ui.panel.lovelace.editor.edit_card.show_code_editor"
: "ui.panel.lovelace.editor.edit_card.show_visual_editor" : "ui.panel.lovelace.editor.edit_card.show_visual_editor"
)} )}
</mwc-button> .path=${isGuiMode ? mdiCodeBraces : mdiListBoxOutline}
></ha-icon-button>
<ha-icon-button <ha-icon-button
.label=${this.hass!.localize( .label=${this.hass!.localize(

View File

@ -1,15 +1,17 @@
import { import {
mdiArrowLeft, mdiArrowLeft,
mdiArrowRight, mdiArrowRight,
mdiDelete, mdiCodeBraces,
mdiContentCut,
mdiContentCopy, mdiContentCopy,
mdiContentCut,
mdiDelete,
mdiListBoxOutline,
mdiPlus, mdiPlus,
} from "@mdi/js"; } from "@mdi/js";
import "@polymer/paper-tabs"; import "@polymer/paper-tabs";
import "@polymer/paper-tabs/paper-tab"; import "@polymer/paper-tabs/paper-tab";
import deepClone from "deep-clone-simple"; import deepClone from "deep-clone-simple";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators"; import { customElement, property, query, state } from "lit/decorators";
import { import {
any, any,
@ -21,7 +23,7 @@ import {
string, string,
} from "superstruct"; } from "superstruct";
import { storage } from "../../../../common/decorators/storage"; import { storage } from "../../../../common/decorators/storage";
import { fireEvent, HASSDomEvent } from "../../../../common/dom/fire_event"; import { HASSDomEvent, fireEvent } from "../../../../common/dom/fire_event";
import "../../../../components/ha-icon-button"; import "../../../../components/ha-icon-button";
import { LovelaceCardConfig, LovelaceConfig } from "../../../../data/lovelace"; import { LovelaceCardConfig, LovelaceConfig } from "../../../../data/lovelace";
import { HomeAssistant } from "../../../../types"; import { HomeAssistant } from "../../../../types";
@ -87,6 +89,8 @@ export class HuiStackCardEditor
const selected = this._selectedCard!; const selected = this._selectedCard!;
const numcards = this._config.cards.length; const numcards = this._config.cards.length;
const isGuiMode = !this._cardEditorEl || this._GUImode;
return html` return html`
<div class="card-config"> <div class="card-config">
<div class="toolbar"> <div class="toolbar">
@ -114,17 +118,17 @@ export class HuiStackCardEditor
${selected < numcards ${selected < numcards
? html` ? html`
<div id="card-options"> <div id="card-options">
<mwc-button <ha-icon-button
class="gui-mode-button"
@click=${this._toggleMode} @click=${this._toggleMode}
.disabled=${!this._guiModeAvailable} .disabled=${!this._guiModeAvailable}
class="gui-mode-button" .label=${this.hass!.localize(
> isGuiMode
${this.hass!.localize(
!this._cardEditorEl || this._GUImode
? "ui.panel.lovelace.editor.edit_card.show_code_editor" ? "ui.panel.lovelace.editor.edit_card.show_code_editor"
: "ui.panel.lovelace.editor.edit_card.show_visual_editor" : "ui.panel.lovelace.editor.edit_card.show_visual_editor"
)} )}
</mwc-button> .path=${isGuiMode ? mdiCodeBraces : mdiListBoxOutline}
></ha-icon-button>
<ha-icon-button <ha-icon-button
.disabled=${selected === 0} .disabled=${selected === 0}

View File

@ -1,5 +1,5 @@
import "@material/mwc-button"; import "@material/mwc-button";
import { mdiArrowLeft } from "@mdi/js"; import { mdiArrowLeft, mdiCodeBraces, mdiListBoxOutline } from "@mdi/js";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, query, state } from "lit/decorators"; import { customElement, property, query, state } from "lit/decorators";
import { fireEvent, HASSDomEvent } from "../../../common/dom/fire_event"; import { fireEvent, HASSDomEvent } from "../../../common/dom/fire_event";
@ -50,17 +50,17 @@ export class HuiSubElementEditor extends LitElement {
)}</span )}</span
> >
</div> </div>
<mwc-button <ha-icon-button
slot="secondaryAction" class="gui-mode-button"
.disabled=${!this._guiModeAvailable}
@click=${this._toggleMode} @click=${this._toggleMode}
> .disabled=${!this._guiModeAvailable}
${this.hass.localize( .label=${this.hass!.localize(
this._guiMode this._guiMode
? "ui.panel.lovelace.editor.edit_card.show_code_editor" ? "ui.panel.lovelace.editor.edit_card.show_code_editor"
: "ui.panel.lovelace.editor.edit_card.show_visual_editor" : "ui.panel.lovelace.editor.edit_card.show_visual_editor"
)} )}
</mwc-button> .path=${this._guiMode ? mdiCodeBraces : mdiListBoxOutline}
></ha-icon-button>
</div> </div>
${this.config.type === "row" ${this.config.type === "row"
? html` ? html`