UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

1,133 lines (1,116 loc) • 35 kB
import { FocusMonitor } from "@angular/cdk/a11y"; import { Directionality } from "@angular/cdk/bidi"; import { DOWN_ARROW, ENTER, UP_ARROW } from "@angular/cdk/keycodes"; import { NgTemplateOutlet } from "@angular/common"; import * as i0 from "@angular/core"; import { Component, DestroyRef, ElementRef, Injector, NgModule, Renderer2, ViewEncapsulation, afterNextRender, booleanAttribute, computed, contentChild, forwardRef, inject, input, linkedSignal, numberAttribute, output, signal, untracked, viewChild } from "@angular/core"; import { takeUntilDestroyed } from "@angular/core/rxjs-interop"; import { NG_VALUE_ACCESSOR } from "@angular/forms"; import { NZ_FORM_SIZE, NZ_FORM_VARIANT, NzFormItemFeedbackIconComponent, NzFormStatusService } from "ng-zorro-antd/core/form"; import { getStatusClassNames, getVariantClassNames, isNil, isNotNil, triggerFocus } from "ng-zorro-antd/core/util"; import * as i2 from "ng-zorro-antd/icon"; import { NzIconModule } from "ng-zorro-antd/icon"; import { NzInputAddonAfterDirective, NzInputAddonBeforeDirective, NzInputPrefixDirective, NzInputSuffixDirective } from "ng-zorro-antd/input"; import * as i1 from "ng-zorro-antd/space"; import { NZ_SPACE_COMPACT_ITEM_TYPE, NZ_SPACE_COMPACT_SIZE, NzSpaceCompactItemDirective } from "ng-zorro-antd/space"; var NzInputNumberComponent = class NzInputNumberComponent { nzId = input(null, ...ngDevMode ? [{ debugName: "nzId" }] : /* istanbul ignore next */ []); nzSize = input("default", ...ngDevMode ? [{ debugName: "nzSize" }] : /* istanbul ignore next */ []); nzPlaceHolder = input(null, ...ngDevMode ? [{ debugName: "nzPlaceHolder" }] : /* istanbul ignore next */ []); nzStatus = input("", ...ngDevMode ? [{ debugName: "nzStatus" }] : /* istanbul ignore next */ []); nzVariant = input(...ngDevMode ? [void 0, { debugName: "nzVariant" }] : /* istanbul ignore next */ []); nzStep = input(1, { ...ngDevMode ? { debugName: "nzStep" } : /* istanbul ignore next */ {}, transform: numberAttribute }); nzMin = input(Number.MIN_SAFE_INTEGER, { ...ngDevMode ? { debugName: "nzMin" } : /* istanbul ignore next */ {}, transform: numberAttribute }); nzMax = input(Number.MAX_SAFE_INTEGER, { ...ngDevMode ? { debugName: "nzMax" } : /* istanbul ignore next */ {}, transform: numberAttribute }); nzPrecision = input(null, ...ngDevMode ? [{ debugName: "nzPrecision" }] : /* istanbul ignore next */ []); nzParser = input(...ngDevMode ? [void 0, { debugName: "nzParser" }] : /* istanbul ignore next */ []); nzFormatter = input(...ngDevMode ? [void 0, { debugName: "nzFormatter" }] : /* istanbul ignore next */ []); nzDisabled = input(false, { ...ngDevMode ? { debugName: "nzDisabled" } : /* istanbul ignore next */ {}, transform: booleanAttribute }); nzReadOnly = input(false, { ...ngDevMode ? { debugName: "nzReadOnly" } : /* istanbul ignore next */ {}, transform: booleanAttribute }); nzAutoFocus = input(false, { ...ngDevMode ? { debugName: "nzAutoFocus" } : /* istanbul ignore next */ {}, transform: booleanAttribute }); nzKeyboard = input(true, { ...ngDevMode ? { debugName: "nzKeyboard" } : /* istanbul ignore next */ {}, transform: booleanAttribute }); nzControls = input(true, { ...ngDevMode ? { debugName: "nzControls" } : /* istanbul ignore next */ {}, transform: booleanAttribute }); nzChangeOnWheel = input(true, { ...ngDevMode ? { debugName: "nzChangeOnWheel" } : /* istanbul ignore next */ {}, transform: booleanAttribute }); nzPrefix = input(...ngDevMode ? [void 0, { debugName: "nzPrefix" }] : /* istanbul ignore next */ []); nzSuffix = input(...ngDevMode ? [void 0, { debugName: "nzSuffix" }] : /* istanbul ignore next */ []); nzAddonBefore = input(...ngDevMode ? [void 0, { debugName: "nzAddonBefore" }] : /* istanbul ignore next */ []); nzAddonAfter = input(...ngDevMode ? [void 0, { debugName: "nzAddonAfter" }] : /* istanbul ignore next */ []); nzBlur = output(); nzFocus = output(); nzOnStep = output(); onChange = () => {}; onTouched = () => {}; isDisabledFirstChange = true; compactSize = inject(NZ_SPACE_COMPACT_SIZE, { optional: true }); inputRef = viewChild.required("input", ...ngDevMode ? [{ debugName: "inputRef" }] : /* istanbul ignore next */ []); hostRef = viewChild("inputNumberHost", ...ngDevMode ? [{ debugName: "hostRef" }] : /* istanbul ignore next */ []); elementRef = inject(ElementRef); renderer = inject(Renderer2); injector = inject(Injector); focusMonitor = inject(FocusMonitor); directionality = inject(Directionality); nzFormStatusService = inject(NzFormStatusService, { optional: true }); autoStepTimer = null; defaultFormatter = (value) => { const precision = this.nzPrecision(); if (isNotNil(precision)) return value.toFixed(precision); return value.toString(); }; value = signal(null, ...ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []); displayValue = signal("", ...ngDevMode ? [{ debugName: "displayValue" }] : /* istanbul ignore next */ []); formSize = inject(NZ_FORM_SIZE, { optional: true }); formVariant = inject(NZ_FORM_VARIANT, { optional: true }); dir = inject(Directionality).valueSignal; focused = signal(false, ...ngDevMode ? [{ debugName: "focused" }] : /* istanbul ignore next */ []); hasFeedback = signal(false, ...ngDevMode ? [{ debugName: "hasFeedback" }] : /* istanbul ignore next */ []); finalStatus = linkedSignal(() => this.nzStatus(), ...ngDevMode ? [{ debugName: "finalStatus" }] : /* istanbul ignore next */ []); finalDisabled = linkedSignal(() => this.nzDisabled(), ...ngDevMode ? [{ debugName: "finalDisabled" }] : /* istanbul ignore next */ []); prefix = contentChild(NzInputPrefixDirective, ...ngDevMode ? [{ debugName: "prefix" }] : /* istanbul ignore next */ []); suffix = contentChild(NzInputSuffixDirective, ...ngDevMode ? [{ debugName: "suffix" }] : /* istanbul ignore next */ []); addonBefore = contentChild(NzInputAddonBeforeDirective, ...ngDevMode ? [{ debugName: "addonBefore" }] : /* istanbul ignore next */ []); addonAfter = contentChild(NzInputAddonAfterDirective, ...ngDevMode ? [{ debugName: "addonAfter" }] : /* istanbul ignore next */ []); hasPrefix = computed(() => !!this.nzPrefix() || !!this.prefix(), ...ngDevMode ? [{ debugName: "hasPrefix" }] : /* istanbul ignore next */ []); hasSuffix = computed(() => !!this.nzSuffix() || !!this.suffix() || this.hasFeedback(), ...ngDevMode ? [{ debugName: "hasSuffix" }] : /* istanbul ignore next */ []); hasAffix = computed(() => this.hasPrefix() || this.hasSuffix(), ...ngDevMode ? [{ debugName: "hasAffix" }] : /* istanbul ignore next */ []); hasAddonBefore = computed(() => !!this.nzAddonBefore() || !!this.addonBefore(), ...ngDevMode ? [{ debugName: "hasAddonBefore" }] : /* istanbul ignore next */ []); hasAddonAfter = computed(() => !!this.nzAddonAfter() || !!this.addonAfter(), ...ngDevMode ? [{ debugName: "hasAddonAfter" }] : /* istanbul ignore next */ []); hasAddon = computed(() => this.hasAddonBefore() || this.hasAddonAfter(), ...ngDevMode ? [{ debugName: "hasAddon" }] : /* istanbul ignore next */ []); class = computed(() => { if (this.hasAddon()) return this.groupWrapperClass(); if (this.hasAffix()) return this.affixWrapperClass(); return this.inputNumberClass(); }, ...ngDevMode ? [{ debugName: "class" }] : /* istanbul ignore next */ []); inputNumberClass = computed(() => { return { "ant-input-number": true, "ant-input-number-lg": this.finalSize() === "large", "ant-input-number-sm": this.finalSize() === "small", "ant-input-number-disabled": this.finalDisabled(), "ant-input-number-readonly": this.nzReadOnly(), "ant-input-number-focused": this.focused(), "ant-input-number-rtl": this.dir() === "rtl", "ant-input-number-in-form-item": !!this.nzFormStatusService, "ant-input-number-out-of-range": this.value() !== null && !isInRange(this.value(), this.nzMin(), this.nzMax()), ...getVariantClassNames("ant-input-number", this.finalVariant()), ...getStatusClassNames("ant-input-number", this.finalStatus(), this.hasFeedback()) }; }, ...ngDevMode ? [{ debugName: "inputNumberClass" }] : /* istanbul ignore next */ []); affixWrapperClass = computed(() => { return { "ant-input-number-affix-wrapper": true, "ant-input-number-affix-wrapper-disabled": this.finalDisabled(), "ant-input-number-affix-wrapper-readonly": this.nzReadOnly(), "ant-input-number-affix-wrapper-focused": this.focused(), "ant-input-number-affix-wrapper-rtl": this.dir() === "rtl", ...getStatusClassNames("ant-input-number-affix-wrapper", this.finalStatus(), this.hasFeedback()), ...getVariantClassNames("ant-input-number-affix-wrapper", this.finalVariant()) }; }, ...ngDevMode ? [{ debugName: "affixWrapperClass" }] : /* istanbul ignore next */ []); groupWrapperClass = computed(() => { return { "ant-input-number-group-wrapper": true, "ant-input-number-group-wrapper-rtl": this.dir() === "rtl", ...getStatusClassNames("ant-input-number-group-wrapper", this.finalStatus(), this.hasFeedback()), ...getVariantClassNames("ant-input-number-group-wrapper", this.finalVariant()) }; }, ...ngDevMode ? [{ debugName: "groupWrapperClass" }] : /* istanbul ignore next */ []); finalSize = computed(() => { if (this.formSize?.()) return this.formSize(); if (this.compactSize) return this.compactSize(); return this.nzSize(); }, ...ngDevMode ? [{ debugName: "finalSize" }] : /* istanbul ignore next */ []); finalVariant = computed(() => this.nzVariant() || this.formVariant?.() || "outlined", ...ngDevMode ? [{ debugName: "finalVariant" }] : /* istanbul ignore next */ []); upDisabled = computed(() => { return !isNil(this.value()) && this.value() >= this.nzMax(); }, ...ngDevMode ? [{ debugName: "upDisabled" }] : /* istanbul ignore next */ []); downDisabled = computed(() => { return !isNil(this.value()) && this.value() <= this.nzMin(); }, ...ngDevMode ? [{ debugName: "downDisabled" }] : /* istanbul ignore next */ []); constructor() { const destroyRef = inject(DestroyRef); afterNextRender(() => { const hostRef = this.hostRef(); const element = hostRef ? hostRef : this.elementRef; this.focusMonitor.monitor(element, true).pipe(takeUntilDestroyed(destroyRef)).subscribe((origin) => { untracked(() => { this.focused.set(!!origin); if (origin) this.nzFocus.emit(); else { this.fixValue(); this.onTouched(); this.nzBlur.emit(); if (!destroyRef.destroyed) afterNextRender(() => { this.syncDisplayValue(); }, { injector: this.injector }); } }); }); destroyRef.onDestroy(() => { this.focusMonitor.stopMonitoring(element); }); }); this.nzFormStatusService?.formStatusChanges.pipe(takeUntilDestroyed()).subscribe(({ status, hasFeedback }) => { this.finalStatus.set(status); this.hasFeedback.set(hasFeedback); }); } ngOnInit() { if (this.nzAutoFocus()) afterNextRender(() => this.focus(), { injector: this.injector }); } writeValue(value) { if (isNil(value)) value = null; untracked(() => { this.value.set(value); this.setValue(value); }); } registerOnChange(fn) { this.onChange = fn; } registerOnTouched(fn) { this.onTouched = fn; } setDisabledState(disabled) { untracked(() => { this.finalDisabled.set(this.isDisabledFirstChange && this.nzDisabled() || disabled); }); this.isDisabledFirstChange = false; } focus(options) { triggerFocus(this.inputRef().nativeElement, options); } blur() { this.inputRef().nativeElement.blur(); } step(event, up, emitter) { if (this.nzReadOnly()) return; if (up && this.upDisabled() || !up && this.downDisabled()) return; let step = event.shiftKey ? this.nzStep() * 10 : this.nzStep(); if (!up) step = -step; const multiple = 10 ** getDecimalPlaces(step); const nextValue = getRangeValue((Math.round((this.value() || 0) * multiple) + Math.round(step * multiple)) / multiple, this.nzMin(), this.nzMax(), this.nzPrecision()); this.setValue(nextValue); this.nzOnStep.emit({ type: up ? "up" : "down", value: this.value(), offset: this.nzStep(), emitter }); this.focus(); } syncDisplayValue() { const input = this.inputRef().nativeElement; const displayValue = this.displayValue(); if (input.value !== displayValue) this.renderer.setProperty(input, "value", displayValue); } setValue(value) { const formatter = this.nzFormatter() ?? this.defaultFormatter; const precision = this.nzPrecision(); if (isNotNil(precision)) value &&= +value.toFixed(precision); const formattedValue = isNil(value) ? "" : formatter(value); this.displayValue.set(formattedValue); this.updateValue(value); } setValueByTyping(value) { this.displayValue.set(value); if (value === "") { this.updateValue(null); return; } const parsedValue = (this.nzParser() ?? defaultParser)(value); if (isNotCompleteNumber(value) || Number.isNaN(parsedValue)) return; const formatter = this.nzFormatter(); if (formatter) { const formattedValue = formatter(parsedValue); this.displayValue.set(formattedValue); } if (!isInRange(parsedValue, this.nzMin(), this.nzMax())) return; this.updateValue(parsedValue); } updateValue(value) { if (this.value() !== value) { this.value.set(value); this.onChange(value); } } fixValue() { const displayValue = this.displayValue(); if (displayValue === "") return; let fixedValue = (this.nzParser() ?? defaultParser)(displayValue); if (Number.isNaN(fixedValue)) fixedValue = this.value(); else { const precision = this.nzPrecision(); if (isNotNil(precision) && getDecimalPlaces(fixedValue) !== precision) fixedValue = +fixedValue.toFixed(precision); if (!isInRange(fixedValue, this.nzMin(), this.nzMax())) fixedValue = getRangeValue(fixedValue, this.nzMin(), this.nzMax(), precision); } this.setValue(fixedValue); } stopAutoStep() { if (this.autoStepTimer !== null) { clearTimeout(this.autoStepTimer); this.autoStepTimer = null; } } onStepMouseDown(event, up) { event.preventDefault(); this.stopAutoStep(); this.step(event, up, "handler"); const loopStep = () => { this.step(event, up, "handler"); this.autoStepTimer = setTimeout(loopStep, STEP_INTERVAL); }; this.autoStepTimer = setTimeout(loopStep, STEP_DELAY); } onKeyDown(event) { switch (event.keyCode) { case UP_ARROW: event.preventDefault(); this.nzKeyboard() && this.step(event, true, "keyboard"); break; case DOWN_ARROW: event.preventDefault(); this.nzKeyboard() && this.step(event, false, "keyboard"); break; case ENTER: this.fixValue(); } } onInput(value) { this.setValueByTyping(value); } onWheel(event) { if (!this.focused() || this.finalDisabled() || this.nzReadOnly() || !this.nzChangeOnWheel()) return; event.preventDefault(); this.step(event, event.deltaY < 0, "wheel"); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzInputNumberComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.2.2", type: NzInputNumberComponent, isStandalone: true, selector: "nz-input-number", inputs: { nzId: { classPropertyName: "nzId", publicName: "nzId", isSignal: true, isRequired: false, transformFunction: null }, nzSize: { classPropertyName: "nzSize", publicName: "nzSize", isSignal: true, isRequired: false, transformFunction: null }, nzPlaceHolder: { classPropertyName: "nzPlaceHolder", publicName: "nzPlaceHolder", isSignal: true, isRequired: false, transformFunction: null }, nzStatus: { classPropertyName: "nzStatus", publicName: "nzStatus", isSignal: true, isRequired: false, transformFunction: null }, nzVariant: { classPropertyName: "nzVariant", publicName: "nzVariant", isSignal: true, isRequired: false, transformFunction: null }, nzStep: { classPropertyName: "nzStep", publicName: "nzStep", isSignal: true, isRequired: false, transformFunction: null }, nzMin: { classPropertyName: "nzMin", publicName: "nzMin", isSignal: true, isRequired: false, transformFunction: null }, nzMax: { classPropertyName: "nzMax", publicName: "nzMax", isSignal: true, isRequired: false, transformFunction: null }, nzPrecision: { classPropertyName: "nzPrecision", publicName: "nzPrecision", isSignal: true, isRequired: false, transformFunction: null }, nzParser: { classPropertyName: "nzParser", publicName: "nzParser", isSignal: true, isRequired: false, transformFunction: null }, nzFormatter: { classPropertyName: "nzFormatter", publicName: "nzFormatter", isSignal: true, isRequired: false, transformFunction: null }, nzDisabled: { classPropertyName: "nzDisabled", publicName: "nzDisabled", isSignal: true, isRequired: false, transformFunction: null }, nzReadOnly: { classPropertyName: "nzReadOnly", publicName: "nzReadOnly", isSignal: true, isRequired: false, transformFunction: null }, nzAutoFocus: { classPropertyName: "nzAutoFocus", publicName: "nzAutoFocus", isSignal: true, isRequired: false, transformFunction: null }, nzKeyboard: { classPropertyName: "nzKeyboard", publicName: "nzKeyboard", isSignal: true, isRequired: false, transformFunction: null }, nzControls: { classPropertyName: "nzControls", publicName: "nzControls", isSignal: true, isRequired: false, transformFunction: null }, nzChangeOnWheel: { classPropertyName: "nzChangeOnWheel", publicName: "nzChangeOnWheel", isSignal: true, isRequired: false, transformFunction: null }, nzPrefix: { classPropertyName: "nzPrefix", publicName: "nzPrefix", isSignal: true, isRequired: false, transformFunction: null }, nzSuffix: { classPropertyName: "nzSuffix", publicName: "nzSuffix", isSignal: true, isRequired: false, transformFunction: null }, nzAddonBefore: { classPropertyName: "nzAddonBefore", publicName: "nzAddonBefore", isSignal: true, isRequired: false, transformFunction: null }, nzAddonAfter: { classPropertyName: "nzAddonAfter", publicName: "nzAddonAfter", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { nzBlur: "nzBlur", nzFocus: "nzFocus", nzOnStep: "nzOnStep" }, host: { listeners: { "keydown": "onKeyDown($event)" }, properties: { "class": "class()" } }, providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => NzInputNumberComponent), multi: true }, { provide: NZ_SPACE_COMPACT_ITEM_TYPE, useValue: "input-number" }], queries: [ { propertyName: "prefix", first: true, predicate: NzInputPrefixDirective, descendants: true, isSignal: true }, { propertyName: "suffix", first: true, predicate: NzInputSuffixDirective, descendants: true, isSignal: true }, { propertyName: "addonBefore", first: true, predicate: NzInputAddonBeforeDirective, descendants: true, isSignal: true }, { propertyName: "addonAfter", first: true, predicate: NzInputAddonAfterDirective, descendants: true, isSignal: true } ], viewQueries: [{ propertyName: "inputRef", first: true, predicate: ["input"], descendants: true, isSignal: true }, { propertyName: "hostRef", first: true, predicate: ["inputNumberHost"], descendants: true, isSignal: true }], exportAs: ["nzInputNumber"], hostDirectives: [{ directive: i1.NzSpaceCompactItemDirective }], ngImport: i0, template: ` @if (hasAddon()) { <ng-template [ngTemplateOutlet]="inputNumberWithAddonInner" /> } @else if (hasAffix()) { <ng-template [ngTemplateOutlet]="inputNumberWithAffixInner" /> } @else { <ng-template [ngTemplateOutlet]="inputNumberInner" /> } <ng-template #inputNumberWithAddonInner> <div class="ant-input-number-wrapper ant-input-number-group"> @if (hasAddonBefore()) { <div class="ant-input-number-group-addon"> <ng-content select="[nzInputAddonBefore]">{{ nzAddonBefore() }}</ng-content> </div> } @if (hasAffix()) { <ng-template [ngTemplateOutlet]="inputNumberWithAffix" /> } @else { <ng-template [ngTemplateOutlet]="inputNumber" /> } @if (hasAddonAfter()) { <div class="ant-input-number-group-addon"> <ng-content select="[nzInputAddonAfter]">{{ nzAddonAfter() }}</ng-content> </div> } </div> </ng-template> <ng-template #inputNumberWithAffix> <div [class]="affixWrapperClass()"> <ng-template [ngTemplateOutlet]="inputNumberWithAffixInner" /> </div> </ng-template> <ng-template #inputNumberWithAffixInner> @if (hasPrefix()) { <span class="ant-input-number-prefix"> <ng-content select="[nzInputPrefix]">{{ nzPrefix() }}</ng-content> </span> } <ng-template [ngTemplateOutlet]="inputNumber" /> @if (hasSuffix()) { <span class="ant-input-number-suffix"> <ng-content select="[nzInputSuffix]">{{ nzSuffix() }}</ng-content> @if (hasFeedback() && finalStatus()) { <nz-form-item-feedback-icon [status]="finalStatus()" /> } </span> } </ng-template> <ng-template #inputNumber> <div #inputNumberHost [class]="inputNumberClass()"> <ng-template [ngTemplateOutlet]="inputNumberInner" /> </div> </ng-template> <ng-template #inputNumberInner> @if (nzControls()) { <div #handlers class="ant-input-number-handler-wrap" (mouseup)="stopAutoStep()" (mouseleave)="stopAutoStep()"> <span role="button" unselectable="on" class="ant-input-number-handler ant-input-number-handler-up" [class.ant-input-number-handler-up-disabled]="upDisabled()" [attr.aria-disabled]="upDisabled()" (mousedown)="onStepMouseDown($event, true)" > <ng-content select="[nzInputNumberUpIcon]"> <nz-icon nzType="up" class="ant-input-number-handler-up-inner" /> </ng-content> </span> <span role="button" unselectable="on" class="ant-input-number-handler ant-input-number-handler-down" [class.ant-input-number-handler-down-disabled]="downDisabled()" [attr.aria-disabled]="downDisabled()" (mousedown)="onStepMouseDown($event, false)" > <ng-content select="[nzInputNumberDownIcon]"> <nz-icon nzType="down" class="ant-input-number-handler-down-inner" /> </ng-content> </span> </div> } <div class="ant-input-number-input-wrap"> <input #input autocomplete="off" role="spinbutton" class="ant-input-number-input" [attr.aria-valuemin]="nzMin()" [attr.aria-valuemax]="nzMax()" [attr.id]="nzId()" [attr.step]="nzStep()" [attr.value]="displayValue()" [value]="displayValue()" [placeholder]="nzPlaceHolder() ?? ''" [disabled]="finalDisabled()" [readOnly]="nzReadOnly()" (input)="onInput(input.value)" (wheel)="onWheel($event)" /> </div> </ng-template> `, isInline: true, dependencies: [ { kind: "ngmodule", type: NzIconModule }, { kind: "directive", type: i2.NzIconDirective, selector: "nz-icon,[nz-icon]", inputs: [ "nzType", "nzTheme", "nzTwotoneColor", "nzSpin", "nzRotate", "nzIconfont", "aria-label" ], exportAs: ["nzIcon"] }, { kind: "component", type: NzFormItemFeedbackIconComponent, selector: "nz-form-item-feedback-icon", inputs: ["status"], exportAs: ["nzFormFeedbackIcon"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: [ "ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector" ] } ], encapsulation: i0.ViewEncapsulation.None }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzInputNumberComponent, decorators: [{ type: Component, args: [{ selector: "nz-input-number", exportAs: "nzInputNumber", imports: [ NzIconModule, NzFormItemFeedbackIconComponent, NgTemplateOutlet ], template: ` @if (hasAddon()) { <ng-template [ngTemplateOutlet]="inputNumberWithAddonInner" /> } @else if (hasAffix()) { <ng-template [ngTemplateOutlet]="inputNumberWithAffixInner" /> } @else { <ng-template [ngTemplateOutlet]="inputNumberInner" /> } <ng-template #inputNumberWithAddonInner> <div class="ant-input-number-wrapper ant-input-number-group"> @if (hasAddonBefore()) { <div class="ant-input-number-group-addon"> <ng-content select="[nzInputAddonBefore]">{{ nzAddonBefore() }}</ng-content> </div> } @if (hasAffix()) { <ng-template [ngTemplateOutlet]="inputNumberWithAffix" /> } @else { <ng-template [ngTemplateOutlet]="inputNumber" /> } @if (hasAddonAfter()) { <div class="ant-input-number-group-addon"> <ng-content select="[nzInputAddonAfter]">{{ nzAddonAfter() }}</ng-content> </div> } </div> </ng-template> <ng-template #inputNumberWithAffix> <div [class]="affixWrapperClass()"> <ng-template [ngTemplateOutlet]="inputNumberWithAffixInner" /> </div> </ng-template> <ng-template #inputNumberWithAffixInner> @if (hasPrefix()) { <span class="ant-input-number-prefix"> <ng-content select="[nzInputPrefix]">{{ nzPrefix() }}</ng-content> </span> } <ng-template [ngTemplateOutlet]="inputNumber" /> @if (hasSuffix()) { <span class="ant-input-number-suffix"> <ng-content select="[nzInputSuffix]">{{ nzSuffix() }}</ng-content> @if (hasFeedback() && finalStatus()) { <nz-form-item-feedback-icon [status]="finalStatus()" /> } </span> } </ng-template> <ng-template #inputNumber> <div #inputNumberHost [class]="inputNumberClass()"> <ng-template [ngTemplateOutlet]="inputNumberInner" /> </div> </ng-template> <ng-template #inputNumberInner> @if (nzControls()) { <div #handlers class="ant-input-number-handler-wrap" (mouseup)="stopAutoStep()" (mouseleave)="stopAutoStep()"> <span role="button" unselectable="on" class="ant-input-number-handler ant-input-number-handler-up" [class.ant-input-number-handler-up-disabled]="upDisabled()" [attr.aria-disabled]="upDisabled()" (mousedown)="onStepMouseDown($event, true)" > <ng-content select="[nzInputNumberUpIcon]"> <nz-icon nzType="up" class="ant-input-number-handler-up-inner" /> </ng-content> </span> <span role="button" unselectable="on" class="ant-input-number-handler ant-input-number-handler-down" [class.ant-input-number-handler-down-disabled]="downDisabled()" [attr.aria-disabled]="downDisabled()" (mousedown)="onStepMouseDown($event, false)" > <ng-content select="[nzInputNumberDownIcon]"> <nz-icon nzType="down" class="ant-input-number-handler-down-inner" /> </ng-content> </span> </div> } <div class="ant-input-number-input-wrap"> <input #input autocomplete="off" role="spinbutton" class="ant-input-number-input" [attr.aria-valuemin]="nzMin()" [attr.aria-valuemax]="nzMax()" [attr.id]="nzId()" [attr.step]="nzStep()" [attr.value]="displayValue()" [value]="displayValue()" [placeholder]="nzPlaceHolder() ?? ''" [disabled]="finalDisabled()" [readOnly]="nzReadOnly()" (input)="onInput(input.value)" (wheel)="onWheel($event)" /> </div> </ng-template> `, providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => NzInputNumberComponent), multi: true }, { provide: NZ_SPACE_COMPACT_ITEM_TYPE, useValue: "input-number" }], encapsulation: ViewEncapsulation.None, host: { "[class]": "class()", "(keydown)": "onKeyDown($event)" }, hostDirectives: [NzSpaceCompactItemDirective] }] }], ctorParameters: () => [], propDecorators: { nzId: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzId", required: false }] }], nzSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzSize", required: false }] }], nzPlaceHolder: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzPlaceHolder", required: false }] }], nzStatus: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzStatus", required: false }] }], nzVariant: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzVariant", required: false }] }], nzStep: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzStep", required: false }] }], nzMin: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzMin", required: false }] }], nzMax: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzMax", required: false }] }], nzPrecision: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzPrecision", required: false }] }], nzParser: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzParser", required: false }] }], nzFormatter: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzFormatter", required: false }] }], nzDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzDisabled", required: false }] }], nzReadOnly: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzReadOnly", required: false }] }], nzAutoFocus: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzAutoFocus", required: false }] }], nzKeyboard: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzKeyboard", required: false }] }], nzControls: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzControls", required: false }] }], nzChangeOnWheel: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzChangeOnWheel", required: false }] }], nzPrefix: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzPrefix", required: false }] }], nzSuffix: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzSuffix", required: false }] }], nzAddonBefore: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzAddonBefore", required: false }] }], nzAddonAfter: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzAddonAfter", required: false }] }], nzBlur: [{ type: i0.Output, args: ["nzBlur"] }], nzFocus: [{ type: i0.Output, args: ["nzFocus"] }], nzOnStep: [{ type: i0.Output, args: ["nzOnStep"] }], inputRef: [{ type: i0.ViewChild, args: ["input", { isSignal: true }] }], hostRef: [{ type: i0.ViewChild, args: ["inputNumberHost", { isSignal: true }] }], prefix: [{ type: i0.ContentChild, args: [i0.forwardRef(() => NzInputPrefixDirective), { isSignal: true }] }], suffix: [{ type: i0.ContentChild, args: [i0.forwardRef(() => NzInputSuffixDirective), { isSignal: true }] }], addonBefore: [{ type: i0.ContentChild, args: [i0.forwardRef(() => NzInputAddonBeforeDirective), { isSignal: true }] }], addonAfter: [{ type: i0.ContentChild, args: [i0.forwardRef(() => NzInputAddonAfterDirective), { isSignal: true }] }] } }); const STEP_INTERVAL = 200; const STEP_DELAY = 600; function defaultParser(value) { const parsedValue = value.trim().replace(/,/g, "").replace(/。/g, "."); if (parsedValue.length) return +parsedValue; return NaN; } function isInRange(value, min, max) { return value >= min && value <= max; } function getRangeValue(value, min, max, precision = null) { if (precision === null) { if (value < min) return min; if (value > max) return max; return value; } const fixedValue = +value.toFixed(precision); const multiple = Math.pow(10, precision); if (fixedValue < min) return Math.ceil(min * multiple) / multiple; if (fixedValue > max) return Math.floor(max * multiple) / multiple; return fixedValue; } function getDecimalPlaces(num) { return num.toString().split(".")[1]?.length || 0; } function isNotCompleteNumber(value) { return /[.。](\d*0)?$/.test(value.toString()); } var NzInputNumberModule = class NzInputNumberModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzInputNumberModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.2.2", ngImport: i0, type: NzInputNumberModule, imports: [ NzInputNumberComponent, NzInputAddonBeforeDirective, NzInputAddonAfterDirective, NzInputPrefixDirective, NzInputSuffixDirective ], exports: [ NzInputNumberComponent, NzInputAddonBeforeDirective, NzInputAddonAfterDirective, NzInputPrefixDirective, NzInputSuffixDirective ] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzInputNumberModule, imports: [NzInputNumberComponent] }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzInputNumberModule, decorators: [{ type: NgModule, args: [{ imports: [ NzInputNumberComponent, NzInputAddonBeforeDirective, NzInputAddonAfterDirective, NzInputPrefixDirective, NzInputSuffixDirective ], exports: [ NzInputNumberComponent, NzInputAddonBeforeDirective, NzInputAddonAfterDirective, NzInputPrefixDirective, NzInputSuffixDirective ] }] }] }); export { NzInputNumberComponent, NzInputNumberModule }; //# sourceMappingURL=ng-zorro-antd-input-number.mjs.map