From 32083ea13d0246726ff5d7aa1fcb58b46bf848fe Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Thu, 29 Aug 2024 16:36:00 +0200 Subject: [PATCH] Use dense layout for section view (#21830) * Use dense layout for section view * Make it an option in view settings * Add expandable --- src/data/lovelace/config/view.ts | 4 +- .../editor/view-editor/hui-view-editor.ts | 52 ++++++++++++------- .../lovelace/views/hui-sections-view.ts | 9 +++- src/translations/en.json | 3 ++ 4 files changed, 48 insertions(+), 20 deletions(-) diff --git a/src/data/lovelace/config/view.ts b/src/data/lovelace/config/view.ts index 4bbf67c5a6cd..dd784c628a1e 100644 --- a/src/data/lovelace/config/view.ts +++ b/src/data/lovelace/config/view.ts @@ -22,7 +22,9 @@ export interface LovelaceBaseViewConfig { visible?: boolean | ShowViewConfig[]; subview?: boolean; back_path?: string; - max_columns?: number; // Only used for section view, it should move to a section view config type when the views will have dedicated editor. + // Only used for section view, it should move to a section view config type when the views will have dedicated editor. + max_columns?: number; + dense_section_placement?: boolean; } export interface LovelaceViewConfig extends LovelaceBaseViewConfig { diff --git a/src/panels/lovelace/editor/view-editor/hui-view-editor.ts b/src/panels/lovelace/editor/view-editor/hui-view-editor.ts index 04cac1ac5bd4..cfb2bc15a371 100644 --- a/src/panels/lovelace/editor/view-editor/hui-view-editor.ts +++ b/src/panels/lovelace/editor/view-editor/hui-view-editor.ts @@ -48,6 +48,12 @@ export class HuiViewEditor extends LitElement { }, { name: "path", selector: { text: {} } }, { name: "theme", selector: { theme: {} } }, + { + name: "subview", + selector: { + boolean: {}, + }, + }, { name: "type", selector: { @@ -71,24 +77,32 @@ export class HuiViewEditor extends LitElement { ...(viewType === SECTION_VIEW_LAYOUT ? ([ { - name: "max_columns", - selector: { - number: { - min: 1, - max: 10, - mode: "slider", - slider_ticks: true, + name: "section_specifics", + type: "expandable", + flatten: true, + expanded: true, + schema: [ + { + name: "max_columns", + selector: { + number: { + min: 1, + max: 10, + mode: "slider", + slider_ticks: true, + }, + }, + }, + { + name: "dense_section_placement", + selector: { + boolean: {}, + }, }, - }, + ], }, ] as const satisfies HaFormSchema[]) : []), - { - name: "subview", - selector: { - boolean: {}, - }, - }, ] as const satisfies HaFormSchema[] ); @@ -164,12 +178,12 @@ export class HuiViewEditor extends LitElement { case "path": return this.hass!.localize("ui.panel.lovelace.editor.card.generic.url"); case "type": - return this.hass.localize("ui.panel.lovelace.editor.edit_view.type"); case "subview": - return this.hass.localize("ui.panel.lovelace.editor.edit_view.subview"); case "max_columns": + case "dense_section_placement": + case "section_specifics": return this.hass.localize( - "ui.panel.lovelace.editor.edit_view.max_columns" + `ui.panel.lovelace.editor.edit_view.${schema.name}` ); default: return this.hass!.localize( @@ -183,9 +197,11 @@ export class HuiViewEditor extends LitElement { ) => { switch (schema.name) { case "subview": + case "dense_section_placement": return this.hass.localize( - "ui.panel.lovelace.editor.edit_view.subview_helper" + `ui.panel.lovelace.editor.edit_view.${schema.name}_helper` ); + default: return undefined; } diff --git a/src/panels/lovelace/views/hui-sections-view.ts b/src/panels/lovelace/views/hui-sections-view.ts index 5d27ac1be1d6..79cb0cf99fbb 100644 --- a/src/panels/lovelace/views/hui-sections-view.ts +++ b/src/panels/lovelace/views/hui-sections-view.ts @@ -9,6 +9,7 @@ import { nothing, } from "lit"; import { customElement, property, state } from "lit/decorators"; +import { classMap } from "lit/directives/class-map"; import { repeat } from "lit/directives/repeat"; import { styleMap } from "lit/directives/style-map"; import "../../../components/ha-icon-button"; @@ -147,7 +148,9 @@ export class SectionsView extends LitElement implements LovelaceViewElement { .rollback=${false} >