@angular/material
Version:
Angular Material
10 lines (9 loc) • 10.3 kB
JavaScript
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/cdk/a11y"),require("@angular/cdk/coercion"),require("@angular/cdk/platform"),require("@angular/core"),require("@angular/forms"),require("@angular/material/core"),require("@angular/cdk/observers"),require("@angular/platform-browser")):"function"==typeof define&&define.amd?define("@angular/material/slideToggle",["exports","@angular/cdk/a11y","@angular/cdk/coercion","@angular/cdk/platform","@angular/core","@angular/forms","@angular/material/core","@angular/cdk/observers","@angular/platform-browser"],t):t((e.ng=e.ng||{},e.ng.material=e.ng.material||{},e.ng.material.slideToggle={}),e.ng.cdk.a11y,e.ng.cdk.coercion,e.ng.cdk.platform,e.ng.core,e.ng.forms,e.ng.material.core,e.ng.cdk.observers,e.ng.platformBrowser)}(this,function(e,t,i,n,r,a,o,l,s){"use strict";function g(e,t){function i(){this.constructor=e}d(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}var d=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])},c=0,u={provide:a.NG_VALUE_ACCESSOR,useExisting:r.forwardRef(function(){return b}),multi:!0},p=function(){function e(e,t){this.source=e,this.checked=t}return e}(),h=function(){function e(e){this._elementRef=e}return e}(),m=o.mixinTabIndex(o.mixinColor(o.mixinDisableRipple(o.mixinDisabled(h)),"accent")),b=function(e){function a(t,i,n,a,o,l){var s=e.call(this,t)||this;return s._platform=i,s._focusMonitor=n,s._changeDetectorRef=a,s._ngZone=l,s.onChange=function(e){},s.onTouched=function(){},s._uniqueId="mat-slide-toggle-"+ ++c,s._required=!1,s._checked=!1,s.name=null,s.id=s._uniqueId,s.labelPosition="after",s.ariaLabel=null,s.ariaLabelledby=null,s.change=new r.EventEmitter,s.tabIndex=parseInt(o)||0,s}return g(a,e),Object.defineProperty(a.prototype,"required",{get:function(){return this._required},set:function(e){this._required=i.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"checked",{get:function(){return this._checked},set:function(e){this._checked=i.coerceBooleanProperty(e),this._changeDetectorRef.markForCheck()},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"inputId",{get:function(){return(this.id||this._uniqueId)+"-input"},enumerable:!0,configurable:!0}),a.prototype.ngAfterContentInit=function(){var e=this;this._slideRenderer=new f(this._elementRef,this._platform),this._focusMonitor.monitor(this._inputElement.nativeElement).subscribe(function(t){return e._onInputFocusChange(t)})},a.prototype.ngOnDestroy=function(){this._focusMonitor.stopMonitoring(this._inputElement.nativeElement)},a.prototype._onChangeEvent=function(e){if(e.stopPropagation(),this._slideRenderer.dragging)return void(this._inputElement.nativeElement.checked=this.checked);this.checked=this._inputElement.nativeElement.checked,this._emitChangeEvent()},a.prototype._onInputClick=function(e){e.stopPropagation()},a.prototype.writeValue=function(e){this.checked=!!e},a.prototype.registerOnChange=function(e){this.onChange=e},a.prototype.registerOnTouched=function(e){this.onTouched=e},a.prototype.setDisabledState=function(e){this.disabled=e,this._changeDetectorRef.markForCheck()},a.prototype.focus=function(){this._focusMonitor.focusVia(this._inputElement.nativeElement,"keyboard")},a.prototype.toggle=function(){this.checked=!this.checked},a.prototype._onInputFocusChange=function(e){this._focusRipple||"keyboard"!==e?e||(this.onTouched(),this._focusRipple&&(this._focusRipple.fadeOut(),this._focusRipple=null)):this._focusRipple=this._ripple.launch(0,0,{persistent:!0})},a.prototype._emitChangeEvent=function(){this.onChange(this.checked),this.change.emit(new p(this,this.checked))},a.prototype._onDragStart=function(){this.disabled||this._slideRenderer.startThumbDrag(this.checked)},a.prototype._onDrag=function(e){this._slideRenderer.dragging&&this._slideRenderer.updateThumbPosition(e.deltaX)},a.prototype._onDragEnd=function(){var e=this;if(this._slideRenderer.dragging){var t=this._slideRenderer.dragPercentage>50;t!==this.checked&&(this.checked=t,this._emitChangeEvent()),this._ngZone.runOutsideAngular(function(){setTimeout(function(){return e._slideRenderer.stopThumbDrag()})})}},a.prototype._onLabelTextChange=function(){this._changeDetectorRef.markForCheck()},a.decorators=[{type:r.Component,args:[{selector:"mat-slide-toggle",exportAs:"matSlideToggle",host:{class:"mat-slide-toggle","[id]":"id","[class.mat-checked]":"checked","[class.mat-disabled]":"disabled","[class.mat-slide-toggle-label-before]":'labelPosition == "before"'},template:'<label class="mat-slide-toggle-label" #label><div class="mat-slide-toggle-bar" [class.mat-slide-toggle-bar-no-side-margin]="!labelContent.textContent || !labelContent.textContent.trim()"><input #input class="mat-slide-toggle-input cdk-visually-hidden" type="checkbox" [id]="inputId" [required]="required" [tabIndex]="tabIndex" [checked]="checked" [disabled]="disabled" [attr.name]="name" [attr.aria-label]="ariaLabel" [attr.aria-labelledby]="ariaLabelledby" (change)="_onChangeEvent($event)" (click)="_onInputClick($event)"><div class="mat-slide-toggle-thumb-container" (slidestart)="_onDragStart()" (slide)="_onDrag($event)" (slideend)="_onDragEnd()"><div class="mat-slide-toggle-thumb"></div><div class="mat-slide-toggle-ripple" mat-ripple [matRippleTrigger]="label" [matRippleDisabled]="disableRipple || disabled" [matRippleCentered]="true" [matRippleRadius]="23" [matRippleAnimation]="{enterDuration: 150}"></div></div></div><span class="mat-slide-toggle-content" #labelContent (cdkObserveContent)="_onLabelTextChange()"><ng-content></ng-content></span></label>',styles:[".mat-slide-toggle{display:inline-block;height:24px;max-width:100%;line-height:24px;white-space:nowrap;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;outline:0}.mat-slide-toggle.mat-checked .mat-slide-toggle-thumb-container{transform:translate3d(16px,0,0)}.mat-slide-toggle.mat-disabled .mat-slide-toggle-label,.mat-slide-toggle.mat-disabled .mat-slide-toggle-thumb-container{cursor:default}.mat-slide-toggle-label{display:flex;flex:1;flex-direction:row;align-items:center;height:inherit;cursor:pointer}.mat-slide-toggle-content{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.mat-slide-toggle-label-before .mat-slide-toggle-label{order:1}.mat-slide-toggle-label-before .mat-slide-toggle-bar{order:2}.mat-slide-toggle-bar,[dir=rtl] .mat-slide-toggle-label-before .mat-slide-toggle-bar{margin-right:8px;margin-left:0}.mat-slide-toggle-label-before .mat-slide-toggle-bar,[dir=rtl] .mat-slide-toggle-bar{margin-left:8px;margin-right:0}.mat-slide-toggle-bar-no-side-margin{margin-left:0;margin-right:0}.mat-slide-toggle-thumb-container{position:absolute;z-index:1;width:20px;height:20px;top:-3px;left:0;transform:translate3d(0,0,0);transition:all 80ms linear;transition-property:transform;cursor:-webkit-grab;cursor:grab}.mat-slide-toggle-thumb-container.mat-dragging,.mat-slide-toggle-thumb-container:active{cursor:-webkit-grabbing;cursor:grabbing;transition-duration:0s}.mat-slide-toggle-thumb{height:20px;width:20px;border-radius:50%;box-shadow:0 2px 1px -1px rgba(0,0,0,.2),0 1px 1px 0 rgba(0,0,0,.14),0 1px 3px 0 rgba(0,0,0,.12)}@media screen and (-ms-high-contrast:active){.mat-slide-toggle-thumb{background:#fff;border:solid 1px #000}}.mat-slide-toggle-bar{position:relative;width:36px;height:14px;flex-shrink:0;border-radius:8px}@media screen and (-ms-high-contrast:active){.mat-slide-toggle-bar{background:#fff}}.mat-slide-toggle-input{bottom:0;left:10px}.mat-slide-toggle-bar,.mat-slide-toggle-thumb{transition:all 80ms linear;transition-property:background-color;transition-delay:50ms}.mat-slide-toggle-ripple{position:absolute;top:calc(50% - 23px);left:calc(50% - 23px);height:46px;width:46px;z-index:1;pointer-events:none}"],providers:[u],inputs:["disabled","disableRipple","color","tabIndex"],encapsulation:r.ViewEncapsulation.None,changeDetection:r.ChangeDetectionStrategy.OnPush}]}],a.ctorParameters=function(){return[{type:r.ElementRef},{type:n.Platform},{type:t.FocusMonitor},{type:r.ChangeDetectorRef},{type:void 0,decorators:[{type:r.Attribute,args:["tabindex"]}]},{type:r.NgZone}]},a.propDecorators={name:[{type:r.Input}],id:[{type:r.Input}],labelPosition:[{type:r.Input}],ariaLabel:[{type:r.Input,args:["aria-label"]}],ariaLabelledby:[{type:r.Input,args:["aria-labelledby"]}],required:[{type:r.Input}],checked:[{type:r.Input}],change:[{type:r.Output}],_inputElement:[{type:r.ViewChild,args:["input"]}],_ripple:[{type:r.ViewChild,args:[o.MatRipple]}]},a}(m),f=function(){function e(e,t){this.dragging=!1,t.isBrowser&&(this._thumbEl=e.nativeElement.querySelector(".mat-slide-toggle-thumb-container"),this._thumbBarEl=e.nativeElement.querySelector(".mat-slide-toggle-bar"))}return e.prototype.startThumbDrag=function(e){this.dragging||(this._thumbBarWidth=this._thumbBarEl.clientWidth-this._thumbEl.clientWidth,this._thumbEl.classList.add("mat-dragging"),this._previousChecked=e,this.dragging=!0)},e.prototype.stopThumbDrag=function(){return!!this.dragging&&(this.dragging=!1,this._thumbEl.classList.remove("mat-dragging"),this._thumbEl.style.transform="",this.dragPercentage>50)},e.prototype.updateThumbPosition=function(e){this.dragPercentage=this._getDragPercentage(e);var t=this.dragPercentage/100*this._thumbBarWidth;this._thumbEl.style.transform="translate3d("+t+"px, 0, 0)"},e.prototype._getDragPercentage=function(e){var t=e/this._thumbBarWidth*100;return this._previousChecked&&(t+=100),Math.max(0,Math.min(t,100))},e}(),_=function(){function e(){}return e.decorators=[{type:r.NgModule,args:[{imports:[o.MatRippleModule,o.MatCommonModule,l.ObserversModule],exports:[b,o.MatCommonModule],declarations:[b],providers:[{provide:s.HAMMER_GESTURE_CONFIG,useClass:o.GestureConfig}]}]}],e}();e.MatSlideToggleModule=_,e.MAT_SLIDE_TOGGLE_VALUE_ACCESSOR=u,e.MatSlideToggleChange=p,e.MatSlideToggleBase=h,e._MatSlideToggleMixinBase=m,e.MatSlideToggle=b,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=material-slide-toggle.umd.min.js.map