ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
16 lines (14 loc) • 9.77 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/cdk/bidi"),require("@angular/cdk/keycodes"),require("@angular/core"),require("@angular/forms"),require("ng-zorro-antd/core/config"),require("rxjs"),require("rxjs/operators"),require("ng-zorro-antd/core/util"),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/bidi","@angular/cdk/keycodes","@angular/core","@angular/forms","ng-zorro-antd/core/config","rxjs","rxjs/operators","ng-zorro-antd/core/util","@angular/common","ng-zorro-antd/icon","ng-zorro-antd/tooltip"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self)["ng-zorro-antd"]=t["ng-zorro-antd"]||{},t["ng-zorro-antd"].rate={}),t.ng.cdk.bidi,t.ng.cdk.keycodes,t.ng.core,t.ng.forms,t["ng-zorro-antd"].core.config,t.rxjs,t.rxjs.operators,t["ng-zorro-antd"].core.util,t.ng.common,t["ng-zorro-antd"].icon,t["ng-zorro-antd"].tooltip)}(this,(function(t,e,n,o,r,a,i,s,l,u,c,p){"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.
***************************************************************************** */function h(t,e,n,o){var r,a=arguments.length,i=a<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(t,e,n,o);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(i=(a<3?r(i):a>3?r(e,n,i):r(e,n))||i);return a>3&&i&&Object.defineProperty(e,n,i),i}function d(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}Object.create;Object.create;var f="rate",y=function(){function t(t,e,n,r){this.nzConfigService=t,this.renderer=e,this.cdr=n,this.directionality=r,this._nzModuleName=f,this.nzAllowClear=!0,this.nzAllowHalf=!1,this.nzDisabled=!1,this.nzAutoFocus=!1,this.nzCount=5,this.nzTooltips=[],this.nzOnBlur=new o.EventEmitter,this.nzOnFocus=new o.EventEmitter,this.nzOnHoverChange=new o.EventEmitter,this.nzOnKeyDown=new o.EventEmitter,this.classMap={},this.starArray=[],this.starStyleArray=[],this.dir="ltr",this.destroy$=new i.Subject,this.hasHalf=!1,this.hoverValue=0,this.isFocused=!1,this._value=0,this.onChange=function(){return null},this.onTouched=function(){return null}}return 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:!1,configurable:!0}),t.prototype.ngOnChanges=function(t){var e=t.nzAutoFocus,n=t.nzCount,o=t.nzValue;if(e&&!e.isFirstChange()){var r=this.ulElement.nativeElement;this.nzAutoFocus&&!this.nzDisabled?this.renderer.setAttribute(r,"autofocus","autofocus"):this.renderer.removeAttribute(r,"autofocus")}n&&this.updateStarArray(),o&&this.updateStarStyle()},t.prototype.ngOnInit=function(){var t,e=this;this.nzConfigService.getConfigChangeEventForComponent(f).pipe(s.takeUntil(this.destroy$)).subscribe((function(){return e.cdr.markForCheck()})),null===(t=this.directionality.change)||void 0===t||t.pipe(s.takeUntil(this.destroy$)).subscribe((function(t){e.dir=t,e.cdr.detectChanges()})),this.dir=this.directionality.value},t.prototype.ngOnDestroy=function(){this.destroy$.next(),this.destroy$.complete()},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)),this.updateStarStyle()}},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),this.updateStarStyle())},t.prototype.onRateLeave=function(){this.hasHalf=!Number.isInteger(this.nzValue),this.hoverValue=Math.ceil(this.nzValue),this.updateStarStyle()},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 e=this.nzValue;t.keyCode===n.RIGHT_ARROW&&this.nzValue<this.nzCount?this.nzValue+=this.nzAllowHalf?.5:1:t.keyCode===n.LEFT_ARROW&&this.nzValue>0&&(this.nzValue-=this.nzAllowHalf?.5:1),e!==this.nzValue&&(this.onChange(this.nzValue),this.nzOnKeyDown.emit(t),this.updateStarStyle(),this.cdr.markForCheck())},t.prototype.updateStarArray=function(){this.starArray=Array(this.nzCount).fill(0).map((function(t,e){return e})),this.updateStarStyle()},t.prototype.updateStarStyle=function(){var t=this;this.starStyleArray=this.starArray.map((function(e){var n,o="ant-rate-star",r=e+1;return(n={})[o+"-full"]=r<t.hoverValue||!t.hasHalf&&r===t.hoverValue,n[o+"-half"]=t.hasHalf&&r===t.hoverValue,n[o+"-active"]=t.hasHalf&&r===t.hoverValue,n[o+"-zero"]=r>t.hoverValue,n[o+"-focused"]=t.hasHalf&&r===t.hoverValue&&t.isFocused,n}))},t.prototype.writeValue=function(t){this.nzValue=t||0,this.updateStarArray(),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}();y.decorators=[{type:o.Component,args:[{changeDetection:o.ChangeDetectionStrategy.OnPush,encapsulation:o.ViewEncapsulation.None,selector:"nz-rate",exportAs:"nzRate",preserveWhitespaces:!1,template:'\n <ul\n #ulElement\n class="ant-rate"\n [class.ant-rate-disabled]="nzDisabled"\n [class.ant-rate-rtl]="dir === \'rtl\'"\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 >\n <li\n *ngFor="let star of starArray; let i = index"\n class="ant-rate-star"\n [ngClass]="starStyleArray[i] || \'\'"\n nz-tooltip\n [nzTooltipTitle]="nzTooltips[i]"\n >\n <div\n 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:r.NG_VALUE_ACCESSOR,useExisting:o.forwardRef((function(){return y})),multi:!0}]}]}],y.ctorParameters=function(){return[{type:a.NzConfigService},{type:o.Renderer2},{type:o.ChangeDetectorRef},{type:e.Directionality,decorators:[{type:o.Optional}]}]},y.propDecorators={ulElement:[{type:o.ViewChild,args:["ulElement",{static:!1}]}],nzAllowClear:[{type:o.Input}],nzAllowHalf:[{type:o.Input}],nzDisabled:[{type:o.Input}],nzAutoFocus:[{type:o.Input}],nzCharacter:[{type:o.Input}],nzCount:[{type:o.Input}],nzTooltips:[{type:o.Input}],nzOnBlur:[{type:o.Output}],nzOnFocus:[{type:o.Output}],nzOnHoverChange:[{type:o.Output}],nzOnKeyDown:[{type:o.Output}]},h([a.WithConfig(),l.InputBoolean(),d("design:type",Boolean)],y.prototype,"nzAllowClear",void 0),h([a.WithConfig(),l.InputBoolean(),d("design:type",Boolean)],y.prototype,"nzAllowHalf",void 0),h([l.InputBoolean(),d("design:type",Boolean)],y.prototype,"nzDisabled",void 0),h([l.InputBoolean(),d("design:type",Boolean)],y.prototype,"nzAutoFocus",void 0),h([l.InputNumber(),d("design:type",Number)],y.prototype,"nzCount",void 0);var g=function(){function t(){this.allowHalf=!1,this.itemHover=new o.EventEmitter,this.itemClick=new o.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}();g.decorators=[{type:o.Component,args:[{changeDetection:o.ChangeDetectionStrategy.OnPush,encapsulation:o.ViewEncapsulation.None,selector:"[nz-rate-item]",exportAs:"nzRateItem",template:'\n <div class="ant-rate-star-second" (mouseover)="hoverRate(false); $event.stopPropagation()" (click)="clickRate(false)">\n <ng-template [ngTemplateOutlet]="character || defaultCharacter"></ng-template>\n </div>\n <div class="ant-rate-star-first" (mouseover)="hoverRate(true); $event.stopPropagation()" (click)="clickRate(true)">\n <ng-template [ngTemplateOutlet]="character || defaultCharacter"></ng-template>\n </div>\n\n <ng-template #defaultCharacter>\n <i nz-icon nzType="star" nzTheme="fill"></i>\n </ng-template>\n '}]}],g.propDecorators={character:[{type:o.Input}],allowHalf:[{type:o.Input}],itemHover:[{type:o.Output}],itemClick:[{type:o.Output}]},h([l.InputBoolean(),d("design:type",Boolean)],g.prototype,"allowHalf",void 0);var z=function(){};z.decorators=[{type:o.NgModule,args:[{exports:[y],declarations:[y,g],imports:[e.BidiModule,u.CommonModule,c.NzIconModule,p.NzToolTipModule]}]}],t.NzRateComponent=y,t.NzRateItemComponent=g,t.NzRateModule=z,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=ng-zorro-antd-rate.umd.min.js.map