Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

991 B
Raw Blame
import { NgClass } from '@angular/common'
import { booleanAttribute, Component, input, OnChanges, OnInit, ChangeDetectionStrategy } from '@angular/core'

export type AlertType = 'success' | 'info' | 'warning' | 'danger' | 'primary'

@Component({
  selector: 'my-alert',
  templateUrl: './alert.component.html',
  changeDetection: ChangeDetectionStrategy.Eager,
  imports: [ NgClass ]
})
export class AlertComponent implements OnInit, OnChanges {
  readonly type = input.required<AlertType>()
  readonly rounded = input(true, { transform: booleanAttribute })

  builtClasses = ''

  ngOnInit () {
    this.buildClasses()
  }

  ngOnChanges () {
    this.buildClasses()
  }

  private buildClasses () {
    this.builtClasses = 'alert'

    const type = this.type()
    if (type === 'primary') {
      this.builtClasses += ' pt-alert-primary'
    } else {
      this.builtClasses += ' alert-' + type
    }

    if (this.rounded() !== true) {
      this.builtClasses += ' rounded-0'
    }
  }
}