ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
2 lines • 7.73 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/cdk/keycodes"),require("@angular/forms"),require("@angular/common"),require("ng-zorro-antd/icon"),require("ng-zorro-antd/tooltip"),require("@angular/core"),require("ng-zorro-antd/core")):"function"==typeof define&&define.amd?define("ng-zorro-antd/rate",["exports","@angular/cdk/keycodes","@angular/forms","@angular/common","ng-zorro-antd/icon","ng-zorro-antd/tooltip","@angular/core","ng-zorro-antd/core"],e):e((t["ng-zorro-antd"]=t["ng-zorro-antd"]||{},t["ng-zorro-antd"].rate={}),t.ng.cdk.keycodes,t.ng.forms,t.ng.common,t["ng-zorro-antd"].icon,t["ng-zorro-antd"].tooltip,t.ng.core,t["ng-zorro-antd"].core)}(this,function(t,n,e,o,r,i,a,s){"use strict";function l(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;0<=s;s--)(r=t[s])&&(a=(i<3?r(a):3<i?r(e,n,a):r(e,n))||a);return 3<i&&a&&Object.defineProperty(e,n,a),a}function u(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}var h=(Object.defineProperty(c.prototype,"nzCount",{get:function(){return this._count},set:function(t){this._count!==t&&(this._count=t,this.updateStarArray())},enumerable:!0,configurable:!0}),Object.defineProperty(c.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}),c.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"))},c.prototype.ngOnInit=function(){this.updateStarArray()},c.prototype.ngAfterViewInit=function(){this.isInit=!0},c.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))}},c.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))},c.prototype.onRateLeave=function(){this.hasHalf=!Number.isInteger(this.nzValue),this.hoverValue=Math.ceil(this.nzValue)},c.prototype.onFocus=function(t){this.isFocused=!0,this.nzOnFocus.emit(t)},c.prototype.onBlur=function(t){this.isFocused=!1,this.nzOnBlur.emit(t)},c.prototype.focus=function(){this.ulElement.nativeElement.focus()},c.prototype.blur=function(){this.ulElement.nativeElement.blur()},c.prototype.onKeyDown=function(t){var e=this.nzValue;t.keyCode===n.RIGHT_ARROW&&this.nzValue<this.nzCount?this.nzValue+=this.nzAllowHalf?.5:1:t.keyCode===n.LEFT_ARROW&&0<this.nzValue&&(this.nzValue-=this.nzAllowHalf?.5:1),e!==this.nzValue&&(this.onChange(this.nzValue),this.nzOnKeyDown.emit(t),this.cdr.markForCheck())},c.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},c.prototype.updateStarArray=function(){this.starArray=Array(this.nzCount).fill(0).map(function(t,e){return e})},c.prototype.writeValue=function(t){this.nzValue=t||0,this.cdr.markForCheck()},c.prototype.setDisabledState=function(t){this.nzDisabled=t},c.prototype.registerOnChange=function(t){this.onChange=t},c.prototype.registerOnTouched=function(t){this.onTouched=t},c.decorators=[{type:a.Component,args:[{changeDetection:a.ChangeDetectionStrategy.OnPush,encapsulation:a.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:e.NG_VALUE_ACCESSOR,useExisting:a.forwardRef(function(){return c}),multi:!0}]}]}],c.ctorParameters=function(){return[{type:a.Renderer2},{type:a.ChangeDetectorRef}]},c.propDecorators={ulElement:[{type:a.ViewChild,args:["ulElement"]}],nzAllowClear:[{type:a.Input}],nzAllowHalf:[{type:a.Input}],nzDisabled:[{type:a.Input}],nzAutoFocus:[{type:a.Input}],nzCharacter:[{type:a.Input}],nzTooltips:[{type:a.Input}],nzOnBlur:[{type:a.Output}],nzOnFocus:[{type:a.Output}],nzOnHoverChange:[{type:a.Output}],nzOnKeyDown:[{type:a.Output}],nzCount:[{type:a.Input}]},l([s.InputBoolean(),u("design:type",Boolean)],c.prototype,"nzAllowClear",void 0),l([s.InputBoolean(),u("design:type",Boolean)],c.prototype,"nzAllowHalf",void 0),l([s.InputBoolean(),u("design:type",Boolean)],c.prototype,"nzDisabled",void 0),l([s.InputBoolean(),u("design:type",Boolean)],c.prototype,"nzAutoFocus",void 0),c);function c(t,e){this.renderer=t,this.cdr=e,this.nzAllowClear=!0,this.nzAllowHalf=!1,this.nzDisabled=!1,this.nzAutoFocus=!1,this.nzTooltips=[],this.nzOnBlur=new a.EventEmitter,this.nzOnFocus=new a.EventEmitter,this.nzOnHoverChange=new a.EventEmitter,this.nzOnKeyDown=new a.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._count=5,this._value=0,this.onChange=function(){return null},this.onTouched=function(){return null}}var p=(f.prototype.hoverRate=function(t){this.itemHover.next(t&&this.allowHalf)},f.prototype.clickRate=function(t){this.itemClick.next(t&&this.allowHalf)},f.decorators=[{type:a.Component,args:[{changeDetection:a.ChangeDetectionStrategy.OnPush,encapsulation:a.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 type="star"\n theme="fill"></i>\n</ng-template>\n'}]}],f.propDecorators={character:[{type:a.Input}],allowHalf:[{type:a.Input}],itemHover:[{type:a.Output}],itemClick:[{type:a.Output}]},l([s.InputBoolean(),u("design:type",Boolean)],f.prototype,"allowHalf",void 0),f);function f(){this.allowHalf=!1,this.itemHover=new a.EventEmitter,this.itemClick=new a.EventEmitter}var d=(z.decorators=[{type:a.NgModule,args:[{exports:[h],declarations:[h,p],imports:[o.CommonModule,r.NzIconModule,i.NzToolTipModule]}]}],z);function z(){}t.NzRateComponent=h,t.NzRateModule=d,t.NzRateItemComponent=p,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=ng-zorro-antd-rate.umd.min.js.map