Skip to content

Commit

Permalink
fix: 🐛 (shadow-form) form -> subFormOptions, and inherit parent
Browse files Browse the repository at this point in the history
  • Loading branch information
charlzyx committed Jul 26, 2024
1 parent 42339a0 commit 9d2be09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/pro-array-table/mixin.pro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const ArrayTableShowModal: React.FC<
CommonShadowPopup
> = (props) => {
const { SchemaField, form, schema } = useShadowForm(
pick(props, "schema", "schemaFieldOptions", "form"),
pick(props, "schema", "schemaFieldOptions", "subFormOptions"),
);
const mySchema = useFieldSchema();
const act = props.act ?? mySchema.name;
Expand Down Expand Up @@ -189,7 +189,7 @@ export const ArrayTableShowModal: React.FC<

return (
<Modal
{...omit(props, "act", "schema", "schemaFieldOptions", "form")}
{...omit(props, "act", "schema", "schemaFieldOptions", "subFormOptions")}
open={visible}
title={field.title}
onCancel={() => {
Expand Down
12 changes: 9 additions & 3 deletions src/shadow-form/shadow-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
SchemaOptionsContext,
createSchemaField,
useField,
useForm,
} from "@formily/react";
import React, { useContext, useMemo } from "react";
import ReactIs from "react-is";
Expand All @@ -32,13 +33,18 @@ export interface IShadowFormOptions {
/** createSchemaField 函数配置, components 和 scope */
schemaFieldOptions?: Parameters<typeof useShadowSchemaField>[0];
/** createForm 创建的表单实例, 有自定义 effects 等可以通过自定义一个 form 这个传入 */
form?: ReturnType<typeof createForm>;
subFormOptions?: Parameters<typeof createForm>[0];
}

export const useShadowForm = (options: IShadowFormOptions) => {
const { schema, schemaFieldOptions, form } = options;
const { schema, schemaFieldOptions, subFormOptions } = options;
const form = useForm();
const SchemaField = useShadowSchemaField(schemaFieldOptions);
const realForm = useMemo(() => form ?? createForm({}), [form]);

const realForm = useMemo(
() => createForm({ ...form.props, ...subFormOptions }),
[subFormOptions, form.props],
);
return {
form: realForm,
schema,
Expand Down

0 comments on commit 9d2be09

Please sign in to comment.