mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 08:43:33 +00:00
[CL-622][CL-562][CL-621][CL-632] various drawer improvements (#14120)
- add focus trap to drawers - add config to open existing dialogs as drawers - make drawer take up fill width/height on smaller screens
This commit is contained in:
41
libs/components/src/utils/has-scrolled-from.ts
Normal file
41
libs/components/src/utils/has-scrolled-from.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { CdkScrollable } from "@angular/cdk/scrolling";
|
||||
import { Signal, inject, signal } from "@angular/core";
|
||||
import { toObservable, toSignal } from "@angular/core/rxjs-interop";
|
||||
import { map, startWith, switchMap } from "rxjs";
|
||||
|
||||
export type ScrollState = {
|
||||
/** `true` when the scrollbar is not at the top-most position */
|
||||
top: boolean;
|
||||
|
||||
/** `true` when the scrollbar is not at the bottom-most position */
|
||||
bottom: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if a `CdkScrollable` instance has been scrolled
|
||||
* @param scrollable The instance to check, defaults to the one provided by the current injector
|
||||
* @returns {Signal<ScrollState>}
|
||||
*/
|
||||
export const hasScrolledFrom = (scrollable?: Signal<CdkScrollable>): Signal<ScrollState> => {
|
||||
const _scrollable = scrollable ?? signal(inject(CdkScrollable));
|
||||
const scrollable$ = toObservable(_scrollable);
|
||||
|
||||
const scrollState$ = scrollable$.pipe(
|
||||
switchMap((_scrollable) =>
|
||||
_scrollable.elementScrolled().pipe(
|
||||
startWith(null),
|
||||
map(() => ({
|
||||
top: _scrollable.measureScrollOffset("top") > 0,
|
||||
bottom: _scrollable.measureScrollOffset("bottom") > 0,
|
||||
})),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return toSignal(scrollState$, {
|
||||
initialValue: {
|
||||
top: false,
|
||||
bottom: false,
|
||||
},
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user