-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3eaf4fc
commit 3507524
Showing
4 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { html, TemplateResult, PropertyValues } from "lit"; | ||
import { customElement, property } from "lit/decorators"; | ||
import "./hacs-dialog"; | ||
import { HacsDialogBase } from "./hacs-dialog-base"; | ||
|
||
@customElement("hacs-progress-dialog") | ||
export class HacsProgressDialog extends HacsDialogBase { | ||
@property() public title?: string; | ||
@property() public content?: string; | ||
@property() public confirmText?: string; | ||
@property() public confirm: () => Promise<void>; | ||
@property({ type: Boolean }) private _inProgress: boolean = false; | ||
|
||
shouldUpdate(changedProperties: PropertyValues) { | ||
return ( | ||
changedProperties.has("active") || | ||
changedProperties.has("title") || | ||
changedProperties.has("content") || | ||
changedProperties.has("confirmText") || | ||
changedProperties.has("confirm") || | ||
changedProperties.has("_inProgress") | ||
); | ||
} | ||
|
||
protected render(): TemplateResult | void { | ||
if (!this.active) return html``; | ||
return html` | ||
<hacs-dialog .active=${this.active} .hass=${this.hass} title=${this.title || ""}> | ||
<div class="content"> | ||
${this.content || ""} | ||
</div> | ||
<mwc-button slot="secondaryaction" ?disabled=${this._inProgress} @click=${this._close}> | ||
${this.hacs.localize("common.cancel")} | ||
</mwc-button> | ||
<mwc-button slot="primaryaction" @click=${this._confirmed}> | ||
${this._inProgress | ||
? html`<ha-circular-progress active size="small"></ha-circular-progress>` | ||
: this.confirmText || this.hacs.localize("confirm.yes")}</mwc-button | ||
> | ||
</mwc-button> | ||
</hacs-dialog> | ||
`; | ||
} | ||
|
||
private async _confirmed() { | ||
this._inProgress = true; | ||
await this.confirm() | ||
this._inProgress = false; | ||
this._close() | ||
} | ||
|
||
private _close() { | ||
this.active = false; | ||
this.dispatchEvent( | ||
new Event("hacs-dialog-closed", { | ||
bubbles: true, | ||
composed: true, | ||
}) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters