Skip to content

Commit

Permalink
Fix dialog headers
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten committed Dec 27, 2023
1 parent a2ffd0a commit f0375a8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 60 deletions.
40 changes: 23 additions & 17 deletions src/components/ha-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ export const createCloseHeading = (
hass: HomeAssistant | undefined,
title: string | TemplateResult
) => html`
<div class="header_title">${title}</div>
<ha-icon-button
.label=${hass?.localize("ui.dialogs.generic.close") ?? "Close"}
.path=${mdiClose}
dialogAction="close"
class="header_button"
></ha-icon-button>
<div class="header_title">
<span>${title}</span>
<ha-icon-button
.label=${hass?.localize("ui.dialogs.generic.close") ?? "Close"}
.path=${mdiClose}
dialogAction="close"
class="header_button"
></ha-icon-button>
</div>
`;

@customElement("ha-dialog")
Expand Down Expand Up @@ -94,15 +96,12 @@ export class HaDialog extends DialogBase {
}
.mdc-dialog__title {
padding: 24px 24px 0 24px;
text-overflow: ellipsis;
overflow: hidden;
}
.mdc-dialog__actions {
padding: 12px 24px 12px 24px;
}
.mdc-dialog__title::before {
display: block;
height: 0px;
content: unset;
}
.mdc-dialog .mdc-dialog__content {
position: var(--dialog-content-position, relative);
Expand All @@ -126,19 +125,26 @@ export class HaDialog extends DialogBase {
flex-direction: column;
}
.header_title {
margin-right: 32px;
margin-inline-end: 32px;
margin-inline-start: initial;
position: relative;
padding-right: 32px;
padding-inline-end: 32px;
padding-inline-start: initial;
direction: var(--direction);
}
.header_title span {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
display: block;
}
.header_button {
position: absolute;
right: 16px;
top: 14px;
right: -8px;
top: -8px;
text-decoration: none;
color: inherit;
inset-inline-start: initial;
inset-inline-end: 16px;
inset-inline-end: -8px;
direction: var(--direction);
}
.dialog-actions {
Expand Down
15 changes: 4 additions & 11 deletions src/panels/calendar/dialog-calendar-event-detail.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import "@material/mwc-button";
import { mdiCalendarClock, mdiClose } from "@mdi/js";
import { mdiCalendarClock } from "@mdi/js";
import { toDate } from "date-fns-tz";
import { addDays, isSameDay } from "date-fns/esm";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
import { property, state } from "lit/decorators";
import { formatDate } from "../../common/datetime/format_date";
import { formatDateTime } from "../../common/datetime/format_date_time";
Expand All @@ -11,6 +11,7 @@ import { fireEvent } from "../../common/dom/fire_event";
import { isDate } from "../../common/string/is_date";
import "../../components/entity/state-info";
import "../../components/ha-date-input";
import { createCloseHeading } from "../../components/ha-dialog";
import "../../components/ha-time-input";
import {
CalendarEventMutableParams,
Expand Down Expand Up @@ -65,15 +66,7 @@ class DialogCalendarEventDetail extends LitElement {
@closed=${this.closeDialog}
scrimClickAction
escapeKeyAction
.heading=${html`
<div class="header_title">${this._data!.summary}</div>
<ha-icon-button
.label=${this.hass.localize("ui.dialogs.generic.close")}
.path=${mdiClose}
dialogAction="close"
class="header_button"
></ha-icon-button>
`}
.heading=${createCloseHeading(this.hass, this._data!.summary)}
>
<div class="content">
${this._error
Expand Down
27 changes: 10 additions & 17 deletions src/panels/calendar/dialog-calendar-event-editor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import "@material/mwc-button";
import { mdiClose } from "@mdi/js";
import { formatInTimeZone, toDate } from "date-fns-tz";
import {
addDays,
Expand All @@ -9,7 +8,7 @@ import {
startOfHour,
} from "date-fns/esm";
import { HassEntity } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one";
import { fireEvent } from "../../common/dom/fire_event";
Expand All @@ -18,23 +17,24 @@ import { supportsFeature } from "../../common/entity/supports-feature";
import { isDate } from "../../common/string/is_date";
import "../../components/entity/ha-entity-picker";
import "../../components/ha-date-input";
import { createCloseHeading } from "../../components/ha-dialog";
import "../../components/ha-textarea";
import "../../components/ha-time-input";
import {
CalendarEntityFeature,
CalendarEventMutableParams,
RecurrenceRange,
createCalendarEvent,
deleteCalendarEvent,
RecurrenceRange,
updateCalendarEvent,
} from "../../data/calendar";
import { TimeZone } from "../../data/translation";
import { haStyleDialog } from "../../resources/styles";
import { HomeAssistant } from "../../types";
import "../lovelace/components/hui-generic-entity-row";
import "./ha-recurrence-rule-editor";
import { showConfirmEventDialog } from "./show-confirm-event-dialog-box";
import { CalendarEventEditDialogParams } from "./show-dialog-calendar-event-editor";
import { TimeZone } from "../../data/translation";

const CALENDAR_DOMAINS = ["calendar"];

Expand Down Expand Up @@ -142,19 +142,12 @@ class DialogCalendarEventEditor extends LitElement {
@closed=${this.closeDialog}
scrimClickAction
escapeKeyAction
.heading=${html`
<div class="header_title">
${isCreate
? this.hass.localize("ui.components.calendar.event.add")
: this._summary}
</div>
<ha-icon-button
.label=${this.hass.localize("ui.dialogs.generic.close")}
.path=${mdiClose}
dialogAction="close"
class="header_button"
></ha-icon-button>
`}
.heading=${createCloseHeading(
this.hass,
isCreate
? this.hass.localize("ui.components.calendar.event.add")
: this._summary
)}
>
<div class="content">
${this._error
Expand Down
23 changes: 8 additions & 15 deletions src/panels/todo/dialog-todo-item-editor.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import "@material/mwc-button";
import { mdiClose } from "@mdi/js";
import { formatInTimeZone, toDate } from "date-fns-tz";
import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one";
import { fireEvent } from "../../common/dom/fire_event";
import { supportsFeature } from "../../common/entity/supports-feature";
import "../../components/ha-date-input";
import { createCloseHeading } from "../../components/ha-dialog";
import "../../components/ha-textarea";
import "../../components/ha-time-input";
import {
Expand All @@ -20,7 +21,6 @@ import { showConfirmationDialog } from "../../dialogs/generic/show-dialog-box";
import { haStyleDialog } from "../../resources/styles";
import { HomeAssistant } from "../../types";
import { TodoItemEditDialogParams } from "./show-dialog-todo-item-editor";
import { supportsFeature } from "../../common/entity/supports-feature";

@customElement("dialog-todo-item-editor")
class DialogTodoItemEditor extends LitElement {
Expand Down Expand Up @@ -100,19 +100,12 @@ class DialogTodoItemEditor extends LitElement {
@closed=${this.closeDialog}
scrimClickAction
escapeKeyAction
.heading=${html`
<div class="header_title">
${isCreate
? this.hass.localize("ui.components.todo.item.add")
: this._summary}
</div>
<ha-icon-button
.label=${this.hass.localize("ui.dialogs.generic.close")}
.path=${mdiClose}
dialogAction="close"
class="header_button"
></ha-icon-button>
`}
.heading=${createCloseHeading(
this.hass,
isCreate
? this.hass.localize("ui.components.todo.item.add")
: this._summary
)}
>
<div class="content">
${this._error
Expand Down

0 comments on commit f0375a8

Please sign in to comment.