UNPKG

ng-zorro-antd

Version:

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

16 lines (14 loc) 6.31 kB
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@angular/cdk/a11y"),require("@angular/cdk/keycodes"),require("@angular/core"),require("@angular/forms"),require("ng-zorro-antd/core/config"),require("ng-zorro-antd/core/util"),require("@angular/common"),require("ng-zorro-antd/core/outlet"),require("ng-zorro-antd/core/wave"),require("ng-zorro-antd/icon")):"function"==typeof define&&define.amd?define("ng-zorro-antd/switch",["exports","@angular/cdk/a11y","@angular/cdk/keycodes","@angular/core","@angular/forms","ng-zorro-antd/core/config","ng-zorro-antd/core/util","@angular/common","ng-zorro-antd/core/outlet","ng-zorro-antd/core/wave","ng-zorro-antd/icon"],n):n(((e=e||self)["ng-zorro-antd"]=e["ng-zorro-antd"]||{},e["ng-zorro-antd"].switch={}),e.ng.cdk.a11y,e.ng.cdk.keycodes,e.ng.core,e.ng.forms,e["ng-zorro-antd"].core.config,e["ng-zorro-antd"].core.util,e.ng.common,e["ng-zorro-antd"].core.outlet,e["ng-zorro-antd"].core.wave,e["ng-zorro-antd"].icon)}(this,(function(e,n,t,o,i,r,c,a,s,d,l){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */function u(e,n,t,o){var i,r=arguments.length,c=r<3?n:null===o?o=Object.getOwnPropertyDescriptor(n,t):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,n,t,o);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(c=(r<3?i(c):r>3?i(n,t,c):i(n,t))||c);return r>3&&c&&Object.defineProperty(n,t,c),c}function h(e,n){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,n)}var p=function(){function e(e,n,t){this.nzConfigService=e,this.cdr=n,this.focusMonitor=t,this.isChecked=!1,this.onChange=function(){},this.onTouched=function(){},this.nzLoading=!1,this.nzDisabled=!1,this.nzControl=!1,this.nzCheckedChildren=null,this.nzUnCheckedChildren=null}return e.prototype.onHostClick=function(e){e.preventDefault(),this.nzDisabled||this.nzLoading||this.nzControl||this.updateValue(!this.isChecked)},e.prototype.updateValue=function(e){this.isChecked!==e&&(this.isChecked=e,this.onChange(this.isChecked))},e.prototype.onKeyDown=function(e){this.nzControl||this.nzDisabled||this.nzLoading||(e.keyCode===t.LEFT_ARROW?(this.updateValue(!1),e.preventDefault()):e.keyCode===t.RIGHT_ARROW?(this.updateValue(!0),e.preventDefault()):e.keyCode!==t.SPACE&&e.keyCode!==t.ENTER||(this.updateValue(!this.isChecked),e.preventDefault()))},e.prototype.focus=function(){this.focusMonitor.focusVia(this.switchElement.nativeElement,"keyboard")},e.prototype.blur=function(){this.switchElement.nativeElement.blur()},e.prototype.ngAfterViewInit=function(){var e=this;this.focusMonitor.monitor(this.switchElement.nativeElement,!0).subscribe((function(n){n||Promise.resolve().then((function(){return e.onTouched()}))}))},e.prototype.ngOnDestroy=function(){this.focusMonitor.stopMonitoring(this.switchElement.nativeElement)},e.prototype.writeValue=function(e){this.isChecked=e,this.cdr.markForCheck()},e.prototype.registerOnChange=function(e){this.onChange=e},e.prototype.registerOnTouched=function(e){this.onTouched=e},e.prototype.setDisabledState=function(e){this.nzDisabled=e,this.cdr.markForCheck()},e.decorators=[{type:o.Component,args:[{selector:"nz-switch",exportAs:"nzSwitch",preserveWhitespaces:!1,changeDetection:o.ChangeDetectionStrategy.OnPush,encapsulation:o.ViewEncapsulation.None,providers:[{provide:i.NG_VALUE_ACCESSOR,useExisting:o.forwardRef((function(){return e})),multi:!0}],template:'\n <button\n nz-wave\n type="button"\n class="ant-switch"\n #switchElement\n [disabled]="nzDisabled"\n [class.ant-switch-checked]="isChecked"\n [class.ant-switch-loading]="nzLoading"\n [class.ant-switch-disabled]="nzDisabled"\n [class.ant-switch-small]="nzSize === \'small\'"\n [nzWaveExtraNode]="true"\n (keydown)="onKeyDown($event)"\n >\n <i *ngIf="nzLoading" nz-icon nzType="loading" class="ant-switch-loading-icon"></i>\n <span class="ant-switch-inner">\n <ng-container *ngIf="isChecked; else uncheckTemplate">\n <ng-container *nzStringTemplateOutlet="nzCheckedChildren">{{ nzCheckedChildren }}</ng-container>\n </ng-container>\n <ng-template #uncheckTemplate>\n <ng-container *nzStringTemplateOutlet="nzUnCheckedChildren">{{ nzUnCheckedChildren }}</ng-container>\n </ng-template>\n </span>\n <div class="ant-click-animating-node"></div>\n </button>\n ',host:{"(click)":"onHostClick($event)"}}]}],e.ctorParameters=function(){return[{type:r.NzConfigService},{type:o.ChangeDetectorRef},{type:n.FocusMonitor}]},e.propDecorators={switchElement:[{type:o.ViewChild,args:["switchElement",{static:!0}]}],nzLoading:[{type:o.Input}],nzDisabled:[{type:o.Input}],nzControl:[{type:o.Input}],nzCheckedChildren:[{type:o.Input}],nzUnCheckedChildren:[{type:o.Input}],nzSize:[{type:o.Input}]},u([c.InputBoolean(),h("design:type",Object)],e.prototype,"nzLoading",void 0),u([c.InputBoolean(),h("design:type",Object)],e.prototype,"nzDisabled",void 0),u([c.InputBoolean(),h("design:type",Object)],e.prototype,"nzControl",void 0),u([r.WithConfig("switch","default"),h("design:type",String)],e.prototype,"nzSize",void 0),e}();var g=function(){function e(){}return e.decorators=[{type:o.NgModule,args:[{exports:[p],declarations:[p],imports:[a.CommonModule,d.NzWaveModule,l.NzIconModule,s.NzOutletModule]}]}],e}();e.NzSwitchComponent=p,e.NzSwitchModule=g,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=ng-zorro-antd-switch.umd.min.js.map