UNPKG

@angular-mdc/web

Version:
22 lines (20 loc) 7.03 kB
/** * @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/icon"),require("@angular/forms"),require("@angular/cdk/coercion"),require("rxjs/operators"),require("@material/ripple"),require("@angular-mdc/web/base"),require("@angular-mdc/web/ripple"),require("@material/icon-button")):"function"==typeof define&&define.amd?define("@angular-mdc/web/icon-button",["exports","@angular/core","@angular/common","@angular-mdc/web/icon","@angular/forms","@angular/cdk/coercion","rxjs/operators","@material/ripple","@angular-mdc/web/base","@angular-mdc/web/ripple","@material/icon-button"],t):t(((e=e||self).ng=e.ng||{},e.ng.web=e.ng.web||{},e.ng.web.iconButton={}),e.ng.core,e.ng.common,e.ng.web.icon,e.ng.forms,e.ng.cdk.coercion,e.rxjs.operators,e.mdc.ripple,e.ng.web.base,e.ng.web.ripple,e.mdc.iconButton)}(this,(function(e,t,n,o,r,i,c,u,a,s,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. ***************************************************************************** */var p=function(e,t){return(p=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 d=function(){return(d=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};function f(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var o=Array(e),r=0;for(t=0;t<n;t++)for(var i=arguments[t],c=0,u=i.length;c<u;c++,r++)o[r]=i[c];return o}var g={provide:r.NG_VALUE_ACCESSOR,useExisting:t.forwardRef((function(){return _})),multi:!0},h=function(e,t){this.source=e,this.value=t},m=0,b=function(){function e(){}return e.decorators=[{type:t.Directive,args:[{selector:"[mdcIconOn]",host:{class:"mdc-icon-button__icon--on"}}]}],e}(),_=function(e){function n(n,o,r){var i=e.call(this,o)||this;return i._changeDetectorRef=n,i.elementRef=o,i.ripple=r,i._uniqueId="mdc-icon-button-"+ ++m,i.id=i._uniqueId,i.name=null,i.icon=null,i._on=!1,i._disabled=!1,i.change=new t.EventEmitter,i._changeSubscription=null,i._onChange=function(){},i._onTouched=function(){},i._root=i.elementRef.nativeElement,i.ripple=i._createRipple(),i.ripple.init(),i}return function(e,t){function n(){this.constructor=e}p(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)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"on",{get:function(){return this._on},set:function(e){this.setOn(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"disabled",{get:function(){return this._disabled},set:function(e){this.setDisabled(e)},enumerable:!0,configurable:!0}),n.prototype.getDefaultFoundation=function(){var e=this,t={addClass:function(t){return e._getHostElement().classList.add(t)},removeClass:function(t){return e._getHostElement().classList.remove(t)},hasClass:function(t){return e._getHostElement().classList.contains(t)},setAttr:function(t,n){return e._getHostElement().setAttribute(t,n)},notifyChange:function(t){e.change.emit(new h(e,t.isOn)),e._onChange(e._foundation.isOn())}};return new l.MDCIconButtonToggleFoundation(t)},n.prototype.ngAfterContentInit=function(){var e=this;this._foundation.init(),this._foundation.toggle(this._on||this._foundation.isOn()),this._changeDetectorRef.detectChanges(),this._changeSubscription=this.icons.changes.pipe(c.startWith(null)).subscribe((function(){e.icons.forEach((function(e){e.elementRef.nativeElement.classList.add("mdc-icon-button__icon"),e.role=null}))}))},n.prototype.ngOnDestroy=function(){this._changeSubscription&&this._changeSubscription.unsubscribe(),this.ripple.destroy(),this._foundation.destroy()},n.prototype.writeValue=function(e){this._onChange(e)},n.prototype.registerOnChange=function(e){this._onChange=e},n.prototype.registerOnTouched=function(e){this._onTouched=e},n.prototype.toggle=function(e){this.on=e?i.coerceBooleanProperty(e):!this.on,this._foundation.toggle(this.on)},n.prototype.setOn=function(e){this._on=i.coerceBooleanProperty(e),this._foundation.toggle(this.on),this._changeDetectorRef.markForCheck()},n.prototype.setDisabled=function(e){this._disabled=i.coerceBooleanProperty(e),this.disabled?this._getHostElement().setAttribute("disabled",""):this._getHostElement().removeAttribute("disabled"),this._changeDetectorRef.markForCheck()},n.prototype.handleClick=function(){1!==this.icons.length&&(this.on=!this.on,this._foundation.handleClick())},n.prototype._createRipple=function(){var e=d(d({},s.MdcRipple.createAdapter(this)),{isUnbounded:function(){return!0}});return new s.MdcRipple(this.elementRef,new u.MDCRippleFoundation(e))},n.prototype._getHostElement=function(){return this.elementRef.nativeElement},n.decorators=[{type:t.Component,args:[{selector:"[mdc-icon-button], button[mdcIconButton], a[mdcIconButton]",exportAs:"mdcIconButton",host:{"[id]":"id",class:"mdc-icon-button","[class.mdc-icon-button--on]":"on","attr.aria-pressed":"false","(click)":"handleClick()"},template:'\n <mdc-icon *ngIf="icon">{{icon}}</mdc-icon>\n <ng-content></ng-content>',providers:[g,s.MdcRipple],changeDetection:t.ChangeDetectionStrategy.OnPush,encapsulation:t.ViewEncapsulation.None}]}],n.ctorParameters=function(){return[{type:t.ChangeDetectorRef},{type:t.ElementRef},{type:s.MdcRipple}]},n.propDecorators={id:[{type:t.Input}],name:[{type:t.Input}],icon:[{type:t.Input}],on:[{type:t.Input}],disabled:[{type:t.Input}],change:[{type:t.Output}],icons:[{type:t.ContentChildren,args:[o.MdcIcon,{descendants:!0}]}]},n}(a.MDCComponent),y=[_,b],C=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{imports:[n.CommonModule,o.MdcIconModule],exports:f(y,[o.MdcIconModule]),declarations:y}]}],e}();e.MDC_ICON_BUTTON_CONTROL_VALUE_ACCESSOR=g,e.MdcIconButton=_,e.MdcIconButtonChange=h,e.MdcIconButtonModule=C,e.MdcIconOn=b,Object.defineProperty(e,"__esModule",{value:!0})}));