mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-11 03:51:07 +00:00
add shadow when scrollable in automation bottom sheet, min height 50vh (#26828)
This commit is contained in:
@@ -30,6 +30,8 @@ export class HaBottomSheet extends LitElement {
|
|||||||
|
|
||||||
@state() private _dialogMaxViewpointHeight = 70;
|
@state() private _dialogMaxViewpointHeight = 70;
|
||||||
|
|
||||||
|
@state() private _dialogMinViewpointHeight = 55;
|
||||||
|
|
||||||
@state() private _dialogViewportHeight?: number;
|
@state() private _dialogViewportHeight?: number;
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -41,6 +43,7 @@ export class HaBottomSheet extends LitElement {
|
|||||||
? `${this._dialogViewportHeight}vh`
|
? `${this._dialogViewportHeight}vh`
|
||||||
: "auto",
|
: "auto",
|
||||||
maxHeight: `${this._dialogMaxViewpointHeight}vh`,
|
maxHeight: `${this._dialogMaxViewpointHeight}vh`,
|
||||||
|
minHeight: `${this._dialogMinViewpointHeight}vh`,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<div class="handle-wrapper">
|
<div class="handle-wrapper">
|
||||||
@@ -80,6 +83,7 @@ export class HaBottomSheet extends LitElement {
|
|||||||
this._dialogViewportHeight =
|
this._dialogViewportHeight =
|
||||||
(this._dialog.offsetHeight / window.innerHeight) * 100;
|
(this._dialog.offsetHeight / window.innerHeight) * 100;
|
||||||
this._dialogMaxViewpointHeight = 90;
|
this._dialogMaxViewpointHeight = 90;
|
||||||
|
this._dialogMinViewpointHeight = 20;
|
||||||
} else {
|
} else {
|
||||||
// after close animation is done close dialog element and fire closed event
|
// after close animation is done close dialog element and fire closed event
|
||||||
this._dialog.close();
|
this._dialog.close();
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
import { ResizeController } from "@lit-labs/observers/resize-controller";
|
||||||
import { mdiClose, mdiDotsVertical } from "@mdi/js";
|
import { mdiClose, mdiDotsVertical } from "@mdi/js";
|
||||||
|
import type { PropertyValues } from "lit";
|
||||||
import { css, html, LitElement, nothing } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import {
|
import {
|
||||||
customElement,
|
customElement,
|
||||||
@@ -43,7 +45,22 @@ export default class HaAutomationSidebarCard extends LitElement {
|
|||||||
|
|
||||||
@state() private _contentScrolled = false;
|
@state() private _contentScrolled = false;
|
||||||
|
|
||||||
@query(".card-content") private _contentElement?: HTMLDivElement;
|
@state() private _contentScrollable = false;
|
||||||
|
|
||||||
|
@query(".card-content") private _contentElement!: HTMLDivElement;
|
||||||
|
|
||||||
|
private _contentSize = new ResizeController(this, {
|
||||||
|
target: null,
|
||||||
|
callback: (entries) => {
|
||||||
|
if (entries[0]?.target) {
|
||||||
|
this._canScrollDown(entries[0].target);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
protected firstUpdated(_changedProperties: PropertyValues): void {
|
||||||
|
this._contentSize.observe(this._contentElement);
|
||||||
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
@@ -94,14 +111,29 @@ export default class HaAutomationSidebarCard extends LitElement {
|
|||||||
<div class="card-content" @scroll=${this._onScroll}>
|
<div class="card-content" @scroll=${this._onScroll}>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</div>
|
</div>
|
||||||
|
${this.narrow
|
||||||
|
? html`
|
||||||
|
<div
|
||||||
|
class="fade ${this._contentScrollable ? "scrollable" : ""}"
|
||||||
|
></div>
|
||||||
|
`
|
||||||
|
: nothing}
|
||||||
</ha-card>
|
</ha-card>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@eventOptions({ passive: true })
|
@eventOptions({ passive: true })
|
||||||
private _onScroll() {
|
private _onScroll(ev) {
|
||||||
const top = this._contentElement?.scrollTop ?? 0;
|
const top = ev.target.scrollTop ?? 0;
|
||||||
this._contentScrolled = top > 0;
|
this._contentScrolled = top > 0;
|
||||||
|
|
||||||
|
this._canScrollDown(ev.target);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _canScrollDown(element: HTMLElement) {
|
||||||
|
this._contentScrollable =
|
||||||
|
(element.scrollHeight ?? 0) - (element.clientHeight ?? 0) >
|
||||||
|
(element.scrollTop ?? 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _closeSidebar() {
|
private _closeSidebar() {
|
||||||
@@ -151,6 +183,20 @@ export default class HaAutomationSidebarCard extends LitElement {
|
|||||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fade {
|
||||||
|
position: fixed;
|
||||||
|
bottom: -12px;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
height: 12px;
|
||||||
|
pointer-events: none;
|
||||||
|
transition: box-shadow 180ms ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fade.scrollable {
|
||||||
|
box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.16);
|
||||||
|
}
|
||||||
|
|
||||||
.card-content {
|
.card-content {
|
||||||
max-height: calc(100% - 80px);
|
max-height: calc(100% - 80px);
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
|
|||||||
Reference in New Issue
Block a user