diff --git a/packages/antd/docs/components/FormDialog.md b/packages/antd/docs/components/FormDialog.md index b2f7db350b5..9dccb2cadce 100644 --- a/packages/antd/docs/components/FormDialog.md +++ b/packages/antd/docs/components/FormDialog.md @@ -288,6 +288,8 @@ type FormDialogRenderer = | React.ReactElement | ((form: Form) => React.ReactElement) +type ModalTitle = string | number | React.ReactElement + interface IFormDialog { forOpen( middleware: ( @@ -307,9 +309,15 @@ interface IFormDialog { close(): void } +interface IModalProps extends ModalProps { + onOk?: (event: React.MouseEvent) => void | boolean // return false can prevent onOk + onCancel?: (event: React.MouseEvent) => void | boolean // return false can prevent onCancel + loadingText?: React.ReactNode +} + interface FormDialog { - (title: ModalProps, id: string, renderer: FormDialogRenderer): IFormDialog - (title: ModalProps, renderer: FormDialogRenderer): IFormDialog + (title: IModalProps, id: string, renderer: FormDialogRenderer): IFormDialog + (title: IModalProps, renderer: FormDialogRenderer): IFormDialog (title: ModalTitle, id: string, renderer: FormDialogRenderer): IFormDialog (title: ModalTitle, renderer: FormDialogRenderer): IFormDialog } diff --git a/packages/antd/docs/components/FormDialog.zh-CN.md b/packages/antd/docs/components/FormDialog.zh-CN.md index f0dc1dc3ab3..7e9c5aac3fc 100644 --- a/packages/antd/docs/components/FormDialog.zh-CN.md +++ b/packages/antd/docs/components/FormDialog.zh-CN.md @@ -297,6 +297,8 @@ type FormDialogRenderer = | React.ReactElement | ((form: Form) => React.ReactElement) +type ModalTitle = string | number | React.ReactElement + interface IFormDialog { forOpen( middleware: ( @@ -316,9 +318,15 @@ interface IFormDialog { close(): void } +interface IModalProps extends ModalProps { + onOk?: (event: React.MouseEvent) => void | boolean // return false can prevent onOk + onCancel?: (event: React.MouseEvent) => void | boolean // return false can prevent onCancel + loadingText?: React.ReactNode +} + interface FormDialog { - (title: ModalProps, id: string, renderer: FormDialogRenderer): IFormDialog - (title: ModalProps, renderer: FormDialogRenderer): IFormDialog + (title: IModalProps, id: string, renderer: FormDialogRenderer): IFormDialog + (title: IModalProps, renderer: FormDialogRenderer): IFormDialog (title: ModalTitle, id: string, renderer: FormDialogRenderer): IFormDialog (title: ModalTitle, renderer: FormDialogRenderer): IFormDialog } diff --git a/packages/antd/docs/components/FormDrawer.md b/packages/antd/docs/components/FormDrawer.md index e2bf77d7f71..3edaa1d561e 100644 --- a/packages/antd/docs/components/FormDrawer.md +++ b/packages/antd/docs/components/FormDrawer.md @@ -300,9 +300,14 @@ interface IFormDrawer { close(): void } +export interface IDrawerProps extends DrawerProps { + onClose?: (e: EventType) => void | boolean // return false can prevent onClose + loadingText?: React.ReactNode +} + interface FormDrawer { - (title: DrawerProps, id: string, renderer: FormDrawerRenderer): IFormDrawer - (title: DrawerProps, renderer: FormDrawerRenderer): IFormDrawer + (title: IDrawerProps, id: string, renderer: FormDrawerRenderer): IFormDrawer + (title: IDrawerProps, renderer: FormDrawerRenderer): IFormDrawer (title: ModalTitle, id: string, renderer: FormDrawerRenderer): IFormDrawer (title: ModalTitle, renderer: FormDrawerRenderer): IFormDrawer } diff --git a/packages/antd/docs/components/FormDrawer.zh-CN.md b/packages/antd/docs/components/FormDrawer.zh-CN.md index 334d0798b3a..10a07b74a29 100644 --- a/packages/antd/docs/components/FormDrawer.zh-CN.md +++ b/packages/antd/docs/components/FormDrawer.zh-CN.md @@ -300,9 +300,14 @@ interface IFormDrawer { close(): void } +export interface IDrawerProps extends DrawerProps { + onClose?: (e: EventType) => void | boolean // return false can prevent onClose + loadingText?: React.ReactNode +} + interface FormDrawer { - (title: DrawerProps, id: string, renderer: FormDrawerRenderer): IFormDrawer - (title: DrawerProps, renderer: FormDrawerRenderer): IFormDrawer + (title: IDrawerProps, id: string, renderer: FormDrawerRenderer): IFormDrawer + (title: IDrawerProps, renderer: FormDrawerRenderer): IFormDrawer (title: ModalTitle, id: string, renderer: FormDrawerRenderer): IFormDrawer (title: ModalTitle, renderer: FormDrawerRenderer): IFormDrawer } diff --git a/packages/antd/src/__builtins__/loading.ts b/packages/antd/src/__builtins__/loading.ts index a6a419a0315..d863a826721 100644 --- a/packages/antd/src/__builtins__/loading.ts +++ b/packages/antd/src/__builtins__/loading.ts @@ -1,9 +1,12 @@ import { message } from 'antd' -export const loading = async (processor: () => Promise) => { +export const loading = async ( + title: React.ReactNode = 'Loading...', + processor: () => Promise +) => { let hide = null let loading = setTimeout(() => { - hide = message.loading('Loading...') + hide = message.loading(title) }, 100) const results = await processor() hide?.() diff --git a/packages/antd/src/form-dialog/index.tsx b/packages/antd/src/form-dialog/index.tsx index cf13015a2c4..1d10c155ace 100644 --- a/packages/antd/src/form-dialog/index.tsx +++ b/packages/antd/src/form-dialog/index.tsx @@ -31,7 +31,7 @@ const isModalTitle = (props: any): props is ModalTitle => { ) } -const getModelProps = (props: any): ModalProps => { +const getModelProps = (props: any): IModalProps => { if (isModalTitle(props)) { return { title: props, @@ -49,25 +49,29 @@ export interface IFormDialog { close(): void } +export interface IModalProps extends ModalProps { + onOk?: (event: React.MouseEvent) => void | boolean + onCancel?: (event: React.MouseEvent) => void | boolean + loadingText?: React.ReactNode +} + export function FormDialog( - title: ModalProps, + title: IModalProps, id: string, - renderer?: FormDialogRenderer + renderer: FormDialogRenderer ): IFormDialog export function FormDialog( - title: ModalProps, - id: FormDialogRenderer, - renderer?: unknown + title: IModalProps, + renderer: FormDialogRenderer ): IFormDialog export function FormDialog( title: ModalTitle, id: string, - renderer?: FormDialogRenderer + renderer: FormDialogRenderer ): IFormDialog export function FormDialog( title: ModalTitle, - id: FormDialogRenderer, - renderer?: unknown + renderer: FormDialogRenderer ): IFormDialog export function FormDialog(title: any, id: any, renderer?: any): IFormDialog { if (isFn(id) || React.isValidElement(id)) { @@ -107,12 +111,14 @@ export function FormDialog(title: any, id: any, renderer?: any): IFormDialog { visible={visible} confirmLoading={env.form.submitting} onCancel={(e) => { - modal?.onCancel?.(e) - reject() + if (modal?.onCancel?.(e) !== false) { + reject() + } }} onOk={async (e) => { - modal?.onOk?.(e) - resolve() + if (modal?.onOk?.(e) !== false) { + resolve() + } }} > @@ -148,7 +154,7 @@ export function FormDialog(title: any, id: any, renderer?: any): IFormDialog { if (env.promise) return env.promise env.promise = new Promise(async (resolve, reject) => { try { - props = await loading(() => + props = await loading(modal.loadingText, () => applyMiddleware(props, env.openMiddlewares) ) env.form = env.form || createForm(props) @@ -168,7 +174,7 @@ export function FormDialog(title: any, id: any, renderer?: any): IFormDialog { .catch(() => {}) }, async () => { - await loading(() => + await loading(modal.loadingText, () => applyMiddleware(env.form, env.cancelMiddlewares) ) formDialog.close() diff --git a/packages/antd/src/form-drawer/index.tsx b/packages/antd/src/form-drawer/index.tsx index 4939b4d479f..a2d3b11cab9 100644 --- a/packages/antd/src/form-drawer/index.tsx +++ b/packages/antd/src/form-drawer/index.tsx @@ -30,13 +30,17 @@ type FormDrawerRenderer = type DrawerTitle = string | number | React.ReactElement +type EventType = + | React.KeyboardEvent + | React.MouseEvent + const isDrawerTitle = (props: any): props is DrawerTitle => { return ( isNum(props) || isStr(props) || isBool(props) || React.isValidElement(props) ) } -const getDrawerProps = (props: any): DrawerProps => { +const getDrawerProps = (props: any): IDrawerProps => { if (isDrawerTitle(props)) { return { title: props, @@ -52,25 +56,28 @@ export interface IFormDrawer { close(): void } +export interface IDrawerProps extends DrawerProps { + onClose?: (e: EventType) => void | boolean + loadingText?: React.ReactNode +} + export function FormDrawer( - title: DrawerProps, + title: IDrawerProps, id: string, - renderer?: FormDrawerRenderer + renderer: FormDrawerRenderer ): IFormDrawer export function FormDrawer( - title: DrawerProps, - id: FormDrawerRenderer, - renderer?: unknown + title: IDrawerProps, + id: FormDrawerRenderer ): IFormDrawer export function FormDrawer( title: DrawerTitle, id: string, - renderer?: FormDrawerRenderer + renderer: FormDrawerRenderer ): IFormDrawer export function FormDrawer( title: DrawerTitle, - id: FormDrawerRenderer, - renderer?: unknown + id: FormDrawerRenderer ): IFormDrawer export function FormDrawer(title: any, id: any, renderer?: any): IFormDrawer { if (isFn(id) || React.isValidElement(id)) { @@ -89,8 +96,9 @@ export function FormDrawer(title: any, id: any, renderer?: any): IFormDrawer { width: '40%', ...props, onClose: (e: any) => { - props?.onClose?.(e) - formDrawer.close() + if (props?.onClose?.(e) !== false) { + formDrawer.close() + } }, afterVisibleChange: (visible: boolean) => { props?.afterVisibleChange?.(visible) @@ -123,7 +131,7 @@ export function FormDrawer(title: any, id: any, renderer?: any): IFormDrawer { if (env.promise) return env.promise env.promise = new Promise(async (resolve, reject) => { try { - props = await loading(() => + props = await loading(drawer.loadingText, () => applyMiddleware(props, env.openMiddlewares) ) env.form = diff --git a/packages/next/docs/components/FormDialog.md b/packages/next/docs/components/FormDialog.md index 6b926aaed03..f26bc1de74c 100644 --- a/packages/next/docs/components/FormDialog.md +++ b/packages/next/docs/components/FormDialog.md @@ -322,9 +322,15 @@ interface IFormDialog { close(): void } +interface IDialogProps extends DialogProps { + onOk?: (event: React.MouseEvent) => void | boolean // return false can prevent onOk + onCancel?: (event: React.MouseEvent) => void | boolean // return false can prevent onCancel + loadingText?: React.ReactText +} + interface FormDialog { - (title: DialogProps, id: string, renderer: FormDialogRenderer): IFormDialog - (title: DialogProps, renderer: FormDialogRenderer): IFormDialog + (title: IDialogProps, id: string, renderer: FormDialogRenderer): IFormDialog + (title: IDialogProps, renderer: FormDialogRenderer): IFormDialog (title: ModalTitle, id: string, renderer: FormDialogRenderer): IFormDialog (title: ModalTitle, renderer: FormDialogRenderer): IFormDialog } diff --git a/packages/next/docs/components/FormDialog.zh-CN.md b/packages/next/docs/components/FormDialog.zh-CN.md index 3bbbf70a38e..36ba5503c00 100644 --- a/packages/next/docs/components/FormDialog.zh-CN.md +++ b/packages/next/docs/components/FormDialog.zh-CN.md @@ -351,9 +351,15 @@ interface IFormDialog { close(): void } +interface IDialogProps extends DialogProps { + onOk?: (event: React.MouseEvent) => void | boolean // return false can prevent onOk + onCancel?: (event: React.MouseEvent) => void | boolean // return false can prevent onCancel + loadingText?: React.ReactText +} + interface FormDialog { - (title: DialogProps, id: string, renderer: FormDialogRenderer): IFormDialog - (title: DialogProps, renderer: FormDialogRenderer): IFormDialog + (title: IDialogProps, id: string, renderer: FormDialogRenderer): IFormDialog + (title: IDialogProps, renderer: FormDialogRenderer): IFormDialog (title: ModalTitle, id: string, renderer: FormDialogRenderer): IFormDialog (title: ModalTitle, renderer: FormDialogRenderer): IFormDialog } diff --git a/packages/next/docs/components/FormDrawer.md b/packages/next/docs/components/FormDrawer.md index 118a25298e9..d13dda129bd 100644 --- a/packages/next/docs/components/FormDrawer.md +++ b/packages/next/docs/components/FormDrawer.md @@ -351,9 +351,14 @@ interface IFormDrawer { close(): void } +interface IDrawerProps extends DrawerProps { + onClose?: (reason: string, e: React.MouseEvent) => void | boolean // return false can prevent onClose + loadingText?: React.ReactNode +} + interface FormDrawer { - (title: DrawerProps, id: string, renderer: FormDrawerRenderer): IFormDrawer - (title: DrawerProps, renderer: FormDrawerRenderer): IFormDrawer + (title: IDrawerProps, id: string, renderer: FormDrawerRenderer): IFormDrawer + (title: IDrawerProps, renderer: FormDrawerRenderer): IFormDrawer (title: ModalTitle, id: string, renderer: FormDrawerRenderer): IFormDrawer (title: ModalTitle, renderer: FormDrawerRenderer): IFormDrawer } diff --git a/packages/next/docs/components/FormDrawer.zh-CN.md b/packages/next/docs/components/FormDrawer.zh-CN.md index ccc834e0a45..3f2b5b43fae 100644 --- a/packages/next/docs/components/FormDrawer.zh-CN.md +++ b/packages/next/docs/components/FormDrawer.zh-CN.md @@ -368,9 +368,14 @@ interface IFormDrawer { close(): void } +interface IDrawerProps extends DrawerProps { + onClose?: (reason: string, e: React.MouseEvent) => void | boolean // return false can prevent onClose + loadingText?: React.ReactNode +} + interface FormDrawer { - (title: DrawerProps, id: string, renderer: FormDrawerRenderer): IFormDrawer - (title: DrawerProps, renderer: FormDrawerRenderer): IFormDrawer + (title: IDrawerProps, id: string, renderer: FormDrawerRenderer): IFormDrawer + (title: IDrawerProps, renderer: FormDrawerRenderer): IFormDrawer (title: ModalTitle, id: string, renderer: FormDrawerRenderer): IFormDrawer (title: ModalTitle, renderer: FormDrawerRenderer): IFormDrawer } diff --git a/packages/next/src/__builtins__/loading.ts b/packages/next/src/__builtins__/loading.ts index 008fc73c433..7163f3233ba 100644 --- a/packages/next/src/__builtins__/loading.ts +++ b/packages/next/src/__builtins__/loading.ts @@ -1,8 +1,11 @@ import { Message } from '@alifd/next' -export const loading = async (processor: () => Promise) => { +export const loading = async ( + title: React.ReactNode = 'Loading...', + processor: () => Promise +) => { let loading = setTimeout(() => { - Message.loading('Loading...') + Message.loading(title as any) }, 100) const results = await processor() Message.hide() diff --git a/packages/next/src/form-dialog/index.tsx b/packages/next/src/form-dialog/index.tsx index 8dd9904a52f..de39300a0c0 100644 --- a/packages/next/src/form-dialog/index.tsx +++ b/packages/next/src/form-dialog/index.tsx @@ -34,7 +34,7 @@ const isModalTitle = (props: any): props is ModalTitle => { ) } -const getModelProps = (props: any): DialogProps => { +const getModelProps = (props: any): IDialogProps => { if (isModalTitle(props)) { return { title: props, @@ -44,6 +44,12 @@ const getModelProps = (props: any): DialogProps => { } } +export interface IDialogProps extends DialogProps { + onOk?: (event: React.MouseEvent) => void | boolean + onCancel?: (event: React.MouseEvent) => void | boolean + loadingText?: React.ReactText +} + export interface IFormDialog { forOpen(middleware: IMiddleware): IFormDialog forConfirm(middleware: IMiddleware): IFormDialog @@ -53,24 +59,22 @@ export interface IFormDialog { } export function FormDialog( - title: DialogProps, + title: IDialogProps, id: string, - renderer?: FormDialogRenderer + renderer: FormDialogRenderer ): IFormDialog export function FormDialog( - title: DialogProps, - id: FormDialogRenderer, - renderer?: unknown + title: IDialogProps, + renderer: FormDialogRenderer ): IFormDialog export function FormDialog( title: ModalTitle, id: string, - renderer?: FormDialogRenderer + renderer: FormDialogRenderer ): IFormDialog export function FormDialog( title: ModalTitle, - id: FormDialogRenderer, - renderer?: unknown + renderer: FormDialogRenderer ): IFormDialog export function FormDialog(title: any, id: any, renderer?: any): IFormDialog { if (isFn(id) || React.isValidElement(id)) { @@ -122,8 +126,9 @@ export function FormDialog(title: any, id: any, renderer?: any): IFormDialog { className={prefix + '-dialog-btn'} loading={env.form.submitting} onClick={(e) => { - modal?.onOk?.(e) - resolve() + if (modal?.onOk?.(e) !== false) { + resolve() + } }} > {modal?.locale?.ok || ctx?.locale?.Dialog?.ok || '确定'} @@ -131,8 +136,9 @@ export function FormDialog(title: any, id: any, renderer?: any): IFormDialog {