mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-20 02:38:53 +00:00
Migrate cropper dialog to wa
This commit is contained in:
@@ -5,14 +5,20 @@ import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
|||||||
import { css, html, LitElement, nothing, unsafeCSS } from "lit";
|
import { css, html, LitElement, nothing, unsafeCSS } from "lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
import "../../components/ha-button";
|
import "../../components/ha-button";
|
||||||
import "../../components/ha-dialog";
|
import "../../components/ha-dialog-footer";
|
||||||
|
import "../../components/ha-wa-dialog";
|
||||||
import { haStyleDialog } from "../../resources/styles";
|
import { haStyleDialog } from "../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
|
import type { HassDialog } from "../make-dialog-manager";
|
||||||
import type { HaImageCropperDialogParams } from "./show-image-cropper-dialog";
|
import type { HaImageCropperDialogParams } from "./show-image-cropper-dialog";
|
||||||
|
|
||||||
@customElement("image-cropper-dialog")
|
@customElement("image-cropper-dialog")
|
||||||
export class HaImagecropperDialog extends LitElement {
|
export class HaImagecropperDialog
|
||||||
|
extends LitElement
|
||||||
|
implements HassDialog<HaImageCropperDialogParams>
|
||||||
|
{
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@state() private _params?: HaImageCropperDialogParams;
|
@state() private _params?: HaImageCropperDialogParams;
|
||||||
@@ -30,12 +36,17 @@ export class HaImagecropperDialog extends LitElement {
|
|||||||
this._open = true;
|
this._open = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public closeDialog() {
|
public closeDialog(): boolean {
|
||||||
this._open = false;
|
this._open = false;
|
||||||
this._params = undefined;
|
|
||||||
this._cropper?.destroy();
|
this._cropper?.destroy();
|
||||||
this._cropper = undefined;
|
this._cropper = undefined;
|
||||||
this._isTargetAspectRatio = false;
|
this._isTargetAspectRatio = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _dialogClosed(): void {
|
||||||
|
this._params = undefined;
|
||||||
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
}
|
}
|
||||||
|
|
||||||
protected updated(changedProperties: PropertyValues) {
|
protected updated(changedProperties: PropertyValues) {
|
||||||
@@ -78,41 +89,54 @@ export class HaImagecropperDialog extends LitElement {
|
|||||||
return Math.abs(targetWidth - imageData.naturalWidth) <= 1;
|
return Math.abs(targetWidth - imageData.naturalWidth) <= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult | typeof nothing {
|
||||||
return html`<ha-dialog
|
if (!this._params) {
|
||||||
@closed=${this.closeDialog}
|
return nothing;
|
||||||
scrimClickAction
|
}
|
||||||
escapeKeyAction
|
|
||||||
|
return html`
|
||||||
|
<ha-wa-dialog
|
||||||
|
.hass=${this.hass}
|
||||||
.open=${this._open}
|
.open=${this._open}
|
||||||
|
header-title=${this.hass.localize(
|
||||||
|
"ui.dialogs.image_cropper.crop_image"
|
||||||
|
)}
|
||||||
|
@closed=${this._dialogClosed}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="container ${classMap({
|
class="container ${classMap({
|
||||||
round: Boolean(this._params?.options.round),
|
round: Boolean(this._params?.options.round),
|
||||||
})}"
|
})}"
|
||||||
>
|
>
|
||||||
<img alt=${this.hass.localize("ui.dialogs.image_cropper.crop_image")} />
|
<img
|
||||||
|
alt=${this.hass.localize("ui.dialogs.image_cropper.crop_image")}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<ha-dialog-footer slot="footer">
|
||||||
<ha-button
|
<ha-button
|
||||||
|
slot="secondaryAction"
|
||||||
appearance="plain"
|
appearance="plain"
|
||||||
slot="primaryAction"
|
|
||||||
@click=${this.closeDialog}
|
@click=${this.closeDialog}
|
||||||
>
|
>
|
||||||
${this.hass.localize("ui.common.cancel")}
|
${this.hass.localize("ui.common.cancel")}
|
||||||
</ha-button>
|
</ha-button>
|
||||||
${this._isTargetAspectRatio
|
${this._isTargetAspectRatio
|
||||||
? html`<ha-button
|
? html`
|
||||||
|
<ha-button
|
||||||
|
slot="secondaryAction"
|
||||||
appearance="plain"
|
appearance="plain"
|
||||||
slot="primaryAction"
|
|
||||||
@click=${this._useOriginal}
|
@click=${this._useOriginal}
|
||||||
>
|
>
|
||||||
${this.hass.localize("ui.dialogs.image_cropper.use_original")}
|
${this.hass.localize("ui.dialogs.image_cropper.use_original")}
|
||||||
</ha-button>`
|
</ha-button>
|
||||||
|
`
|
||||||
: nothing}
|
: nothing}
|
||||||
|
|
||||||
<ha-button slot="primaryAction" @click=${this._cropImage}>
|
<ha-button slot="primaryAction" @click=${this._cropImage}>
|
||||||
${this.hass.localize("ui.dialogs.image_cropper.crop")}
|
${this.hass.localize("ui.dialogs.image_cropper.crop")}
|
||||||
</ha-button>
|
</ha-button>
|
||||||
</ha-dialog>`;
|
</ha-dialog-footer>
|
||||||
|
</ha-wa-dialog>
|
||||||
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _cropImage() {
|
private _cropImage() {
|
||||||
|
|||||||
Reference in New Issue
Block a user