Skip to content

Angular directives used to generate identicons using Jdenticon.

License

Notifications You must be signed in to change notification settings

dmester/ngx-jdenticon

Repository files navigation

ngx-jdenticon

Angular directives used to generate identicons using Jdenticon.

Sample identicons

GitHub Workflow Status Downloads License MIT

🚀 Sample app at StackBlitz

Install

Install the ngx-jdenticon and jdenticon NPM packages.

npm install --save ngx-jdenticon jdenticon

Import NgxJdenticonModule into your app.module.ts (or another module).

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { NgxJdenticonModule } from 'ngx-jdenticon'; // <--- Add

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NgxJdenticonModule, // <--- Add
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Add an icon by decorating either an <svg> or <canvas> element with the data-jdenticon-value or data-jdenticon-hash attribute.

<svg width="100" height="100" data-jdenticon-value="John Doe"></svg>

Customize look

If you don't like the default colors, use the icon designer to customize the look of identicons generated by ngx-jdenticon.

Icon style configurations are applied by adding a provider for the JDENTICON_CONFIG injection token.

import { NgxJdenticonModule, JDENTICON_CONFIG } from 'ngx-jdenticon';

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    NgxJdenticonModule,
  ],
  providers: [
    { 
      // Custom identicon style
      // https://jdenticon.com/icon-designer.html?config=222222ff014132321e363f52
      provide: JDENTICON_CONFIG,
      useValue: {
        lightness: {
          color: [0.31, 0.54],
          grayscale: [0.63, 0.82],
        },
        saturation: {
          color: 0.50,
          grayscale: 0.50,
        },
        backColor: '#222',
      },
    }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

🚀 Run on StackBlitz

See also

Jdenticon homepage