Search results

How To

As the avatar is a completely customizable and integral component, this section shows some of the customization and integration of avatar with other components.

Customize avatars

Colour customization

The avatar comes with default background colour (grey). This can be easily customized to desired colour by adding custom class or directly selecting the avatar class from the CSS.

Source
Preview
app.component.ts
app.module.ts
main.ts
import { Component } from '@angular/core';

@Component({
    selector: 'my-app',
    template: `
    <div id='element'>
            <span class="e-avatar e-avatar-xlarge e-avatar-circle green">AJ</span>
            <span class="e-avatar e-avatar-xlarge e-avatar-circle violet">JK</span>
            <span class="e-avatar e-avatar-xlarge e-avatar-circle rose">EL</span>
            <span class="e-avatar e-avatar-xlarge e-avatar-circle blue">SR</span>
            <span class="e-avatar e-avatar-xlarge e-avatar-circle red">PD</span>
    </div>
    `
})

export class AppComponent { }
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Customize avatar sizes

Even though the avatar comes with five predefined sizes, sometimes it’s not enough. So, the avatar is designed in such a way that the width and height will be relative to font-size. By changing the font-size of the avatar element, you can change the width and height automatically.

Source
Preview
app.component.ts
app.module.ts
main.ts
import { Component } from '@angular/core';

@Component({
    selector: 'my-app',
    template: `
    <div id='element'>
            <span class="e-avatar">26px</span>
            <span class="e-avatar">24px</span>
            <span class="e-avatar">22px</span>
            <span class="e-avatar">20px</span>
            <span class="e-avatar">18px</span>
    </div>
    `
})

export class AppComponent { }
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Use various media in avatar

Avatars can be used with a wide variety of media formats like SVG, font-icons, images, letters, words, etc. Some of them are given below.

Source
Preview
app.component.ts
app.module.ts
main.ts
import { Component } from '@angular/core';

@Component({
    selector: 'my-app',
    template: `
    <div id='element'>
            <div class="sample_container avatar-types">
                <div class="avatar-block">
                    <!-- Card Component -->
                    <div class="e-card e-avatar-showcase">
                        <div class="e-card-content">
                            <!-- XLarge Circle Avatar Component -->
                            <div class="e-avatar e-avatar-xlarge e-avatar-circle image"></div>
                        </div>
                        <div class="e-card-content">
                            <div>Image</div>
                        </div>
                    </div>
                </div>

                <div class="avatar-block">
                    <!-- Card Component -->
                    <div class="e-card e-avatar-showcase">
                        <div class="e-card-content">
                            <!-- XLarge Circle Avatar Component -->
                            <div class="e-avatar e-avatar-xlarge e-avatar-circle">
                                <div class="svg_icons chrome"></div>
                            </div>
                        </div>
                        <div class="e-card-content">
                            <div>SVG</div>
                        </div>
                    </div>
                </div>

                <div class="avatar-block">
                    <!-- Card Component -->
                    <div class="e-card e-avatar-showcase">
                        <div class="e-card-content">
                            <!-- XLarge Circle Avatar Component -->
                            <div class="e-avatar e-avatar-xlarge e-avatar-circle">GR</div>
                        </div>
                        <div class="e-card-content">
                            <div>Initial</div>
                        </div>
                    </div>
                </div>

                <div class="avatar-block">
                    <!-- Card Component -->
                    <div class="e-card e-avatar-showcase">
                        <div class="e-card-content">
                            <!-- XLarge Circle Avatar Component -->
                            <div class="e-avatar e-avatar-xlarge e-avatar-circle">
                                <div class="e-people icons"></div>
                            </div>
                        </div>
                        <div class="e-card-content">
                            <div>FontIcon</div>
                        </div>
                    </div>
                </div>

                <div class="avatar-block">
                    <!-- Card Component -->
                    <div class="e-card e-avatar-showcase">
                        <div class="e-card-content">
                            <!-- XLarge Circle Avatar Component -->
                            <div class="e-avatar e-avatar-xlarge e-avatar-circle">User</div>
                        </div>
                        <div class="e-card-content">
                            <div>Word</div>
                        </div>
                    </div>
                </div>

                <div class="avatar-block">
                    <!-- Card Component -->
                    <div class="e-card e-avatar-showcase">
                        <div class="e-card-content">
                            <!-- XLarge Circle Avatar Component -->
                            <div class="e-avatar e-avatar-xlarge e-avatar-circle custom">
                                <div class="e-people icons"></div>
                            </div>
                        </div>
                        <div class="e-card-content">
                            <div>Custom</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    `
})

