{"version":3,"sources":["../../src/app/components/radiobutton/radiobutton.ts"],"names":["RADIO_VALUE_ACCESSOR","provide","NG_VALUE_ACCESSOR","useExisting","forwardRef","RadioButton","multi","RadioControlRegistry","this","accessors","prototype","add","control","accessor","push","remove","filter","c","select","_this","forEach","isSameGroup","writeValue","value","controlPair","root","name","Injectable","args","providedIn","cd","injector","registry","onClick","EventEmitter","onFocus","onBlur","onModelChange","onModelTouched","ngOnInit","formControlName","get","NgControl","checkName","handleClick","event","radioButton","focus","preventDefault","disabled","inputViewChild","nativeElement","checked","emit","markForCheck","registerOnChange","fn","registerOnTouched","setDisabledState","val","onInputFocus","focused","onInputBlur","onChange","ngOnDestroy","throwNameError","Error","Component","selector","template","providers","changeDetection","ChangeDetectionStrategy","OnPush","ChangeDetectorRef","Injector","Input","Output","ViewChild","NgModule","imports","CommonModule","exports","declarations"],"mappings":"udAIaA,EAA4B,CACrCC,QAASC,EAAAA,kBACTC,YAAaC,EAAAA,YAAW,WAAM,OAAAC,KAC9BC,OAAO,gBAGX,SAAAC,IAIYC,KAAAC,UAAmB,UAE3BF,EAAAG,UAAAC,IAAA,SAAIC,EAAoBC,GACpBL,KAAKC,UAAUK,KAAK,CAACF,EAASC,KAGlCN,EAAAG,UAAAK,OAAA,SAAOF,GACHL,KAAKC,UAAYD,KAAKC,UAAUO,QAAO,SAACC,GACpC,OAAOA,EAAE,KAAOJ,MAIxBN,EAAAG,UAAAQ,OAAA,SAAOL,GAAP,IAAAM,EAAAX,KACIA,KAAKC,UAAUW,SAAQ,SAACH,GAChBE,EAAKE,YAAYJ,EAAGJ,IAAaI,EAAE,KAAOJ,GAC1CI,EAAE,GAAGK,WAAWT,EAASU,WAK7BhB,EAAAG,UAAAW,YAAA,SAAYG,EAAuCX,GACvD,QAAKW,EAAY,GAAGZ,UAIbY,EAAY,GAAGZ,QAAQa,OAASZ,EAASD,QAAQA,QAAQa,MAAQD,EAAY,GAAGE,OAASb,EAASa,2HA7BhHC,EAAAA,WAAUC,KA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itter,forwardRef,ViewChild,ChangeDetectorRef,ChangeDetectionStrategy, Injectable, Injector, OnInit, OnDestroy} from '@angular/core';\nimport {CommonModule} from '@angular/common';\nimport {NG_VALUE_ACCESSOR, ControlValueAccessor, NgControl} from '@angular/forms';\n\nexport const RADIO_VALUE_ACCESSOR: any = {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => RadioButton),\n multi: true\n};\n\n@Injectable({\n providedIn: 'root',\n})\nexport class RadioControlRegistry {\n private accessors: any[] = [];\n\n add(control: NgControl, accessor: RadioButton) {\n this.accessors.push([control, accessor]);\n }\n\n remove(accessor: RadioButton) {\n this.accessors = this.accessors.filter((c) => {\n return c[1] !== accessor;\n })\n }\n\n select(accessor: RadioButton) {\n this.accessors.forEach((c) => {\n if (this.isSameGroup(c, accessor) && c[1] !== accessor) {\n c[1].writeValue(accessor.value);\n }\n });\n }\n\n private isSameGroup(controlPair: [NgControl, RadioButton], accessor: RadioButton): boolean {\n if (!controlPair[0].control) {\n return false;\n }\n\n return controlPair[0].control.root === accessor.control.control.root && controlPair[1].name === accessor.name;\n }\n}\n\n@Component({\n selector: 'p-radioButton',\n template: `\n
\n
\n \n
\n
\n \n
\n
\n \n `,\n providers: [RADIO_VALUE_ACCESSOR],\n changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class RadioButton implements ControlValueAccessor, OnInit, OnDestroy {\n\n @Input() value: any;\n\n @Input() formControlName: string;\n\n @Input() name: string;\n\n @Input() disabled: boolean;\n\n @Input() label: string;\n\n @Input() tabindex: number;\n\n @Input() inputId: string;\n\n @Input() ariaLabelledBy: string;\n\n @Input() style: any;\n\n @Input() styleClass: string;\n\n @Input() labelStyleClass: string;\n\n @Output() onClick: EventEmitter = new EventEmitter();\n\n @Output() onFocus: EventEmitter = new EventEmitter();\n\n @Output() onBlur: EventEmitter = new EventEmitter();\n\n @ViewChild('rb') inputViewChild: ElementRef;\n\n public onModelChange: Function = () => {};\n\n public onModelTouched: Function = () => {};\n\n public checked: boolean;\n\n public focused: boolean;\n\n control: NgControl;\n\n constructor(public cd: ChangeDetectorRef, private injector: Injector, private registry: RadioControlRegistry) {}\n\n ngOnInit() {\n if (this.formControlName) {\n this.control = this.injector.get(NgControl);\n this.checkName();\n this.registry.add(this.control, this);\n }\n }\n \n handleClick(event, radioButton, focus) {\n event.preventDefault();\n\n if (this.disabled) {\n return;\n }\n\n this.select(event);\n\n if (focus) {\n radioButton.focus();\n }\n }\n \n select(event) {\n if (!this.disabled) {\n this.inputViewChild.nativeElement.checked = true;\n this.checked = true;\n this.onModelChange(this.value);\n \n if (this.formControlName) {\n this.registry.select(this);\n }\n\n this.onClick.emit(event);\n }\n }\n\n writeValue(value: any) : void {\n this.checked = (value == this.value);\n\n if (this.inputViewChild && this.inputViewChild.nativeElement) {\n this.inputViewChild.nativeElement.checked = this.checked;\n }\n\n this.cd.markForCheck();\n }\n\n registerOnChange(fn: Function): void {\n this.onModelChange = fn;\n }\n\n registerOnTouched(fn: Function): void {\n this.onModelTouched = fn;\n }\n\n setDisabledState(val: boolean): void {\n this.disabled = val;\n this.cd.markForCheck();\n }\n\n onInputFocus(event) {\n this.focused = true;\n this.onFocus.emit(event);\n }\n\n onInputBlur(event) {\n this.focused = false;\n this.onModelTouched();\n this.onBlur.emit(event);\n }\n\n onChange(event) {\n this.select(event);\n }\n\n focus() {\n this.inputViewChild.nativeElement.focus();\n }\n\n ngOnDestroy() {\n if (this.formControlName) {\n this.registry.remove(this);\n }\n }\n\n private checkName() {\n if (this.name && this.formControlName && this.name !== this.formControlName) {\n this.throwNameError();\n }\n if (!this.name && this.formControlName) {\n this.name = this.formControlName;\n }\n }\n\n private throwNameError() {\n throw new Error(`\n If you define both a name and a formControlName attribute on your radio button, their values\n must match. Ex: \n `);\n }\n}\n\n@NgModule({\n imports: [CommonModule],\n exports: [RadioButton],\n declarations: [RadioButton]\n})\nexport class RadioButtonModule { }"]}