libs/core/dynamic-form/number-stepper/src/number-stepper.component.ts

Extends

DfBaseComponent<DfNumberStepperConfig>

Implements

OnInit

Metadata

Relationships

Used by

No results matching.

Depends on

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor()

Inputs

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 DfBaseConfig config interface as needed and expose that their own config interface.

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

Outputs

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.

Methods

onBlur
onBlur(event: FocusEvent)
Parameters :
Name Type Optional
event FocusEvent No
Returns : void

Properties

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, DfInfoIconComponent } from '@allianz/taly-core/dynamic-form';
import {
  ChangeDetectionStrategy,
  Component,
  computed,
  ElementRef,
  inject,
  input,
  OnInit
} from '@angular/core';
import { ReactiveFormsModule, UntypedFormControl } from '@angular/forms';
import { DfNumberStepperConfig } from './number-stepper.model';
import {
  NxNumberStepperComponent,
  NxNumberStepperPrefixDirective,
  NxNumberStepperSuffixDirective
} from '@allianz/ng-aquila/number-stepper';
import { AsyncPipe, NgClass } from '@angular/common';
import { InterpolateFromStorePipe, ValidationConfig } from '@allianz/taly-core';
import { NxFormfieldAppendixDirective } from '@allianz/ng-aquila/formfield';
import { NxMessageComponent } from '@allianz/ng-aquila/message';
import { NxErrorComponent, NxLabelComponent } from '@allianz/ng-aquila/base';
import { LocalizeFn } from '@angular/localize/init';
import { InputElementInjectorModule } from '@allianz/taly-acl/input-element-injector-directive';

declare let $localize: LocalizeFn;

@Component({
  selector: 'df-number-stepper',
  styleUrls: ['./number-stepper.component.scss'],
  templateUrl: './number-stepper.component.html',
  imports: [
    NxNumberStepperComponent,
    AsyncPipe,
    DfInfoIconComponent,
    InterpolateFromStorePipe,
    NxFormfieldAppendixDirective,
    NxLabelComponent,
    NgClass,
    NxMessageComponent,
    ReactiveFormsModule,
    NxNumberStepperSuffixDirective,
    NxNumberStepperPrefixDirective,
    InputElementInjectorModule,
    NxErrorComponent
  ],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class DfNumberStepperComponent
  extends DfBaseComponent<DfNumberStepperConfig>
  implements OnInit
{
  override control = input<UntypedFormControl>(new UntypedFormControl());

  private el = inject(ElementRef);

  constructor() {
    super();

    this.enrichedValidationConfigs = computed(() => {
      const baseValidations = this.validationConfigs() || [];

      return [
        ...baseValidations,
        {
          validatorName: 'nxNumberStepperStepError',
          errorMessage:
            this.config().valueOutsideRangeErrorMessage ||
            $localize`:@@validation.error.number-stepper-outside-range:The value must be within the allowed range and match the step size.`
        } as ValidationConfig,
        {
          validatorName: 'nxNumberStepperFormatError',
          errorMessage:
            this.config().invalidFormatErrorMessage ||
            $localize`:@@validation.error.number-stepper-format-error:The value must be a number.`
        } as ValidationConfig
      ];
    });
  }

  override ngOnInit() {
    super.ngOnInit();
    this.emitFormControlEventOnValueChangesWithDebounce();
  }

  onBlur(event: FocusEvent) {
    const toggleButtonHasFocus = this.el.nativeElement.contains(event.relatedTarget);
    if (toggleButtonHasFocus) {
      return;
    }
    this.emitFormEvent('onBlurEvent', this.control().value);
  }
}
<span
  class="df-number-stepper-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>

<nx-number-stepper
  [id]="config().id"
  [formControl]="control()"
  [max]="config().max ?? 100"
  [min]="config().min ?? 0"
  [step]="config().step ?? 1"
  [size]="config().size || (isRetailChannel() ? 'big' : 'normal')"
  [resize]="true"
  [leadingZero]="false"
  [attr.data-testid]="config().testId"
  [ngClass]="{ 'is-centered': isRetailChannel() }"
  [incrementAriaLabel]="config().incrementAriaLabel ?? ''"
  [decrementAriaLabel]="config().decrementAriaLabel ?? ''"
  [inputAriaLabel]="config().inputAriaLabel ?? null"
  (focusout)="onBlur($event)"
>
  @if (config().suffix) {
  <nx-number-stepper-suffix>{{ config().suffix }}</nx-number-stepper-suffix>
  } @if (config().prefix) {
  <nx-number-stepper-prefix>{{ config().prefix }}</nx-number-stepper-prefix>
  } @for (message$ of errorMessages(); track $index) {
  <nx-error [appearance]="nxErrorAppearance">{{ message$ | async }}</nx-error>
  }
</nx-number-stepper>

@if (config().note && !(control().touched && control().invalid)) {
<nx-message context="info">
  <span>{{ config().note | interpolateFromStore | async }}</span>
</nx-message>
}

./number-stepper.component.scss

:host {
  display: block;

  df-info-icon {
    padding-left: 8px;
  }

  .df-number-stepper-label {
    display: flex;
    margin-bottom: 16px;

    &.is-centered {
      justify-content: center;
    }
  }

  nx-number-stepper {
    ::ng-deep.nx-stepper__input-container {
      display: flex;
    }

    &.is-centered {
      ::ng-deep.nx-stepper__input-container {
        justify-content: center;
      }
    }
  }
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""