Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions projects/components/src/radio/radio-group.component.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -22,10 +22,16 @@ import { RadioOption } from './radio-option';
[ngClass]="[this.optionsDirection, this.disabled ? 'disabled' : '']"
[value]="option.value"
>
<ht-label class="radio-button-label" [label]="option.label"></ht-label>
<ng-container
*ngTemplateOutlet="
this.isLabelAString(option.label) ? defaultLabel : option.label;
context: { $implicit: option.label }
"
></ng-container>
<span *ngIf="option.description" class="radio-button-description">{{ option.description }}</span>
</mat-radio-button>
</mat-radio-group>
<ng-template #defaultLabel let-label><ht-label class="radio-button-label" [label]="label"></ht-label></ng-template>
`
})
export class RadioGroupComponent implements OnInit {
Expand Down Expand Up @@ -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 isLabelAString(label: string | TemplateRef<unknown>): boolean {
return typeof label === 'string';
}
}

export const enum OptionsDirection {
Expand Down
4 changes: 3 additions & 1 deletion projects/components/src/radio/radio-option.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { TemplateRef } from '@angular/core';

export interface RadioOption {
value: string;
label: string;
label: string | TemplateRef<unknown>;
description?: string;
}