Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | 68x 68x 68x 68x 1x 1x 1x 1x | import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { mapValues } from 'lodash-es';
import { ListEditorComponent } from '../../component/list-editor/list-editor.component';
import { CodeComponent } from '../code/code.component';
@Component({
selector: 'app-themes',
templateUrl: './themes.component.html',
styleUrls: ['./themes.component.scss'],
host: { 'class': 'form-group' },
imports: [ListEditorComponent, CodeComponent]
})
export class ThemesFormComponentI implements OnChanges {
@Input()
fieldName = 'themes';
@Input()
label = $localize`theme`;
@Input()
group!: UntypedFormGroup;
keys: string[] = [];
selectedTheme?: string;
constructor(
private fb: UntypedFormBuilder,
) { }
ngOnChanges(changes: SimpleChanges) {
if (changes.group?.currentValue) {
this.keys = Object.keys(this.themes.value);
}
}
get themes() {
if (!this.group.contains(this.fieldName)) {
this.group.addControl(this.fieldName, this.fb.group({}));
}
return this.group.get(this.fieldName) as UntypedFormGroup;
}
addTheme(name: string, value = '') {
this.themes.addControl(name, this.fb.control(value));
}
removeTheme(name: string) {
this.themes.removeControl(name);
}
edit(name?: string) {
this.selectedTheme = name;
}
}
export function themesForm(fb: UntypedFormBuilder, themes: Record<string, string>) {
return fb.group(mapValues(themes, v => fb.control(v)));
}
|