Compare commits

...

31 Commits

Author SHA1 Message Date
Paul Bottein
71ad83b660 Compensate mobile margin 2025-11-27 20:22:46 +01:00
Paul Bottein
44c366f5f8 Add rtl support 2025-11-27 20:16:20 +01:00
Aidan Timson
af7c6d9f03 Restore old fullscreen heights 2025-11-27 17:00:06 +00:00
Aidan Timson
2ee6b2c89d Explain transform 2025-11-27 16:18:13 +00:00
Aidan Timson
c7a955367f Fix fullscreen 2025-11-27 16:12:54 +00:00
Aidan Timson
20fc34dc5f Remove clamp on safe areas 2025-11-27 15:49:44 +00:00
Aidan Timson
9dfe9f4af3 Align title to content 2025-11-27 15:44:10 +00:00
Aidan Timson
1844680c55 Explain 2025-11-27 15:15:10 +00:00
Aidan Timson
0b6abb555e Cleanup 2025-11-27 15:12:08 +00:00
Aidan Timson
32dbd2a7f2 Format 2025-11-27 15:11:21 +00:00
Aidan Timson
eceec1a657 Remove extra fallback 2025-11-27 15:02:09 +00:00
Aidan Timson
a26169638e Revert unwanted changes to dialog-box 2025-11-27 14:58:45 +00:00
Aidan Timson
e38a31a12f Translate X and Y 2025-11-27 14:52:59 +00:00
Aidan Timson
1e947a43eb Use transform to move dialog based on offset x 2025-11-27 14:48:10 +00:00
Aidan Timson
dc17ac6ec0 Apply suggestion from @bramkragten
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2025-11-27 14:42:32 +00:00
Aidan Timson
888f0552f4 Revert "Add debug section to dialog"
This reverts commit 57a5b6efb9.
2025-11-27 14:24:51 +00:00
Aidan Timson
9c22e3a66e Remove test 2025-11-27 14:23:08 +00:00
Aidan Timson
2b89e314e3 Fix 2025-11-27 14:20:35 +00:00
Aidan Timson
53b66dbcff Fix 2025-11-27 12:52:02 +00:00
Aidan Timson
d5a8511170 Remove use of svh/svw, use globals 2025-11-27 12:34:19 +00:00
Aidan Timson
5302eb94ed Dont rely on ha-vars 2025-11-27 12:33:22 +00:00
Aidan Timson
d7238a067a Create safe width and height globals 2025-11-27 12:31:15 +00:00
Aidan Timson
e5d33ee994 Move safe area 0px clamp to globals 2025-11-27 12:29:38 +00:00
Aidan Timson
a337d4dfe2 Safe area on standard dialog (actual) 2025-11-27 11:24:51 +00:00
Aidan Timson
64b6411277 Flip 2025-11-27 11:24:35 +00:00
Aidan Timson
9f2abcff6e Safe width on standard dialog 2025-11-27 11:24:16 +00:00
Aidan Timson
6db2b02bc3 Safe width 2025-11-27 11:23:55 +00:00
Aidan Timson
b11f866610 Move custom logic for close button to alert type in wa 2025-11-27 11:13:08 +00:00
Aidan Timson
eb92e3ab34 Add type to wa-dialog 2025-11-27 11:08:10 +00:00
Aidan Timson
57a5b6efb9 Add debug section to dialog 2025-11-27 10:53:01 +00:00
Aidan Timson
c8e2a2ac06 Set minimum safe areas in ha-wa-dialog 2025-11-27 10:25:38 +00:00
3 changed files with 78 additions and 36 deletions

View File

