diff --git a/src/components/ha-expansion-panel.ts b/src/components/ha-expansion-panel.ts index 5f82762fa387..47c108e5bd38 100644 --- a/src/components/ha-expansion-panel.ts +++ b/src/components/ha-expansion-panel.ts @@ -21,6 +21,8 @@ export class HaExpansionPanel extends LitElement { @property({ type: Boolean, reflect: true }) leftChevron = false; + @property({ type: Boolean, reflect: true }) noCollapse = false; + @property() header?: string; @property() secondary?: string; @@ -34,16 +36,17 @@ export class HaExpansionPanel extends LitElement {
- ${this.leftChevron + ${this.leftChevron && !this.noCollapse ? html` ${this.secondary}
- ${!this.leftChevron + ${!this.leftChevron && !this.noCollapse ? html` ; + input?: Record; description?: string; source_url?: string; author?: string; @@ -26,6 +26,14 @@ export interface BlueprintInput { default?: any; } +export interface BlueprintInputSection { + name?: string; + icon?: string; + description?: string; + collapsed?: boolean; + input: Record; +} + export interface BlueprintImportResult { suggested_filename: string; raw_data: string; diff --git a/src/panels/config/blueprint/blueprint-generic-editor.ts b/src/panels/config/blueprint/blueprint-generic-editor.ts index 188ef35e25f9..bae63f6dc7e3 100644 --- a/src/panels/config/blueprint/blueprint-generic-editor.ts +++ b/src/panels/config/blueprint/blueprint-generic-editor.ts @@ -1,5 +1,5 @@ import "@material/mwc-button/mwc-button"; -import { css, CSSResultGroup, html, LitElement } from "lit"; +import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { customElement, property, state } from "lit/decorators"; import { fireEvent } from "../../../common/dom/fire_event"; import { nestedArrayMove } from "../../../common/util/array-move"; @@ -11,7 +11,12 @@ import "../../../components/ha-markdown"; import "../../../components/ha-selector/ha-selector"; import "../../../components/ha-settings-row"; import { BlueprintAutomationConfig } from "../../../data/automation"; -import { BlueprintOrError, Blueprints } from "../../../data/blueprint"; +import { + BlueprintInput, + BlueprintInputSection, + BlueprintOrError, + Blueprints, +} from "../../../data/blueprint"; import { BlueprintScriptConfig } from "../../../data/script"; import { haStyle } from "../../../resources/styles"; import { HomeAssistant } from "../../../types"; @@ -46,6 +51,7 @@ export abstract class HaBlueprintGenericEditor extends LitElement { protected renderCard() { const blueprint = this._blueprint; + let border = true; return html` { - const selector = value?.selector ?? { text: undefined }; - const type = Object.keys(selector)[0]; - const enhancedSelector = [ - "action", - "condition", - "trigger", - ].includes(type) - ? { - [type]: { - ...selector[type], - path: [key], - }, - } - : selector; - - return html` - ${value?.name || key} - - ${html``} - `; + if (value && "input" in value) { + const section = this.renderSection(key, value); + border = false; + return section; + } + const row = this.renderSettingRow(key, value, border); + border = true; + return row; } ) : html`

@@ -141,6 +117,85 @@ export abstract class HaBlueprintGenericEditor extends LitElement { `; } + private renderSection(sectionKey: string, section: BlueprintInputSection) { + const title = section?.name || sectionKey; + const anyRequired = + section.input && + Object.values(section.input).some( + (item) => item === null || item.default === undefined + ); + const expanded = !section.collapsed || anyRequired; + + return html` +

+ ${section?.icon + ? html` ` + : nothing} + +
+
+ ${section?.description + ? html`` + : nothing} + ${section.input + ? Object.entries(section.input).map(([key, value]) => + this.renderSettingRow(key, value, true) + ) + : nothing} +
+ `; + } + + private renderSettingRow( + key: string, + value: BlueprintInput | null, + border: boolean + ) { + const selector = value?.selector ?? { text: undefined }; + const type = Object.keys(selector)[0]; + const enhancedSelector = ["action", "condition", "trigger"].includes(type) + ? { + [type]: { + ...selector[type], + path: [key], + }, + } + : selector; + return html` + ${value?.name || key} + + ${html``} + `; + } + protected abstract _getBlueprints(); private _blueprintChanged(ev) { @@ -219,6 +274,7 @@ export abstract class HaBlueprintGenericEditor extends LitElement { } ha-card.blueprint { margin: 0 auto; + margin-bottom: 64px; } .padding { padding: 16px; @@ -253,8 +309,15 @@ export abstract class HaBlueprintGenericEditor extends LitElement { --paper-time-input-justify-content: flex-end; --settings-row-content-width: 100%; --settings-row-prefix-display: contents; + } + ha-settings-row.border { border-top: 1px solid var(--divider-color); } + ha-expansion-panel { + margin: 8px; + margin-left: 8px; + margin-right: 8px; + } ha-alert { margin-bottom: 16px; display: block; @@ -263,6 +326,13 @@ export abstract class HaBlueprintGenericEditor extends LitElement { border-radius: var(--ha-card-border-radius, 12px); overflow: hidden; } + div.section-header { + display: flex; + vertical-align: middle; + } + ha-icon.section-header { + padding-right: 10px; + } `, ]; }