UNPKG

@taiga-ui/kit

Version:
16 lines (14 loc) 10.7 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/forms"),require("@taiga-ui/cdk"),require("@taiga-ui/core"),require("@taiga-ui/kit/tokens"),require("rxjs"),require("@angular/common"),require("@taiga-ui/kit/directives"),require("angular2-text-mask")):"function"==typeof define&&define.amd?define("@taiga-ui/kit/components/input-count",["exports","@angular/core","@angular/forms","@taiga-ui/cdk","@taiga-ui/core","@taiga-ui/kit/tokens","rxjs","@angular/common","@taiga-ui/kit/directives","angular2-text-mask"],e):e(((t=t||self)["taiga-ui"]=t["taiga-ui"]||{},t["taiga-ui"].kit=t["taiga-ui"].kit||{},t["taiga-ui"].kit.components=t["taiga-ui"].kit.components||{},t["taiga-ui"].kit.components["input-count"]={}),t.ng.core,t.ng.forms,t.cdk,t.core$1,t["taiga-ui"].kit.tokens,t.rxjs,t.ng.common,t["taiga-ui"].kit.directives,t.angular2TextMask)}(this,(function(t,e,n,i,o,u,a,r,s,l){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */var c=function(t,e){return(c=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function p(t,e,n,i){var o,u=arguments.length,a=u<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,i);else for(var r=t.length-1;r>=0;r--)(o=t[r])&&(a=(u<3?o(a):u>3?o(e,n,a):o(e,n))||a);return u>3&&a&&Object.defineProperty(e,n,a),a}function d(t,e){return function(n,i){e(n,i,t)}}var f=function(t){function r(e,n,i,o,u,a){var r=t.call(this,e,n)||this;return r.appearance=i,r.textfieldSize=o,r.minusTexts$=u,r.isMobile=a,r.step=1,r.min=0,r.max=1/0,r.hideButtons=!1,r.postfix="",r}var s;return function(t,e){function n(){this.constructor=t}c(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(r,t),s=r,r.prototype.getMask=function(t){return{mask:o.tuiCreateNumberMask({allowNegative:t}),guide:!1}},Object.defineProperty(r.prototype,"nativeFocusableElement",{get:function(){return!this.primitiveTextfield||this.computedDisabled?null:this.primitiveTextfield.nativeFocusableElement},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"size",{get:function(){return this.textfieldSize.size},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"focused",{get:function(){return i.isNativeFocused(this.nativeFocusableElement)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"hasButtons",{get:function(){return!this.hideButtons&&"table"!==this.appearance},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"exampleText",{get:function(){return String(this.min)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"computedValue",{get:function(){return o.formatNumber(this.value)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"minusButtonDisabled",{get:function(){return this.disabled||this.readOnly||i.isPresent(this.value)&&this.value<=this.min},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"plusButtonDisabled",{get:function(){return this.disabled||this.readOnly||i.isPresent(this.value)&&this.value>=this.max},enumerable:!0,configurable:!0}),r.prototype.onButtonMouseDown=function(t,e){void 0===e&&(e=!1),e||!this.nativeFocusableElement||this.isMobile||(t.preventDefault(),i.setNativeFocused(this.nativeFocusableElement))},r.prototype.onFocused=function(t){t||this.onBlur(),this.updateFocused(t)},r.prototype.onHovered=function(t){this.updateHovered(t)},r.prototype.onPressed=function(t){this.updatePressed(t)},r.prototype.onValueChange=function(){var t=this.capValue(this.nativeNumberValue);if(null!==t&&!isNaN(t)){var e=o.formatNumber(t);this.nativeValue!==e&&(this.nativeValue=e),this.updateValue(t)}},r.prototype.decreaseValue=function(){if(!this.readOnly){var t=(this.value||0)-this.step;this.safeUpdateValue(t)}},r.prototype.increaseValue=function(){if(!this.readOnly){var t=(this.value||0)+this.step;this.safeUpdateValue(t)}},r.prototype.onKeydown=function(t){switch(t.key){case"ArrowUp":case"Up":this.increaseValue(),t.preventDefault();break;case"ArrowDown":case"Down":this.decreaseValue(),t.preventDefault()}},r.prototype.getFallbackValue=function(){return 0},Object.defineProperty(r.prototype,"nativeNumberValue",{get:function(){return parseInt(this.nativeValue.split(i.CHAR_NO_BREAK_SPACE).join(""),10)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"nativeValue",{get:function(){return this.nativeFocusableElement?this.nativeFocusableElement.value:""},set:function(t){this.nativeFocusableElement&&(this.nativeFocusableElement.value=t)},enumerable:!0,configurable:!0}),r.prototype.safeUpdateValue=function(t){var e=i.clamp(t,this.min,this.max);this.updateValue(e),this.nativeValue=o.formatNumber(e)},r.prototype.capValue=function(t){var e=Math.min(t,this.max);return isNaN(e)||e<this.min?null:e},r.prototype.onBlur=function(){var t=Math.max(this.nativeNumberValue||0,this.min),e=o.formatNumber(t);this.nativeValue=e,this.updateValue(t),this.primitiveTextfield&&(this.primitiveTextfield.value=e)},r.ctorParameters=function(){return[{type:n.NgControl,decorators:[{type:e.Optional},{type:e.Self},{type:e.Inject,args:[n.NgControl]}]},{type:e.ChangeDetectorRef,decorators:[{type:e.Inject,args:[e.ChangeDetectorRef]}]},{type:String,decorators:[{type:e.Inject,args:[o.TUI_TEXTFIELD_APPEARANCE]}]},{type:o.TuiTextfieldSizeDirective,decorators:[{type:e.Inject,args:[o.TUI_TEXTFIELD_SIZE]}]},{type:a.Observable,decorators:[{type:e.Inject,args:[u.TUI_PLUS_MINUS_TEXTS]}]},{type:Boolean,decorators:[{type:e.Inject,args:[i.TUI_IS_MOBILE]}]}]},p([e.Input(),i.tuiDefaultProp()],r.prototype,"step",void 0),p([e.Input(),i.tuiDefaultProp()],r.prototype,"min",void 0),p([e.Input(),i.tuiDefaultProp()],r.prototype,"max",void 0),p([e.Input(),i.tuiDefaultProp()],r.prototype,"hideButtons",void 0),p([e.Input(),i.tuiDefaultProp()],r.prototype,"postfix",void 0),p([i.tuiPure],r.prototype,"getMask",null),p([e.ViewChild(o.TuiPrimitiveTextfieldComponent)],r.prototype,"primitiveTextfield",void 0),p([e.HostBinding("attr.data-tui-host-size")],r.prototype,"size",null),p([e.HostBinding("class._has-buttons")],r.prototype,"hasButtons",null),r=s=p([e.Component({selector:"tui-input-count",template:'<tui-primitive-textfield\n class="textfield"\n tuiValueAccessor\n tuiTextfieldAutocomplete="off"\n tuiTextfieldInputMode="numeric"\n [tuiTextfieldMaxLength]="18"\n [pseudoFocused]="pseudoFocused"\n [pseudoHovered]="pseudoHovered"\n [pseudoPressed]="pseudoPressed"\n [focusable]="focusable"\n [nativeId]="nativeId"\n [postfix]="postfix"\n [disabled]="disabled"\n [readOnly]="readOnly"\n [textMask]="getMask(min < 0)"\n [invalid]="computedInvalid"\n [value]="computedValue"\n (valueChange)="onValueChange()"\n (keydown)="onKeydown($event)"\n (focusedChange)="onFocused($event)"\n (hoveredChange)="onHovered($event)"\n (pressedChange)="onPressed($event)"\n>\n <ng-content></ng-content>\n</tui-primitive-textfield>\n<ng-container *ngIf="hasButtons && (minusTexts$ | async) as texts">\n <section class="buttons">\n <button\n tuiIconButton\n type="button"\n automation-id="tui-input-count__plus-button"\n size="s"\n icon="tuiIconPlus"\n class="button button_plus"\n appearance="textfield"\n [title]="texts[0]"\n [disabled]="plusButtonDisabled"\n [focusable]="false"\n (mousedown)="onButtonMouseDown($event, plusButtonDisabled)"\n (click)="increaseValue()"\n ></button>\n <button\n tuiIconButton\n type="button"\n automation-id="tui-input-count__minus-button"\n size="s"\n icon="tuiIconMinus"\n class="button button_minus"\n appearance="textfield"\n [disabled]="minusButtonDisabled"\n [focusable]="false"\n [title]="texts[1]"\n (mousedown)="onButtonMouseDown($event, minusButtonDisabled)"\n (click)="decreaseValue()"\n ></button>\n </section>\n</ng-container>\n',changeDetection:e.ChangeDetectionStrategy.OnPush,providers:[{provide:i.TUI_FOCUSABLE_ITEM_ACCESSOR,useExisting:e.forwardRef((function(){return s}))}],styles:[":host{font:var(--tui-font-text-s);display:flex;border-radius:var(--tui-radius-m);height:var(--tui-height-m);color:var(--tui-text-01)}:host._disabled{pointer-events:none}:host[data-tui-host-size='l']{font:var(--tui-font-text-m);height:var(--tui-height-l)}.textfield{position:relative;border-radius:inherit;width:100%}:host._has-buttons .textfield{border-top-right-radius:0;border-bottom-right-radius:0}.buttons{display:flex;flex-direction:column;margin-left:2px;height:100%}.button.button{display:flex;width:calc(var(--tui-height-m) * .75);height:calc(50% - 1px)}.button.button_plus{margin-bottom:2px;border-radius:0 var(--tui-radius-m) 0 0}.button.button_minus{border-radius:0 0 var(--tui-radius-m)}:host[data-tui-host-size='l'] .button.button{width:calc(var(--tui-height-l) * .75)}"]}),d(0,e.Optional()),d(0,e.Self()),d(0,e.Inject(n.NgControl)),d(1,e.Inject(e.ChangeDetectorRef)),d(2,e.Inject(o.TUI_TEXTFIELD_APPEARANCE)),d(3,e.Inject(o.TUI_TEXTFIELD_SIZE)),d(4,e.Inject(u.TUI_PLUS_MINUS_TEXTS)),d(5,e.Inject(i.TUI_IS_MOBILE))],r)}(i.AbstractTuiControl),h=function(){function t(){}return t=p([e.NgModule({imports:[r.CommonModule,l.TextMaskModule,o.TuiButtonModule,o.TuiPrimitiveTextfieldModule,o.TuiTextfieldControllerModule,s.TuiValueAccessorModule],declarations:[f],exports:[f]})],t)}();t.TuiInputCountComponent=f,t.TuiInputCountModule=h,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=taiga-ui-kit-components-input-count.umd.min.js.map