Browse Source

feat(lib): implement input signals

pull/6533/head
KenTandrian 3 weeks ago
parent
commit
23f93154fa
  1. 6
      libs/ui/src/lib/toggle/toggle.component.html
  2. 10
      libs/ui/src/lib/toggle/toggle.component.ts

6
libs/ui/src/lib/toggle/toggle.component.html

@ -3,13 +3,13 @@
[formControl]="optionFormControl"
(change)="onValueChange()"
>
@for (option of options; track option) {
@for (option of options(); track option) {
<mat-radio-button
class="d-inline-flex"
[disabled]="isLoading"
[disabled]="isLoading()"
[ngClass]="{
'cursor-default': option.value === optionFormControl.value,
'cursor-pointer': !isLoading && option.value !== optionFormControl.value
'cursor-pointer': !isLoading() && option.value !== optionFormControl.value
}"
[value]="option.value"
>{{ option.label }}</mat-radio-button

10
libs/ui/src/lib/toggle/toggle.component.ts

@ -4,8 +4,8 @@ import { CommonModule } from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
Input,
OnChanges,
input,
output
} from '@angular/core';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
@ -19,15 +19,15 @@ import { MatRadioModule } from '@angular/material/radio';
templateUrl: './toggle.component.html'
})
export class GfToggleComponent implements OnChanges {
@Input() defaultValue: string;
@Input() isLoading: boolean;
@Input() options: ToggleOption[] = [];
public readonly defaultValue = input.required<string>();
public readonly isLoading = input<boolean>(false);
public readonly options = input<ToggleOption[]>([]);
protected readonly optionFormControl = new FormControl<string | null>(null);
protected readonly valueChange = output<Pick<ToggleOption, 'value'>>();
public ngOnChanges() {
this.optionFormControl.setValue(this.defaultValue);
this.optionFormControl.setValue(this.defaultValue());
}
public onValueChange() {

Loading…
Cancel
Save