import { Component, inject } from '@angular/core';
import { delay, of } from 'rxjs';
import { DelonFormModule, SFSchema } from '@delon/form';
import { SFSegmentedWidgetSchema, SegmentedWidget } from '@delon/form/widgets/segmented';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzSegmentedOptions } from 'ng-zorro-antd/segmented';
@Component({
selector: 'form-segmented-simple',
template: `<sf [schema]="schema" (formSubmit)="submit($event)" />`,
standalone: true,
imports: [DelonFormModule]
})
export class FormSegmentedSimpleComponent {
private readonly msg = inject(NzMessageService);
schema: SFSchema = {
properties: {
base: {
type: 'string',
title: 'Base',
default: 2,
enum: ['Daily', 'Weekly', 'Monthly', 'Quarterly', 'Yearly'],
ui: {
widget: SegmentedWidget.KEY,
valueChange: console.log
} as SFSegmentedWidgetSchema
},
asyncData: {
type: 'string',
title: 'Async Data',
ui: {
widget: SegmentedWidget.KEY,
asyncData: () =>
of([
{ label: 'Label1', value: 'a' },
{ label: 'Label2', value: 'b' },
{ label: 'Label3', value: 'c', disabled: true }
] as NzSegmentedOptions).pipe(delay(1000)),
valueChange: console.log
} as SFSegmentedWidgetSchema
}
}
};
submit(value: {}): void {
this.msg.success(JSON.stringify(value));
}
}