Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add view header #24237

Open
wants to merge 33 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
69ca428
Create basic section heading
piitaya Feb 6, 2025
1508b51
Update badge position
piitaya Feb 6, 2025
2be5457
Don't allow to move card
piitaya Feb 10, 2025
be6f213
Remove view badges in section
piitaya Feb 11, 2025
308d5b8
Improve heading section UX
piitaya Feb 13, 2025
28e1b88
Add basic editor for heading section
piitaya Feb 13, 2025
e6fa425
Add badges position option
piitaya Feb 14, 2025
f1e922f
Add layout and badge position
piitaya Feb 14, 2025
61c6ae2
Improve button
piitaya Feb 17, 2025
37494e9
Use layout
piitaya Feb 17, 2025
9f20308
Simplify edit mode
piitaya Feb 17, 2025
5e59fbd
Fix CSS
piitaya Feb 17, 2025
ca51ed8
Fix add heading button
piitaya Feb 17, 2025
eb6ecf6
Improve badges
piitaya Feb 17, 2025
9185b08
Rename to extra space
piitaya Feb 17, 2025
236fdc3
Fix add top badge position
piitaya Feb 17, 2025
1184600
Add migration
piitaya Feb 17, 2025
bfd86e6
Fix delete section confirmation
piitaya Feb 17, 2025
c9effc5
Add translations
piitaya Feb 17, 2025
cfe55bc
Update comment
piitaya Feb 17, 2025
71b6027
Add header config to view
piitaya Feb 19, 2025
34209d7
Add edit card overlay
piitaya Feb 19, 2025
5852a12
Remove badge support for sections
piitaya Feb 19, 2025
6e59518
Remove section badges
piitaya Feb 19, 2025
aee84ce
Clean section
piitaya Feb 19, 2025
1740bd8
Fix header visibility
piitaya Feb 19, 2025
141d1b1
Update translations
piitaya Feb 19, 2025
1e7ea43
Add view header editor
piitaya Feb 20, 2025
4723919
Use new markdown card option
piitaya Feb 20, 2025
6ccd497
Revert useless changes
piitaya Feb 20, 2025
f8aab92
Add options translations
piitaya Feb 20, 2025
4faa1b3
Use edit dialog
piitaya Feb 20, 2025
e90f2f7
Unify font
piitaya Feb 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/data/lovelace/config/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export interface LovelaceViewBackgroundConfig {
attachment?: "scroll" | "fixed";
}

export interface LovelaceViewHeaderConfig {
card?: LovelaceCardConfig;
layout?: "start" | "center" | "responsive";
badges_position?: "bottom" | "top";
extra_space?: boolean;
}

