import { Component, inject } from '@angular/core';
import { of, delay } from 'rxjs';
import { YelonFormModule, SFCheckboxWidgetSchema, SFSchema } from '@yelon/form';
import type { SFCascaderWidgetSchema } from '@yelon/form/widgets/cascader';
import { NzMessageService } from 'ng-zorro-antd/message';
@Component({
selector: 'form-checkbox-simple',
template: ` <sf [schema]="schema" (formSubmit)="submit($event)" /> `,
standalone: true,
imports: [YelonFormModule]
})
export class FormCheckboxSimpleComponent {
private readonly msg = inject(NzMessageService);
schema: SFSchema = {
properties: {
// 单个多选框
single: {
type: 'boolean',
title: '同意本协议',
description: '《用户协议》',
ui: {
widget: 'checkbox'
} as SFCascaderWidgetSchema,
default: true
},
// 多选框组
mulit: {
type: 'string',
title: 'Mulit',
enum: ['Apple', 'Pear', 'Orange'],
ui: {
widget: 'checkbox',
span: 8, // 指定每一项 8 个单元的布局
checkAll: true
} as SFCheckboxWidgetSchema,
default: ['Apple']
},
// 异步数据
async: {
type: 'string',
title: 'Async',
ui: {
widget: 'checkbox',
asyncData: () =>
of([
{ label: 'Apple', value: 'Apple' },
{ label: 'Pear', value: 'Pear' },
{ label: 'Orange', value: 'Orange' }
]).pipe(delay(200))
} as SFCheckboxWidgetSchema,
default: ['Apple']
}
}
};
submit(value: {}): void {
this.msg.success(JSON.stringify(value));
}
}