12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- import { ChangeDetectionStrategy, Component, ContentChildren, EventEmitter, Input, Optional, Output, forwardRef, } from '@angular/core';
- import { FormGenericComponent } from '../../services/form-generic.abstract';
- import { provideControlContainer, provideValueAccessor } from '../utils/form.util';
- import { RadioButtonComponent } from '../radio-button/radio-button.component';
- import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
- import { LabelComponent } from '../label/label.component';
- import { FormErrorComponent } from '../error/error.component';
- import * as i0 from "@angular/core";
- import * as i1 from "@angular/forms";
- export class RadioGroupComponent extends FormGenericComponent {
- constructor(destroyRef, formGroupDirective) {
- super(formGroupDirective);
- this.destroyRef = destroyRef;
- this.formGroupDirective = formGroupDirective;
- this.formControlName = '';
- this.key = '';
- this.label = '';
- this.value = '';
- this.helper = '';
- this.showError = false;
- this.selected = new EventEmitter();
- }
- ngAfterContentInit() {
- if (this.value)
- this.writeValue(this.value);
- this.radios.forEach(radio => radio.valueChange.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(value => this.setValue(value)));
- }
- writeValue(value) {
- this.value = value;
- if (this.radios)
- this.updateRadios(value);
- }
- setValue(value) {
- this.value = value;
- this.updateRadios(value);
- this.triggerChange(value);
- this.selected.emit(value);
- }
- updateRadios(value) {
- this.radios.forEach(radio => {
- radio.writeValue(radio.value === value);
- });
- }
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.5", ngImport: i0, type: RadioGroupComponent, deps: [{ token: i0.DestroyRef }, { token: i1.FormGroupDirective, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "17.3.5", type: RadioGroupComponent, isStandalone: true, selector: "ct-radio-group", inputs: { formControlName: "formControlName", key: "key", label: "label", value: "value", helper: "helper", showError: "showError" }, outputs: { selected: "selected" }, providers: [provideValueAccessor(forwardRef(() => RadioGroupComponent))], queries: [{ propertyName: "radios", predicate: RadioButtonComponent }], usesInheritance: true, ngImport: i0, template: "<div class=\"flex w-full flex-col gap-4\">\n @if (label) {\n <ct-form-label [text]=\"label\" [hasError]=\"hasErrors(formControl)\" [showError]=\"showError\" />\n }\n <div class=\"flex w-full flex-col justify-between gap-4 md:flex-row\">\n <ng-content select=\"ct-radio-button\" />\n </div>\n @if (formControl) {\n <ct-form-alert\n [hasErrors]=\"hasErrors(formControl)\"\n [helper]=\"helper\"\n [errors]=\"formControl.errors ?? {}\"\n size=\"xs\" />\n }\n</div>\n", dependencies: [{ kind: "component", type: LabelComponent, selector: "ct-form-label", inputs: ["text", "type", "formControlName", "hasError", "showError"] }, { kind: "component", type: FormErrorComponent, selector: "ct-form-alert", inputs: ["errors", "size", "hasErrors", "fullSize", "helper", "errorMessages"] }], viewProviders: [provideControlContainer()], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
- }
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.5", ngImport: i0, type: RadioGroupComponent, decorators: [{
- type: Component,
- args: [{ selector: 'ct-radio-group', standalone: true, imports: [LabelComponent, FormErrorComponent], providers: [provideValueAccessor(forwardRef(() => RadioGroupComponent))], viewProviders: [provideControlContainer()], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"flex w-full flex-col gap-4\">\n @if (label) {\n <ct-form-label [text]=\"label\" [hasError]=\"hasErrors(formControl)\" [showError]=\"showError\" />\n }\n <div class=\"flex w-full flex-col justify-between gap-4 md:flex-row\">\n <ng-content select=\"ct-radio-button\" />\n </div>\n @if (formControl) {\n <ct-form-alert\n [hasErrors]=\"hasErrors(formControl)\"\n [helper]=\"helper\"\n [errors]=\"formControl.errors ?? {}\"\n size=\"xs\" />\n }\n</div>\n" }]
- }], ctorParameters: () => [{ type: i0.DestroyRef }, { type: i1.FormGroupDirective, decorators: [{
- type: Optional
- }] }], propDecorators: { formControlName: [{
- type: Input
- }], key: [{
- type: Input
- }], label: [{
- type: Input
- }], value: [{
- type: Input
- }], helper: [{
- type: Input
- }], showError: [{
- type: Input
- }], selected: [{
- type: Output
- }], radios: [{
- type: ContentChildren,
- args: [RadioButtonComponent]
- }] } });
|