export interface LovelaceBaseViewConfig {
index?: number;
title?: string;
Expand All @@ -46,6 +53,7 @@ export interface LovelaceViewConfig extends LovelaceBaseViewConfig {
badges?: (string | Partial<LovelaceBadgeConfig>)[]; // Badge can be just an entity_id or without type
cards?: LovelaceCardConfig[];
sections?: LovelaceSectionRawConfig[];
header?: LovelaceViewHeaderConfig;
}

export interface LovelaceStrategyViewConfig extends LovelaceBaseViewConfig {
Expand Down
56 changes: 39 additions & 17 deletions src/panels/lovelace/badges/hui-view-badges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import "../../../components/ha-svg-icon";
import type { HomeAssistant } from "../../../types";
import "../components/hui-badge-edit-mode";
import { moveBadge } from "../editor/config-util";
import type { LovelaceCardPath } from "../editor/lovelace-path";
import type { Lovelace } from "../types";
import type { HuiBadge } from "./hui-badge";

Expand Down Expand Up @@ -89,6 +90,20 @@ export class HuiViewBadges extends LitElement {
this.lovelace!.saveConfig(newConfig);
}

private _badgeAdded(ev) {
ev.stopPropagation();
const { index, data } = ev.detail;
const oldPath = data as LovelaceCardPath;
const newPath = [this.viewIndex!, index] as LovelaceCardPath;
const newConfig = moveBadge(this.lovelace!.config, oldPath, newPath);
this.lovelace!.saveConfig(newConfig);
}

private _badgeRemoved(ev) {
ev.stopPropagation();
// Do nothing, it's handle by the "item-added" event from the new parent.
}

private _dragStart() {
this._dragging = true;
}
Expand All @@ -114,6 +129,8 @@ export class HuiViewBadges extends LitElement {
<ha-sortable
.disabled=${!editMode}
@item-moved=${this._badgeMoved}
@item-added=${this._badgeAdded}
@item-removed=${this._badgeRemoved}
@drag-start=${this._dragStart}
@drag-end=${this._dragEnd}
group="badge"
Expand All @@ -126,21 +143,25 @@ export class HuiViewBadges extends LitElement {
${repeat(
badges,
(badge) => this._getBadgeKey(badge),
(badge, idx) => html`
${editMode
? html`
<hui-badge-edit-mode
data-sortable
.hass=${this.hass}
.lovelace=${this.lovelace}
.path=${[this.viewIndex, idx]}
.hiddenOverlay=${this._dragging}
>
${badge}
</hui-badge-edit-mode>
`
: badge}
`
(badge, idx) => {
const badgePath = [this.viewIndex, idx] as LovelaceCardPath;
return html`
${editMode
? html`
<hui-badge-edit-mode
data-sortable
.hass=${this.hass}
.lovelace=${this.lovelace}
.path=${[this.viewIndex, idx]}
.hiddenOverlay=${this._dragging}
.sortableData=${badgePath}
>
${badge}
</hui-badge-edit-mode>
`
: badge}
`;
}
)}
${editMode
? html`
Expand Down Expand Up @@ -179,8 +200,8 @@ export class HuiViewBadges extends LitElement {
.badges {
display: flex;
align-items: flex-start;
flex-wrap: wrap;
justify-content: center;
flex-wrap: var(--badges-wrap, wrap);
justify-content: var(--badges-aligmnent, center);
gap: 8px;
margin: 0;
}
Expand All @@ -197,6 +218,7 @@ export class HuiViewBadges extends LitElement {
display: flex;
flex-direction: row;
align-items: center;
outline: none;
gap: 8px;
height: 36px;
padding: 6px 20px 6px 20px;
Expand Down
53 changes: 36 additions & 17 deletions src/panels/lovelace/components/hui-card-edit-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export class HuiCardEditMode extends LitElement {
@property({ type: Boolean, attribute: "no-duplicate" })
public noDuplicate = false;

@property({ type: Boolean, attribute: "no-move" })
public noMove = false;

@state()
public _menuOpened = false;

Expand Down Expand Up @@ -179,23 +182,39 @@ export class HuiCardEditMode extends LitElement {
)}
</ha-list-item>
`}
<ha-list-item
graphic="icon"
@click=${this._handleAction}
.action=${"copy"}
>
<ha-svg-icon slot="graphic" .path=${mdiContentCopy}></ha-svg-icon>
${this.hass.localize("ui.panel.lovelace.editor.edit_card.copy")}
</ha-list-item>
<ha-list-item
graphic="icon"
@click=${this._handleAction}
.action=${"cut"}
>
<ha-svg-icon slot="graphic" .path=${mdiContentCut}></ha-svg-icon>
${this.hass.localize("ui.panel.lovelace.editor.edit_card.cut")}
</ha-list-item>
<li divider role="separator"></li>
${this.noMove
? nothing
: html`
<ha-list-item
graphic="icon"
@click=${this._handleAction}
.action=${"copy"}
>
<ha-svg-icon
slot="graphic"
.path=${mdiContentCopy}
></ha-svg-icon>
${this.hass.localize(
"ui.panel.lovelace.editor.edit_card.copy"
)}
</ha-list-item>
<ha-list-item
graphic="icon"
@click=${this._handleAction}
.action=${"cut"}
>
<ha-svg-icon
slot="graphic"
.path=${mdiContentCut}
></ha-svg-icon>
${this.hass.localize(
"ui.panel.lovelace.editor.edit_card.cut"
)}
</ha-list-item>
`}
${this.noDuplicate && this.noEdit && this.noMove
? nothing
: html`<li divider role="separator"></li>`}
<ha-list-item
graphic="icon"
class="warning"
Expand Down
Loading
Loading