ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
2 lines • 8.25 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/cdk/keycodes"),require("@angular/core"),require("@angular/forms"),require("ng-zorro-antd/core"),require("rxjs"),require("rxjs/operators"),require("@angular/common"),require("ng-zorro-antd/icon"),require("ng-zorro-antd/tooltip")):"function"==typeof define&&define.amd?define("ng-zorro-antd/rate",["exports","@angular/cdk/keycodes","@angular/core","@angular/forms","ng-zorro-antd/core","rxjs","rxjs/operators","@angular/common","ng-zorro-antd/icon","ng-zorro-antd/tooltip"],e):e(((t=t||self)["ng-zorro-antd"]=t["ng-zorro-antd"]||{},t["ng-zorro-antd"].rate={}),t.ng.cdk.keycodes,t.ng.core,t.ng.forms,t["ng-zorro-antd"].core,t.rxjs,t.rxjs.operators,t.ng.common,t["ng-zorro-antd"].icon,t["ng-zorro-antd"].tooltip)}(this,function(t,e,n,o,r,i,a,s,l,u){"use strict";function c(t,e,n,o){var r,i=arguments.length,a=i<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,o);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(a=(i<3?r(a):i>3?r(e,n,a):r(e,n))||a);return i>3&&a&&Object.defineProperty(e,n,a),a}function h(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}var p=function(){function t(t,e,o){this.nzConfigService=t,this.renderer=e,this.cdr=o,this.nzDisabled=!1,this.nzAutoFocus=!1,this.nzTooltips=[],this.nzOnBlur=new n.EventEmitter,this.nzOnFocus=new n.EventEmitter,this.nzOnHoverChange=new n.EventEmitter,this.nzOnKeyDown=new n.EventEmitter,this.hasHalf=!1,this.hoverValue=0,this.prefixCls="ant-rate",this.innerPrefixCls=this.prefixCls+"-star",this.isFocused=!1,this.isInit=!1,this.starArray=[],this.destroy$=new i.Subject,this._count=5,this._value=0,this.onChange=function(){return null},this.onTouched=function(){return null}}return Object.defineProperty(t.prototype,"nzCount",{get:function(){return this._count},set:function(t){this._count!==t&&(this._count=t,this.updateStarArray())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"nzValue",{get:function(){return this._value},set:function(t){this._value!==t&&(this._value=t,this.hasHalf=!Number.isInteger(t),this.hoverValue=Math.ceil(t))},enumerable:!0,configurable:!0}),t.prototype.ngOnChanges=function(t){t.nzAutoFocus&&!t.nzAutoFocus.isFirstChange()&&(this.nzAutoFocus&&!this.nzDisabled?this.renderer.setAttribute(this.ulElement.nativeElement,"autofocus","autofocus"):this.renderer.removeAttribute(this.ulElement.nativeElement,"autofocus"))},t.prototype.ngOnInit=function(){var t=this;this.updateStarArray(),this.nzConfigService.getConfigChangeEventForComponent(r.trimComponentName(this.constructor.name)).pipe(a.takeUntil(this.destroy$)).subscribe(function(){return t.cdr.markForCheck()})},t.prototype.ngOnDestroy=function(){this.destroy$.next(),this.destroy$.complete()},t.prototype.ngAfterViewInit=function(){this.isInit=!0},t.prototype.onItemClick=function(t,e){if(!this.nzDisabled){this.hoverValue=t+1;var n=e?t+.5:t+1;this.nzValue===n?this.nzAllowClear&&(this.nzValue=0,this.onChange(this.nzValue)):(this.nzValue=n,this.onChange(this.nzValue))}},t.prototype.onItemHover=function(t,e){this.nzDisabled||this.hoverValue===t+1&&e===this.hasHalf||(this.hoverValue=t+1,this.hasHalf=e,this.nzOnHoverChange.emit(this.hoverValue))},t.prototype.onRateLeave=function(){this.hasHalf=!Number.isInteger(this.nzValue),this.hoverValue=Math.ceil(this.nzValue)},t.prototype.onFocus=function(t){this.isFocused=!0,this.nzOnFocus.emit(t)},t.prototype.onBlur=function(t){this.isFocused=!1,this.nzOnBlur.emit(t)},t.prototype.focus=function(){this.ulElement.nativeElement.focus()},t.prototype.blur=function(){this.ulElement.nativeElement.blur()},t.prototype.onKeyDown=function(t){var n=this.nzValue;t.keyCode===e.RIGHT_ARROW&&this.nzValue<this.nzCount?this.nzValue+=this.nzAllowHalf?.5:1:t.keyCode===e.LEFT_ARROW&&this.nzValue>0&&(this.nzValue-=this.nzAllowHalf?.5:1),n!==this.nzValue&&(this.onChange(this.nzValue),this.nzOnKeyDown.emit(t),this.cdr.markForCheck())},t.prototype.setClasses=function(t){var e;return(e={})[this.innerPrefixCls+"-full"]=t+1<this.hoverValue||!this.hasHalf&&t+1===this.hoverValue,e[this.innerPrefixCls+"-half"]=this.hasHalf&&t+1===this.hoverValue,e[this.innerPrefixCls+"-active"]=this.hasHalf&&t+1===this.hoverValue,e[this.innerPrefixCls+"-zero"]=t+1>this.hoverValue,e[this.innerPrefixCls+"-focused"]=this.hasHalf&&t+1===this.hoverValue&&this.isFocused,e},t.prototype.updateStarArray=function(){this.starArray=Array(this.nzCount).fill(0).map(function(t,e){return e})},t.prototype.writeValue=function(t){this.nzValue=t||0,this.cdr.markForCheck()},t.prototype.setDisabledState=function(t){this.nzDisabled=t},t.prototype.registerOnChange=function(t){this.onChange=t},t.prototype.registerOnTouched=function(t){this.onTouched=t},t.decorators=[{type:n.Component,args:[{changeDetection:n.ChangeDetectionStrategy.OnPush,encapsulation:n.ViewEncapsulation.None,selector:"nz-rate",exportAs:"nzRate",preserveWhitespaces:!1,template:'<ul #ulElement\n class="ant-rate"\n [class.ant-rate-disabled]="nzDisabled"\n [ngClass]="classMap"\n (blur)="onBlur($event)"\n (focus)="onFocus($event)"\n (keydown)="onKeyDown($event); $event.preventDefault();"\n (mouseleave)="onRateLeave(); $event.stopPropagation();"\n [tabindex]="nzDisabled ? -1 : 1">\n <li *ngFor="let star of starArray; let i = index"\n class="ant-rate-star"\n [ngClass]="setClasses(star)"\n nz-tooltip\n [nzTitle]="nzTooltips[ i ]">\n <div nz-rate-item\n [allowHalf]="nzAllowHalf"\n [character]="nzCharacter"\n (itemHover)="onItemHover(i, $event)"\n (itemClick)="onItemClick(i, $event)">\n </div>\n </li>\n</ul>\n',providers:[{provide:o.NG_VALUE_ACCESSOR,useExisting:n.forwardRef(function(){return t}),multi:!0}]}]}],t.ctorParameters=function(){return[{type:r.NzConfigService},{type:n.Renderer2},{type:n.ChangeDetectorRef}]},t.propDecorators={ulElement:[{type:n.ViewChild,args:["ulElement",{static:!1}]}],nzAllowClear:[{type:n.Input}],nzAllowHalf:[{type:n.Input}],nzDisabled:[{type:n.Input}],nzAutoFocus:[{type:n.Input}],nzCharacter:[{type:n.Input}],nzTooltips:[{type:n.Input}],nzOnBlur:[{type:n.Output}],nzOnFocus:[{type:n.Output}],nzOnHoverChange:[{type:n.Output}],nzOnKeyDown:[{type:n.Output}],nzCount:[{type:n.Input}]},c([r.WithConfig(!0),r.InputBoolean(),h("design:type",Boolean)],t.prototype,"nzAllowClear",void 0),c([r.WithConfig(!1),r.InputBoolean(),h("design:type",Boolean)],t.prototype,"nzAllowHalf",void 0),c([r.InputBoolean(),h("design:type",Boolean)],t.prototype,"nzDisabled",void 0),c([r.InputBoolean(),h("design:type",Boolean)],t.prototype,"nzAutoFocus",void 0),t}();var f=function(){function t(){this.allowHalf=!1,this.itemHover=new n.EventEmitter,this.itemClick=new n.EventEmitter}return t.prototype.hoverRate=function(t){this.itemHover.next(t&&this.allowHalf)},t.prototype.clickRate=function(t){this.itemClick.next(t&&this.allowHalf)},t.decorators=[{type:n.Component,args:[{changeDetection:n.ChangeDetectionStrategy.OnPush,encapsulation:n.ViewEncapsulation.None,selector:"[nz-rate-item]",exportAs:"nzRateItem",template:'<div class="ant-rate-star-second"\n (mouseover)="hoverRate(false); $event.stopPropagation();"\n (click)="clickRate(false);">\n <ng-template [ngTemplateOutlet]="character || defaultCharacter"></ng-template>\n</div>\n<div class="ant-rate-star-first"\n (mouseover)="hoverRate(true); $event.stopPropagation();"\n (click)="clickRate(true);">\n <ng-template [ngTemplateOutlet]="character || defaultCharacter"></ng-template>\n</div>\n\n<ng-template #defaultCharacter>\n <i nz-icon\n nzType="star"\n nzTheme="fill"></i>\n</ng-template>\n'}]}],t.propDecorators={character:[{type:n.Input}],allowHalf:[{type:n.Input}],itemHover:[{type:n.Output}],itemClick:[{type:n.Output}]},c([r.InputBoolean(),h("design:type",Boolean)],t.prototype,"allowHalf",void 0),t}();var d=function(){function t(){}return t.decorators=[{type:n.NgModule,args:[{exports:[p],declarations:[p,f],imports:[s.CommonModule,l.NzIconModule,u.NzToolTipModule]}]}],t}();t.NzRateComponent=p,t.NzRateItemComponent=f,t.NzRateModule=d,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=ng-zorro-antd-rate.umd.min.js.map