libs/core/dynamic-form/circle-toggle-group/src/circle-toggle-group.component.ts
DfBaseComponent<DfCircleToggleGroupConfig>
| changeDetection | ChangeDetectionStrategy.OnPush |
| selector | df-circle-toggle-group |
| styleUrls | ./circle-toggle-group.component.scss |
| templateUrl | ./circle-toggle-group.component.html |
Properties |
|
Methods |
Inputs |
Outputs |
| control | |
Default value : new UntypedFormControl()
|
|
|
Inherited from
DfBaseComponent
|
|
| responsive | |
Type : boolean
|
|
Default value : false
|
|
| 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
|
| Readonly circleToggles |
Type : unknown
|
Default value : computed<DfCircleToggle[]>(() => this.config().options)
|
| Readonly columnSpan |
Type : unknown
|
Default value : computed(() =>
this.config().layout?.optionsColumnSpan ? String(this.config().layout?.optionsColumnSpan) : '4'
)
|
| Readonly optionsLeftAlignInExpert |
Type : unknown
|
Default value : computed(
() => !this.isRetailChannel() && Boolean(this.config().layout?.optionsLeftAlignInExpert)
)
|
| Readonly rowJustify |
Type : unknown
|
Default value : computed(() =>
!this.isRetailChannel() || this.isA1 ? 'start' : 'center'
)
|
| 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 { IS_A1 } from '@allianz/taly-core';
import { DfBaseComponent } from '@allianz/taly-core/dynamic-form';
import {
ChangeDetectionStrategy,
Component,
computed,
ElementRef,
inject,
input,
InputSignal,
OnInit
} from '@angular/core';
import { UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { DfCircleToggle, DfCircleToggleGroupConfig } from './circle-toggle-group.model';
@Component({
selector: 'df-circle-toggle-group',
templateUrl: './circle-toggle-group.component.html',
styleUrls: ['./circle-toggle-group.component.scss'],
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class DfCircleToggleGroupComponent
extends DfBaseComponent<DfCircleToggleGroupConfig>
implements OnInit
{
override control: InputSignal<UntypedFormControl> | InputSignal<UntypedFormGroup> = input(
new UntypedFormControl()
);
responsive = input(false);
protected isA1 = inject(IS_A1);
private el = inject(ElementRef);
readonly circleToggles = computed<DfCircleToggle[]>(() => this.config().options);
readonly rowJustify = computed(() =>
!this.isRetailChannel() || this.isA1 ? 'start' : 'center'
);
readonly columnSpan = computed(() =>
this.config().layout?.optionsColumnSpan ? String(this.config().layout?.optionsColumnSpan) : '4'
);
readonly optionsLeftAlignInExpert = computed(
() => !this.isRetailChannel() && Boolean(this.config().layout?.optionsLeftAlignInExpert)
);
override ngOnInit() {
super.ngOnInit();
this.emitFormControlEventOnValueChanges();
}
onBlur(event: FocusEvent) {
const circleToggleGroupHasFocus = this.el.nativeElement.contains(event.relatedTarget);
if (circleToggleGroupHasFocus) {
return;
}
this.emitFormEvent('onBlurEvent', this.control().value);
}
}
@if (config().label || config().infoIcon) {
<span
class="df-circle-toggle-group-label"
[ngClass]="{
'is-centered': isRetailChannel() && !isA1
}"
>
@if (config().label && isRetailChannel()) {
<p nxHeadline="subsection-xsmall" class="nx-font-weight-regular">
{{ config().label | interpolateFromStore | async }}
</p>
} @else if (config().label && !isRetailChannel()) {
<p nxCopytext class="nx-margin-bottom-s nx-font-weight-semibold">
{{ config().label | interpolateFromStore | async }}
</p>
} @if (config().infoIcon) {
<df-info-icon nxFormfieldAppendix [config]="config().infoIcon"> </df-info-icon>
}
</span>
}
<nx-circle-toggle-group
[formControl]="$any(control())"
[responsive]="responsive()"
[attr.data-testid]="config().testId"
(focusout)="onBlur($event)"
>
<div nxLayout="grid maxwidth nopadding">
<div nxRow [rowJustify]="rowJustify()" data-testid="optionsRow">
@for (item of circleToggles(); track item.value) {
<div
[nxCol]="columnSpan()"
[ngClass]="{
'options-center': !optionsLeftAlignInExpert() && !(isRetailChannel() && isA1)
}"
data-testid="optionsCol"
>
<nx-circle-toggle
[label]="(item.label | interpolateFromStore | async) ?? ''"
[value]="item.value"
id="{{ item.value }}"
data-testid="circleToggle"
[icon]="item.icon ?? ''"
[svg]="item.svg ?? '' | talyNormalizeUrl"
[svgChecked]="item.svgChecked ?? '' | talyNormalizeUrl"
[hint]="(item.hint | interpolateFromStore | async) ?? ''"
[circleText]="(item.circleText | interpolateFromStore | async) ?? ''"
>
</nx-circle-toggle>
</div>
}
</div>
</div>
@for (message$ of errorMessages(); track $index) {
<nx-error class="nx-margin-top-xs" [appearance]="nxErrorAppearance">{{
message$ | async
}}</nx-error>
}
</nx-circle-toggle-group>
@if (config().note && !(control().touched && control().invalid)) {
<nx-message context="info">
<span>{{ config().note }}</span>
</nx-message>
}
./circle-toggle-group.component.scss
:host {
df-info-icon {
::ng-deep {
padding-left: 8px;
}
}
}
.options-center {
display: flex;
justify-content: center;
}
.df-circle-toggle-group-label {
display: block;
margin-bottom: 16px;
&.is-centered {
text-align: center;
}
p {
display: inline;
}
}