Add warning and error methods. Refactor types (#26)
* Add warning and error methods. Refactor types * Remove obsolete CSS style
This commit is contained in:
+24
-19
@@ -7,6 +7,7 @@ import {
|
|||||||
handleAction,
|
handleAction,
|
||||||
LovelaceCardEditor,
|
LovelaceCardEditor,
|
||||||
getLovelace,
|
getLovelace,
|
||||||
|
LovelaceCard,
|
||||||
} from 'custom-card-helpers';
|
} from 'custom-card-helpers';
|
||||||
|
|
||||||
import './editor';
|
import './editor';
|
||||||
@@ -43,8 +44,8 @@ export class BoilerplateCard extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO Add any properities that should cause your element to re-render here
|
// TODO Add any properities that should cause your element to re-render here
|
||||||
@property() public hass?: HomeAssistant;
|
@property() public hass!: HomeAssistant;
|
||||||
@property() private _config?: BoilerplateCardConfig;
|
@property() private _config!: BoilerplateCardConfig;
|
||||||
|
|
||||||
public setConfig(config: BoilerplateCardConfig): void {
|
public setConfig(config: BoilerplateCardConfig): void {
|
||||||
// TODO Check for required fields and that they are of the proper format
|
// TODO Check for required fields and that they are of the proper format
|
||||||
@@ -67,17 +68,9 @@ export class BoilerplateCard extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult | void {
|
protected render(): TemplateResult | void {
|
||||||
if (!this._config || !this.hass) {
|
|
||||||
return html``;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO Check for stateObj or other necessary things and render a warning if missing
|
// TODO Check for stateObj or other necessary things and render a warning if missing
|
||||||
if (this._config.show_warning) {
|
if (this._config.show_warning) {
|
||||||
return html`
|
return this.showWarning(localize('common.show_warning'));
|
||||||
<ha-card>
|
|
||||||
<div class="warning">${localize('common.show_warning')}</div>
|
|
||||||
</ha-card>
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
@@ -100,14 +93,26 @@ export class BoilerplateCard extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static get styles(): CSSResult {
|
private showWarning(warning: string): TemplateResult {
|
||||||
return css`
|
return html`
|
||||||
.warning {
|
<hui-warning>${warning}</hui-warning>
|
||||||
display: block;
|
|
||||||
color: black;
|
|
||||||
background-color: #fce588;
|
|
||||||
padding: 8px;
|
|
||||||
}
|
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private showError(error: string): TemplateResult {
|
||||||
|
const errorCard = document.createElement('hui-error-card') as LovelaceCard;
|
||||||
|
errorCard.setConfig({
|
||||||
|
type: 'error',
|
||||||
|
error,
|
||||||
|
origConfig: this._config,
|
||||||
|
});
|
||||||
|
|
||||||
|
return html`
|
||||||
|
${errorCard}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles(): CSSResult {
|
||||||
|
return css``;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
import { ActionConfig } from 'custom-card-helpers';
|
import { ActionConfig, LovelaceCardConfig } from 'custom-card-helpers';
|
||||||
|
|
||||||
// TODO Add your configuration elements here for type-checking
|
// TODO Add your configuration elements here for type-checking
|
||||||
export interface BoilerplateCardConfig {
|
export interface BoilerplateCardConfig extends LovelaceCardConfig {
|
||||||
type: string;
|
type: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
show_warning?: boolean;
|
show_warning?: boolean;
|
||||||
|
|||||||
Reference in New Issue
Block a user