import { Component, inject } from '@angular/core';
import { of, delay } from 'rxjs';
import { YelonFormModule, SFRadioWidgetSchema, SFSchema } from '@yelon/form';
import { NzMessageService } from 'ng-zorro-antd/message';
@Component({
selector: 'form-radio-simple',
template: ` <sf [schema]="schema" (formSubmit)="submit($event)" /> `,
standalone: true,
imports: [YelonFormModule]
})
export class FormRadioSimpleComponent {
private readonly msg = inject(NzMessageService);
schema: SFSchema = {
properties: {
btn: {
type: 'string',
title: 'Button',
enum: ['A', 'B', 'C'],
ui: {
widget: 'radio',
styleType: 'button',
buttonStyle: 'solid'
} as SFRadioWidgetSchema,
default: 'A'
},
// 异步数据
async: {
type: 'string',
title: 'Async',
ui: {
widget: 'radio',
asyncData: () =>
of([
{ label: '男', value: 'M' },
{ label: '女', value: 'F' },
{ label: '未知', value: 'N' }
]).pipe(delay(100)),
change: console.log
} as SFRadioWidgetSchema,
default: 'N'
}
}
};
submit(value: {}): void {
this.msg.success(JSON.stringify(value));
}
}