refactor(ui): radio group button icon support (#2262)
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
viewChildren,
|
||||
} from '@angular/core';
|
||||
import { type FormValueControl } from '@angular/forms/signals';
|
||||
import { LucideDynamicIcon, type LucideIconData } from '@lucide/angular';
|
||||
import { cn } from '../cn';
|
||||
import { AppControlTransitionDirective } from '../control.styles';
|
||||
import { APP_FIELD } from '../field/app-field.context';
|
||||
@@ -25,6 +26,7 @@ import {
|
||||
export interface RadioOption<T> {
|
||||
readonly value: T;
|
||||
readonly label: string;
|
||||
readonly icon?: LucideIconData;
|
||||
readonly description?: string;
|
||||
readonly disabled?: boolean;
|
||||
}
|
||||
@@ -35,7 +37,7 @@ let nextGroupId = 0;
|
||||
@Component({
|
||||
selector: 'app-radio-group',
|
||||
standalone: true,
|
||||
imports: [AppControlTransitionDirective],
|
||||
imports: [AppControlTransitionDirective, LucideDynamicIcon],
|
||||
host: { class: 'block' },
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
@@ -62,6 +64,9 @@ let nextGroupId = 0;
|
||||
(change)="onSelect(option)"
|
||||
(blur)="touched.set(true)" />
|
||||
@if (variant() === 'segmented') {
|
||||
@if (option.icon; as optionIcon) {
|
||||
<svg [lucideIcon]="optionIcon" [class]="segmentIconClass" aria-hidden="true"></svg>
|
||||
}
|
||||
<span class="truncate leading-none">{{ option.label }}</span>
|
||||
} @else {
|
||||
<span appControlTransition [class]="dotClass()" aria-hidden="true"></span>
|
||||
@@ -127,6 +132,7 @@ export class AppRadioGroupComponent<T> implements FormValueControl<T | null> {
|
||||
this.variant() === 'card' && 'peer-checked:text-primary-text',
|
||||
),
|
||||
);
|
||||
protected readonly segmentIconClass = 'size-[1em] shrink-0';
|
||||
|
||||
protected isSelected(option: RadioOption<T>): boolean {
|
||||
const value = this.value();
|
||||
|
||||
Reference in New Issue
Block a user