Skip to content

Commit

Permalink
refactor(antd/core): refactor FormDialog/FormDrawer/Form.setValues/se…
Browse files Browse the repository at this point in the history
…tInitialValues (#1876)
  • Loading branch information
janryWang authored Jul 24, 2021
1 parent 4e191e0 commit 849ba7c
Show file tree
Hide file tree
Showing 30 changed files with 1,306 additions and 659 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ coverage/
node_modules/
examples/test
.idea/
.vscode/
TODO.md
tsconfig.tsbuildinfo
package/
Expand Down
19 changes: 19 additions & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "0.1",
"language": "en",
"ignoreWords": [
"autorun",
"Formily",
"formily",
"untracked",
"Unmount",
"antd",
"Antd",
"alifd",
"Mixins",
"builtins",
"cascader",
"Cascader",
"middlewares"
]
}
2 changes: 1 addition & 1 deletion docs/guide/advanced/build.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ yarn add babel-plugin-import --dev
"import",
{
"libraryName": "@formily/antd",
"libraryDirectory": "esn",
"libraryDirectory": "esm",
"style": true
}
]
Expand Down
112 changes: 91 additions & 21 deletions packages/antd/docs/components/FormDialog.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,27 @@ export default () => {
</FormLayout>
)
})
.forOpen((payload, next) => {
setTimeout(() => {
next({
initialValues: {
aaa: '123',
},
})
}, 1000)
})
.forConfirm((payload, next) => {
setTimeout(() => {
console.log(payload)
next(payload)
}, 1000)
})
.forCancel((payload, next) => {
setTimeout(() => {
console.log(payload)
next(payload)
}, 1000)
})
.open({
initialValues: {
aaa: '123',
Expand Down Expand Up @@ -137,6 +158,27 @@ export default () => {
</FormLayout>
)
})
.forOpen((payload, next) => {
setTimeout(() => {
next({
initialValues: {
aaa: '123',
},
})
}, 1000)
})
.forConfirm((payload, next) => {
setTimeout(() => {
console.log(payload)
next(payload)
}, 1000)
})
.forCancel((payload, next) => {
setTimeout(() => {
console.log(payload)
next(payload)
}, 1000)
})
.open({
initialValues: {
aaa: '123',
Expand Down Expand Up @@ -200,6 +242,27 @@ export default () => {
</FormLayout>
)
})
.forOpen((payload, next) => {
setTimeout(() => {
next({
initialValues: {
aaa: '123',
},
})
}, 1000)
})
.forConfirm((payload, next) => {
setTimeout(() => {
console.log(payload)
next(payload)
}, 1000)
})
.forCancel((payload, next) => {
setTimeout(() => {
console.log(payload)
next(payload)
}, 1000)
})
.open({
initialValues: {
aaa: '123',
Expand All @@ -219,33 +282,36 @@ export default () => {
### FormDialog

```ts pure
import { IFormProps } from '@formily/core'
import { IFormProps, Form } from '@formily/core'

type FormDialogRenderer =
| React.ReactElement
| ((form: Form) => React.ReactElement)

type FormDialogHandler = {
//Open the pop-up window and receive the form attributes, you can pass in initialValues/values/effects etc.
interface IFormDialog {
forOpen(
middleware: (
props: IFormProps,
next: (props?: IFormProps) => Promise<any>
) => any
): any //Middleware interceptor, can intercept Dialog to open
forConfirm(
middleware: (props: Form, next: (props?: Form) => Promise<any>) => any
): any //Middleware interceptor, which can intercept Dialog confirmation
forCancel(
middleware: (props: Form, next: (props?: Form) => Promise<any>) => any
): any //Middleware interceptor, can intercept Dialog to cancel
//Open the pop-up window to receive form attributes, you can pass in initialValues/values/effects etc.
open(props: IFormProps): Promise<any> //return form data
//Close the pop-up window
close(): void
}

interface IFormDialog {
(
title: React.ReactNode, //If it is ReactNode, it will be passed in as a pop-up window title
renderer: (resolve: () => void, reject: () => void) => React.ReactElement
): FormDialogHandler
(
title: IFormModalProps, //If it is an object, it is passed in as IFormModalProps
renderer: (resolve: () => void, reject: () => void) => React.ReactElement
): FormDialogHandler
}
```

### IFormModalProps

```ts pure
interface IFormModalProps extends ModalProps {
// If the return value is true, the dialog will not be closed after clicking Cancel or OK. At this time, you need to manually call FormDialogHandler.close() to close the dialog.
onCancel?: (e: React.MouseEvent<HTMLElement>) => boolean | void
interface FormDialog {
(title: ModalProps, id: string, renderer: FormDialogRenderer): IFormDialog
(title: ModalProps, id: FormDialogRenderer, renderer: unknown): IFormDialog
(title: ModalTitle, id: string, renderer: FormDialogRenderer): IFormDialog
(title: ModalTitle, id: FormDialogRenderer, renderer: unknown): IFormDialog
}
```

Expand All @@ -254,3 +320,7 @@ interface IFormModalProps extends ModalProps {
### FormDialog.Footer

No attributes, only child nodes are received

### FormDialog.Portal

Receive the optional id attribute, the default value is `form-dialog`, if there are multiple prefixCls in an application, and the prefixCls in the pop-up window of different regions are different, then it is recommended to specify the id as the region-level id
Loading

0 comments on commit 849ba7c

Please sign in to comment.