Skip to content

Commit

Permalink
Use dense layout for section view (#21830)
Browse files Browse the repository at this point in the history
* Use dense layout for section view

* Make it an option in view settings

* Add expandable
  • Loading branch information
piitaya authored Aug 29, 2024
1 parent 18210f3 commit 32083ea
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/data/lovelace/config/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
52 changes: 34 additions & 18 deletions src/panels/lovelace/editor/view-editor/hui-view-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export class HuiViewEditor extends LitElement {
},
{ name: "path", selector: { text: {} } },
{ name: "theme", selector: { theme: {} } },
{
name: "subview",
selector: {
boolean: {},
},
},
{
name: "type",
selector: {
Expand All @@ -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[]
);

Expand Down Expand Up @@ -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(
Expand All @@ -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;
}
Expand Down
9 changes: 8 additions & 1 deletion src/panels/lovelace/views/hui-sections-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -147,7 +148,9 @@ export class SectionsView extends LitElement implements LovelaceViewElement {
.rollback=${false}
>
<div
class="container"
class="container ${classMap({
dense: Boolean(this._config?.dense_section_placement),
})}"
style=${styleMap({
"--total-section-count": totalSectionCount,
"--max-column-count": maxColumnCount,
Expand Down Expand Up @@ -323,6 +326,7 @@ export class SectionsView extends LitElement implements LovelaceViewElement {
align-items: start;
justify-content: center;
grid-template-columns: repeat(var(--column-count), 1fr);
grid-auto-flow: row;
gap: var(--row-gap) var(--column-gap);
padding: var(--row-gap) var(--column-gap);
box-sizing: content-box;
Expand All @@ -332,6 +336,9 @@ export class SectionsView extends LitElement implements LovelaceViewElement {
(var(--column-count) - 1) * var(--column-gap)
);
}
.container.dense {
grid-auto-flow: row dense;
}
@media (max-width: 600px) {
.container {
Expand Down
3 changes: 3 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5550,6 +5550,9 @@
},
"subview": "Subview",
"max_columns": "Max number of sections wide",
"section_specifics": "Sections view specifics settings",
"dense_section_placement": "Dense section placement",
"dense_section_placement_helper": "Will try to fill gaps with sections that fit the gap. This may make section placement less predictable.",
"subview_helper": "Subviews don't appear in tabs and have a back button.",
"edit_ui": "Edit in visual editor",
"edit_yaml": "Edit in YAML",
Expand Down

0 comments on commit 32083ea

Please sign in to comment.