Allow partial open of sidebar

This commit is contained in:
Bram Kragten 2023-04-01 18:46:52 +02:00
parent ddfe02eb70
commit a548d13931
No known key found for this signature in database
GPG Key ID: FBE2DFDB363EF55B
4 changed files with 15 additions and 2 deletions

View File

@ -11,6 +11,9 @@ export class HaDrawer extends DrawerBase {
.mdc-drawer { .mdc-drawer {
top: 0; top: 0;
} }
.mdc-drawer--modal.mdc-drawer--open {
left: min(0px, var(--drawer-modal-left-offset));
}
`, `,
]; ];
} }

View File

@ -53,7 +53,10 @@ const handleExternalMessage = (
result: null, result: null,
}); });
} else if (msg.command === "sidebar/show") { } else if (msg.command === "sidebar/show") {
fireEvent(hassMainEl, "hass-toggle-menu", { open: true }); fireEvent(hassMainEl, "hass-toggle-menu", {
open: true,
screenPercentage: msg.data?.screenPercentage,
});
bus.fireMessage({ bus.fireMessage({
id: msg.id, id: msg.id,
type: "result", type: "result",

View File

@ -131,6 +131,7 @@ interface EMIncomingMessageShowSidebar {
id: number; id: number;
type: "command"; type: "command";
command: "sidebar/show"; command: "sidebar/show";
data?: { screenPercentage: number };
} }
export type EMIncomingMessageCommands = export type EMIncomingMessageCommands =

View File

@ -19,7 +19,9 @@ import "./partial-panel-resolver";
declare global { declare global {
// for fire event // for fire event
interface HASSDomEvents { interface HASSDomEvents {
"hass-toggle-menu": undefined | { open?: boolean }; "hass-toggle-menu":
| undefined
| { open?: boolean; screenPercentage?: number };
"hass-edit-sidebar": EditSideBarEvent; "hass-edit-sidebar": EditSideBarEvent;
"hass-show-notifications": undefined; "hass-show-notifications": undefined;
} }
@ -120,6 +122,10 @@ export class HomeAssistantMain extends LitElement {
} }
if (this._sidebarNarrow) { if (this._sidebarNarrow) {
this._drawerOpen = ev.detail?.open ?? !this._drawerOpen; this._drawerOpen = ev.detail?.open ?? !this._drawerOpen;
const offset = ev.detail?.screenPercentage
? -256 + screen.width * (ev.detail.screenPercentage / 100)
: 0;
this.style.setProperty("--drawer-modal-left-offset", `${offset}px`);
} else { } else {
fireEvent(this, "hass-dock-sidebar", { fireEvent(this, "hass-dock-sidebar", {
dock: ev.detail?.open dock: ev.detail?.open