import "@polymer/paper-dialog-scrollable/paper-dialog-scrollable"; import "@polymer/paper-input/paper-input"; import { css, CSSResult, customElement, html, LitElement, property, TemplateResult, } from "lit-element"; import { classMap } from "lit-html/directives/class-map"; import "../../components/dialog/ha-paper-dialog"; import "../../components/ha-switch"; import { PolymerChangedEvent } from "../../polymer-types"; import { haStyleDialog } from "../../resources/styles"; import { HomeAssistant } from "../../types"; import { DialogParams } from "./show-dialog-box"; @customElement("dialog-box") class DialogBox extends LitElement { @property() public hass!: HomeAssistant; @property() private _params?: DialogParams; @property() private _value?: string; public async showDialog(params: DialogParams): Promise { this._params = params; if (params.prompt) { this._value = params.defaultValue; } } protected render(): TemplateResult { if (!this._params) { return html``; } const confirmPrompt = this._params.confirmation || this._params.prompt; return html`

${this._params.title ? this._params.title : this._params.confirmation && this.hass.localize( "ui.dialogs.generic.default_confirmation_title" )}

${this._params.text ? html`

${this._params.text}

` : ""} ${this._params.prompt ? html` ` : ""}
${confirmPrompt && html` ${this._params.dismissText ? this._params.dismissText : this.hass.localize("ui.dialogs.generic.cancel")} `} ${this._params.confirmText ? this._params.confirmText : this.hass.localize("ui.dialogs.generic.ok")}
`; } private _valueChanged(ev: PolymerChangedEvent) { this._value = ev.detail.value; } private async _dismiss(): Promise { if (this._params!.cancel) { this._params!.cancel(); } this._params = undefined; } private _handleKeyUp(ev: KeyboardEvent) { if (ev.keyCode === 13) { this._confirm(); } } private async _confirm(): Promise { if (this._params!.confirm) { this._params!.confirm(this._value); } this._dismiss(); } private _openedChanged(ev: PolymerChangedEvent): void { if (!(ev.detail as any).value) { this._params = undefined; } } static get styles(): CSSResult[] { return [ haStyleDialog, css` :host([inert]) { pointer-events: initial !important; cursor: initial !important; } ha-paper-dialog { min-width: 400px; max-width: 500px; } @media (max-width: 400px) { ha-paper-dialog { min-width: initial; } } a { color: var(--primary-color); } p { margin: 0; padding-top: 6px; padding-bottom: 24px; color: var(--primary-text-color); } .no-bottom-padding { padding-bottom: 0; } .secondary { color: var(--secondary-text-color); } `, ]; } } declare global { interface HTMLElementTagNameMap { "dialog-box": DialogBox; } }