mirror of
https://github.com/home-assistant/frontend.git
synced 2026-07-13 16:41:06 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1d007a5aaf | |||
| 94c1af7729 | |||
| d7aaf9bc41 | |||
| c0aed4325d | |||
| 79a56fabdf | |||
| 14c2b60538 | |||
| 79f3dfdfce | |||
| 3de4dffa02 | |||
| 0ff2f1bf75 | |||
| d28f1f07e7 |
+1
-1
@@ -216,7 +216,7 @@
|
||||
"husky": "9.1.5",
|
||||
"instant-mocha": "1.5.2",
|
||||
"jszip": "3.10.1",
|
||||
"lint-staged": "15.2.9",
|
||||
"lint-staged": "15.2.10",
|
||||
"lit-analyzer": "2.0.3",
|
||||
"lodash.merge": "4.6.2",
|
||||
"lodash.template": "4.5.0",
|
||||
|
||||
@@ -67,7 +67,9 @@ export class HaNumberSelector extends LitElement {
|
||||
}
|
||||
|
||||
return html`
|
||||
${this.label ? html`${this.label}${this.required ? "*" : ""}` : nothing}
|
||||
${this.label && !isBox
|
||||
? html`${this.label}${this.required ? "*" : ""}`
|
||||
: nothing}
|
||||
<div class="input">
|
||||
${!isBox
|
||||
? html`
|
||||
|
||||
@@ -25,6 +25,8 @@ export interface LovelaceBaseViewConfig {
|
||||
// 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;
|
||||
column_breakpoints?: Record<string, number>;
|
||||
experimental_breakpoints?: boolean;
|
||||
}
|
||||
|
||||
export interface LovelaceViewConfig extends LovelaceBaseViewConfig {
|
||||
|
||||
@@ -12,6 +12,7 @@ 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 { listenMediaQuery } from "../../../common/dom/media_query";
|
||||
import "../../../components/ha-icon-button";
|
||||
import "../../../components/ha-sortable";
|
||||
import "../../../components/ha-svg-icon";
|
||||
@@ -28,8 +29,29 @@ import { showEditSectionDialog } from "../editor/section-editor/show-edit-sectio
|
||||
import { HuiSection } from "../sections/hui-section";
|
||||
import type { Lovelace } from "../types";
|
||||
|
||||
type Breakpoints = Record<string, number>;
|
||||
|
||||
export const DEFAULT_MAX_COLUMNS = 4;
|
||||
|
||||
export const DEFAULT_BREAKPOINTS: Breakpoints = {
|
||||
"0": 1,
|
||||
"768": 2,
|
||||
"1280": 3,
|
||||
"1600": 4,
|
||||
"1920": 5,
|
||||
"2560": 6,
|
||||
};
|
||||
|
||||
const buildMediaQueries = (breakpoints: Breakpoints) =>
|
||||
Object.keys(breakpoints).map((breakpoint, index, array) => {
|
||||
const nextBreakpoint = array[index + 1] as string | undefined;
|
||||
let mediaQuery = `(min-width: ${breakpoint}px)`;
|
||||
if (nextBreakpoint) {
|
||||
mediaQuery += ` and (max-width: ${parseInt(nextBreakpoint) - 1}px)`;
|
||||
}
|
||||
return mediaQuery;
|
||||
});
|
||||
|
||||
const parsePx = (value: string) => parseInt(value.replace("px", ""));
|
||||
|
||||
@customElement("hui-sections-view")
|
||||
@@ -52,8 +74,15 @@ export class SectionsView extends LitElement implements LovelaceViewElement {
|
||||
|
||||
@state() _dragging = false;
|
||||
|
||||
private _listeners: Array<() => void> = [];
|
||||
|
||||
@state() private _breakpointsColumns: number = 1;
|
||||
|
||||
private _columnsController = new ResizeController(this, {
|
||||
callback: (entries) => {
|
||||
// Don't do anything if we are using breakpoints
|
||||
if (this._config?.experimental_breakpoints) return 1;
|
||||
|
||||
const totalWidth = entries[0]?.contentRect.width;
|
||||
|
||||
const style = getComputedStyle(this);
|
||||
@@ -76,8 +105,13 @@ export class SectionsView extends LitElement implements LovelaceViewElement {
|
||||
},
|
||||
});
|
||||
|
||||
private get _sizeColumns() {
|
||||
return this._columnsController.value ?? 1;
|
||||
}
|
||||
|
||||
public setConfig(config: LovelaceViewConfig): void {
|
||||
this._config = config;
|
||||
this._attachMediaQueriesListeners();
|
||||
}
|
||||
|
||||
private _sectionConfigKeys = new WeakMap<HuiSection, string>();
|
||||
@@ -100,12 +134,35 @@ export class SectionsView extends LitElement implements LovelaceViewElement {
|
||||
this._computeSectionsCount();
|
||||
};
|
||||
|
||||
private _attachMediaQueriesListeners() {
|
||||
this._detachMediaQueriesListeners();
|
||||
if (!this._config?.experimental_breakpoints) return;
|
||||
const breakpoints = this._config?.column_breakpoints ?? DEFAULT_BREAKPOINTS;
|
||||
const maxColumns = this._config?.max_columns ?? DEFAULT_MAX_COLUMNS;
|
||||
const mediaQueries = buildMediaQueries(breakpoints);
|
||||
this._listeners = mediaQueries.map((mediaQuery, index) =>
|
||||
listenMediaQuery(mediaQuery, (matches) => {
|
||||
if (matches) {
|
||||
const columns = Object.values(breakpoints)[index];
|
||||
this._breakpointsColumns = Math.min(maxColumns, columns);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private _detachMediaQueriesListeners() {
|
||||
while (this._listeners.length) {
|
||||
this._listeners.pop()!();
|
||||
}
|
||||
}
|
||||
|
||||
connectedCallback(): void {
|
||||
super.connectedCallback();
|
||||
this.addEventListener(
|
||||
"section-visibility-changed",
|
||||
this._sectionVisibilityChanged
|
||||
);
|
||||
this._attachMediaQueriesListeners();
|
||||
}
|
||||
|
||||
disconnectedCallback(): void {
|
||||
@@ -114,6 +171,7 @@ export class SectionsView extends LitElement implements LovelaceViewElement {
|
||||
"section-visibility-changed",
|
||||
this._sectionVisibilityChanged
|
||||
);
|
||||
this._detachMediaQueriesListeners();
|
||||
}
|
||||
|
||||
willUpdate(changedProperties: PropertyValues<typeof this>): void {
|
||||
@@ -130,7 +188,9 @@ export class SectionsView extends LitElement implements LovelaceViewElement {
|
||||
this._sectionColumnCount + (this.lovelace?.editMode ? 1 : 0);
|
||||
const editMode = this.lovelace.editMode;
|
||||
|
||||
const maxColumnCount = this._columnsController.value ?? 1;
|
||||
const maxColumnCount = this._config?.experimental_breakpoints
|
||||
? this._breakpointsColumns
|
||||
: this._sizeColumns;
|
||||
|
||||
return html`
|
||||
<hui-view-badges
|
||||
@@ -321,9 +381,9 @@ export class SectionsView extends LitElement implements LovelaceViewElement {
|
||||
:host {
|
||||
--row-height: var(--ha-view-sections-row-height, 56px);
|
||||
--row-gap: var(--ha-view-sections-row-gap, 8px);
|
||||
--column-gap: var(--ha-view-sections-column-gap, 32px);
|
||||
--column-max-width: var(--ha-view-sections-column-max-width, 500px);
|
||||
--column-gap: var(--ha-view-sections-column-gap, 24px);
|
||||
--column-min-width: var(--ha-view-sections-column-min-width, 320px);
|
||||
--column-max-width: var(--ha-view-sections-column-max-width, 500px);
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
||||
@@ -9070,7 +9070,7 @@ __metadata:
|
||||
jszip: "npm:3.10.1"
|
||||
leaflet: "npm:1.9.4"
|
||||
leaflet-draw: "npm:1.0.4"
|
||||
lint-staged: "npm:15.2.9"
|
||||
lint-staged: "npm:15.2.10"
|
||||
lit: "npm:2.8.0"
|
||||
lit-analyzer: "npm:2.0.3"
|
||||
lodash.merge: "npm:4.6.2"
|
||||
@@ -10497,9 +10497,9 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"lint-staged@npm:15.2.9":
|
||||
version: 15.2.9
|
||||
resolution: "lint-staged@npm:15.2.9"
|
||||
"lint-staged@npm:15.2.10":
|
||||
version: 15.2.10
|
||||
resolution: "lint-staged@npm:15.2.10"
|
||||
dependencies:
|
||||
chalk: "npm:~5.3.0"
|
||||
commander: "npm:~12.1.0"
|
||||
@@ -10507,13 +10507,13 @@ __metadata:
|
||||
execa: "npm:~8.0.1"
|
||||
lilconfig: "npm:~3.1.2"
|
||||
listr2: "npm:~8.2.4"
|
||||
micromatch: "npm:~4.0.7"
|
||||
micromatch: "npm:~4.0.8"
|
||||
pidtree: "npm:~0.6.0"
|
||||
string-argv: "npm:~0.3.2"
|
||||
yaml: "npm:~2.5.0"
|
||||
bin:
|
||||
lint-staged: bin/lint-staged.js
|
||||
checksum: 10/2f7342ca3fc7e2a8a0cc3db79ca8d2ad0269b98b13220f3a6745a514aacf1f83487a23a550569081ea962f9a576af7df8d687a8330a9c3c2c27348d5a4d5440e
|
||||
checksum: 10/ab6930cd633dbb5b6ec7c81fc06c65df41e9f80d93dd22e0d79c6e272cdfd8110a0fbdec60303d46a06b30bcd92261153630e2c937531b77ec5ae41e7e9d90d3
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -10937,7 +10937,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"micromatch@npm:^4.0.2, micromatch@npm:^4.0.4, micromatch@npm:~4.0.7":
|
||||
"micromatch@npm:^4.0.2, micromatch@npm:^4.0.4, micromatch@npm:~4.0.8":
|
||||
version: 4.0.8
|
||||
resolution: "micromatch@npm:4.0.8"
|
||||
dependencies:
|
||||
|
||||
Reference in New Issue
Block a user