You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

status-led.directive.ts 1.2KB

1234567891011121314151617181920212223242526272829303132333435
  1. import {Directive, ElementRef, Input, OnChanges, SimpleChanges} from '@angular/core';
  2. import {StatusEnumViewModel} from '../view-models/status-enum.view-model';
  3. @Directive({
  4. selector: '[appStatusLed]'
  5. })
  6. export class StatusLedDirective implements OnChanges {
  7. @Input()
  8. appStatusLed: string;
  9. constructor(private el: ElementRef) {
  10. const size = 15;
  11. this.el.nativeElement.style.width = `${size}px`;
  12. this.el.nativeElement.style.height = `${size}px`;
  13. this.el.nativeElement.style.borderRadius = `${size / 2}px`;
  14. this.el.nativeElement.style.display = 'inline-block';
  15. }
  16. static colorFromValue(value: StatusEnumViewModel): string {
  17. if (value === StatusEnumViewModel.Ok) {
  18. return '#01ff01';
  19. } else if (value === StatusEnumViewModel.Warning) {
  20. return '#ffa500';
  21. } else if (value === StatusEnumViewModel.Error) {
  22. return '#ff0000';
  23. }
  24. return null;
  25. }
  26. ngOnChanges(changes: SimpleChanges): void {
  27. if (changes.appStatusLed) {
  28. this.el.nativeElement.style.backgroundColor = StatusLedDirective.colorFromValue(changes.appStatusLed.currentValue);
  29. }
  30. }
  31. }