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