import { Component, ChangeDetectionStrategy } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AvatarComponent } from '../../../../../ui-essentials/src/lib/components/data-display/avatar/avatar.component';
interface Activity {
user: string;
action: string;
time: string;
status?: 'online' | 'offline' | 'away' | 'busy';
}
@Component({
selector: 'ui-avatar-demo',
standalone: true,
imports: [
CommonModule,
AvatarComponent
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
Avatar Component Showcase
Activity List Example
Recent Activity
@for (activity of activities; track activity.user) {
{{ activity.user }}
{{ activity.action }}
{{ activity.time }}
}
User List Example
@for (user of userProfiles; track user.id) {
0 ? user.notifications.toString() : ''">
{{ user.name }}
{{ user.role }}
{{ user.email }}
Last seen
{{ user.lastSeen }}
}
Avatar Group Example
@for (member of teamMembers; track member.name; let i = $index) {
0 ? '-8px' : '0'">
}
+{{ teamMembers.length }} members
Usage Examples
Basic Avatar:
<ui-avatar
size="md"
name="Current User"
status="online">
</ui-avatar>
Avatar with Image:
<ui-avatar
size="lg"
name="John Doe"
imageUrl="https://example.com/avatar.jpg"
altText="John's profile picture"
status="away"
badge="5">
</ui-avatar>
Custom Styled Avatar:
<ui-avatar
size="xl"
name="Admin User"
color="primary"
shape="rounded"
badge="⭐"
[loading]="false">
</ui-avatar>
Interactive Example
Size: {{ interactiveSize }}
Status: {{ interactiveStatus || 'none' }}
Badge: {{ interactiveBadge || 'none' }}
`,
styles: [`
h2 {
color: hsl(279, 14%, 11%);
font-size: 2rem;
margin-bottom: 2rem;
border-bottom: 2px solid hsl(258, 100%, 47%);
padding-bottom: 0.5rem;
}
h3 {
color: hsl(279, 14%, 25%);
font-size: 1.5rem;
margin-bottom: 1rem;
}
h4 {
color: hsl(287, 12%, 35%);
font-size: 1.125rem;
margin-bottom: 0.75rem;
}
section {
border: 1px solid hsl(289, 14%, 90%);
border-radius: 8px;
padding: 1.5rem;
background: hsl(286, 20%, 99%);
}
pre {
font-size: 0.875rem;
line-height: 1.5;
margin: 0.5rem 0;
}
code {
font-family: 'JetBrains Mono', monospace;
color: #d63384;
}
`]
})
export class AvatarDemoComponent {
activities: Activity[] = [
{
user: 'Alice Johnson',
action: 'Updated the project documentation and added new API endpoints',
time: '2 min ago',
status: 'online'
},
{
user: 'Bob Smith',
action: 'Completed code review for the authentication module',
time: '15 min ago',
status: 'away'
},
{
user: 'Carol Williams',
action: 'Created new user interface mockups for the dashboard',
time: '1 hour ago',
status: 'online'
},
{
user: 'David Brown',
action: 'Fixed critical bug in the payment processing system',
time: '2 hours ago',
status: 'busy'
},
{
user: 'Eve Davis',
action: 'Deployed version 2.1.0 to production environment',
time: '3 hours ago',
status: 'offline'
}
];
userProfiles = [
{
id: 1,
name: 'Alice Johnson',
role: 'Senior Developer',
email: 'alice@company.com',
status: 'online' as const,
notifications: 3,
lastSeen: '2 min ago',
avatar: 'https://images.unsplash.com/photo-1494790108755-2616b612b786?w=150&h=150&fit=crop&crop=face'
},
{
id: 2,
name: 'Bob Smith',
role: 'Product Manager',
email: 'bob@company.com',
status: 'away' as const,
notifications: 0,
lastSeen: '15 min ago',
avatar: 'https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?w=150&h=150&fit=crop&crop=face'
},
{
id: 3,
name: 'Carol Williams',
role: 'UX Designer',
email: 'carol@company.com',
status: 'online' as const,
notifications: 12,
lastSeen: 'Just now',
avatar: 'https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=150&h=150&fit=crop&crop=face'
}
];
teamMembers = [
{ name: 'Alex Chen', status: 'online' as const, avatar: 'https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=150&h=150&fit=crop&crop=face' },
{ name: 'Maria Garcia', status: 'away' as const, avatar: 'https://images.unsplash.com/photo-1517841905240-472988babdf9?w=150&h=150&fit=crop&crop=face' },
{ name: 'James Wilson', status: 'busy' as const, avatar: 'https://images.unsplash.com/photo-1500648767791-00dcc994a43e?w=150&h=150&fit=crop&crop=face' },
{ name: 'Sarah Kim', status: 'online' as const, avatar: 'https://images.unsplash.com/photo-1534751516642-a1af1ef26a56?w=150&h=150&fit=crop&crop=face' },
];
// Interactive demo properties
interactiveSize: any = 'lg';
interactiveStatus: any = 'online';
interactiveBadge = '3';
private statusCycle: any[] = ['online', 'away', 'busy', 'offline', null];
private statusIndex = 0;
private sizeCycle: any[] = ['xs', 'sm', 'md', 'lg', 'xl', 'xxl'];
private sizeIndex = 3; // Start with 'lg'
cycleStatus(): void {
this.statusIndex = (this.statusIndex + 1) % this.statusCycle.length;
this.interactiveStatus = this.statusCycle[this.statusIndex];
}
toggleBadge(): void {
if (this.interactiveBadge) {
this.interactiveBadge = '';
} else {
this.interactiveBadge = Math.floor(Math.random() * 99 + 1).toString();
}
}
cycleSize(): void {
this.sizeIndex = (this.sizeIndex + 1) % this.sizeCycle.length;
this.interactiveSize = this.sizeCycle[this.sizeIndex];
}
}