Skip to content

Commit 8093f7f

Browse files
authored
Add background opacity option to section styling (#26651)
* Add background opacity option to section styling * Run updated prettier
1 parent b26c914 commit 8093f7f

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/data/lovelace/config/section.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { LovelaceStrategyConfig } from "./strategy";
44

55
export interface LovelaceSectionStyleConfig {
66
background_color?: string;
7+
background_opacity?: number;
78
}
89

910
export interface LovelaceBaseSectionConfig {

src/panels/lovelace/editor/section-editor/hui-section-settings-editor.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface SettingsData {
1818
column_span?: number;
1919
background_type: "none" | "color";
2020
background_color?: number[];
21+
background_opacity?: number;
2122
}
2223

2324
@customElement("hui-section-settings-editor")
@@ -84,6 +85,19 @@ export class HuiDialogEditSection extends LitElement {
8485
},
8586
disabled: !enableBackground,
8687
},
88+
{
89+
name: "background_opacity",
90+
selector: {
91+
number: {
92+
min: 0,
93+
max: 100,
94+
step: 1,
95+
mode: "slider",
96+
unit_of_measurement: "%",
97+
},
98+
},
99+
disabled: !enableBackground,
100+
},
87101
],
88102
},
89103
],
@@ -108,6 +122,7 @@ export class HuiDialogEditSection extends LitElement {
108122
background_color: this.config.style?.background_color
109123
? hex2rgb(this.config.style?.background_color as any)
110124
: [],
125+
background_opacity: this.config.style?.background_opacity || 100,
111126
};
112127

113128
const schema = this._schema(
@@ -156,11 +171,13 @@ export class HuiDialogEditSection extends LitElement {
156171
newConfig.style = {
157172
...newConfig.style,
158173
background_color: rgb2hex(newData.background_color as any),
174+
background_opacity: newData.background_opacity,
159175
};
160176
} else {
161177
newConfig.style = {
162178
...newConfig.style,
163179
background_color: undefined,
180+
background_opacity: undefined,
164181
};
165182
}
166183

src/panels/lovelace/sections/hui-grid-section.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import "../components/hui-card-edit-mode";
2020
import { moveCard } from "../editor/config-util";
2121
import type { LovelaceCardPath } from "../editor/lovelace-path";
2222
import type { Lovelace } from "../types";
23+
import { hex2rgb } from "../../../common/color/convert-color";
2324

2425
const CARD_SORTABLE_OPTIONS: HaSortableOptions = {
2526
delay: 100,
@@ -86,7 +87,11 @@ export class GridSection extends LitElement implements LovelaceSectionElement {
8687
? IMPORT_MODE_CARD_SORTABLE_OPTIONS
8788
: CARD_SORTABLE_OPTIONS;
8889

89-
const background = this._config.style?.background_color;
90+
const backgroundOpacity =
91+
(this._config.style?.background_opacity || 100) / 100;
92+
const background = this._config.style?.background_color
93+
? `rgba(${hex2rgb(this._config.style.background_color)}, ${backgroundOpacity})`
94+
: undefined;
9095

9196
return html`
9297
<ha-sortable

src/translations/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7263,7 +7263,8 @@
72637263
"background_type": "Background type",
72647264
"background_type_none_option": "None",
72657265
"background_type_color_option": "Color",
7266-
"background_color": "Background color"
7266+
"background_color": "Background color",
7267+
"background_opacity": "Background opacity"
72677268
},
72687269
"visibility": {
72697270
"explanation": "The section will be shown when ALL conditions below are fulfilled. If no conditions are set, the section will always be shown."

0 commit comments

Comments
 (0)