Add styling to popups

This commit is contained in:
Thomas Lovén 2022-07-24 20:27:13 +00:00
parent d58a29f4f9
commit 0b195e8841
4 changed files with 23 additions and 7 deletions

View File

@ -1131,7 +1131,7 @@ class BrowserModPopup extends s {
}, 10); }, 10);
} }
} }
async setupDialog(title, content, { right_button = undefined, right_button_action = undefined, left_button = undefined, left_button_action = undefined, dismissable = true, dismiss_action = undefined, timeout = undefined, timeout_action = undefined, size = undefined, } = {}) { async setupDialog(title, content, { right_button = undefined, right_button_action = undefined, left_button = undefined, left_button_action = undefined, dismissable = true, dismiss_action = undefined, timeout = undefined, timeout_action = undefined, size = undefined, style = undefined, } = {}) {
this.title = title; this.title = title;
if (content && typeof content === "object") { if (content && typeof content === "object") {
// Create a card from config in content // Create a card from config in content
@ -1160,6 +1160,7 @@ class BrowserModPopup extends s {
}; };
this.wide = size === "wide" ? "" : undefined; this.wide = size === "wide" ? "" : undefined;
this.fullscreen = size === "fullscreen" ? "" : undefined; this.fullscreen = size === "fullscreen" ? "" : undefined;
this._style = style;
} }
_primary() { _primary() {
var _a, _b, _c; var _a, _b, _c;
@ -1237,6 +1238,9 @@ class BrowserModPopup extends s {
></mwc-button> ></mwc-button>
` `
: ""} : ""}
<style>
${this._style}
</style>
</ha-dialog> </ha-dialog>
`; `;
} }
@ -1367,6 +1371,9 @@ __decorate([
__decorate([ __decorate([
e$2({ reflect: true }) e$2({ reflect: true })
], BrowserModPopup.prototype, "fullscreen", void 0); ], BrowserModPopup.prototype, "fullscreen", void 0);
__decorate([
e$2()
], BrowserModPopup.prototype, "_style", void 0);
customElements.define("browser-mod-popup", BrowserModPopup); customElements.define("browser-mod-popup", BrowserModPopup);
const PopupMixin = (SuperClass) => { const PopupMixin = (SuperClass) => {
return class PopupMixinClass extends SuperClass { return class PopupMixinClass extends SuperClass {
@ -1408,8 +1415,7 @@ const PopupMixin = (SuperClass) => {
// }, // },
// "" // ""
// ); // );
this._popupEl.setupDialog(...args); this._popupEl.setupDialog(...args).then(() => this._popupEl.openDialog());
this._popupEl.openDialog();
} }
closePopup(...args) { closePopup(...args) {
this._popupEl.closeDialog(); this._popupEl.closeDialog();
@ -1989,7 +1995,7 @@ const BrowserIDMixin = (SuperClass) => {
x Device -> Browser x Device -> Browser
- Popups - Popups
X Basic popups X Basic popups
- Card-mod integration x Styling
X Timeout X Timeout
X Fullscreen X Fullscreen
x Popup-card x Popup-card

View File

@ -112,6 +112,11 @@ popup:
description: Action to perform when popup is closed by timeout description: Action to perform when popup is closed by timeout
selector: selector:
object: object:
style:
name: Styles
description: CSS code to apply to the popup window
selector:
object:
more_info: more_info:
description: "Show more-info dialog" description: "Show more-info dialog"

View File

@ -24,7 +24,7 @@ import { BrowserIDMixin } from "./browserID";
x Device -> Browser x Device -> Browser
- Popups - Popups
X Basic popups X Basic popups
- Card-mod integration x Styling
X Timeout X Timeout
X Fullscreen X Fullscreen
x Popup-card x Popup-card

View File

@ -18,6 +18,7 @@ class BrowserModPopup extends LitElement {
timeout; timeout;
_timeoutStart; _timeoutStart;
_timeoutTimer; _timeoutTimer;
@property() _style;
closeDialog() { closeDialog() {
this.open = false; this.open = false;
@ -50,6 +51,7 @@ class BrowserModPopup extends LitElement {
timeout = undefined, timeout = undefined,
timeout_action = undefined, timeout_action = undefined,
size = undefined, size = undefined,
style = undefined,
} = {} } = {}
) { ) {
this.title = title; this.title = title;
@ -81,6 +83,7 @@ class BrowserModPopup extends LitElement {
}; };
this.wide = size === "wide" ? "" : undefined; this.wide = size === "wide" ? "" : undefined;
this.fullscreen = size === "fullscreen" ? "" : undefined; this.fullscreen = size === "fullscreen" ? "" : undefined;
this._style = style;
} }
_primary() { _primary() {
@ -153,6 +156,9 @@ class BrowserModPopup extends LitElement {
></mwc-button> ></mwc-button>
` `
: ""} : ""}
<style>
${this._style}
</style>
</ha-dialog> </ha-dialog>
`; `;
} }
@ -303,8 +309,7 @@ export const PopupMixin = (SuperClass) => {
// }, // },
// "" // ""
// ); // );
this._popupEl.setupDialog(...args); this._popupEl.setupDialog(...args).then(() => this._popupEl.openDialog());
this._popupEl.openDialog();
} }
closePopup(...args) { closePopup(...args) {