Skip to content

Commit

Permalink
Rename to grid density
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Aug 19, 2024
1 parent 05ba6c6 commit 4d291e9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/data/lovelace/config/section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface LovelaceSectionConfig extends LovelaceBaseSectionConfig {
}

export interface LovelaceGridSectionConfig extends LovelaceSectionConfig {
column_base?: number;
grid_base?: number;
}

export interface LovelaceStrategySectionConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { HomeAssistant } from "../../../../types";
import { HuiCard } from "../../cards/hui-card";
import {
computeSizeOnGrid,
DEFAULT_COLUMN_BASE,
DEFAULT_GRID_BASE,
} from "../../sections/hui-grid-section";
import { LovelaceLayoutOptions } from "../../types";
import { LovelaceGridSectionConfig } from "../../../../data/lovelace/config/section";
Expand Down Expand Up @@ -142,7 +142,7 @@ export class HuiCardLayoutEditor extends LitElement {
.rowMax=${options.grid_max_rows}
.columnMin=${options.grid_min_columns}
.columnMax=${options.grid_max_columns}
.columns=${this.sectionConfig.column_base || DEFAULT_COLUMN_BASE}
.columns=${this.sectionConfig.grid_base || DEFAULT_GRID_BASE}
></ha-grid-size-picker>
`}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import {
LovelaceSectionRawConfig,
} from "../../../../data/lovelace/config/section";
import { HomeAssistant } from "../../../../types";
import { DEFAULT_COLUMN_BASE } from "../../sections/hui-grid-section";
import { DEFAULT_GRID_BASE } from "../../sections/hui-grid-section";

type ColumnDensity = "default" | "dense" | "custom";
type GridDensity = "default" | "dense" | "custom";

type SettingsData = {
title: string;
column_density?: ColumnDensity;
grid_density?: GridDensity;
};

@customElement("hui-section-settings-editor")
Expand All @@ -32,7 +32,7 @@ export class HuiDialogEditSection extends LitElement {
(
localize: LocalizeFunc,
type?: string | undefined,
columnDensity?: ColumnDensity,
columnDensity?: GridDensity,
columnBase?: number
) =>
[
Expand All @@ -43,22 +43,22 @@ export class HuiDialogEditSection extends LitElement {
...(type === "grid"
? ([
{
name: "column_density",
name: "grid_density",
default: "default",
selector: {
select: {
mode: "list",
options: [
{
label: localize(
`ui.panel.lovelace.editor.edit_section.settings.column_density_options.default`,
`ui.panel.lovelace.editor.edit_section.settings.grid_density_options.default`,
{ count: 4 }
),
value: "default",
},
{
label: localize(
`ui.panel.lovelace.editor.edit_section.settings.column_density_options.dense`,
`ui.panel.lovelace.editor.edit_section.settings.grid_density_options.dense`,
{ count: 6 }
),
value: "dense",
Expand All @@ -67,7 +67,7 @@ export class HuiDialogEditSection extends LitElement {
? [
{
label: localize(
`ui.panel.lovelace.editor.edit_section.settings.column_density_options.custom`,
`ui.panel.lovelace.editor.edit_section.settings.grid_density_options.custom`,
{ count: columnBase }
),
value: "custom",
Expand All @@ -90,16 +90,16 @@ export class HuiDialogEditSection extends LitElement {
}

render() {
const columnBase = this._isGridSectionConfig(this.config)
? this.config.column_base || DEFAULT_COLUMN_BASE
const gridBase = this._isGridSectionConfig(this.config)
? this.config.grid_base || DEFAULT_GRID_BASE
: undefined;

const columnDensity =
columnBase === 6 ? "dense" : columnBase === 4 ? "default" : "custom";
gridBase === 6 ? "dense" : gridBase === 4 ? "default" : "custom";

const data: SettingsData = {
title: this.config.title || "",
column_density: columnDensity,
grid_density: columnDensity,
};

const type = "type" in this.config ? this.config.type : undefined;
Expand All @@ -108,7 +108,7 @@ export class HuiDialogEditSection extends LitElement {
this.hass.localize,
type,
columnDensity,
columnBase
gridBase
);

return html`
Expand Down Expand Up @@ -141,23 +141,23 @@ export class HuiDialogEditSection extends LitElement {
ev.stopPropagation();
const newData = ev.detail.value as SettingsData;

const { title, column_density } = newData;
const { title, grid_density } = newData;

const newConfig: LovelaceSectionRawConfig = {
...this.config,
title,
};

if (this._isGridSectionConfig(newConfig)) {
const column_base =
column_density === "default"
const gridBase =
grid_density === "default"
? 4
: column_density === "dense"
: grid_density === "dense"
? 6
: undefined;

if (column_base) {
(newConfig as LovelaceGridSectionConfig).column_base = column_base;
if (gridBase) {
(newConfig as LovelaceGridSectionConfig).grid_base = gridBase;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/panels/lovelace/sections/hui-grid-section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const computeSizeOnGrid = (
};
};

export const DEFAULT_COLUMN_BASE = 4;
export const DEFAULT_GRID_BASE = 4;

export class GridSection extends LitElement implements LovelaceSectionElement {
@property({ attribute: false }) public hass!: HomeAssistant;
Expand Down Expand Up @@ -100,7 +100,7 @@ export class GridSection extends LitElement implements LovelaceSectionElement {

const editMode = Boolean(this.lovelace?.editMode && !this.isStrategy);

const columnCount = this._config.column_base ?? DEFAULT_COLUMN_BASE;
const columnCount = this._config.grid_base ?? DEFAULT_GRID_BASE;

return html`
${this._config.title || this.lovelace?.editMode
Expand Down
4 changes: 2 additions & 2 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5646,8 +5646,8 @@
"settings": {
"title": "Title",
"title_helper": "The title will appear at the top of section. Leave empty to hide the title.",
"column_density": "Column density",
"column_density_options": {
"grid_density": "Grid density",
"grid_density_options": {
"default": "Default ({count} columns)",
"dense": "Dense ({count} columns)",
"custom": "Custom ({count} {count, plural,\n one {column}\n other {columns}\n})"
Expand Down

0 comments on commit 4d291e9

Please sign in to comment.