import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, HostListener, Injector, NgZone, forwardRef, } from '@angular/core'; import { NG_VALUE_ACCESSOR } from '@angular/forms'; import { ValueAccessor } from '@ionic/angular/common'; import type { Components } from '@ionic/core/components'; import { defineCustomElement } from '@ionic/core/components/ion-radio.js'; import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils'; const RADIO_INPUTS = ['color', 'disabled', 'justify', 'labelPlacement', 'legacy', 'mode', 'name', 'value']; /** * Pulling the provider into an object and using PURE works * around an ng-packagr issue that causes * components with multiple decorators and * a provider to be re-assigned. This re-assignment * is not supported by Webpack and causes treeshaking * to not work on these kinds of components. */ const accessorProvider = { provide: NG_VALUE_ACCESSOR, useExisting: /*@__PURE__*/ forwardRef(() => IonRadio), multi: true, }; @ProxyCmp({ defineCustomElementFn: defineCustomElement, inputs: RADIO_INPUTS, }) @Component({ selector: 'ion-radio', changeDetection: ChangeDetectionStrategy.OnPush, template: '', // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property inputs: RADIO_INPUTS, providers: [accessorProvider], standalone: true, }) export class IonRadio extends ValueAccessor { protected el: HTMLElement; constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone, injector: Injector) { super(injector, r); c.detach(); this.el = r.nativeElement; proxyOutputs(this, this.el, ['ionFocus', 'ionBlur']); } @HostListener('ionSelect', ['$event.target']) handleIonSelect(el: any): void { /** * The `el` type is any to access the `checked` state property * that is not exposed on the type interface. */ this.handleValueChange(el, el.checked); } } export declare interface IonRadio extends Components.IonRadio { /** * Emitted when the radio button has focus. */ ionFocus: EventEmitter>; /** * Emitted when the radio button loses focus. */ ionBlur: EventEmitter>; }