@angular-mdc/web
Version:
22 lines (20 loc) • 12.1 kB
JavaScript
/**
* @license
* Copyright (c) Dominic Carretto
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/trimox/angular-mdc-web/blob/master/LICENSE
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common"),require("@angular-mdc/web/form-field"),require("@angular/forms"),require("@angular/cdk/coercion"),require("@angular/cdk/platform"),require("rxjs"),require("rxjs/operators"),require("@angular-mdc/web/dom"),require("@material/ripple"),require("@material/checkbox"),require("@angular-mdc/web/base"),require("@angular-mdc/web/ripple")):"function"==typeof define&&define.amd?define("@angular-mdc/web/checkbox",["exports","@angular/core","@angular/common","@angular-mdc/web/form-field","@angular/forms","@angular/cdk/coercion","@angular/cdk/platform","rxjs","rxjs/operators","@angular-mdc/web/dom","@material/ripple","@material/checkbox","@angular-mdc/web/base","@angular-mdc/web/ripple"],t):t(((e=e||self).ng=e.ng||{},e.ng.web=e.ng.web||{},e.ng.web.checkbox={}),e.ng.core,e.ng.common,e.ng.web.formField,e.ng.forms,e.ng.cdk.coercion,e.ng.cdk.platform,e.rxjs,e.rxjs.operators,e.ng.web.dom,e.mdc.ripple,e.mdc.checkbox,e.ng.web.base,e.ng.web.ripple)}(this,(function(e,t,n,r,i,o,a,c,u,s,l,d,p,h){"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.
***************************************************************************** */var f=function(e,t){return(f=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};var m=function(){return(m=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function b(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function c(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}))}function _(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(o){return function(c){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=(i=a.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,c])}}}var g=0,y=function(e,t){this.source=e,this.checked=t},v={provide:i.NG_VALUE_ACCESSOR,useExisting:t.forwardRef((function(){return k})),multi:!0},k=function(e){function n(n,r,i,o,a,u){var s=e.call(this,o)||this;return s._platform=n,s._ngZone=r,s._changeDetectorRef=i,s.elementRef=o,s.ripple=a,s._parentFormField=u,s._destroy=new c.Subject,s._initialized=!1,s._uniqueId="mdc-checkbox-"+ ++g,s.id=s._uniqueId,s.name=null,s._checked=!1,s._touch=!1,s._disabled=!1,s.value=null,s._indeterminate=!1,s._indeterminateToChecked=!0,s._disableRipple=!1,s.tabIndex=0,s.ariaLabel="",s.ariaLabelledby=null,s.change=new t.EventEmitter,s.indeterminateChange=new t.EventEmitter,s._onChange=function(){},s._onTouched=function(){},s._root=s.elementRef.nativeElement,s._parentFormField&&u.elementRef.nativeElement.classList.add("mdc-form-field"),s}return function(e,t){function n(){this.constructor=e}f(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(n,e),Object.defineProperty(n.prototype,"inputId",{get:function(){return(this.id||this._uniqueId)+"-input"},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"checked",{get:function(){return this._checked},set:function(e){e!==this.checked&&(this._checked=o.coerceBooleanProperty(e),this._changeDetectorRef.markForCheck())},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"touch",{get:function(){return this._touch},set:function(e){this._touch=o.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"disabled",{get:function(){return this._disabled},set:function(e){this.setDisabledState(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"indeterminate",{get:function(){return this._indeterminate},set:function(e){var t;if(!this.disabled){var n=o.coerceBooleanProperty(e);n!==this._indeterminate&&(this._indeterminate=n,n&&(this.checked=!1),this.indeterminateChange.emit({source:this,indeterminate:this._indeterminate}),this._changeDetectorRef.markForCheck(),null===(t=this._foundation)||void 0===t||t.handleChange())}},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"indeterminateToChecked",{get:function(){return this._indeterminateToChecked},set:function(e){this._indeterminateToChecked=o.coerceBooleanProperty(e),this._changeDetectorRef.markForCheck()},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"disableRipple",{get:function(){return this._disableRipple},set:function(e){this._disableRipple=o.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),n.prototype.getDefaultFoundation=function(){var e=this;if(this._initialized){var t={addClass:function(t){return e._root.classList.add(t)},removeClass:function(t){return e._root.classList.remove(t)},setNativeControlAttr:function(t,n){return e._inputElement.nativeElement.setAttribute(t,n)},removeNativeControlAttr:function(t){return e._inputElement.nativeElement.removeAttribute(t)},isIndeterminate:function(){return e.indeterminate},isChecked:function(){return e.checked},hasNativeControl:function(){return!0},setNativeControlDisabled:function(t){return e._inputElement.nativeElement.disabled=t},forceLayout:function(){return e._root.offsetWidth},isAttachedToDOM:function(){return!0}};return new d.MDCCheckboxFoundation(t)}},n.prototype._asyncBuildFoundation=function(){return b(this,void 0,void 0,(function(){return _(this,(function(e){return this._foundation=this.getDefaultFoundation(),[2]}))}))},n.prototype.ngAfterViewInit=function(){var e=this;this._initialized=!0,this._asyncBuildFoundation().then((function(){e._foundation.init(),e.setDisabledState(e._inputElement.nativeElement.disabled),e.ripple=e._createRipple(),e.ripple.init()})),this._loadListeners()},n.prototype.ngOnDestroy=function(){this._destroy.next(),this._destroy.complete(),this.ripple.destroy(),this._foundation.destroy()},n.prototype.writeValue=function(e){this.checked=!!e},n.prototype.registerOnChange=function(e){this._onChange=e},n.prototype.registerOnTouched=function(e){this._onTouched=e},n.prototype.focus=function(){this.disabled||this._inputElement.nativeElement.focus()},n.prototype.toggle=function(e){this._setState(e)},n.prototype._onInteraction=function(e){e.stopPropagation(),this._setState(),this._onChange(this.checked),this._changeDetectorRef.markForCheck(),this.change.emit(new y(this,this.checked))},n.prototype._onInputClick=function(e){e.stopPropagation()},n.prototype.setDisabledState=function(e){var t,n=o.coerceBooleanProperty(e);n!==this._disabled&&(this._disabled=n,null===(t=this._foundation)||void 0===t||t.setDisabled(n),this._changeDetectorRef.markForCheck())},n.prototype._setState=function(e){var t=this;this.disabled||(this.indeterminate?(this._checked=this.indeterminateToChecked,this.indeterminate=!1):this.checked=e||!this.checked,this._inputElement.nativeElement.checked=this.checked,this._ngZone.runOutsideAngular((function(){return requestAnimationFrame((function(){return t._foundation.handleChange()}))})))},n.prototype._createRipple=function(){var e=this,t=m(m({},h.MdcRipple.createAdapter(this)),{isSurfaceActive:function(){return s.matches(e._inputElement.nativeElement,":active")},isUnbounded:function(){return!0},isSurfaceDisabled:function(){return e.disableRipple},deregisterInteractionHandler:function(t,n){return e._inputElement.nativeElement.removeEventListener(t,n,a.supportsPassiveEventListeners())},registerInteractionHandler:function(t,n){return e._inputElement.nativeElement.addEventListener(t,n,a.supportsPassiveEventListeners())}});return new h.MdcRipple(this.elementRef,new l.MDCRippleFoundation(t))},n.prototype._loadListeners=function(){var e=this;this._platform.isBrowser&&this._ngZone.runOutsideAngular((function(){return c.fromEvent(e._root,"animationend").pipe(u.takeUntil(e._destroy),u.filter((function(t){return t.target===e._root}))).subscribe((function(){return e._ngZone.run((function(){return e._foundation.handleAnimationEnd()}))}))}))},n.decorators=[{type:t.Component,args:[{selector:"mdc-checkbox",exportAs:"mdcCheckbox",host:{"[id]":"id",class:"mdc-checkbox","[class.mdc-checkbox--touch]":"touch"},template:'\n <input type="checkbox"\n #input\n class="mdc-checkbox__native-control"\n [id]="inputId"\n [attr.name]="name"\n [tabIndex]="tabIndex"\n [attr.aria-label]="ariaLabel || null"\n [attr.aria-labelledby]="ariaLabelledby"\n [disabled]="disabled"\n [checked]="checked"\n [attr.value]="value"\n [indeterminate]="indeterminate"\n (change)="_onInteraction($event)"\n (click)="_onInputClick($event)"/>\n <div class="mdc-checkbox__background">\n <svg\n class="mdc-checkbox__checkmark"\n viewBox="0 0 24 24"\n focusable="false">\n <path class="mdc-checkbox__checkmark-path"\n fill="none"\n d="M1.73,12.91 8.1,19.28 22.79,4.59"/>\n </svg>\n <div class="mdc-checkbox__mixedmark"></div>\n </div>\n <div *ngIf="!disableRipple && !disabled" class="mdc-checkbox__ripple"></div>\n ',providers:[v,h.MdcRipple,{provide:r.MdcFormFieldControl,useExisting:n}],encapsulation:t.ViewEncapsulation.None,changeDetection:t.ChangeDetectionStrategy.OnPush}]}],n.ctorParameters=function(){return[{type:a.Platform},{type:t.NgZone},{type:t.ChangeDetectorRef},{type:t.ElementRef},{type:h.MdcRipple},{type:r.MdcFormField,decorators:[{type:t.Optional}]}]},n.propDecorators={id:[{type:t.Input}],name:[{type:t.Input}],checked:[{type:t.Input}],touch:[{type:t.Input}],disabled:[{type:t.Input}],value:[{type:t.Input}],indeterminate:[{type:t.Input}],indeterminateToChecked:[{type:t.Input}],disableRipple:[{type:t.Input}],tabIndex:[{type:t.Input}],ariaLabel:[{type:t.Input,args:["aria-label"]}],ariaLabelledby:[{type:t.Input,args:["aria-labelledby"]}],change:[{type:t.Output}],indeterminateChange:[{type:t.Output}],_inputElement:[{type:t.ViewChild,args:["input",{static:!0}]}]},n}(p.MDCComponent),C=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{imports:[n.CommonModule,r.MdcFormFieldModule],exports:[r.MdcFormFieldModule,k],declarations:[k]}]}],e}();e.MDC_CHECKBOX_CONTROL_VALUE_ACCESSOR=v,e.MdcCheckbox=k,e.MdcCheckboxChange=y,e.MdcCheckboxModule=C,Object.defineProperty(e,"__esModule",{value:!0})}));