export class AppComponent { }
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Dynamic avatar rendering from datasource

We can render avatar component dynamically from a data-source. In this sample we have rendered the avatar component using a data-source which contains the image source in different sizes dynamically. This is applicable also for data-source from the server or remote data or AJAX. We have also rendered the avatar using CSS property background-image and using image tag.

Source
Preview
app.component.ts
app.module.ts
main.ts
import { Component } from '@angular/core';

@Component({
    selector: 'my-app',
    template: `
    <div class='control-pane'>
        <div class="sample_container avatar-badge">
            <div class="avatar-block">
                <div class="e-card e-avatar-showcase">
                    <div class="e-card-content">
                        <div *ngFor="let item of dataSource"
                            [style.backgroundImage]="'url('+ item.src +')'"
                            class="e-avatar e-avatar-circle {{item.size}}">
                        </div>
                    </div>
                    <div class="e-card-content">
                        <div>Using <code>background-image</code> property</div>
                    </div>
                </div>
            </div>

            <div class="circleAvatar avatar-block">
                <div class="e-card e-avatar-showcase">
                    <div class="e-card-content">
                        <div *ngFor="let item of dataSource" class="e-avatar e-avatar-circle {{item.size}}">
                            <img src= {{item.src}}/>
                        </div>
                    </div>
                    <div class="e-card-content">
                        <div>Using <code>img</code> tag</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    `
})

export class AppComponent {
    public dataSource: { [key: string]: string }[] = [
        { src: '../pic01.png', size: 'e-avatar-xsmall' },
        { src: '../pic01.png', size: 'e-avatar-small' },
        { src: '../pic01.png', size: 'e-avatar' },
        { src: '../pic01.png', size: 'e-avatar-large' },
        { src: '../pic01.png', size: 'e-avatar-xlarge' }
    ];
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Integrate avatars

Avatar can be integrated into various components to make a wide variety of applications. Some of the integrations are shown in the following section.

Listview

Avatar is integrated into the listview to create contacts applications. The xsmall size avatar is used to match the size of the list item. Letters and images are also used as avatar content.

Source
Preview
app.component.ts
app.module.ts
main.ts
import { Component } from '@angular/core';

@Component({
    selector: 'my-app',
    template: `
    <div id="letterAvatarList">
        <ejs-listview id='letterAvatarList' [dataSource]='dataSource' [headerTitle]='headerTitle' [showHeader]='true' [sortOrder]='sortOrder'>
            <ng-template #template let-dataSource="">
                <div class="listWrapper">
                    <span class="e-avatar e-avatar-small e-avatar-circle {{dataSource.color}}" *ngIf="dataSource.avatar !== ''">{{dataSource.avatar}}</span>
                    <span class="{{dataSource.pic}} e-avatar e-avatar-small e-avatar-circle" *ngIf="dataSource.pic !== '' "> </span>
                    <span class="text">{{dataSource.text}}</span>
                </div>
            </ng-template>
        </ejs-listview>
    </div>
    `
})

export class AppComponent { 
     // Listview datasource with avatar and image source fields
     public dataSource: { [key: string]: Object; }[] = [
        { id: 's_01', text: 'Robert', avatar: '', pic: 'pic04', color: '' },
        { id: 's_02', text: 'Nancy', avatar: 'N', pic: '', color: 'green' },
        { id: 's_05', text: 'John', pic: 'pic01', avatar: '', color: '' },
        { id: 's_03', text: 'Andrew', avatar: 'A', pic: '', color: 'blue' },
        { id: 's_06', text: 'Michael', pic: 'pic02', avatar: '', color: '' },
        { id: 's_07', text: 'Steven', pic: 'pic03', avatar: '', color: '' },
        { id: 's_08', text: 'Margaret', avatar: 'M', pic: '', color: 'red' }
    ];

