import { UIDescriptor } from '@/descriptors/UIDescriptor' ; import { Components } from '@/lib/Components' ; import { EnumField , RadioField , IEnumItemDescriptor , EnumDescriptor , Component , ScalarKind } from '../../types' ; import { ItemUIDescriptor } from './ItemUIDescriptor' ; const DEFAULT_KIND = 'radio' ; export class EnumUIDescriptor extends ItemUIDescriptor < EnumField , RadioField , EnumDescriptor > { readonly layout : Component ; readonly children : IEnumItemDescriptor [ ] = [ ] ; constructor ( options , field , components ) { super ( options , field , components ) ; this . layout = options . layout || 'fieldset' ; } getChildren ( field ) { return field . children . map ( ( childField ) => this . getChildDescriptor ( childField ) ) ; } getChildDescriptor ( field ) { const options = this . items [ `${ field . value }` ] || { } ; if ( ! options . kind ) { options . kind = DEFAULT_KIND ; } return UIDescriptor . get ( options , field , this . components ) as IEnumItemDescriptor || UIDescriptor . get ( { kind : DEFAULT_KIND } , field , this . components ) as IEnumItemDescriptor ; } parse ( field ) { super . parse ( field ) ; this . children . push ( ... this . getChildren ( field ) ) ; } } UIDescriptor . register ( 'enum' , EnumUIDescriptor ) ;