File

src/lib/default-header/user-profile-icon/user-profile-icon.component.ts

Metadata

Index

Properties
Methods
Inputs

Inputs

profile
Required :  true

Methods

Public logout
logout()
Returns : void

Properties

Protected Readonly extractUsernameFromProfile
Type : ExtractUsernameFromProfileFn
Default value : inject(EXTRACT_USERNAME_FROM_PROFILE)
Public Readonly profile
Protected Readonly pubSubService
Default value : inject(PubSubService)
Public Readonly username
Default value : computed(() => { const profile = this.profile(); if (profile) { return this.extractUsernameFromProfile(profile); } return null; })
import {
  ChangeDetectionStrategy,
  Component,
  computed,
  inject,
  input,
} from '@angular/core';
import { MatIconModule } from '@angular/material/icon';
import { MatMenuModule } from '@angular/material/menu';
import {
  PubSubService,
  RXAP_TOPICS,
} from '@rxap/ngx-pub-sub';
import { EXTRACT_USERNAME_FROM_PROFILE } from '../../tokens';
import { ExtractUsernameFromProfileFn } from '../../types';

@Component({
    selector: 'rxap-user-profile-icon',
    templateUrl: './user-profile-icon.component.html',
    styleUrls: ['./user-profile-icon.component.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush,
    imports: [
        MatMenuModule,
        MatIconModule,
    ]
})
export class UserProfileIconComponent {

  protected readonly extractUsernameFromProfile: ExtractUsernameFromProfileFn = inject(EXTRACT_USERNAME_FROM_PROFILE);
  protected readonly pubSubService = inject(PubSubService);

  public readonly profile = input.required();

  public readonly username = computed(() => {
    const profile = this.profile();
    if (profile) {
      return this.extractUsernameFromProfile(profile);
    }
    return null;
  });

  public logout() {
    this.pubSubService.publish(RXAP_TOPICS.authentication.logout);
  }


}
<button [matMenuTriggerFor]="menu"
        class="rounded-full cursor-pointer outline-none overflow-hidden h-8 w-8 bg-center bg-no-repeat bg-cover flex flex-row justify-center items-center">
  <mat-icon class="h-8 w-8 text-[32px]" svgIcon="account-circle"></mat-icon>
</button>

<mat-menu #menu="matMenu" [yPosition]="'below'" class="!max-w-none">
  @if (this.username(); as username) {
  <button mat-menu-item>
    <span class="flex flex-row gap-2">
      <mat-icon svgIcon="account"></mat-icon>
      <span>{{username}}</span>
    </span>
  </button>
  }
  <button (click)="logout()" mat-menu-item>
    <span class="flex flex-row gap-2">
      <mat-icon svgIcon="logout"></mat-icon>
      <span i18n>Logout</span>
    </span>
  </button>
</mat-menu>

./user-profile-icon.component.scss

Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""