    public headerTitle: string = 'Contacts';
    public sortOrder: string = 'Ascending';
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { ListViewModule } from '@syncfusion/ej2-angular-lists';
/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        ListViewModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Badge

The badge is dependent and supportive component, and it can be used with avatar to create a notification avatar. The default avatar (.e-avatar) and circle avatar (.e-avatar-circle) have been used with notification badges (.e-badge-notification) in the following sample.

Source
Preview
app.component.ts
app.module.ts
main.ts
import { Component } from '@angular/core';

@Component({
    selector: 'my-app',
    template: `
    <div id='element'>
    <div class="sample_container avatar-badge">
        <div class="avatar-block">
            <!-- Card Component -->
            <div class="e-card e-avatar-showcase">
                <div class="e-card-content">
                    <div class="avatar-sub-block">
                        <!-- xSmall Avatar-->
                        <div class="e-avatar e-avatar-xsmall">
                            <img src="../pic01.png" alt="profile_pic">
                        </div>
                        <!-- Notification Badge -->
                        <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification e-badge-circle">6</span>
                    </div>
                    <div class="avatar-sub-block">
                        <!-- Small Avatar-->
                        <div class="e-avatar e-avatar-small">
                            <img src="../pic01.png" alt="profile_pic">
                        </div>
                        <!-- Notification Badge -->
                        <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification e-badge-circle">12</span>
                    </div>
                    <div class="avatar-sub-block">
                        <!-- Avatar-->
                        <div class="e-avatar">
                            <img src="../pic01.png" alt="profile_pic">
                        </div>
                        <!-- Notification Badge -->
                        <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification">46</span>
                    </div>
                    <div class="avatar-sub-block">
                        <!-- Large Avatar-->
                        <div class="e-avatar e-avatar-large">
                            <img src= alt="profile_pic">
                        </div>
                        <!-- Notification Badge -->
                        <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification">82</span>
                    </div>
                    <div class="avatar-sub-block">
                        <!-- xLarge Avatar-->
                        <div class="e-avatar e-avatar-xlarge">
                            <img src= alt="profile_pic">
                        </div>
                        <!-- Notification Badge -->
                        <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification">99+</span>
                    </div>
                </div>
            </div>
        </div>

        <div class="circleAvatar avatar-block">
            <!-- Card Component -->
            <div class="e-card e-avatar-showcase">
                <div class="e-card-content">
                    <div class="avatar-sub-block">
                        <!-- xSmall Circle Avatar-->
                        <div class="e-avatar e-avatar-circle e-avatar-xsmall">
                            <img src= alt="profile_pic">
                        </div>
                        <!-- Notification Badge -->
                        <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification e-badge-circle">6</span>
                    </div>
                    <div class="avatar-sub-block">
                        <!-- Small Circle Avatar-->
                        <div class="e-avatar e-avatar-circle e-avatar-small">
                            <img src= alt="profile_pic">
                        </div>
                        <!-- Notification Badge -->
                        <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification e-badge-circle">12</span>
                    </div>
                    <div class="avatar-sub-block">
                        <!-- Circle Avatar-->
                        <div class="e-avatar e-avatar-circle">
                            <img src= alt="profile_pic">
                        </div>
                        <!-- Notification Badge -->
                        <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification">46</span>
                    </div>
                    <div class="avatar-sub-block">
                        <!-- Large Circle Avatar-->
                        <div class="e-avatar e-avatar-circle e-avatar-large">
                            <img src= alt="profile_pic">
                        </div>
                        <!-- Notification Badge -->
                        <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification">82</span>
                    </div>
                    <div class="avatar-sub-block">
                        <!-- xLarge Circle Avatar-->
                        <div class="e-avatar e-avatar-circle e-avatar-xlarge">
                            <img src= alt="profile_pic">
                        </div>
                        <!-- Notification Badge -->
                        <span class="e-badge e-badge-primary e-badge-overlap e-badge-notification">99+</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
    `
})

export class AppComponent { }
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);