import { Component, EventEmitter, Input, Output } from '@angular/core'; export type NativeSelectOption = | string | { value: string; label: string; sub?: string; disabled?: boolean }; const val = (o: NativeSelectOption): string => (typeof o === 'string' ? o : o.value); const lbl = (o: NativeSelectOption): string => (typeof o === 'string' ? o : o.label); const subOf = (o: NativeSelectOption): string | undefined => typeof o === 'object' ? o.sub : undefined; @Component({ selector: 'vsp-radio', template: ``, }) export class VspRadio { @Input() checked = false; @Input() label?: string; @Input() sub?: string; @Input() name?: string; @Input() value?: string; @Input() disabled = false; @Output() select = new EventEmitter(); get dotCls(): string { return this.checked ? 'ui-radio-dot on' : 'ui-radio-dot'; } } @Component({ selector: 'vsp-radio-group', imports: [VspRadio], template: `
@for (o of options; track val(o)) { }
`, }) export class VspRadioGroup { @Input() value?: string; @Output() valueChange = new EventEmitter(); @Input() options: NativeSelectOption[] = []; @Input() name = 'vsp-radio'; @Input() disabled = false; @Input() orientation: 'vertical' | 'horizontal' = 'vertical'; val = val; lbl = lbl; subOf = subOf; disOf(o: NativeSelectOption): boolean { return typeof o === 'object' && !!o.disabled; } pick(v: string): void { this.value = v; this.valueChange.emit(v); } } @Component({ selector: 'vsp-slider', template: ``, }) export class VspSlider { @Input() value = 0; @Output() valueChange = new EventEmitter(); @Input() min = 0; @Input() max = 100; @Input() step = 1; @Input() disabled = false; @Input() id?: string; @Input('aria-label') ariaLabel?: string; onInput(e: Event): void { this.value = Number((e.target as HTMLInputElement).value); this.valueChange.emit(this.value); } } @Component({ selector: 'vsp-native-select', template: ``, }) export class VspNativeSelect { @Input() value?: string; @Output() valueChange = new EventEmitter(); @Input() options: NativeSelectOption[] = []; val = val; lbl = lbl; onChange(e: Event): void { this.value = (e.target as HTMLSelectElement).value; this.valueChange.emit(this.value); } }