add shadow when scrollable in automation bottom sheet, min height 50vh (#26828)
parent
5ac42e17b0
commit
dfb9c662e7
|
@ -30,6 +30,8 @@ export class HaBottomSheet extends LitElement {
|
|||
|
||||
@state() private _dialogMaxViewpointHeight = 70;
|
||||
|
||||
@state() private _dialogMinViewpointHeight = 55;
|
||||
|
||||
@state() private _dialogViewportHeight?: number;
|
||||
|
||||
render() {
|
||||
|
@ -41,6 +43,7 @@ export class HaBottomSheet extends LitElement {
|
|||
? `${this._dialogViewportHeight}vh`
|
||||
: "auto",
|
||||
maxHeight: `${this._dialogMaxViewpointHeight}vh`,
|
||||
minHeight: `${this._dialogMinViewpointHeight}vh`,
|
||||
})}
|
||||
>
|
||||
<div class="handle-wrapper">
|
||||
|
@ -80,6 +83,7 @@ export class HaBottomSheet extends LitElement {
|
|||
this._dialogViewportHeight =
|
||||
(this._dialog.offsetHeight / window.innerHeight) * 100;
|
||||
this._dialogMaxViewpointHeight = 90;
|
||||
this._dialogMinViewpointHeight = 20;
|
||||
} else {
|
||||
// after close animation is done close dialog element and fire closed event
|
||||
this._dialog.close();
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import { ResizeController } from "@lit-labs/observers/resize-controller";
|
||||
import { mdiClose, mdiDotsVertical } from "@mdi/js";
|
||||
import type { PropertyValues } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import {
|
||||
customElement,
|
||||
|
@ -43,7 +45,22 @@ export default class HaAutomationSidebarCard extends LitElement {
|
|||
|
||||
@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() {
|
||||
return html`
|
||||
|
@ -94,14 +111,29 @@ export default class HaAutomationSidebarCard extends LitElement {
|
|||
<div class="card-content" @scroll=${this._onScroll}>
|
||||
<slot></slot>
|
||||
</div>
|
||||
${this.narrow
|
||||
? html`
|
||||
<div
|
||||
class="fade ${this._contentScrollable ? "scrollable" : ""}"
|
||||
></div>
|
||||
`
|
||||
: nothing}
|
||||
</ha-card>
|
||||
`;
|
||||
}
|
||||
|
||||
@eventOptions({ passive: true })
|
||||
private _onScroll() {
|
||||
const top = this._contentElement?.scrollTop ?? 0;
|
||||
private _onScroll(ev) {
|
||||
const top = ev.target.scrollTop ?? 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() {
|
||||
|
@ -151,6 +183,20 @@ export default class HaAutomationSidebarCard extends LitElement {
|
|||
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 {
|
||||
max-height: calc(100% - 80px);
|
||||
overflow: auto;
|
||||
|
|
Loading…
Reference in New Issue