Skip to content

Commit

Permalink
feat: 🎸 ProAddition now can use more than one
Browse files Browse the repository at this point in the history
  • Loading branch information
charlzyx committed Apr 26, 2024
1 parent 6932f5c commit 42339a0
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 9 deletions.
Binary file modified bun.lockb
Binary file not shown.
51 changes: 51 additions & 0 deletions docs/components/demos/ProArrayTableWithShadow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,57 @@ const schema: ISchema = {
},
title: "添加条目",
},
add2: {
type: "void",
"x-component": "ProArrayTable.ProAddition",
"x-component-props": {
onOk: (
data: any,
ctx: ReturnType<typeof ProArrayTable.useProArrayTableContext>,
) => {
// 如果添加数据后将超过当前页,则自动切换到下一页
const total = ctx?.array.field?.value.length || 0;
if (
total >=
ctx.pagination!.current! * ctx.pagination.pageSize!
) {
ctx.pagination.setPagination((memo) => {
return { ...memo, current: memo.current + 1 };
});
}

ctx.array.field.push(data);
console.log(data);
},
schema: {
type: "void",
properties: {
id: {
title: "ID",
type: "string",
"x-decorator": "FormItem",
"x-component": "Input",
},
domain: {
title: "域名",
"x-decorator": "FormItem",
type: "string",
"x-component": "Input",
},
desc: {
title: "描述",
"x-decorator": "FormItem",
type: "string",
"x-component": "Input.TextArea",
"x-component-props": {
rows: 4,
},
},
},
},
},
title: "演示多个添加共存",
},
},
},
},
Expand Down
9 changes: 9 additions & 0 deletions docs/components/demos/ShadowFormAll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ const schema: ISchema = {
layout: "vertical",
},
properties: {
_modal: {
type: "void",
title: "Void内置的Modal",
"x-decorator": "ShadowForm",
"x-component": "ShadowModal",
"x-decorator-props": {
schema: shadowSchema,
},
},
info: {
type: "object",
"x-read-pretty": true,
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,7 @@
"rimraf": "^5.0.5",
"rspress": "latest"
},
"files": ["dist"]
}
"files": [
"dist"
]
}
8 changes: 4 additions & 4 deletions src/pro-array-table/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ export const useExpandRender = (index: number) => {

export const useAddition = () => {
const schema = useFieldSchema();
return schema.reduceProperties((addition, schema, key) => {
return schema.reduceProperties((buf, schema, key) => {
if (isAdditionComponent(schema)) {
return <RecursionField schema={schema} name={key} />;
buf.push(<RecursionField schema={schema} name={key} />);
}
return addition;
}, null);
return buf;
}, [] as React.ReactElement[]);
};

export const useShadowComponents = () => {
Expand Down
8 changes: 5 additions & 3 deletions src/pro-array-table/mixin.pro.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FormProvider, useField, useFieldSchema } from "@formily/react";
import { toJS } from "@formily/reactive";
import React, { useContext, useEffect, useRef } from "react";
import React, { useContext, useEffect, useId, useRef } from "react";
import { empty, omit, pick } from "../__builtins__";
import { Alert, BUTTON_TYPE, Button, Divider, Modal, Space } from "../adaptor";
import { ArrayBase } from "../adaptor/adaptor";
Expand Down Expand Up @@ -271,13 +271,15 @@ export const ProAddition = ({
React.ComponentProps<typeof Modal>,
"onOk" | "onCancel" | "children"
>) => {
const id = useId();
const actName = `_pro_additino_${id}`;
return (
<React.Fragment>
<ArrayTableShowModal act="_pro_addition" {...props}></ArrayTableShowModal>
<ArrayTableShowModal act={actName} {...props}></ArrayTableShowModal>
<DelegateAction
initLoader={() => empty}
index={Infinity}
act={"_pro_addition"}
act={actName}
></DelegateAction>
</React.Fragment>
);
Expand Down

0 comments on commit 42339a0

Please sign in to comment.