import { Component, OnInit, Input, Output, EventEmitter, ElementRef, ContentChild, TemplateRef, HostBinding } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { CfSelectableComponent } from '../selectable/selectable.component'; import { SelectableModel } from '../../models/selectable/selectable.model'; import { RadioStylingModel } from '../../models/selectable/radio-styling.model'; import { RadioTemplates } from '../../templates/radio.template'; /** *

Radio is creating using SelectableModel Class/Component based on Angular Material Radio button and has abbility to customize md-radio-button's template.

. *

Example of using Radio:

*
 * <cf-radio [settings]="myFruits" (cfOnChange)="log($event)"></cf-radio>
 * 
*/ @Component({ selector: 'cf-radio', template: "
", styles: [":host { position: relative; z-index: 0; display: inline-flex; } :host.notification-clickable cf-notification:hover { cursor: pointer; } .cf-radio-group-container { display: inline-block; } md-radio-group { display: flex; flex-direction: column; } md-radio-group md-radio-button { align-items: center; padding: 2px 0px; } :host /deep/ .mat-radio-label { display: flex; align-items: center; } :host /deep/ .before .mat-radio-label { justify-content: flex-end; } :host /deep/ .mat-radio-container { top: 0px !important; } [hidden] { display: none !important; } "] }) export class CfRadioComponent extends CfSelectableComponent implements OnInit { @HostBinding('class') notifacationClickable = ''; /** * Component property for rendering template for each radio button if that template was defined in html. */ @ContentChild(TemplateRef) cfRadioTemplate; cfRadio: SelectableModel; /** *

The styling property of the radio.

*/ @Input() public styling: RadioStylingModel; constructor(public elementRef: ElementRef) { super(elementRef); } /** * It will be generated cfRadio object and rendered inside component template. Also cfCheckStates function will initialize checkboxes states. */ ngOnInit() { this.activeTemplate = RadioTemplates["defaultTemplate"]; if(this.compTemplate!=null && this.compTemplate!="") { if(RadioTemplates[this.compTemplate]!=null) { this.activeTemplate = RadioTemplates[this.compTemplate]; } else this.activeTemplate = this.compTemplate; } if(this.properties==null) { this.properties = new SelectableModel(this.activeTemplate["property"]); } else { var mainKeys = Object.keys(this.activeTemplate["property"]); for(let key of mainKeys) { if(this.properties[key]==null) this.properties[key]=this.activeTemplate["property"][key]; } } if(this.styling==null) this.styling = new RadioStylingModel (this.activeTemplate["style"]); if(this.disable!=null) this.properties.disable = this.disable; if(this.display!=null) this.properties.display = this.display; if(this.value!=null) this.properties.value = this.value; if(this.item!=null) this.properties.item = this.item; if(this.checked!=null) this.properties.checked = this.selected; if(this.itemPosition!=null) this.properties.itemPosition = this.itemPosition; this.cfRadio = this.properties; } ngOnChanges(changes: any){ if(this.properties!=null) { if(changes.disable!=null) this.properties.disable = changes.disable.currentValue; if(changes.display!=null) this.properties.display = changes.display.currentValue; if(changes.value!=null) this.properties.value = changes.value.currentValue; if(changes.item!=null) this.properties.item = changes.item.currentValue; if(changes.itemPosition!=null) this.properties.itemPosition = changes.itemPosition.currentValue; } } notifyGroup(){ this.selected = !this.selected; this.checked = this.selected; this.clicked.emit({"id":this.internalId, "value": this.selected}); } }