Skip to content

Commit 8000c3c

Browse files
author
prgrmr
committed
fix: 优化 formSideSheet & formDialog
1 parent 95f1bd0 commit 8000c3c

File tree

4 files changed

+177
-115
lines changed

4 files changed

+177
-115
lines changed

packages/components/src/form-dialog/index.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,14 @@ export interface IFormDialog {
4949

5050
export interface IModalProps
5151
extends Omit<ModalReactProps, "onOk" | "onCancel"> {
52-
onOk?: (e: React.MouseEvent) => void | boolean | Promise<any>;
53-
onCancel?: (e: React.MouseEvent) => void | boolean | Promise<any>;
52+
getModalProps?: (
53+
props: IModalProps & {
54+
triggerConfirm?: () => any;
55+
triggerCancel?: () => any;
56+
}
57+
) => IModalProps;
58+
onOk?: (e: any) => void | Promise<any> | boolean;
59+
onCancel?: (e: any) => void | Promise<any> | boolean;
5460
loadingText?: React.ReactNode;
5561
}
5662

@@ -113,6 +119,11 @@ export function FormDialog(title: any, id: any, renderer?: any): IFormDialog {
113119
{() => (
114120
<Modal
115121
{...modal}
122+
{...(modal?.getModalProps?.({
123+
...modal,
124+
triggerConfirm: resolve,
125+
triggerCancel: reject,
126+
}) || {})}
116127
visible={visible}
117128
confirmLoading={env?.form?.submitting}
118129
onCancel={(e) => {
@@ -209,7 +220,9 @@ const DialogFooter: React.FC = (props) => {
209220
const ref = useRef<HTMLDivElement>(null);
210221
const [footer, setFooter] = useState<HTMLDivElement>();
211222
const footerRef = useRef<HTMLDivElement>();
212-
const prefixCls = usePrefixCls("modal");
223+
const prefixCls = usePrefixCls("", {
224+
prefixCls: "semi-modal",
225+
});
213226
useLayoutEffect(() => {
214227
const content = ref.current?.closest(`.${prefixCls}-content`);
215228
if (content) {

packages/components/src/form-side-sheet/demo/index_2.tsx

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,73 @@
1-
import React from 'react';
2-
import { FormSideSheet, FormLayout, Submit, Reset, FormButtonGroup, SchemaRender } from '@formily/semi';
3-
import { Button } from '@douyinfe/semi-ui';
1+
import React from "react";
2+
import {
3+
FormSideSheet,
4+
FormLayout,
5+
Submit,
6+
Reset,
7+
FormButtonGroup,
8+
SchemaRender,
9+
} from "@formily/semi";
10+
import { Button } from "@douyinfe/semi-ui";
11+
import { Form } from "@formily/core";
412

513
const schema = {
6-
type: 'object',
14+
type: "object",
715
properties: {
816
aaa: {
9-
type: 'string',
10-
title: '输入框1',
17+
type: "string",
18+
title: "输入框1",
1119
required: true,
12-
'x-decorator': 'FormItem',
13-
'x-component': 'Input',
20+
"x-decorator": "FormItem",
21+
"x-component": "Input",
1422
},
1523
bbb: {
16-
type: 'string',
17-
title: '输入框2',
24+
type: "string",
25+
title: "输入框2",
1826
required: true,
19-
'x-decorator': 'FormItem',
20-
'x-component': 'Input',
27+
"x-decorator": "FormItem",
28+
"x-component": "Input",
2129
},
2230
ccc: {
23-
type: 'string',
24-
title: '输入框3',
31+
type: "string",
32+
title: "输入框3",
2533
required: true,
26-
'x-decorator': 'FormItem',
27-
'x-component': 'Input',
34+
"x-decorator": "FormItem",
35+
"x-component": "Input",
2836
},
2937
ddd: {
30-
type: 'string',
31-
title: '输入框4',
38+
type: "string",
39+
title: "输入框4",
3240
required: true,
33-
'x-decorator': 'FormItem',
34-
'x-component': 'Input',
41+
"x-decorator": "FormItem",
42+
"x-component": "Input",
3543
},
3644
},
3745
};
3846

3947
export default () => (
4048
<Button
4149
onClick={() => {
42-
FormSideSheet('弹窗表单', resolve => (
50+
FormSideSheet("弹窗表单", (form: Form) => (
4351
<FormLayout labelCol={6} wrapperCol={10}>
4452
<SchemaRender schema={schema} />
4553
<FormSideSheet.Footer>
4654
<FormButtonGroup align="right">
47-
<Submit onClick={resolve}>提交</Submit>
55+
<Submit onClick={form.submit}>提交</Submit>
4856
<Reset>重置</Reset>
4957
</FormButtonGroup>
5058
</FormSideSheet.Footer>
5159
</FormLayout>
5260
))
53-
.open({
54-
initialValues: {
55-
aaa: '123',
56-
},
61+
.forOpen((form, next) => {
62+
setTimeout(() => {
63+
next({
64+
initialValues: {
65+
aaa: "123",
66+
},
67+
});
68+
}, 1000);
5769
})
70+
.open()
5871
.then(console.log);
5972
}}
6073
>

0 commit comments

Comments
 (0)