@@ -53,6 +53,7 @@ export type DialogWidth = "small" | "medium" | "large" | "full";
* @cssprop --dialog-surface-margin-top - Top margin for the dialog surface.
*
* @attr {boolean} open - Controls the dialog open state.
* @attr {("alert"|"standard")} type - Dialog type. Defaults to "standard".
* @attr {("small"|"medium"|"large"|"full")} width - Preferred dialog width preset. Defaults to "medium".
* @attr {boolean} prevent-scrim-close - Prevents closing the dialog by clicking the scrim/overlay. Defaults to false.
* @attr {string} header-title - Header title text. If not set, the headerTitle slot is used.
@@ -84,6 +85,9 @@ export class HaWaDialog extends LitElement {
@property({ type: Boolean, reflect: true })
public open = false;
@property({ reflect: true })
public type: "alert" | "standard" = "standard";
@property({ type: String, reflect: true, attribute: "width" })
public width: DialogWidth = "medium";
@@ -198,18 +202,7 @@ export class HaWaDialog extends LitElement {
haStyleScrollbar,
css`
wa-dialog {
--full-width: var(
--ha-dialog-width-full,
min(
95vw,
calc(
100vw - var(--safe-area-inset-left, var(--ha-space-0)) - var(
--safe-area-inset-right,
var(--ha-space-0)
)
)
)
);
--full-width: var(--ha-dialog-width-full, min(95vw, var(--safe-width)));
--width: min(var(--ha-dialog-width-md, 580px), var(--full-width));
--spacing: var(--dialog-content-padding, var(--ha-space-6));
--show-duration: var(--ha-dialog-show-duration, 200ms);
@@ -226,8 +219,7 @@ export class HaWaDialog extends LitElement {
--ha-dialog-border-radius,
var(--ha-border-radius-3xl)
);
max-width: var(--ha-dialog-max-width, 100vw);
max-width: var(--ha-dialog-max-width, 100svw);
max-width: var(--ha-dialog-max-width, var(--safe-width));
}
:host([width="small"]) wa-dialog {
@@ -247,34 +239,57 @@ export class HaWaDialog extends LitElement {
max-width: var(--width, var(--full-width));
max-height: var(
--ha-dialog-max-height,
calc(100% - var(--ha-space-20))
calc(var(--safe-height) - var(--ha-space-20))
);
min-height: var(--ha-dialog-min-height);
position: var(--dialog-surface-position, relative);
margin-top: var(--dialog-surface-margin-top, auto);
/* Used to offset the dialog from the safe areas when space is limited */
transform: translate(
calc(
var(--safe-area-offset-left, var(--ha-space-0)) - var(
--safe-area-offset-right,
var(--ha-space-0)
)
),
calc(
var(--safe-area-offset-top, var(--ha-space-0)) - var(
--safe-area-offset-bottom,
var(--ha-space-0)
)
)
);
display: flex;
flex-direction: column;
overflow: hidden;
}
@media all and (max-width: 450px), all and (max-height: 500px) {
:host {
:host([type="standard"]) {
--ha-dialog-border-radius: var(--ha-space-0);
}
wa-dialog {
--full-width: var(--ha-dialog-width-full, 100vw);
}
wa-dialog {
/* Make the container fill the whole screen width and not the safe width */
--full-width: var(--ha-dialog-width-full, 100vw);
--width: var(--full-width);
}
wa-dialog::part(dialog) {
min-height: var(--ha-dialog-min-height, 100vh);
min-height: var(--ha-dialog-min-height, 100svh);
max-height: var(--ha-dialog-max-height, 100vh);
max-height: var(--ha-dialog-max-height, 100svh);
padding-top: var(--safe-area-inset-top, var(--ha-space-0));
padding-bottom: var(--safe-area-inset-bottom, var(--ha-space-0));
padding-left: var(--safe-area-inset-left, var(--ha-space-0));
padding-right: var(--safe-area-inset-right, var(--ha-space-0));
wa-dialog::part(dialog) {
/* Make the dialog fill the whole screen height and not the safe height */
min-height: var(--ha-dialog-min-height, 100vh);
min-height: var(--ha-dialog-min-height, 100dvh);
max-height: var(--ha-dialog-max-height, 100vh);
max-height: var(--ha-dialog-max-height, 100dvh);
margin-top: 0;
margin-bottom: 0;
/* Use safe area as padding instead of the container size */
padding-top: var(--safe-area-inset-top);
padding-bottom: var(--safe-area-inset-bottom);
padding-left: var(--safe-area-inset-left);
padding-right: var(--safe-area-inset-right);
/* Reset the transform to center the dialog */
transform: none;
}
}
}

View File

@@ -1,6 +1,7 @@
import { mdiAlertOutline, mdiClose } from "@mdi/js";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { ifDefined } from "lit/directives/if-defined";
import { fireEvent } from "../../common/dom/fire_event";
import "../../components/ha-button";
@@ -64,6 +65,7 @@ class DialogBox extends LitElement {
<ha-wa-dialog
.hass=${this.hass}
.open=${this._open}
type=${confirmPrompt ? "alert" : "standard"}
?prevent-scrim-close=${confirmPrompt}
@closed=${this._dialogClosed}
aria-labelledby="dialog-box-title"
@@ -79,7 +81,11 @@ class DialogBox extends LitElement {
></ha-icon-button
></slot>`
: nothing}
<span slot="title" id="dialog-box-title">
<span
class=${classMap({ title: true, alert: confirmPrompt })}
slot="title"
id="dialog-box-title"
>
${this._params.warning
? html`<ha-svg-icon
.path=${mdiAlertOutline}
@@ -199,6 +205,14 @@ class DialogBox extends LitElement {
ha-textfield {
width: 100%;
}
.title.alert {
padding: 0 var(--ha-space-2);
}
@media all and (min-width: 450px) and (min-height: 500px) {
.title.alert {
padding: 0 var(--ha-space-1);
}
}
`;
}

View File

@@ -27,14 +27,27 @@ export const mainStyles = css`
--margin-title-ltr: 0 0 0 24px;
--margin-title-rtl: 0 24px 0 0;
/* safe-area-insets */
--safe-area-inset-top: var(--app-safe-area-inset-top, env(safe-area-inset-top, 0));
--safe-area-inset-bottom: var(--app-safe-area-inset-bottom, env(safe-area-inset-bottom, 0));
--safe-area-inset-left: var(--app-safe-area-inset-left, env(safe-area-inset-left, 0));
--safe-area-inset-right: var(--app-safe-area-inset-right, env(safe-area-inset-right, 0));
/* Safe area insets */
--safe-area-inset-top: var(--app-safe-area-inset-top, env(safe-area-inset-top, 0px));
--safe-area-inset-bottom: var(--app-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
--safe-area-inset-left: var(--app-safe-area-inset-left, env(safe-area-inset-left, 0px));
--safe-area-inset-right: var(--app-safe-area-inset-right, env(safe-area-inset-right, 0px));
--safe-area-inset-y: calc(var(--safe-area-inset-top, 0px) + var(--safe-area-inset-bottom, 0px));
/* Safe area inset x and y */
--safe-area-inset-x: calc(var(--safe-area-inset-left, 0px) + var(--safe-area-inset-right, 0px));
--safe-area-inset-y: calc(var(--safe-area-inset-top, 0px) + var(--safe-area-inset-bottom, 0px));
/* Offsets for centering elements within asymmetric safe areas */
--safe-area-offset-left: calc(max(var(--safe-area-inset-left, 0px) - var(--safe-area-inset-right, 0px), 0px) / 2);
--safe-area-offset-right: calc(max(var(--safe-area-inset-right, 0px) - var(--safe-area-inset-left, 0px), 0px) / 2);
--safe-area-offset-top: calc(max(var(--safe-area-inset-top, 0px) - var(--safe-area-inset-bottom, 0px), 0px) / 2);
--safe-area-offset-bottom: calc(max(var(--safe-area-inset-bottom, 0px) - var(--safe-area-inset-top, 0px), 0px) / 2);
/* Safe width and height for use instead of 100vw and 100vh
* when working with areas like dialogs which need to fill the entire safe area.
*/
--safe-width: calc(100vw - var(--safe-area-inset-left) - var(--safe-area-inset-right));
--safe-height: calc(100vh - var(--safe-area-inset-top) - var(--safe-area-inset-bottom));
}
`;