Skip to content

Commit d195fd3

Browse files
authored
Views: allow showing both icon & text title (#28690)
1 parent 231cd63 commit d195fd3

File tree

5 files changed

+45
-18
lines changed

5 files changed

+45
-18
lines changed

src/data/lovelace/config/view.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface LovelaceBaseViewConfig {
4949
title?: string;
5050
path?: string;
5151
icon?: string;
52+
show_icon_and_title?: boolean;
5253
theme?: string;
5354
panel?: boolean;
5455
background?: string | LovelaceViewBackgroundConfig;

src/panels/lovelace/common/generate-lovelace-config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ export const generateViewConfig = (
368368
path: string,
369369
title: string | undefined,
370370
icon: string | undefined,
371+
show_icon_and_title: boolean | undefined,
371372
entities: HassEntities
372373
): LovelaceViewConfig => {
373374
const ungroupedEntitites: Record<string, string[]> = {};
@@ -497,6 +498,9 @@ export const generateViewConfig = (
497498
if (icon) {
498499
view.icon = icon;
499500
}
501+
if (show_icon_and_title) {
502+
view.show_icon_and_title = show_icon_and_title;
503+
}
500504

501505
return view;
502506
};
@@ -517,6 +521,7 @@ export const generateDefaultViewConfig = (
517521
const path = "default_view";
518522
const title = "Home";
519523
const icon = undefined;
524+
const show_icon_and_title = undefined;
520525

521526
// In the case of a default view, we want to use the group order attribute
522527
const groupOrders = {};
@@ -566,6 +571,7 @@ export const generateDefaultViewConfig = (
566571
path,
567572
title,
568573
icon,
574+
show_icon_and_title,
569575
splittedByGroups.ungrouped
570576
);
571577

src/panels/lovelace/editor/view-editor/hui-view-editor.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ export class HuiViewEditor extends LitElement {
7373
icon: {},
7474
},
7575
},
76+
{
77+
name: "show_icon_and_title",
78+
selector: {
79+
boolean: {},
80+
},
81+
},
7682
{ name: "path", selector: { text: {} } },
7783
{ name: "theme", selector: { theme: {} } },
7884
{
@@ -207,6 +213,7 @@ export class HuiViewEditor extends LitElement {
207213
case "path":
208214
return this.hass!.localize("ui.panel.lovelace.editor.card.generic.url");
209215
case "type":
216+
case "show_icon_and_title":
210217
case "subview":
211218
case "max_columns":
212219
case "dense_section_placement":
@@ -227,6 +234,7 @@ export class HuiViewEditor extends LitElement {
227234
) => {
228235
switch (schema.name) {
229236
case "path":
237+
case "show_icon_and_title":
230238
case "subview":
231239
case "dense_section_placement":
232240
case "top_margin":

src/panels/lovelace/hui-root.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,10 @@ class HUIRoot extends LitElement {
496496

497497
const tabs = html`<ha-tab-group @wa-tab-show=${this._handleViewSelected}>
498498
${views.map((view, index) => {
499+
const icon_and_title =
500+
view.show_icon_and_title && view.icon && view.title;
501+
const icon_only = view.icon && !icon_and_title;
502+
const title_only = !icon_only && !icon_and_title;
499503
const hidden =
500504
!this._editMode && (view.subview || _isTabHiddenForUser(view));
501505
return html`
@@ -506,7 +510,8 @@ class HUIRoot extends LitElement {
506510
.disabled=${hidden}
507511
aria-label=${ifDefined(view.title)}
508512
class=${classMap({
509-
icon: Boolean(view.icon),
513+
"icon-only": Boolean(icon_only),
514+
"icon-and-title": Boolean(icon_and_title),
510515
"hide-tab": Boolean(hidden),
511516
})}
512517
>
@@ -523,18 +528,20 @@ class HUIRoot extends LitElement {
523528
></ha-icon-button-arrow-prev>
524529
`
525530
: nothing}
526-
${view.icon
527-
? html`
528-
<ha-icon
529-
class=${classMap({
530-
"child-view-icon": Boolean(view.subview),
531-
})}
532-
title=${ifDefined(view.title)}
533-
.icon=${view.icon}
534-
></ha-icon>
535-
`
536-
: view.title ||
537-
this.hass.localize("ui.panel.lovelace.views.unnamed_view")}
531+
${icon_only || icon_and_title
532+
? html`<ha-icon
533+
class=${classMap({
534+
"child-view-icon": Boolean(view.subview),
535+
})}
536+
title=${ifDefined(view.title)}
537+
.icon=${view.icon}
538+
></ha-icon>`
539+
: nothing}
540+
${icon_and_title ? view.title : nothing}
541+
${title_only
542+
? view.title ||
543+
this.hass.localize("ui.panel.lovelace.views.unnamed_view")
544+
: nothing}
538545
${this._editMode
539546
? html`
540547
<ha-icon-button
@@ -1489,24 +1496,27 @@ class HUIRoot extends LitElement {
14891496
ha-tab-group-tab {
14901497
--ha-tab-group-tab-height: var(--header-height, 56px);
14911498
}
1499+
.tab-bar ha-tab-group-tab {
1500+
--ha-tab-group-tab-height: var(--tab-bar-height, 56px);
1501+
}
14921502
ha-tab-group-tab[aria-selected="true"] .edit-icon {
14931503
display: inline-flex;
14941504
}
1505+
14951506
ha-tab-group-tab::part(base) {
14961507
padding-inline-start: var(--ha-tab-padding-start, var(--wa-space-l));
14971508
padding-inline-end: var(--ha-tab-padding-end, var(--wa-space-l));
1498-
}
1499-
ha-tab-group-tab::part(base) {
15001509
padding-top: calc((var(--ha-tab-group-tab-height) - 20px) / 2);
15011510
}
1502-
ha-tab-group-tab.icon::part(base) {
1511+
ha-tab-group-tab.icon-only::part(base),
1512+
ha-tab-group-tab.icon-and-title::part(base) {
15031513
padding-top: calc((var(--ha-tab-group-tab-height) - 20px) / 2 - 2px);
15041514
padding-bottom: calc(
15051515
(var(--ha-tab-group-tab-height) - 20px) / 2 - 4px
15061516
);
15071517
}
1508-
.tab-bar ha-tab-group-tab {
1509-
--ha-tab-group-tab-height: var(--tab-bar-height, 56px);
1518+
ha-tab-group-tab.icon-and-title ha-icon {
1519+
margin-inline-end: var(--ha-space-2);
15101520
}
15111521
.edit-mode ha-tab-group-tab[aria-selected="true"]::part(base) {
15121522
padding: 0;

src/translations/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7603,13 +7603,15 @@
76037603
"sidebar": "Sidebar",
76047604
"panel": "Panel (single card)"
76057605
},
7606+
"show_icon_and_title": "Show icon and title",
76067607
"subview": "Subview",
76077608
"max_columns": "Max number of sections wide",
76087609
"section_specifics": "Sections view specific settings",
76097610
"dense_section_placement": "Dense section placement",
76107611
"dense_section_placement_helper": "Will try to fill gaps with sections that fit the gap. This may make section placement less predictable.",
76117612
"top_margin": "Add additional space above",
76127613
"top_margin_helper": "Helps reveal more of the background",
7614+
"show_icon_and_title_helper": "Show both icon and text title.",
76137615
"subview_helper": "Subviews don't appear in tabs and have a back button.",
76147616
"path_helper": "This value will become part of the URL path to open this view.",
76157617
"edit_ui": "Edit in visual editor",

0 commit comments

Comments
 (0)