Add style support.
This commit is contained in:
+17
-12
@@ -64,7 +64,10 @@ export class FrigateCardMenu extends LitElement {
|
|||||||
* @param ev The action event.
|
* @param ev The action event.
|
||||||
* @param button The button configuration.
|
* @param button The button configuration.
|
||||||
*/
|
*/
|
||||||
protected _actionHandler(ev: CustomEvent<{action: string, config?: Actions}>, config?: Actions): void {
|
protected _actionHandler(
|
||||||
|
ev: CustomEvent<{ action: string; config?: Actions }>,
|
||||||
|
config?: Actions,
|
||||||
|
): void {
|
||||||
if (!ev) {
|
if (!ev) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -145,10 +148,18 @@ export class FrigateCardMenu extends LitElement {
|
|||||||
* @returns A rendered template or void.
|
* @returns A rendered template or void.
|
||||||
*/
|
*/
|
||||||
protected _renderButton(button: MenuButton): TemplateResult | void {
|
protected _renderButton(button: MenuButton): TemplateResult | void {
|
||||||
|
if (button.type == 'custom:frigate-card-menu-submenu') {
|
||||||
|
return html` <frigate-card-submenu
|
||||||
|
.submenu=${button}
|
||||||
|
@action=${this._actionHandler.bind(this)}
|
||||||
|
>
|
||||||
|
</frigate-card-submenu>`;
|
||||||
|
}
|
||||||
|
|
||||||
let state: HassEntity | null = null;
|
let state: HassEntity | null = null;
|
||||||
let title = button.title;
|
let title = button.title;
|
||||||
let icon = button.icon;
|
let icon = button.icon;
|
||||||
let style = ('style' in button ? button.style : {}) || {};
|
let style = button.style || {};
|
||||||
|
|
||||||
if (icon == FRIGATE_BUTTON_MENU_ICON) {
|
if (icon == FRIGATE_BUTTON_MENU_ICON) {
|
||||||
icon =
|
icon =
|
||||||
@@ -180,15 +191,6 @@ export class FrigateCardMenu extends LitElement {
|
|||||||
button: true,
|
button: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (button.type == 'custom:frigate-card-menu-submenu') {
|
|
||||||
return html`
|
|
||||||
<frigate-card-submenu
|
|
||||||
.submenu=${button}
|
|
||||||
@action=${this._actionHandler.bind(this)}
|
|
||||||
>
|
|
||||||
</frigate-card-submenu>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Upon a safe distance from the release of HA 2021.11 these
|
// TODO: Upon a safe distance from the release of HA 2021.11 these
|
||||||
// attributes can be removed from the <ha-icon-button>.
|
// attributes can be removed from the <ha-icon-button>.
|
||||||
// - icon (replaced with the embedded <ha-icon>)
|
// - icon (replaced with the embedded <ha-icon>)
|
||||||
@@ -219,7 +221,10 @@ export class FrigateCardMenu extends LitElement {
|
|||||||
}
|
}
|
||||||
const mode = this._menuConfig.mode;
|
const mode = this._menuConfig.mode;
|
||||||
|
|
||||||
if (mode == 'none' || !evaluateCondition(this._menuConfig.conditions, this.conditionState)) {
|
if (
|
||||||
|
mode == 'none' ||
|
||||||
|
!evaluateCondition(this._menuConfig.conditions, this.conditionState)
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { MenuSubmenu } from '../types.js';
|
|||||||
|
|
||||||
import submenuStyle from '../scss/submenu.scss';
|
import submenuStyle from '../scss/submenu.scss';
|
||||||
import { hasAction } from 'custom-card-helpers';
|
import { hasAction } from 'custom-card-helpers';
|
||||||
|
import { styleMap } from 'lit/directives/style-map';
|
||||||
|
|
||||||
@customElement('frigate-card-submenu')
|
@customElement('frigate-card-submenu')
|
||||||
export class FrigateCardSubmenu extends LitElement {
|
export class FrigateCardSubmenu extends LitElement {
|
||||||
@@ -19,6 +20,7 @@ export class FrigateCardSubmenu extends LitElement {
|
|||||||
return html`
|
return html`
|
||||||
<ha-button-menu corner="BOTTOM_LEFT">
|
<ha-button-menu corner="BOTTOM_LEFT">
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
|
style="${styleMap(this.submenu.style || {})}"
|
||||||
class="button"
|
class="button"
|
||||||
slot="trigger"
|
slot="trigger"
|
||||||
.label=${this.submenu.title || ''}
|
.label=${this.submenu.title || ''}
|
||||||
@@ -32,6 +34,7 @@ export class FrigateCardSubmenu extends LitElement {
|
|||||||
${this.submenu.items.map(
|
${this.submenu.items.map(
|
||||||
(item) => html`
|
(item) => html`
|
||||||
<mwc-list-item
|
<mwc-list-item
|
||||||
|
style="${styleMap(item.style || {})}"
|
||||||
graphic="icon"
|
graphic="icon"
|
||||||
aria-label="${item.title || ''}"
|
aria-label="${item.title || ''}"
|
||||||
@action=${(ev) => {
|
@action=${(ev) => {
|
||||||
@@ -45,7 +48,12 @@ export class FrigateCardSubmenu extends LitElement {
|
|||||||
>
|
>
|
||||||
${item.title || ''}
|
${item.title || ''}
|
||||||
${item.icon
|
${item.icon
|
||||||
? html` <ha-icon slot="graphic" icon="${item.icon}"> </ha-icon>`
|
? html` <ha-icon
|
||||||
|
style="${styleMap(item.style || {})}"
|
||||||
|
slot="graphic"
|
||||||
|
icon="${item.icon}"
|
||||||
|
>
|
||||||
|
</ha-icon>`
|
||||||
: ``}
|
: ``}
|
||||||
</mwc-list-item>
|
</mwc-list-item>
|
||||||
`,
|
`,
|
||||||
|
|||||||
Reference in New Issue
Block a user