import { Component, TemplateRef, ViewChild } from '@angular/core'; import { CommonModule } from '@angular/common'; import { ScrollContainerComponent, ScrollVirtualConfig } from '../../../../../ui-essentials/src/lib/components/layout/scroll-container/scroll-container.component'; @Component({ selector: 'ui-scroll-container-demo', standalone: true, imports: [CommonModule, ScrollContainerComponent], template: `

ScrollContainer Demo

Basic Vertical Scrolling

@for (item of longContent; track item; let i = $index) {

{{ i + 1 }}. {{ item }}

}

Scroll events: Top reached {{ topCount }} times, Bottom reached {{ bottomCount }} times

Direction Variants

Vertical

@for (item of shortContent; track item; let i = $index) {

{{ i + 1 }}. {{ item }}

}

Horizontal

@for (item of horizontalItems; track item) {
{{ item }}
}

Both Directions

@for (row of tableData; track row.id) { }
{{ row.id }} {{ row.name }} {{ row.description }} {{ row.value }} {{ row.status }}

Scrollbar Visibility

@for (visibility of scrollbarOptions; track visibility) {

{{ visibility | titlecase }}

@for (item of shortContent; track item; let i = $index) {

{{ i + 1 }}. {{ item }}

}
}

Virtual Scrolling

Virtual scrolling with {{ largeDataset.length }} items (only visible items are rendered)

Scroll Controls & Smooth Scrolling

@for (item of longContent; track item; let i = $index) {

{{ i + 1 }}. {{ item }}

}

Scroll Position Restoration

Scroll position is saved and restored automatically (uses sessionStorage)

@for (item of longContent; track item; let i = $index) {

{{ i + 1 }}. {{ item }}

}

Interactive Example

Current scroll position: {{ currentScrollPosition.top }}px (top), {{ currentScrollPosition.left }}px (left)

Is scrolling: {{ isScrolling ? 'Yes' : 'No' }}

@for (item of gridData; track item.id) {

Item {{ item.id }}

{{ item.content }}

}
Item {{ index + 1 }}: {{ item.name }} - {{ item.description }}
`, styleUrl: './scroll-container-demo.component.scss' }) export class ScrollContainerDemoComponent { @ViewChild('controllableScroll') controllableScroll!: ScrollContainerComponent; @ViewChild('itemTemplate') itemTemplate!: TemplateRef; // Content data longContent = [ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 'Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', 'Ut enim ad minim veniam, quis nostrud exercitation ullamco.', 'Duis aute irure dolor in reprehenderit in voluptate velit esse.', 'Excepteur sint occaecat cupidatat non proident, sunt in culpa.', 'Qui officia deserunt mollit anim id est laborum.', 'At vero eos et accusamus et iusto odio dignissimos ducimus.', 'Et harum quidem rerum facilis est et expedita distinctio.', 'Nam libero tempore, cum soluta nobis est eligendi optio.', 'Temporibus autem quibusdam et aut officiis debitis aut rerum.', 'Itaque earum rerum hic tenetur a sapiente delectus.', 'Ut aut reiciendis voluptatibus maiores alias consequatur.', 'Sed ut perspiciatis unde omnis iste natus error sit.', 'Voluptatem accusantium doloremque laudantium, totam rem.', 'Aperiam, eaque ipsa quae ab illo inventore veritatis.', 'Quasi architecto beatae vitae dicta sunt explicabo.', 'Nemo enim ipsam voluptatem quia voluptas sit aspernatur.', 'Neque porro quisquam est, qui dolorem ipsum quia dolor.', 'Consectetur, adipisci velit, sed quia non numquam eius.', 'Modi tempora incidunt ut labore et dolore magnam.' ]; shortContent = this.longContent.slice(0, 8); horizontalItems = [ 'Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6', 'Item 7', 'Item 8', 'Item 9', 'Item 10' ]; tableData = Array.from({ length: 20 }, (_, i) => ({ id: i + 1, name: `Row ${i + 1}`, description: `Description for row ${i + 1} with some longer text`, value: Math.floor(Math.random() * 1000), status: i % 3 === 0 ? 'Active' : i % 3 === 1 ? 'Pending' : 'Inactive' })); // Virtual scrolling data largeDataset = Array.from({ length: 10000 }, (_, i) => ({ id: i + 1, name: `Item ${i + 1}`, description: `This is a description for item number ${i + 1}. It contains some sample text to demonstrate virtual scrolling.` })); virtualConfig: ScrollVirtualConfig = { itemHeight: 60, bufferSize: 5, enabled: true }; gridData = Array.from({ length: 50 }, (_, i) => ({ id: i + 1, content: `Grid item content ${i + 1} with some descriptive text that makes it interesting.` })); // Options scrollbarOptions = ['auto', 'always', 'never'] as const; // State topCount = 0; bottomCount = 0; smoothScrollEnabled = false; currentScrollPosition = { top: 0, left: 0 }; isScrolling = false; // Event handlers onScroll(position: any): void { // Handle scroll event if needed } onReachedTop(): void { this.topCount++; } onReachedBottom(): void { this.bottomCount++; } updateScrollPosition(position: any): void { this.currentScrollPosition = position; } onScrollStart(): void { this.isScrolling = true; } onScrollEnd(): void { this.isScrolling = false; } // Control methods scrollToTop(): void { this.controllableScroll?.scrollToTop(); } scrollToBottom(): void { this.controllableScroll?.scrollToBottom(); } scrollToMiddle(): void { this.controllableScroll?.scrollTo({ top: 1000 }); } toggleSmoothScroll(): void { this.smoothScrollEnabled = !this.smoothScrollEnabled; } // Virtual scrolling trackByItem(item: any): any { return item.id; } }