From 746018f6b81b40e8858303662ac9ec5ce59ac6eb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 28 Apr 2021 11:49:34 +0200 Subject: Refactor actor avatar display --- .../shared-actor-image/actor-avatar.component.html | 19 ++++ .../shared-actor-image/actor-avatar.component.scss | 101 +++++++++++++++++++ .../shared-actor-image/actor-avatar.component.ts | 110 +++++++++++++++++++++ client/src/app/shared/shared-actor-image/index.ts | 1 + .../shared-actor-image.module.ts | 23 +++++ 5 files changed, 254 insertions(+) create mode 100644 client/src/app/shared/shared-actor-image/actor-avatar.component.html create mode 100644 client/src/app/shared/shared-actor-image/actor-avatar.component.scss create mode 100644 client/src/app/shared/shared-actor-image/actor-avatar.component.ts create mode 100644 client/src/app/shared/shared-actor-image/index.ts create mode 100644 client/src/app/shared/shared-actor-image/shared-actor-image.module.ts (limited to 'client/src/app/shared/shared-actor-image') diff --git a/client/src/app/shared/shared-actor-image/actor-avatar.component.html b/client/src/app/shared/shared-actor-image/actor-avatar.component.html new file mode 100644 index 000000000..607f28e5b --- /dev/null +++ b/client/src/app/shared/shared-actor-image/actor-avatar.component.html @@ -0,0 +1,19 @@ + + + +
+ {{ initial }} +
+
+ + + + + + + + + + + + diff --git a/client/src/app/shared/shared-actor-image/actor-avatar.component.scss b/client/src/app/shared/shared-actor-image/actor-avatar.component.scss new file mode 100644 index 000000000..f014dec48 --- /dev/null +++ b/client/src/app/shared/shared-actor-image/actor-avatar.component.scss @@ -0,0 +1,101 @@ +@import '_variables'; +@import '_mixins'; + +.avatar { + --avatarSize: 100%; + --initialFontSize: 22px; + + width: var(--avatarSize); + height: var(--avatarSize); + min-width: var(--avatarSize); + min-height: var(--avatarSize); + + &.account { + object-fit: cover; + border-radius: 50%; + } + + &.channel { + border-radius: 5px; + } +} + +.avatar-18 { + --avatarSize: 18px; + --initialFontSize: 13px; +} + +.avatar-25 { + --avatarSize: 25px; +} + +.avatar-32 { + --avatarSize: 32px; +} + +.avatar-34 { + --avatarSize: 34px; +} + +.avatar-36 { + --avatarSize: 36px; +} + +.avatar-40 { + --avatarSize: 40px; +} + +.avatar-100 { + --avatarSize: 100px; + --initialFontSize: 40px; + } + +.avatar-120 { + --avatarSize: 120px; + --initialFontSize: 46px; +} + +a:hover { + text-decoration: none; +} + +.initial { + background-color: #3C2109; + color: #fff; + display: flex; + align-items: center; + justify-content: center; + font-size: var(--initialFontSize); + + &.blue { + background-color: #009FD4; + } + + &.green { + background-color: #00AA55; + } + + &.purple { + background-color: #B381B3; + } + + &.gray { + background-color: #939393; + } + + &.yellow { + background-color: #AA8F00; + } + + &.orange { + background-color: #D47500; + } + + &.red { + background-color: #E76E3C; + } + + &.dark-blue { + background-color: #0A3055; + } +} diff --git a/client/src/app/shared/shared-actor-image/actor-avatar.component.ts b/client/src/app/shared/shared-actor-image/actor-avatar.component.ts new file mode 100644 index 000000000..6bb3b65fa --- /dev/null +++ b/client/src/app/shared/shared-actor-image/actor-avatar.component.ts @@ -0,0 +1,110 @@ +import { Component, Input } from '@angular/core' +import { SafeResourceUrl } from '@angular/platform-browser' +import { VideoChannel } from '../shared-main' +import { Account } from '../shared-main/account/account.model' + +type ActorInput = { + name: string + avatar?: { url?: string, path: string } + url: string +} + +@Component({ + selector: 'my-actor-avatar', + styleUrls: [ './actor-avatar.component.scss' ], + templateUrl: './actor-avatar.component.html' +}) +export class ActorAvatarComponent { + @Input() account: ActorInput + @Input() channel: ActorInput + + @Input() previewImage: SafeResourceUrl + + @Input() size: '18' | '25' | '32' | '34' | '36' | '40' | '100' | '120' + + // Use an external link + @Input() href: string + // Use routerLink + @Input() internalHref: string | any[] + + @Input() set title (value) { + this._title = value + } + + private _title: string + + get title () { + if (this._title) return this._title + if (this.account) return $localize`${this.account.name} (account page)` + if (this.channel) return $localize`${this.channel.name} (channel page)` + + return '' + } + + get alt () { + if (this.account) return $localize`Account avatar` + if (this.channel) return $localize`Channel avatar` + + return '' + } + + get class () { + const base = [ 'avatar' ] + + if (this.size) base.push(`avatar-${this.size}`) + + if (this.account) base.push('account') + else base.push('channel') + + if (this.initial) { + base.push('initial') + base.push(this.getColorTheme()) + } + + return base + } + + get defaultAvatarUrl () { + if (this.account) Account.GET_DEFAULT_AVATAR_URL() + if (this.channel) return VideoChannel.GET_DEFAULT_AVATAR_URL() + + return '' + } + + get avatarUrl () { + if (this.account) return Account.GET_ACTOR_AVATAR_URL(this.account) + if (this.channel) return VideoChannel.GET_ACTOR_AVATAR_URL(this.account) + + return '' + } + + get initial () { + const name = this.account?.name + if (!name) return '' + + return name.slice(0, 1) + } + + hasActor () { + return !!this.account || !!this.channel + } + + private getColorTheme () { + // Keep consistency with CSS + const themes = { + abc: 'blue', + def: 'green', + ghi: 'purple', + jkl: 'gray', + mno: 'yellow', + pqr: 'orange', + stv: 'red', + wxyz: 'dark-blue' + } + + const theme = Object.keys(themes) + .find(chars => chars.includes(this.initial)) + + return themes[theme] + } +} diff --git a/client/src/app/shared/shared-actor-image/index.ts b/client/src/app/shared/shared-actor-image/index.ts new file mode 100644 index 000000000..18a9038eb --- /dev/null +++ b/client/src/app/shared/shared-actor-image/index.ts @@ -0,0 +1 @@ +export * from './shared-actor-image.module' diff --git a/client/src/app/shared/shared-actor-image/shared-actor-image.module.ts b/client/src/app/shared/shared-actor-image/shared-actor-image.module.ts new file mode 100644 index 000000000..8ea4bb2bf --- /dev/null +++ b/client/src/app/shared/shared-actor-image/shared-actor-image.module.ts @@ -0,0 +1,23 @@ + +import { NgModule } from '@angular/core' +import { SharedGlobalIconModule } from '../shared-icons' +import { SharedMainModule } from '../shared-main/shared-main.module' +import { ActorAvatarComponent } from './actor-avatar.component' + +@NgModule({ + imports: [ + SharedMainModule, + SharedGlobalIconModule + ], + + declarations: [ + ActorAvatarComponent + ], + + exports: [ + ActorAvatarComponent + ], + + providers: [ ] +}) +export class SharedActorImageModule { } -- cgit v1.2.3