chore: copia de libs/shared con prefijo Pi y APIs de terceros actualizadas
This commit is contained in:
5
libs/ui/src/lib/util/scroll-to/index.ts
Normal file
5
libs/ui/src/lib/util/scroll-to/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export * from './scroll-to.module';
|
||||
|
||||
export * from './scroll-to.directive';
|
||||
|
||||
export * from './scroll-to.service';
|
||||
15
libs/ui/src/lib/util/scroll-to/scroll-to.directive.ts
Normal file
15
libs/ui/src/lib/util/scroll-to/scroll-to.directive.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import {
|
||||
Directive,
|
||||
HostBinding
|
||||
} from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
standalone: false,
|
||||
selector: '[pi-scroll-to-element]',
|
||||
})
|
||||
export class PiScrollToElementDirective {
|
||||
@HostBinding('class') get classes(): string {
|
||||
return 'pi-scroll-to pi-scroll-to__element';
|
||||
}
|
||||
}
|
||||
|
||||
12
libs/ui/src/lib/util/scroll-to/scroll-to.module.ts
Normal file
12
libs/ui/src/lib/util/scroll-to/scroll-to.module.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { PiScrollToElementDirective } from './scroll-to.directive';
|
||||
import { PiSharedUtilScrollService } from './scroll-to.service';
|
||||
|
||||
@NgModule({
|
||||
imports: [CommonModule],
|
||||
declarations: [PiScrollToElementDirective],
|
||||
exports: [PiScrollToElementDirective],
|
||||
providers: [PiSharedUtilScrollService],
|
||||
})
|
||||
export class PiSharedUtilScrollToModule {}
|
||||
43
libs/ui/src/lib/util/scroll-to/scroll-to.service.ts
Normal file
43
libs/ui/src/lib/util/scroll-to/scroll-to.service.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { ElementRef, Injectable, QueryList } from '@angular/core';
|
||||
|
||||
@Injectable()
|
||||
export class PiSharedUtilScrollService {
|
||||
scrollToNextElement(elements: QueryList<ElementRef>): void {
|
||||
for (let i = 0; i <= elements.length; i++) {
|
||||
const element: ElementRef = elements.toArray()[i];
|
||||
if (this.isScrolledToBottom()) {
|
||||
this.scrollToTop();
|
||||
break;
|
||||
}
|
||||
if (i === elements.length) {
|
||||
this.scrollToBottom();
|
||||
break;
|
||||
}
|
||||
if (this.isElementInView(element.nativeElement)) {
|
||||
element.nativeElement.scrollIntoView({ behavior: 'smooth' });
|
||||
break;
|
||||
}
|
||||
this.scrollToTop();
|
||||
}
|
||||
}
|
||||
|
||||
isElementInView(element: Element): boolean {
|
||||
const rect = element.getBoundingClientRect();
|
||||
return rect.top > 40;
|
||||
}
|
||||
|
||||
scrollToTop(): void {
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
}
|
||||
|
||||
scrollToBottom(): void {
|
||||
window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
|
||||
}
|
||||
|
||||
isScrolledToBottom(): boolean {
|
||||
const documentHeight = document.body.scrollHeight;
|
||||
const currentScroll = window.scrollY + window.innerHeight;
|
||||
return documentHeight <= currentScroll;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user