rename file

This commit is contained in:
Paul Bottein 2022-12-01 17:25:18 +01:00
parent bfc1ec583a
commit 34f2d404b8
No known key found for this signature in database
4 changed files with 45 additions and 31 deletions

View File

@ -9,6 +9,7 @@ import {
unsafeCSS, unsafeCSS,
} from "lit"; } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
@customElement("ha-chip") @customElement("ha-chip")
export class HaChip extends LitElement { export class HaChip extends LitElement {
@ -18,9 +19,17 @@ export class HaChip extends LitElement {
@property({ type: Boolean }) public noText = false; @property({ type: Boolean }) public noText = false;
@property({ type: Boolean }) public outline = false;
protected render(): TemplateResult { protected render(): TemplateResult {
return html` return html`
<div class="mdc-chip ${this.noText ? "no-text" : ""}"> <div
class=${classMap({
"mdc-chip": true,
"no-text": this.noText,
outline: this.outline,
})}
>
${this.hasIcon ${this.hasIcon
? html`<div class="mdc-chip__icon mdc-chip__icon--leading"> ? html`<div class="mdc-chip__icon mdc-chip__icon--leading">
<slot name="icon"></slot> <slot name="icon"></slot>
@ -81,6 +90,11 @@ export class HaChip extends LitElement {
:host { :host {
outline: none; outline: none;
} }
.mdc-chip.outline {
background: none;
border: 1px solid rgba(var(--rgb-primary-text-color), 0.5);
}
`; `;
} }
} }

View File

@ -11,16 +11,17 @@ import { stateIconPath } from "../../common/entity/state_icon_path";
import "../../components/ha-chip"; import "../../components/ha-chip";
import "../../components/ha-chip-set"; import "../../components/ha-chip-set";
import "../../components/ha-icon"; import "../../components/ha-icon";
import "../../components/ha-svg-icon";
import { HomeAssistant } from "../../types"; import { HomeAssistant } from "../../types";
declare global { declare global {
interface HASSDomEvents { interface HASSDomEvents {
"related-entity": { entityId: string }; "shortcut-clicked": { entityId: string };
} }
} }
@customElement("more-info-related-info") @customElement("ha-more-info-device-entities-shortcuts")
class MoreInfoContent extends LitElement { class MoreInfoDevicesEntitiesShortcuts extends LitElement {
@property({ attribute: false }) public hass?: HomeAssistant; @property({ attribute: false }) public hass?: HomeAssistant;
@property({ attribute: false }) public stateObj?: HassEntity; @property({ attribute: false }) public stateObj?: HassEntity;
@ -37,9 +38,15 @@ class MoreInfoContent extends LitElement {
); );
}); });
private _handleChipClick(ev: Event) { private _handleChipClick(ev) {
if (ev.defaultPrevented) {
return;
}
if (ev.type === "keydown" && ev.key !== "Enter" && ev.key !== " ") {
return;
}
const entityId = (ev.target as any).entityId as string; const entityId = (ev.target as any).entityId as string;
fireEvent(this, "related-entity", { entityId }); fireEvent(this, "shortcut-clicked", { entityId });
} }
protected render(): TemplateResult | null { protected render(): TemplateResult | null {
@ -72,6 +79,7 @@ class MoreInfoContent extends LitElement {
const icon = stateObj.attributes.icon; const icon = stateObj.attributes.icon;
const iconPath = stateIconPath(stateObj); const iconPath = stateIconPath(stateObj);
const state = computeStateDisplay( const state = computeStateDisplay(
this.hass!.localize, this.hass!.localize,
stateObj, stateObj,
@ -82,7 +90,7 @@ class MoreInfoContent extends LitElement {
const active = stateActive(stateObj); const active = stateActive(stateObj);
const iconStyle = styleMap({ const iconStyle = styleMap({
"--icon-color": "--ha-chip-icon-color":
color && active color && active
? `rgb(var(--rgb-state-${color}-color))` ? `rgb(var(--rgb-state-${color}-color))`
: undefined, : undefined,
@ -91,14 +99,17 @@ class MoreInfoContent extends LitElement {
const name = stateObj.attributes.friendly_name ?? ""; const name = stateObj.attributes.friendly_name ?? "";
return html` return html`
<button <ha-chip
outline
role="button"
type="button" type="button"
class="chip"
@click=${this._handleChipClick} @click=${this._handleChipClick}
@keydown=${this._handleChipClick}
.entityId=${stateObj.entity_id} .entityId=${stateObj.entity_id}
aria-label=${name} aria-label=${name}
.title=${name} .title=${name}
style=${iconStyle} style=${iconStyle}
hasIcon
> >
${icon ${icon
? html`<ha-icon slot="icon" .icon=${icon}></ha-icon>` ? html`<ha-icon slot="icon" .icon=${icon}></ha-icon>`
@ -106,7 +117,7 @@ class MoreInfoContent extends LitElement {
<ha-svg-icon slot="icon" .path=${iconPath}></ha-svg-icon> <ha-svg-icon slot="icon" .path=${iconPath}></ha-svg-icon>
`} `}
${state} ${state}
</button> </ha-chip>
`; `;
})} })}
</div> </div>
@ -126,24 +137,13 @@ class MoreInfoContent extends LitElement {
.container > * { .container > * {
margin: 4px; margin: 4px;
} }
.chip { ha-chip {
border: 1px solid var(--secondary-text-color);
border-radius: 8px;
cursor: pointer; cursor: pointer;
background: none; --ha-chip-icon-color: rgb(var(--rgb-state-default-color));
color: var(--primary-text-color);
padding: 6px 16px 6px 8px;
font-weight: 500;
font-size: 14px;
line-height: 20px;
--icon-color: rgb(var(--rgb-state-default-color));
} }
.chip ha-icon, ha-chip ha-icon,
.chip ha-svg-icon { ha-chip ha-svg-icon {
color: var(--icon-color);
pointer-events: none; pointer-events: none;
--mdc-icon-size: 18px;
color: var(--icon-color);
} }
`; `;
} }
@ -151,6 +151,6 @@ class MoreInfoContent extends LitElement {
declare global { declare global {
interface HTMLElementTagNameMap { interface HTMLElementTagNameMap {
"more-info-related-info": MoreInfoContent; "ha-more-info-device-entities-shortcuts": MoreInfoDevicesEntitiesShortcuts;
} }
} }

View File

@ -62,7 +62,7 @@ export class MoreInfoDialog extends LitElement {
fireEvent(this, "dialog-closed", { dialog: this.localName }); fireEvent(this, "dialog-closed", { dialog: this.localName });
} }
private _relatedEntityClicked(ev: CustomEvent) { private _entityShortcutClicked(ev: CustomEvent) {
ev.stopPropagation(); ev.stopPropagation();
this._entityId = ev.detail.entityId; this._entityId = ev.detail.entityId;
} }
@ -165,7 +165,7 @@ export class MoreInfoDialog extends LitElement {
<ha-more-info-info <ha-more-info-info
.hass=${this.hass} .hass=${this.hass}
.entityId=${this._entityId} .entityId=${this._entityId}
@related-entity=${this._relatedEntityClicked} @shortcut-clicked=${this._entityShortcutClicked}
></ha-more-info-info> ></ha-more-info-info>
` `
: this._currTab === "history" : this._currTab === "history"

View File

@ -13,9 +13,9 @@ import {
DOMAINS_NO_INFO, DOMAINS_NO_INFO,
DOMAINS_WITH_MORE_INFO, DOMAINS_WITH_MORE_INFO,
} from "./const"; } from "./const";
import "./ha-more-info-device-entities-shortcuts";
import "./ha-more-info-history"; import "./ha-more-info-history";
import "./ha-more-info-logbook"; import "./ha-more-info-logbook";
import "./more-info-related-info";
@customElement("ha-more-info-info") @customElement("ha-more-info-info")
export class MoreInfoInfo extends LitElement { export class MoreInfoInfo extends LitElement {
@ -71,10 +71,10 @@ export class MoreInfoInfo extends LitElement {
.hass=${this.hass} .hass=${this.hass}
.entityId=${this.entityId} .entityId=${this.entityId}
></ha-more-info-logbook>`} ></ha-more-info-logbook>`}
<more-info-content <ha-more-info-device-entities-shortcuts
.stateObj=${stateObj} .stateObj=${stateObj}
.hass=${this.hass} .hass=${this.hass}
></more-info-content> ></ha-more-info-device-entities-shortcuts>
<more-info-related-info .stateObj=${stateObj} .hass=${this.hass}> <more-info-related-info .stateObj=${stateObj} .hass=${this.hass}>
</more-info-related-info> </more-info-related-info>
`; `;