Merge pull request #650 from dermotduffy/editor.border

Improve editor submenu styling
This commit is contained in:
Dermot Duffy
2022-06-08 19:12:01 -07:00
committed by GitHub
2 changed files with 270 additions and 255 deletions
+42 -38
View File
@@ -1,6 +1,7 @@
import { fireEvent, HomeAssistant, LovelaceCardEditor } from 'custom-card-helpers'; import { fireEvent, HomeAssistant, LovelaceCardEditor } from 'custom-card-helpers';
import { CSSResultGroup, html, LitElement, TemplateResult, unsafeCSS } from 'lit'; import { CSSResultGroup, html, LitElement, TemplateResult, unsafeCSS } from 'lit';
import { customElement, property, state } from 'lit/decorators.js'; import { customElement, property, state } from 'lit/decorators.js';
import { classMap } from 'lit/directives/class-map.js';
import { import {
copyConfig, copyConfig,
deleteConfigValue, deleteConfigValue,
@@ -598,7 +599,12 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
} }
protected _renderViewScanMenu(): TemplateResult { protected _renderViewScanMenu(): TemplateResult {
const submenuClasses = {
submenu: true,
selected: !!this._expandedMenus[MENU_VIEW_SCAN],
};
return html` return html`
<div class="${classMap(submenuClasses)}">
<div <div
class="submenu-header" class="submenu-header"
@click=${this._toggleMenu} @click=${this._toggleMenu}
@@ -633,6 +639,7 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
})} })}
</div>` </div>`
: ''} : ''}
</div>
`; `;
} }
@@ -647,8 +654,13 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
{ value: 'matching', label: localize('config.menu.buttons.alignments.matching') }, { value: 'matching', label: localize('config.menu.buttons.alignments.matching') },
{ value: 'opposing', label: localize('config.menu.buttons.alignments.opposing') }, { value: 'opposing', label: localize('config.menu.buttons.alignments.opposing') },
]; ];
const submenuClasses = {
submenu: true,
selected: this._expandedMenus[MENU_BUTTONS] === button,
};
return html` return html`
<div class="${classMap(submenuClasses)}">
<div <div
class="submenu-header" class="submenu-header"
@click=${this._toggleMenu} @click=${this._toggleMenu}
@@ -689,38 +701,6 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
})} })}
</div>` </div>`
: ''} : ''}
`;
}
/**
* Render a camera header.
* @param cameraIndex The index of the camera to edit/add.
* @param cameraConfig The configuration of the camera in question.
* @param addNewCamera Whether or not this is a header to add a new camera.
* @returns A rendered template.
*/
protected _renderCameraHeader(
cameraIndex: number,
cameraConfig?: RawFrigateCardConfig,
addNewCamera?: boolean,
): TemplateResult {
return html`
<div
class="submenu-header"
@click=${this._toggleMenu}
.domain=${MENU_CAMERAS}
.key=${cameraIndex}
>
<ha-icon .icon=${addNewCamera ? 'mdi:video-plus' : 'mdi:video'}></ha-icon>
<span>
${addNewCamera
? html` <span class="new-camera">
[${localize('editor.add_new_camera')}...]
</span>`
: html`<span
>${this._getEditorCameraTitle(cameraIndex, cameraConfig || {})}</span
>`}
</span>
</div> </div>
`; `;
} }
@@ -772,8 +752,33 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
} }
}; };
const submenuClasses = {
submenu: true,
selected: this._expandedMenus[MENU_CAMERAS] === cameraIndex,
};
return html` return html`
${this._renderCameraHeader(cameraIndex, cameras[cameraIndex], addNewCamera)} <div class="${classMap(submenuClasses)}">
<div
class="submenu-header"
@click=${this._toggleMenu}
.domain=${MENU_CAMERAS}
.key=${cameraIndex}
>
<ha-icon .icon=${addNewCamera ? 'mdi:video-plus' : 'mdi:video'}></ha-icon>
<span>
${addNewCamera
? html` <span class="new-camera">
[${localize('editor.add_new_camera')}...]
</span>`
: html`<span
>${this._getEditorCameraTitle(
cameraIndex,
cameras[cameraIndex] || {},
)}</span
>`}
</span>
</div>
${this._expandedMenus[MENU_CAMERAS] === cameraIndex ${this._expandedMenus[MENU_CAMERAS] === cameraIndex
? html` <div class="values"> ? html` <div class="values">
<div class="controls"> <div class="controls">
@@ -901,6 +906,7 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
)} )}
</div>` </div>`
: ``} : ``}
</div>
`; `;
} }
@@ -1014,10 +1020,10 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
<div class="card-config"> <div class="card-config">
${this._renderOptionSetHeader('cameras')} ${this._renderOptionSetHeader('cameras')}
${this._expandedMenus[MENU_OPTIONS] === 'cameras' ${this._expandedMenus[MENU_OPTIONS] === 'cameras'
? html` <div class="submenu"> ? html`
${cameras.map((_, index) => this._renderCamera(cameras, index, entities))} ${cameras.map((_, index) => this._renderCamera(cameras, index, entities))}
${this._renderCamera(cameras, cameras.length, entities, true)} ${this._renderCamera(cameras, cameras.length, entities, true)}
</div>` `
: ''} : ''}
${this._renderOptionSetHeader('view')} ${this._renderOptionSetHeader('view')}
${this._expandedMenus[MENU_OPTIONS] === 'view' ${this._expandedMenus[MENU_OPTIONS] === 'view'
@@ -1051,7 +1057,6 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
min: BUTTON_SIZE_MIN, min: BUTTON_SIZE_MIN,
})} })}
</div> </div>
<div class="submenu">
${this._renderMenuButton('frigate') /* */} ${this._renderMenuButton('frigate') /* */}
${this._renderMenuButton('cameras') /* */} ${this._renderMenuButton('cameras') /* */}
${this._renderMenuButton('live') /* */} ${this._renderMenuButton('live') /* */}
@@ -1063,7 +1068,6 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
${this._renderMenuButton('fullscreen')} ${this._renderMenuButton('fullscreen')}
${this._renderMenuButton('timeline')} ${this._renderMenuButton('timeline')}
${this._renderMenuButton('media_player')} ${this._renderMenuButton('media_player')}
</div>
` `
: ''} : ''}
${this._renderOptionSetHeader('live')} ${this._renderOptionSetHeader('live')}
@@ -1305,7 +1309,7 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor
const domain = ev.target.domain; const domain = ev.target.domain;
const key = ev.target.key; const key = ev.target.key;
if (this._expandedMenus[domain] == key) { if (this._expandedMenus[domain] === key) {
this._closeMenu(domain); this._closeMenu(domain);
} else { } else {
this._openMenu(domain, key); this._openMenu(domain, key);
+19 -8
View File
@@ -23,10 +23,8 @@
pointer-events: none; pointer-events: none;
} }
.values { .values {
padding: 10px;
background: var(--secondary-background-color); background: var(--secondary-background-color);
display: grid; display: grid;
margin-bottom: 10px;
} }
div.upgrade { div.upgrade {
width: auto; width: auto;
@@ -42,26 +40,39 @@ div.upgrade span {
.submenu-header { .submenu-header {
display: flex; display: flex;
margin-top: 10px; padding: 10px;
cursor: pointer; cursor: pointer;
} }
.submenu.selected .submenu-header {
background-color: var(--primary-color);
color: var(--primary-text-color);
}
.submenu-header * { .submenu-header * {
flex-basis: auto; flex-basis: auto;
// Only allow clicks on the header. // Only allow clicks on the header.
pointer-events: none; pointer-events: none;
} }
.submenu-header ha-icon {
padding-right: 10px;
}
.submenu-header .new-camera { .submenu-header .new-camera {
font-style: italic; font-style: italic;
}
.submenu:not(.selected) .submenu-header .new-camera {
color: var(--secondary-text-color, 'black'); color: var(--secondary-text-color, 'black');
} }
.submenu {
margin: 5px 5px 10px 20px; .submenu-header ha-icon {
padding-right: 15px;
} }
.submenu {
border: 1px solid var(--divider-color);
}
.submenu.selected {
border: 1px solid var(--primary-color);
}
.submenu .controls { .submenu .controls {
display: inline-block; display: inline-block;
margin-left: auto; margin-left: auto;