UNPKG

@lidorsystems/integralui-web

Version:

IntegralUI Web - Advanced UI Components for Angular

15 lines (12 loc) 7.63 kB
/* filename: integralui.radiobutton.js version : 20.2.0 Copyright © 2016-2020 Lidor Systems. All rights reserved. This file is part of the "IntegralUI Web" Library. The contents of this file are subject to the IntegralUI Web License, and may not be used except in compliance with the License. A copy of the License should have been installed in the product's root installation directory or it can be found at http://www.lidorsystems.com/products/web/studio/license-agreement.aspx. This SOFTWARE is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Any infringement will be prosecuted under applicable laws. */ "use strict";var __extends=this&&this.__extends||function(){var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)if(t.hasOwnProperty(n))e[n]=t[n]})(t,n)};return function(t,n){e(t,n);function i(){this.constructor=t}t.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();Object.defineProperty(exports,"__esModule",{value:!0});var core_1=require("@angular/core"),animations_1=require("@angular/animations"),integralui_core_1=require("./integralui.core"),integralui_common_service_1=require("../services/integralui.common.service"),forms_1=require("@angular/forms"),i0=require("@angular/core"),i1=require("../services/integralui.common.service"),i2=require("@angular/common"),_c0=["*"],IntegralUIRadioButton=function(e){__extends(t,e);function t(t,n){var i=e.call(this,t,n)||this;i.elemRef=t;i.commonService=n;i.animationState="out";i.checkedValue=!1;i.buttonClass=[];i.checkedChanged=new core_1.EventEmitter;return i}Object.defineProperty(t.prototype,"checked",{get:function(){return this.checkedValue},set:function(e){if(this.checkedValue!=e)this.updateValue(e)},enumerable:!0,configurable:!0});t.prototype.ngOnInit=function(){this.generalClassName="iui-radio-button";this.buttonClassName=this.generalClassName+"-btn";this.contentClassName=this.generalClassName+"-content";this.initStyle()};t.prototype.initStyle=function(){this.defaultStyle={general:{disabled:this.generalClassName+"-disabled",focused:this.generalClassName+"-focused",normal:this.generalClassName,hovered:this.generalClassName+"-hovered",selected:this.generalClassName+"-selected"},button:{general:this.buttonClassName,disabled:this.buttonClassName+"-disabled",checked:this.buttonClassName+"-checked",unchecked:this.buttonClassName+"-unchecked"},content:{disabled:this.contentClassName+"-disabled",focused:this.contentClassName+"-focused",normal:this.contentClassName,hovered:this.contentClassName+"-hovered",selected:this.contentClassName+"-selected"}};this.updateStyle(this.controlStyle);this.updateControlClass();this.updateButtonClass();this.updateContentClass()};t.prototype.ngAfterViewInit=function(){};t.prototype.updateValue=function(e){var t=this;if(!e)t.animationState="out";t.checkedValue=e;var n=setTimeout(function(){if(e)t.animationState="in";t.checkedChanged.emit({checked:t.checkedValue,value:t.value});t.updateButtonClass();clearTimeout(n)},175)};t.prototype.checkMouseDown=function(e){if(this.isEnabled&&1==e.which)this.checked=void 0!=this.checked?!this.checked:!0};t.prototype.getControlStyle=function(){var e={};if(this.ctrlSize.width>0)e.width=this.ctrlSize.width+"px";if(this.ctrlSize.height>0)e.height=this.ctrlSize.height+"px";return e};t.prototype.updateButtonClass=function(){this.buttonClass.length=0;this.buttonClass.push(this.buttonClassName);if(this.options.currentStyle){this.buttonClass.push(this.options.currentStyle.button.general);this.buttonClass.push(this.checked?this.options.currentStyle.button.checked:this.options.currentStyle.button.unchecked);if(this.state&integralui_core_1.IntegralUIObjectState.disabled)this.buttonClass.push(this.options.currentStyle.button.disabled)}};t.prototype.getButtonClass=function(){return this.buttonClass};t.prototype.getButtonStyle=function(e){if(this.commonService.isString(e))return e;else if(e)return{general:this.commonService.isFieldAvailable(e.general,this.buttonClassName),disabled:this.commonService.isFieldAvailable(e.disabled,this.buttonClassName+"-disabled"),checked:this.commonService.isFieldAvailable(e.checked,this.buttonClassName+"-checked"),indeterminate:this.commonService.isFieldAvailable(e.indeterminate,this.buttonClassName+"-indeterminate"),unchecked:this.commonService.isFieldAvailable(e.unchecked,this.buttonClassName+"-unchecked")};else return{general:this.defaultStyle.button.general,disabled:this.defaultStyle.button.disabled,checked:this.defaultStyle.button.checked,unchecked:this.defaultStyle.button.unchecked}};t.prototype.updateStyle=function(e){if(e)this.options.currentStyle={general:this.getGeneralStyle(e.general),button:this.getButtonStyle(e.button),content:this.getContentStyle(e.button)};else this.options.currentStyle={general:{disabled:this.defaultStyle.general.disabled,focused:this.defaultStyle.general.focused,hovered:this.defaultStyle.general.hovered,normal:this.defaultStyle.general.normal,selected:this.defaultStyle.general.selected},button:{general:this.defaultStyle.button.general,disabled:this.defaultStyle.button.disabled,checked:this.defaultStyle.button.checked,unchecked:this.defaultStyle.button.unchecked},content:{disabled:this.defaultStyle.content.disabled,focused:this.defaultStyle.content.focused,hovered:this.defaultStyle.content.hovered,normal:this.defaultStyle.content.normal,selected:this.defaultStyle.content.selected}}};t.ɵfac=function(e){return new(e||t)(i0.ɵɵdirectiveInject(i0.ElementRef),i0.ɵɵdirectiveInject(i1.IntegralUICommonService))};t.ɵcmp=i0.ɵɵdefineComponent({type:t,selectors:[["iui-radio-button"]],inputs:{controlStyle:"controlStyle",data:"data",enabled:"enabled",name:"name",size:"size",state:"state",value:"value",checked:"checked"},outputs:{valueChanged:"valueChanged",checkedChanged:"checkedChanged"},features:[i0.ɵɵProvidersFeature([{provide:forms_1.NG_VALUE_ACCESSOR,useExisting:core_1.forwardRef(function(){return t}),multi:!0}]),i0.ɵɵInheritDefinitionFeature],ngContentSelectors:_c0,decls:5,vars:5,consts:[["draggable","true",3,"ngClass","ngStyle","dragstart","mousedown"],[3,"ngClass"]],template:function(e,t){if(1&e){i0.ɵɵprojectionDef();i0.ɵɵelementStart(0,"div",0);i0.ɵɵlistener("dragstart",function(e){return t.preventDragStart(e)})("mousedown",function(e){return t.checkMouseDown(e)});i0.ɵɵelementStart(1,"div",1);i0.ɵɵelement(2,"span");i0.ɵɵelementEnd();i0.ɵɵelementStart(3,"div",1);i0.ɵɵprojection(4);i0.ɵɵelementEnd();i0.ɵɵelementEnd()}if(2&e){i0.ɵɵproperty("ngClass",t.getControlClass())("ngStyle",t.getControlStyle());i0.ɵɵadvance(1);i0.ɵɵproperty("ngClass",t.getButtonClass());i0.ɵɵadvance(1);i0.ɵɵproperty("@ctrlAnimation",t.allowAnimation&&t.animationState);i0.ɵɵadvance(1);i0.ɵɵproperty("ngClass",t.getContentClass())}},directives:[i2.NgClass,i2.NgStyle],encapsulation:2,data:{animation:[animations_1.trigger("ctrlAnimation",[animations_1.state("out",animations_1.style({opacity:"0.5"})),animations_1.state("in",animations_1.style({opacity:"1"})),animations_1.transition("out => in",animations_1.animate("175ms ease-in")),animations_1.transition("in => out",animations_1.animate("175ms ease-out"))])]}});return t}(integralui_core_1.IntegralUIBaseValueComponent);exports.IntegralUIRadioButton=IntegralUIRadioButton;