import { Component, Input, OnInit } from '@angular/core'; import { IBadge } from '../../badge/interfaces'; import { Background, backgroundEnum, sizeEnum, Sizes } from '../../../shared/enums'; @Component ({ selector: 'cmn-avatar', templateUrl: './avatar.component.html', styleUrls: [ './avatar.component.scss' ], }) export class AvatarComponent implements OnInit { @Input() public text: string; @Input() public badge: IBadge; @Input() public readonly image: string; @Input() public readonly isCircle: boolean = true; @Input() public readonly size: Sizes = sizeEnum.medium; @Input() public readonly background: Background = backgroundEnum.default; public ngOnInit(): void { if (!this.image && this.text) { const textArray: string[] = this.text.split(' '); this.text = textArray.length > 1 ? this.getInitialUpperCase(textArray) : this.getTwoFirstLetters(this.text); } } private getInitialUpperCase = (textArray: string[]): string => { return textArray[0][0].toUpperCase() + textArray[1][0].toUpperCase(); } private getTwoFirstLetters = (text: string): string => { return text[0].toUpperCase() + text[1].toLowerCase(); } }