From da693d1f1a218c2fbc190e1f6a259d691f1816d3 Mon Sep 17 00:00:00 2001 From: heinerwalter Date: Tue, 29 Oct 2024 16:43:36 +0100 Subject: [PATCH] Update boolean-input.component.ts --- .../boolean-input/boolean-input.component.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/projects/ngx-property-editor/src/lib/components/input/boolean-input/boolean-input.component.ts b/projects/ngx-property-editor/src/lib/components/input/boolean-input/boolean-input.component.ts index 4743391..d20e158 100644 --- a/projects/ngx-property-editor/src/lib/components/input/boolean-input/boolean-input.component.ts +++ b/projects/ngx-property-editor/src/lib/components/input/boolean-input/boolean-input.component.ts @@ -1,6 +1,9 @@ import { Component, Input } from '@angular/core'; import { InputBaseWithValue } from '../input-base'; +type RadioInputDataSourceOption = { value: boolean | undefined, name: string }; + + @Component({ selector: 'pe-boolean-input', templateUrl: './boolean-input.component.html', @@ -22,6 +25,37 @@ export class BooleanInputComponent extends InputBaseWithValue { */ @Input() public allowIndeterminate: boolean = false; + // region Radio Input + + /** + * Only if `type == 'radio'`: + * Optional yes label used by the radio input. If undefined, the default label is used instead. + */ + @Input() public yesLabel: string | undefined = undefined; + /** + * Only if `type == 'radio'`: + * Optional no label used by the radio input. If undefined, the default label is used instead. + */ + @Input() public noLabel: string | undefined = undefined; + /** + * Only if `type == 'radio'`: + * Optional indeterminate label used by the radio input. If undefined, the default label is used instead. + */ + @Input() public indeterminateLabel: string | undefined = undefined; + + /** Returns a data source for the radio input component based on the input properties of this component. */ + protected get radioInputDataSource(): RadioInputDataSourceOption[] { + const yesOption: RadioInputDataSourceOption = { value: true, name: this.yesLabel || 'Ja' }; + const noOption: RadioInputDataSourceOption = { value: false, name: this.noLabel || 'Nein' }; + if (!allowIndeterminate) + return [yesOption, noOption]; + + const indeterminateOption: RadioInputDataSourceOption = { value: undefined, name: this.indeterminateLabel || 'Keine Angabe' }; + return [yesOption, noOption, indeterminateOption]; + } + + // endregion + public constructor() { super(); }