libs/core/dynamic-form/notification/src/notification.component.ts
DfBaseComponent<DfNotificationConfig>
| changeDetection | ChangeDetectionStrategy.OnPush |
| selector | df-notification |
| standalone | true |
| imports | |
| styleUrls | ./notification.component.scss |
| templateUrl | ./notification.component.html |
No results matching.
Properties |
|
Inputs |
Outputs |
| control | |
Default value : undefined
|
|
|
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. |
|
| Readonly isHidden |
Type : unknown
|
Default value : computed(() => this.closedNotification() || !this.visibilityFromConfig())
|
| 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 } from '@allianz/taly-core/dynamic-form';
import { ChangeDetectionStrategy, Component, computed, inject, input, signal } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { LocalizeFn } from '@angular/localize/init';
import { CommonModule } from '@angular/common';
import { NxGridModule } from '@allianz/ng-aquila/grid';
import { NxMessageModule } from '@allianz/ng-aquila/message';
import { TalyStateService } from '@allianz/taly-core';
import { MarkdownToHtmlComponent } from '@allianz/taly-core/ui';
import { DfNotificationConfig } from './notification.model';
declare let $localize: LocalizeFn;
@Component({
selector: 'df-notification',
templateUrl: './notification.component.html',
styleUrls: ['./notification.component.scss'],
imports: [CommonModule, NxGridModule, NxMessageModule, DfBaseModule, MarkdownToHtmlComponent],
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class DfNotificationComponent extends DfBaseComponent<DfNotificationConfig> {
override control = input(undefined);
private closedNotification = signal(false);
private visibilityFromConfig = signal(true);
private stateService = inject(TalyStateService, { optional: true });
readonly isHidden = computed(() => this.closedNotification() || !this.visibilityFromConfig());
override ngOnInit(): void {
super.ngOnInit();
const visibleIf = this.config().visibleIf;
if (visibleIf) {
if (this.stateService) {
this.stateService
.evaluateCondition$(visibleIf)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((visible) => {
this.visibilityFromConfig.set(visible);
if (visible) {
this.closedNotification.set(false);
}
});
} else {
console.warn(
`The "visibleIf" property requires TalyStateService which is unavailable. Notification will remain visible.`
);
}
}
}
protected onClose(): void {
this.closedNotification.set(true);
}
protected getCloseButtonLabel(): string {
const config = this.config();
if (config.closeButtonLabel) {
return config.closeButtonLabel;
}
const contextLabel: Record<DfNotificationConfig['context'], string> = {
info: $localize`:Context of an info notification:info`,
success: $localize`:Context of a success notification:success`,
warning: $localize`:Context of a warning notification:warning`,
error: $localize`:Context of an error notification:error`
};
return $localize`:Label for the close button in a notification:Close ${
contextLabel[config.context]
} notification`;
}
}
@if (!isHidden()) {
<nx-message
[context]="config().context"
[closable]="config().closable ?? true"
[closeButtonLabel]="getCloseButtonLabel()"
(close)="onClose()"
[attr.data-testid]="config().testId"
>
<div>
@if (config().title) {
<span class="nx-font-weight-bold" data-testid="notification-title">
{{ config().title | interpolateFromStore | async }}
</span>
<br />
}
<taly-markdown-to-html [markdown]="(config().message | interpolateFromStore | async) || ''" />
</div>
</nx-message>
}
./notification.component.scss
:host {
display: block;
}