@angular-mdc/web
Version:
22 lines (20 loc) • 8.71 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/cdk/coercion"),require("rxjs"),require("rxjs/operators"),require("@angular-mdc/web/base"),require("@material/textfield")):"function"==typeof define&&define.amd?define("@angular-mdc/web/form-field",["exports","@angular/core","@angular/common","@angular/cdk/coercion","rxjs","rxjs/operators","@angular-mdc/web/base","@material/textfield"],t):t(((e=e||self).ng=e.ng||{},e.ng.web=e.ng.web||{},e.ng.web.formField={}),e.ng.core,e.ng.common,e.ng.cdk.coercion,e.rxjs,e.rxjs.operators,e.ng.web.base,e.mdc.textfield)}(this,(function(e,t,n,r,o,i,a,s){"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 c=function(e,t){return(c=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)};function l(e,t){function n(){this.constructor=e}c(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var u=function(){this.value=null},p=function(e){function n(t){var n=e.call(this,t)||this;return n.elementRef=t,n}return l(n,e),Object.defineProperty(n.prototype,"foundation",{get:function(){return this._foundation},enumerable:!0,configurable:!0}),n.prototype.getDefaultFoundation=function(){var e=this,t={setContent:function(t){return e.elementRef.nativeElement.textContent=t}};return new s.MDCTextFieldCharacterCounterFoundation(t)},n.prototype.ngOnDestroy=function(){this.destroy()},n.decorators=[{type:t.Component,args:[{selector:"[mdcCharacterCounter]",exportAs:"mdcCharacterCounter",host:{class:"mdc-text-field-character-counter"},template:"<ng-content></ng-content>"}]}],n.ctorParameters=function(){return[{type:t.ElementRef}]},n}(a.MDCComponent),d=function(){function e(e){this.elementRef=e,this.characterCounter=!1,this._persistent=!1,this._validation=!1}return Object.defineProperty(e.prototype,"persistent",{get:function(){return this._persistent},set:function(e){this._persistent=r.coerceBooleanProperty(e),this._foundation&&this._foundation.setPersistent(this._persistent)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"validation",{get:function(){return this._validation},set:function(e){this._validation=r.coerceBooleanProperty(e),this._foundation&&this._foundation.setValidation(this._validation)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"foundation",{get:function(){return this._foundation},enumerable:!0,configurable:!0}),e.prototype.setValidity=function(e){this._foundation.setValidity(e)},e.prototype.showToScreenReader=function(){this._foundation.showToScreenReader()},e.prototype.init=function(e){this._foundation=new e(this._createAdapter()),this._foundation.setPersistent(this.persistent),this._foundation.setValidation(this.validation)},e.prototype.addHelperTextClass=function(e){this._helperTextElement.nativeElement.classList.add(e+"-helper-text")},e.prototype._createAdapter=function(){var e=this;return{addClass:function(t){return e._helperTextElement.nativeElement.classList.add(t)},removeClass:function(t){return e._helperTextElement.nativeElement.classList.remove(t)},hasClass:function(t){return e._helperTextElement.nativeElement.classList.contains(t)},setAttr:function(t,n){return e._helperTextElement.nativeElement.setAttribute(t,n)},removeAttr:function(t){return e._helperTextElement.nativeElement.removeAttribute(t)}}},e.decorators=[{type:t.Component,args:[{selector:"mdc-helper-text, [mdcHelperText], mdc-text-field-helper-text, [mdcTextFieldHelperText]",exportAs:"mdcHelperText",host:{class:"mdc-text-field-helper-line"},template:'<div #helperText><ng-content></ng-content></div>\n <div mdcCharacterCounter *ngIf="characterCounter"></div>',changeDetection:t.ChangeDetectionStrategy.OnPush,encapsulation:t.ViewEncapsulation.None}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e.propDecorators={id:[{type:t.Input}],persistent:[{type:t.Input}],validation:[{type:t.Input}],_helperTextElement:[{type:t.ViewChild,args:["helperText",{static:!0}]}],_characterCounterElement:[{type:t.ViewChild,args:[p,{static:!1}]}]},e}(),f=function(){function e(e,t,n){this._changeDetectorRef=e,this._ngZone=t,this.elementRef=n,this._destroy=new o.Subject,this._fluid=!1,this._alignEnd=!1}return Object.defineProperty(e.prototype,"fluid",{get:function(){return this._fluid},set:function(e){this._fluid=r.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"alignEnd",{get:function(){return this._alignEnd},set:function(e){this._alignEnd=r.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),e.prototype.ngAfterContentInit=function(){var e,t,n=this;if(this._control){var r=this._control.elementRef.nativeElement;"LABEL"===(null===(t=null===(e=r)||void 0===e?void 0:e.nextElementSibling)||void 0===t?void 0:t.tagName)&&(this.label=r.nextElementSibling,this.label&&this._control.inputId&&(this.label.setAttribute("for",this._control.inputId),this._loadListeners()))}this.assistiveElements.changes.pipe(i.startWith(null),i.takeUntil(this._destroy)).subscribe((function(){n.assistiveElements.forEach((function(e){return n._initHelperTextFoundation(e)}))}))},e.prototype.ngOnDestroy=function(){this._destroy.next(),this._destroy.complete()},e.prototype._initHelperTextFoundation=function(e){var t,n=this._control;(null===(t=n)||void 0===t?void 0:t.controlType)&&(n.helperText=e,this._changeDetectorRef.markForCheck())},e.prototype._loadListeners=function(){var e=this;this._ngZone.runOutsideAngular((function(){return o.fromEvent(e.label,"click").pipe(i.takeUntil(e._destroy)).subscribe((function(){return e._ngZone.run((function(){e._control.ripple.activateRipple(),"undefined"!=typeof requestAnimationFrame&&requestAnimationFrame((function(){return e._control.ripple.deactivateRipple()}))}))}))}))},e.decorators=[{type:t.Component,args:[{selector:"mdc-form-field",exportAs:"mdcFormField",host:{"[class.ngx-mdc-form-field--fluid]":"fluid","[class.mdc-form-field--align-end]":"alignEnd"},template:'<ng-content></ng-content>\n <ng-content select="[mdcHelperText, mdc-helper-text]"></ng-content>',encapsulation:t.ViewEncapsulation.None,changeDetection:t.ChangeDetectionStrategy.OnPush}]}],e.ctorParameters=function(){return[{type:t.ChangeDetectorRef},{type:t.NgZone},{type:t.ElementRef}]},e.propDecorators={fluid:[{type:t.Input}],alignEnd:[{type:t.Input}],_control:[{type:t.ContentChild,args:[u,{static:!1}]}],assistiveElements:[{type:t.ContentChildren,args:[d,{descendants:!0}]}]},e}(),h=[p,f,d],m=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{imports:[n.CommonModule],exports:[h],declarations:[h]}]}],e}();var g=function(){function e(){}return e.prototype.isErrorState=function(e,t){return!!(e&&e.invalid&&(e.touched||t&&t.submitted))},e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ɵprov21=t["ɵɵdefineInjectable"]({factory:function(){return new e},token:e,providedIn:"root"}),e}();e.ErrorStateMatcher=g,e.MdcCharacterCounter=p,e.MdcFormField=f,e.MdcFormFieldControl=u,e.MdcFormFieldModule=m,e.MdcHelperText=d,e.mixinErrorState=function(e){return function(e){function t(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=e.apply(this,t)||this;return r.errorState=!1,r.required=!1,r}return l(t,e),t.prototype.updateErrorState=function(){var e=this.errorState,t=this._parentFormGroup||this._parentForm,n=this.errorStateMatcher||this._defaultErrorStateMatcher,r=this.ngControl?this.ngControl.control:null,o=n.isErrorState(r,t);o!==e&&(this.errorState=o),r&&!this.required&&(this.required=r.hasError("required"))},t}(e)},Object.defineProperty(e,"__esModule",{value:!0})}));