libs/core/dynamic-form/toggle-button/src/toggle-button.component.ts
DfBaseComponent<DfToggleButtonConfig>
| changeDetection | ChangeDetectionStrategy.OnPush |
| selector | df-toggle-button |
| standalone | true |
| imports | |
| styleUrls | ./toggle-button.component.scss |
| templateUrl | ./toggle-button.component.html |
No results matching.
Properties |
Methods |
Inputs |
Outputs |
| control | |
Type : UntypedFormControl
|
|
Default value : new UntypedFormControl()
|
|
|
Inherited from
DfBaseComponent
|
|
| config | |
Type : C
|
|
| Required : true | |
|
Inherited from
DfBaseComponent
|
|
|
The configuration object for this formfield. Note that derived formfield components should extend the |
|
| formAclPath | |
Type : string
|
|
|
Inherited from
DfBaseComponent
|
|
| isAclHandled | |
Type : boolean
|
|
Default value : false
|
|
|
Inherited from
DfBaseComponent
|
|
| isRetailChannel | |
Type : boolean
|
|
|
Inherited from
DfBaseComponent
|
|
| validationConfigs | |
Type : ValidationConfig[] | undefined
|
|
|
Inherited from
DfBaseComponent
|
|
| formEvent | |
Type : DfEventPayload
|
|
|
Inherited from
DfBaseComponent
|
|
|
Emits when events associated to the form control happen. The emitted object contains the data necessary to uniquely identify the event (field id and event type). It also contains the event data. |
|
| onBlur | ||||||
onBlur(event: FocusEvent)
|
||||||
|
Parameters :
Returns :
void
|
| DfToggleButtonSize |
Type : unknown
|
Default value : DfToggleButtonSize
|
| componentOrControlInitFinished |
Type : unknown
|
Default value : new ReplaySubject<AbstractControl | undefined>(1)
|
|
Inherited from
DfBaseComponent
|
|
This ReplaySubject is provided to emit the control once it is initialized. |
| errorMessages |
Type : WritableSignal<Observable[]>
|
Default value : signal([])
|
|
Inherited from
DfBaseComponent
|
|
The resolved validation error messages for the current control state. |
| Readonly nxErrorAppearance |
Type : ErrorStyleType
|
Default value : inject(ERROR_DEFAULT_OPTIONS, { optional: true })?.appearance ||
(inject<CHANNEL>(CHANNEL_TOKEN) === CHANNEL.EXPERT ? 'text' : 'message')
|
|
Inherited from
DfBaseComponent
|
import {
DfBaseComponent,
DfBaseModule,
DfInfoIconComponent,
DfOptionsProviderService
} from '@allianz/taly-core/dynamic-form';
import {
ChangeDetectionStrategy,
Component,
ElementRef,
inject,
input,
OnInit
} from '@angular/core';
import { toObservable } from '@angular/core/rxjs-interop';
import { ReactiveFormsModule, UntypedFormControl } from '@angular/forms';
import { DfToggleButtonConfig, DfToggleButtonSize } from './toggle-button.model';
import { NxLabelModule } from '@allianz/ng-aquila/base';
import { NxRadioToggleModule } from '@allianz/ng-aquila/radio-toggle';
import { NxIconModule } from '@allianz/ng-aquila/icon';
import { NxMessageModule } from '@allianz/ng-aquila/message';
import { NxFormfieldModule } from '@allianz/ng-aquila/formfield';
import { of } from 'rxjs';
import { switchMap } from 'rxjs/operators';
@Component({
selector: 'df-toggle-button',
styleUrls: ['./toggle-button.component.scss'],
templateUrl: './toggle-button.component.html',
imports: [
ReactiveFormsModule,
NxLabelModule,
NxRadioToggleModule,
NxIconModule,
NxMessageModule,
DfBaseModule,
DfInfoIconComponent,
NxFormfieldModule
],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class DfToggleButtonComponent
extends DfBaseComponent<DfToggleButtonConfig>
implements OnInit
{
override control = input<UntypedFormControl>(new UntypedFormControl());
DfToggleButtonSize = DfToggleButtonSize;
toggleButtonOptions$ = toObservable(this.config).pipe(
switchMap((config) => {
if (Array.isArray(config.options)) {
return of(config.options);
}
if (this.optionsProviderService) {
return this.optionsProviderService.getDfOptions(config.options);
}
return of([]);
})
);
private optionsProviderService = inject(DfOptionsProviderService, { optional: true });
private el = inject(ElementRef);
override ngOnInit() {
super.ngOnInit();
this.emitFormControlEventOnValueChanges();
}
onBlur(event: FocusEvent) {
const toggleButtonHasFocus = this.el.nativeElement.contains(event.relatedTarget);
if (toggleButtonHasFocus) {
return;
}
this.emitFormEvent('onBlurEvent', this.control().value);
}
}
@if (config().label) {
<div class="df-toggle-button-label__container" [ngClass]="{ 'is-centered': isRetailChannel() }">
<nx-label
[size]="isRetailChannel() ? 'large' : 'small'"
[ngClass]="{
'nx-font-weight-regular': isRetailChannel()
}"
>{{ config().label | interpolateFromStore | async }}
</nx-label>
@if (config().infoIcon) {
<df-info-icon nxFormfieldAppendix [config]="config().infoIcon"></df-info-icon>
}
</div>
}
<nx-radio-toggle
[formControl]="control()"
[id]="config().id"
[attr.data-testid]="config().testId"
[variant]="isRetailChannel() ? config().size || '' : DfToggleButtonSize.Small"
(focusout)="onBlur($event)"
[ngClass]="{ 'is-centered': isRetailChannel() }"
>
@for (option of toggleButtonOptions$ | async; track $index) {
<nx-radio-toggle-button [value]="option.value" [attr.data-testid]="option?.testId"
><span>{{ option.label | interpolateFromStore | async }}</span>
</nx-radio-toggle-button>
} @for (message$ of errorMessages(); track $index) {
<nx-error [appearance]="nxErrorAppearance">{{ message$ | async }}</nx-error>
}
</nx-radio-toggle>
@if (config().note && !(control().touched && control().invalid)) {
<nx-message context="info">
<span>{{ config().note | interpolateFromStore | async }}</span>
</nx-message>
}
./toggle-button.component.scss
:host {
display: block;
}
.df-toggle-button-label__container {
display: flex;
margin-bottom: 16px;
&.is-centered {
justify-content: center;
}
}
df-info-icon {
padding-left: 8px;
}
nx-radio-toggle.is-centered ::ng-deep .nx-radio-toggle {
justify-content: center;
}