libs/core/dynamic-form/tile/src/tile.component.ts
| changeDetection | ChangeDetectionStrategy.OnPush |
| selector | df-tile |
| standalone | true |
| imports |
NxTileComponent
NxTileGroupComponent
NxFormfieldAppendixDirective
NxLabelComponent
NxErrorComponent
|
| styleUrls | ./tile.component.scss |
| templateUrl | ./tile.component.html |
No results matching.
ReactiveFormsModule
AsyncPipe
NgClass
NxTileComponent
NxTileGroupComponent
NxGridModule
NxCopytextModule
NxMessageModule
DfBaseModule
DfInfoIconComponent
NxFormfieldAppendixDirective
NxLabelComponent
NxErrorComponent
DfBaseComponent<DfTileConfig>
OnInit
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
|
| Readonly maxColumns |
Type : unknown
|
Default value : computed(() => {
const layout = this.config().layout;
if (layout && this.isAutogridLayout(layout)) {
return layout.maxColumns ?? 4;
}
return 4;
})
|
| Readonly selectionMode |
Type : Signal<NxTileSelectionMode>
|
Default value : computed(() =>
this.config().multiSelect ? 'multi' : 'single'
)
|
| Readonly tiles |
Type : unknown
|
Default value : computed<DfTile[]>(() => this.config().options)
|
| Readonly useAutogrid |
Type : unknown
|
Default value : computed(() => this.config().layout?.useAutogrid ?? false)
|
| 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 { AsyncPipe, NgClass } from '@angular/common';
import { NxCopytextModule } from '@allianz/ng-aquila/copytext';
import { NxGridModule } from '@allianz/ng-aquila/grid';
import { NxMessageModule } from '@allianz/ng-aquila/message';
import {
NxTileComponent,
NxTileGroupComponent,
NxTileSelectionMode
} from '@allianz/ng-aquila/tile';
import {
CONTAINER_BREAKPOINT_M,
DfBaseComponent,
DfBaseModule,
DfInfoIconComponent,
FORM_CONTAINER_WIDTH
} from '@allianz/taly-core/dynamic-form';
import {
ChangeDetectionStrategy,
Component,
computed,
ElementRef,
inject,
input,
OnInit,
Signal
} from '@angular/core';
import { ReactiveFormsModule, UntypedFormControl } from '@angular/forms';
import {
DfTile,
DfTileAutogridLayout,
DfTileConfig,
DfTileFixedWidthLayout,
TileLayoutDirection,
TileWidth
} from './tile.model';
import { NxFormfieldAppendixDirective } from '@allianz/ng-aquila/formfield';
import { NxLabelComponent, NxErrorComponent } from '@allianz/ng-aquila/base';
@Component({
selector: 'df-tile',
templateUrl: './tile.component.html',
styleUrls: ['./tile.component.scss'],
imports: [
ReactiveFormsModule,
AsyncPipe,
NgClass,
NxTileComponent,
NxTileGroupComponent,
NxGridModule,
NxCopytextModule,
NxMessageModule,
DfBaseModule,
DfInfoIconComponent,
NxFormfieldAppendixDirective,
NxLabelComponent,
NxErrorComponent
],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class DfTileComponent extends DfBaseComponent<DfTileConfig> implements OnInit {
override control = input<UntypedFormControl>(new UntypedFormControl());
readonly tiles = computed<DfTile[]>(() => this.config().options);
private el = inject(ElementRef);
private formContainerWidth = inject(FORM_CONTAINER_WIDTH, { optional: true });
private readonly isMobile = computed(
() => (this.formContainerWidth?.() ?? Infinity) <= CONTAINER_BREAKPOINT_M
);
readonly useAutogrid = computed(() => this.config().layout?.useAutogrid ?? false);
readonly maxColumns = computed(() => {
const layout = this.config().layout;
if (layout && this.isAutogridLayout(layout)) {
return layout.maxColumns ?? 4;
}
return 4;
});
readonly tileLayout = computed(() => {
const configLayout = this.config().layout?.tileLayout;
const useFixedTileLayout =
configLayout === TileLayoutDirection.Horizontal ||
configLayout === TileLayoutDirection.Vertical;
if (useFixedTileLayout) {
return configLayout;
}
return this.isMobile() ? TileLayoutDirection.Horizontal : TileLayoutDirection.Vertical;
});
readonly tileWidth = computed(() => {
const layout = this.config().layout;
if (layout && this.isFixedWidthLayout(layout)) {
return layout.tileWidth ?? TileWidth.Small;
}
return TileWidth.Small;
});
readonly selectionMode: Signal<NxTileSelectionMode> = computed(() =>
this.config().multiSelect ? 'multi' : 'single'
);
readonly fixedTileWidth = computed(() => {
if (this.useAutogrid()) {
return null;
}
const layout = this.tileLayout();
const width = this.tileWidth();
const widthMap = {
[TileLayoutDirection.Vertical]: {
[TileWidth.Small]: 180,
[TileWidth.Medium]: 210,
[TileWidth.Large]: 240
},
[TileLayoutDirection.Horizontal]: {
[TileWidth.Small]: 256,
[TileWidth.Medium]: 291,
[TileWidth.Large]: 327
}
};
return widthMap[layout][width];
});
private isAutogridLayout(layout: DfTileConfig['layout']): layout is DfTileAutogridLayout {
return layout !== undefined && layout.useAutogrid === true;
}
private isFixedWidthLayout(layout: DfTileConfig['layout']): layout is DfTileFixedWidthLayout {
return layout !== undefined && layout.useAutogrid !== true;
}
override ngOnInit() {
super.ngOnInit();
this.emitFormControlEventOnValueChanges();
}
onBlur(event: FocusEvent) {
const tileGroupHasFocus = this.el.nativeElement.contains(event.relatedTarget);
if (tileGroupHasFocus) {
return;
}
this.emitFormEvent('onBlurEvent', this.control().value);
}
}
<span
class="df-tile-label"
[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>
}
</span>
<div
class="tile-group-wrapper"
[class.tile-group-wrapper--fixed-width]="!useAutogrid()"
[style.--tile-fixed-width.px]="fixedTileWidth()"
[style.--tile-justify]="isRetailChannel() ? 'center' : 'left'"
>
<nx-tile-group
[formControl]="control()"
[autoGrid]="useAutogrid()"
[maxColumns]="maxColumns()"
[selectionMode]="selectionMode()"
[tileLayout]="tileLayout()"
[attr.data-testid]="config().testId"
(focusout)="onBlur($event)"
>
@for (tile of tiles(); track tile.value) {
<nx-tile
[value]="tile.value"
[label]="(tile.label | interpolateFromStore | async) ?? ''"
[hint]="(tile.hint | interpolateFromStore | async) ?? ''"
[icon]="tile.icon ?? ''"
[attr.data-testid]="tile?.testId"
/>
} @for (message$ of errorMessages(); track $index) {
<nx-error [appearance]="nxErrorAppearance">{{ message$ | async }}</nx-error>
}
</nx-tile-group>
</div>
@if (config().note && !(control().touched && control().invalid)) {
<nx-message context="info">
<span>{{ config().note | interpolateFromStore | async }}</span>
</nx-message>
}
./tile.component.scss
@use '../../src/breakpoints.scss' as *;
:host {
df-info-icon {
padding-left: 8px;
}
}
.df-tile-label {
display: flex;
margin-bottom: var(--vertical-inner-section-spacing);
&.is-centered {
justify-content: center;
}
p {
display: inline;
}
}
.tile-group-wrapper {
&--fixed-width {
nx-tile-group ::ng-deep .nx-tile-group__tiles {
display: grid;
grid-template-columns: repeat(auto-fit, var(--tile-fixed-width));
justify-content: var(--tile-justify);
gap: 16px;
}
}
@container (max-width: #{$container-breakpoint-m}) {
nx-tile-group ::ng-deep .nx-tile-group__tiles {
grid-template-columns: 1fr;
}
}
}