import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ImageContainerComponent, ImageContainerSize, ImageContainerAspectRatio, ImageContainerObjectFit, ImageContainerShape } from '../../../../../ui-essentials/src/lib/components/data-display/image-container/image-container.component';
import { BadgeComponent } from '../../../../../ui-essentials/src/lib/components/data-display/badge/badge.component';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { faRefresh, faHeart, faPlay } from '@fortawesome/free-solid-svg-icons';
@Component({
selector: 'ui-image-container-demo',
standalone: true,
imports: [CommonModule, ImageContainerComponent, BadgeComponent, FontAwesomeModule],
template: `
Image Container Demo
A flexible image container with lazy loading, aspect ratios, and various display options.
Sizes
@for (size of sizes; track size) {
{{ size }}
}
Aspect Ratios
@for (ratio of aspectRatios; track ratio) {
{{ ratio }}
}
Object Fit
@for (fit of objectFits; track fit) {
{{ fit }}
}
Shapes
@for (shape of shapes; track shape) {
{{ shape }}
}
Loading States
Loading
Custom Error
Error State
Eager Load
Advanced Examples
Custom Caption Content
With additional styled elements
Featured
Hero Banner
Responsive Gallery
@for (image of galleryImages; track image.id; let i = $index) {
{{ image.title }}
}
@if (eventLog.length > 0) {
Event Log
@for (event of eventLog.slice(-5); track event.id) {
{{ event.time | date:'HH:mm:ss' }}
{{ event.type }}
{{ event.message }}
}
}
`,
styleUrl: './image-container-demo.component.scss'
})
export class ImageContainerDemoComponent {
// Icons
faRefresh = faRefresh;
faHeart = faHeart;
faPlay = faPlay;
// Demo data
sizes: ImageContainerSize[] = ['sm', 'md', 'lg', 'xl'];
aspectRatios: ImageContainerAspectRatio[] = ['1/1', '4/3', '16/9', '3/2', '2/1', '3/4', '9/16'];
objectFits: ImageContainerObjectFit[] = ['contain', 'cover', 'fill', 'scale-down'];
shapes: ImageContainerShape[] = ['square', 'rounded', 'circle'];
// Sample images (using placeholder service)
sampleImages = {
landscape: 'https://picsum.photos/800/600?random=1',
portrait: 'https://picsum.photos/600/800?random=2',
square: 'https://picsum.photos/600/600?random=3'
};
galleryImages = [
{ id: 1, url: 'https://picsum.photos/400/400?random=10', title: 'Nature', alt: 'Beautiful nature scene' },
{ id: 2, url: 'https://picsum.photos/400/300?random=11', title: 'Architecture', alt: 'Modern building' },
{ id: 3, url: 'https://picsum.photos/400/500?random=12', title: 'Portrait', alt: 'Person portrait' },
{ id: 4, url: 'https://picsum.photos/400/400?random=13', title: 'Urban', alt: 'City landscape' },
{ id: 5, url: 'https://picsum.photos/400/300?random=14', title: 'Technology', alt: 'Tech equipment' },
{ id: 6, url: 'https://picsum.photos/400/400?random=15', title: 'Abstract', alt: 'Abstract art' }
];
// Event tracking
eventLog: Array<{id: number, type: string, message: string, time: Date}> = [];
private eventId = 1;
handleImageClick(context: string): void {
this.logEvent('click', `Image clicked in ${context} context`);
}
handleGalleryClick(image: any, index: number): void {
this.logEvent('gallery-click', `Gallery image "${image.title}" clicked (index ${index})`);
}
handleImageLoad(imageId: number): void {
this.logEvent('load', `Image ${imageId} loaded successfully`);
}
handleImageError(imageId: number): void {
this.logEvent('error', `Image ${imageId} failed to load`);
}
retryImage(event: Event): void {
event.stopPropagation();
this.logEvent('retry', 'Retry button clicked for failed image');
// In a real implementation, this would retry loading the image
}
private logEvent(type: string, message: string): void {
this.eventLog.push({
id: this.eventId++,
type,
message,
time: new Date()
});
// Keep only last 20 events
if (this.eventLog.length > 20) {
this.eventLog.splice(0, this.eventLog.length - 20);
}
}
}