import {
AfterViewInit,
ChangeDetectionStrategy,
Component,
EventEmitter,
Input,
OnChanges,
OnDestroy,
OnInit,
Output,
ViewChild,
} from '@angular/core';
import { FormsModule } from '@angular/forms';
import { Subscription } from 'rxjs';
import { OptionDirective, SelectBoxComponent, unsubscribe } from '@deepkit/desktop-ui';
import { TypeEnum } from '@deepkit/type';
@Component({
template: `
@for (kv of keyValues; track kv) {
{{ kv.label }}
}
`,
changeDetection: ChangeDetectionStrategy.Eager,
imports: [SelectBoxComponent, FormsModule, OptionDirective],
})
export class EnumInputComponent implements OnChanges, OnInit, AfterViewInit, OnDestroy {
@Input() model: any;
@Output() modelChange = new EventEmitter();
@Input() type!: TypeEnum;
keyValues: { value: any; label: string }[] = [];
@Output() done = new EventEmitter();
@Output() keyDown = new EventEmitter();
@ViewChild('select') select?: SelectBoxComponent;
@unsubscribe()
protected dropdownSub?: Subscription;
ngOnDestroy() {}
ngOnInit() {
this.load();
}
ngOnChanges() {
this.load();
}
ngAfterViewInit() {
this.select?.open();
}
load() {
for (const [label, value] of Object.entries(this.type.enum)) {
this.keyValues.push({ value, label });
}
}
}