jsketcher/web/app/cad/mdf/ui/SubFormWidget.tsx
2022-06-25 15:19:47 -07:00

34 lines
881 B
TypeScript

import React from 'react';
import {ContainerBasicProps, ContainerWidget} from "cad/mdf/ui/ContainerWidget";
import {Group, SubForm} from "cad/craft/wizard/components/form/Form";
import {ParamsPathSegment} from "cad/craft/wizard/wizardTypes";
import {Types} from "cad/craft/schema/types";
import {FieldBasicProps, fieldToSchemaGeneric} from "cad/mdf/ui/field";
export interface SubFormWidgetProps extends ContainerBasicProps, FieldBasicProps {
type: 'sub-form',
name: ParamsPathSegment
}
export function SubFormWidget({name, content}: SubFormWidgetProps) {
return <Group>
<SubForm name={name}>
<ContainerWidget content={content} />
</SubForm>
</Group>;
}
SubFormWidget.propsToSchema = (props: SubFormWidgetProps, deriveSchema) => {
return {
type: Types.object,
schema: deriveSchema(props.content),
...fieldToSchemaGeneric(props),
}
}