From 3e681a65ef3ed494864b38c3f63b2cb1aecf028a Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Sharma Date: Wed, 8 Sep 2021 11:42:55 +0530 Subject: [PATCH 1/2] feat: template functionality for radio button label --- .../components/src/radio/radio-group.component.ts | 14 ++++++++++++-- projects/components/src/radio/radio-option.ts | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/projects/components/src/radio/radio-group.component.ts b/projects/components/src/radio/radio-group.component.ts index a2d2488b0..903d43253 100644 --- a/projects/components/src/radio/radio-group.component.ts +++ b/projects/components/src/radio/radio-group.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; +import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output, TemplateRef } from '@angular/core'; import { MatRadioChange } from '@angular/material/radio'; import { LoggerService } from '@hypertrace/common'; import { RadioOption } from './radio-option'; @@ -22,10 +22,16 @@ import { RadioOption } from './radio-option'; [ngClass]="[this.optionsDirection, this.disabled ? 'disabled' : '']" [value]="option.value" > - + {{ option.description }} + ` }) export class RadioGroupComponent implements OnInit { @@ -67,6 +73,10 @@ export class RadioGroupComponent implements OnInit { this.selected = this.options.find(option => option.value === event.value); this.selectedChange.emit(event.value); } + + public isLabelAsString(label: string | TemplateRef): boolean { + return typeof label === 'string'; + } } export const enum OptionsDirection { diff --git a/projects/components/src/radio/radio-option.ts b/projects/components/src/radio/radio-option.ts index d7c3b10cb..e38c28f03 100644 --- a/projects/components/src/radio/radio-option.ts +++ b/projects/components/src/radio/radio-option.ts @@ -1,5 +1,7 @@ +import { TemplateRef } from '@angular/core'; + export interface RadioOption { value: string; - label: string; + label: string | TemplateRef; description?: string; } From 8bb4a84cbf5cb7a76f65cbe57d4b0d0302a18587 Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Sharma Date: Wed, 8 Sep 2021 12:23:12 +0530 Subject: [PATCH 2/2] fix: addressing review comments --- projects/components/src/radio/radio-group.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/components/src/radio/radio-group.component.ts b/projects/components/src/radio/radio-group.component.ts index 903d43253..ee8c07f0c 100644 --- a/projects/components/src/radio/radio-group.component.ts +++ b/projects/components/src/radio/radio-group.component.ts @@ -24,7 +24,7 @@ import { RadioOption } from './radio-option'; > @@ -74,7 +74,7 @@ export class RadioGroupComponent implements OnInit { this.selectedChange.emit(event.value); } - public isLabelAsString(label: string | TemplateRef): boolean { + public isLabelAString(label: string | TemplateRef): boolean { return typeof label === 'string'; } }