import { ToggleOption } from '@ghostfolio/common/interfaces'; import { ChangeDetectionStrategy, Component, effect, input, output } from '@angular/core'; import { FormControl, ReactiveFormsModule } from '@angular/forms'; import { MatRadioModule } from '@angular/material/radio'; @Component({ changeDetection: ChangeDetectionStrategy.OnPush, imports: [MatRadioModule, ReactiveFormsModule], selector: 'gf-toggle', styleUrls: ['./toggle.component.scss'], templateUrl: './toggle.component.html' }) export class GfToggleComponent { public readonly defaultValue = input.required(); public readonly isLoading = input(false); public readonly options = input([]); protected readonly optionFormControl = new FormControl(null); protected readonly valueChange = output>(); public constructor() { effect(() => { this.optionFormControl.setValue(this.defaultValue()); }); } public onValueChange() { const value = this.optionFormControl.value; if (value !== null) { this.valueChange.emit({ value }); } } }