{"version":3,"file":"primeng-radiobutton.umd.js","sources":["../../src/app/components/radiobutton/radiobutton.ts","../../src/app/components/radiobutton/primeng-radiobutton.ts"],"sourcesContent":["import {NgModule,Component,Input,Output,ElementRef,EventEmitter,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 { }","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":["NG_VALUE_ACCESSOR","forwardRef","Injectable","EventEmitter","NgControl","Component","ChangeDetectionStrategy","ChangeDetectorRef","Injector","Input","Output","ViewChild","NgModule","CommonModule"],"mappings":";;;;;;QAIa,oBAAoB,GAAQ;QACrC,OAAO,EAAEA,uBAAiB;QAC1B,WAAW,EAAEC,aAAU,CAAC,cAAM,OAAA,WAAW,GAAA,CAAC;QAC1C,KAAK,EAAE,IAAI;MACb;;QAEF;YAIY,cAAS,GAAU,EAAE,CAAC;SA2BjC;QAzBG,kCAAG,GAAH,UAAI,OAAkB,EAAE,QAAqB;YACzC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;SAC5C;QAED,qCAAM,GAAN,UAAO,QAAqB;YACxB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAC,CAAC;gBACrC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC;aAC5B,CAAC,CAAA;SACL;QAED,qCAAM,GAAN,UAAO,QAAqB;YAA5B,iBAMC;YALG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAC,CAAC;gBACrB,IAAI,KAAI,CAAC,WAAW,CAAC,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;oBACpD,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;iBACnC;aACJ,CAAC,CAAC;SACN;QAEO,0CAAW,GAAX,UAAY,WAAqC,EAAE,QAAqB;YAC5E,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE;gBACzB,OAAO,KAAK,CAAC;a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