1.0.8 • Published 2 years ago

ng-avataaars-library v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

ng-avataaars

ng-avataaars is an angular component you can include in your project to allow users to make their own avatars.

You can also use it here to get the generated svg for your own use.

Features

  • Billions of permutations of avatars available.
  • Svgs are generated on client.
  • Can be localised into other languages
  • Unwanted options can be turned of
  • Can wire up your own services to save/load avatar. This example uses local storage.
  • Uses bootstrap for styling. So you will need to add bootstrap to your css files.

Angular component ported from the React Component developed by Fang-Pen Lin, based on the Sketch library Avataaars designed by Pablo Stanley.

Free for personal and commercial use.

Using the package

Navigate to the level of your package.json and type

 npm install ng-avataaars-library --save

Import the module into your app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { NgAvataaarsLibraryModule } from 'ng-avataaars-library';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NgAvataaarsLibraryModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

You can then use in one of your component html pages.

<kip-custom-avatar (avatarSaved)="onAvatarSaved($event)" [avatarSelection]="avatarSelection"></kip-custom-avatar>

Options that can be passed in

avatarSelection - used for setting the current avatar.

interface AvatarSelection {
  avatarStyle: AvatarStyle;
  topType: TopType;
  accessoriesType: AccessoriesType;
  hairColor: HairColor;
  facialHairType: FacialHairType;
  facialHairColor: HairColor;
  clotheType: ClotheType;
  clotheColor: ClotheColor;
  clotheColor2: ClotheColor;
  clotheColor3: ClotheColor;
  eyeType: EyeType;
  eyebrowType: EyebrowType;
  eyebrowColor: HairColor;
  mouthType: MouthType;
  skinColor: SkinColor;
  backgroundColor: BackgroundColor;
  graphicType: GraphicType;
  petType: PetType;
  awardType: AwardType;
  hatColor: HatColor;
  accessoriesColor: AccessoriesColor;
  noseType: NoseType;
  earringType: EarringType;
  earringColor: EarringColor;
}

avatarText - used for localizing.

interface AvatarText {
  save: string;
  random: string;
  revert: string;
  svg: string;
  background: string;
  backgroundColor: string;
  eyes: string;
  eyebrows: string;
  eyebrowColors: string;
  accessories: string;
  accessoryColors: string;
  facialHairs: string;
  facialHairColors: string;
  noses: string;
  mouths: string;
  pets: string;
  awards: string;
  hatsAndHairStyles: string;
  hairColors: string;
  hatColors: string;
  clothes: string;
  clotheColors1: string;
  clotheColors2: string;
  clotheColors3: string;
  graphics: string;
  skinColors: string;
  earrings: string;
  earringColors: string;
}

avatarExclusion - used for disabling choices. Example

avatarExclusion: AvatarExclusion = {
    mouthTypes: [MouthType.Vomit],
    graphicTypes: [GraphicType.Hola],
    topTypes: [TopType.Eyepatch],
    eyeTypes: [EyeType.Dizzy]
  };

Config options available

OptionTypeDefaultDescription
noNosebooleantrueTurns on nose choices (being extended)
noEarringbooleantrueTurns on earring choices (being extended)
noPetbooleantrueTurns on pet choices (being extended) - appears bottom left
noAwardbooleantrueTurns on awards/birthday graphics (being extended) - appears bottom right
noFacialHairbooleantrueTurns off ability to choose/see facial hair - could be used for children/women
noSvgOutputbooleantrueDisables ability to see/use svg output button
noRandombooleanfalseDisables ability to see/use random button
noColorBackgroundbooleanfalseDisables ability to choose the background/circle option
noSavebooleanfalseDisables ability to see/use save button

Saving of the avatar can be achieved by wiring up the avatarSaved event.

Example using local storage.

import { Component } from '@angular/core';
import { AccessoriesColor, AccessoriesType, AvatarSelection, AvatarStyle, AwardType, BackgroundColor, ClotheColor, ClotheType, EarringColor, EarringType, EyebrowType, EyeType, FacialHairType, GraphicType, HairColor, HatColor, MouthType, NoseType, PetType, SaveAvatar, SkinColor, TopType } from 'ng-avataaars-library';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {

  avatarSelection: AvatarSelection = {
    avatarStyle: AvatarStyle.Circle,
    topType: TopType.ShortHairShortFlat,
    accessoriesType: AccessoriesType.Blank,
    hairColor: HairColor.Black,
    facialHairType: FacialHairType.Blank,
    facialHairColor: HairColor.Black,
    eyebrowColor: HairColor.Black,
    clotheType: ClotheType.BlazerShirt,
    clotheColor: ClotheColor.Blue02,
    clotheColor2: ClotheColor.Blue01,
    clotheColor3: ClotheColor.Black,
    eyeType: EyeType.Default,
    eyebrowType: EyebrowType.Default,
    mouthType: MouthType.Smile,
    skinColor: SkinColor.Light,
    backgroundColor: BackgroundColor.ColorH,
    graphicType: GraphicType.Bat,
    petType: PetType.None,
    awardType: AwardType.None,
    hatColor: HatColor.Black,
    accessoriesColor: AccessoriesColor.Black,
    noseType: NoseType.Default,
    earringType: EarringType.Blank,
    earringColor: EarringColor.Black
  };

  onAvatarSaved(saveAvatar: SaveAvatar) {
    localStorage.setItem('avatar', JSON.stringify(saveAvatar.avatarSelection));
  }

  ngOnInit() {
    const avatar = localStorage.getItem('avatar');
    if (avatar) {
      this.avatarSelection = JSON.parse(avatar);
    }
  }
}

Demo

A demo can be found here.

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.1

5 years ago