diff --git a/libs/avatar/package.json b/libs/avatar/package.json index b54836eb..90ed477f 100644 --- a/libs/avatar/package.json +++ b/libs/avatar/package.json @@ -1,6 +1,6 @@ { "name": "@ngx-bio-components/avatar", - "version": "0.0.14", + "version": "0.0.15", "license": "MIT", "author": "Umut Yerebakmaz (https://github.com/umutyerebakmaz)", "repository": { diff --git a/libs/avatar/src/lib/components/avatar/avatar.component.html b/libs/avatar/src/lib/components/avatar/avatar.component.html index d002dbdc..60cd34a8 100644 --- a/libs/avatar/src/lib/components/avatar/avatar.component.html +++ b/libs/avatar/src/lib/components/avatar/avatar.component.html @@ -1,11 +1,16 @@
-
{{ avatar.placeholder }}
- + diff --git a/libs/avatar/src/lib/components/avatar/avatar.component.stories.ts b/libs/avatar/src/lib/components/avatar/avatar.component.stories.ts index 19ccc702..bd311fae 100644 --- a/libs/avatar/src/lib/components/avatar/avatar.component.stories.ts +++ b/libs/avatar/src/lib/components/avatar/avatar.component.stories.ts @@ -17,8 +17,7 @@ export const primary = { badgeColor: 'green', badgePosition: 'topRight', path: 'http://localhost:4000/images/users/', - img: '28b4bf01-a067-46cb-9244-c55809608727.jpg', - placeholder: 'IO', + img: 'ecefa734-6a02-47dc-ae56-67102a8627ca.jpg', } } } diff --git a/libs/avatar/src/lib/components/avatar/avatar.component.ts b/libs/avatar/src/lib/components/avatar/avatar.component.ts index cbdb1d22..8e1d8baa 100644 --- a/libs/avatar/src/lib/components/avatar/avatar.component.ts +++ b/libs/avatar/src/lib/components/avatar/avatar.component.ts @@ -1,4 +1,4 @@ -import { Component, ChangeDetectionStrategy, Input, OnInit } from '@angular/core'; +import { Component, ChangeDetectionStrategy, Input, OnInit, SimpleChanges } from '@angular/core'; export type Avatar = { shape?: 'circular' | 'rounded'; @@ -20,24 +20,15 @@ export type Avatar = { export class BioAvatarComponent implements OnInit { @Input() avatar!: Avatar; + src!: string; ngOnInit(): void { + this.handler(); - if (this.avatar.path && this.avatar.img) { - this.avatar.img = this.avatar.path + this.avatar.img; - } - - if (!this.avatar.shape || this.avatar.shape === null) { - this.avatar.shape = 'circular'; - } - - if (!this.avatar.size || this.avatar.size === null) { - this.avatar.size = 'md' - } + } - if (this.avatar.placeholder) { - delete this.avatar.img; - } + ngOnChanges(changes: SimpleChanges): void { + this.handler(); } get addPlaceHolderContainerClass() { @@ -90,4 +81,23 @@ export class BioAvatarComponent implements OnInit { 'xl': this.avatar.size === 'xl' } } + + handler() { + if (this.avatar.path && this.avatar.img) { + this.src = this.avatar.path + this.avatar.img; + } + + if (!this.avatar.shape || this.avatar.shape === null) { + this.avatar.shape = 'circular'; + } + + if (!this.avatar.size || this.avatar.size === null) { + this.avatar.size = 'md' + } + + if (this.avatar.placeholder) { + delete this.avatar.img; + } + } + }