diff --git a/src/modal/demos/advance.tsx b/src/modal/demos/advance.tsx index 710c84dc4..237958f4f 100644 --- a/src/modal/demos/advance.tsx +++ b/src/modal/demos/advance.tsx @@ -2,14 +2,21 @@ import React, { useState } from 'react'; import { Button, Form, Input, InputNumber, Table } from 'antd'; import { Modal } from 'dt-react-component'; -interface Data { - key: string; +interface FormValues { name: string; age: number; address: string; } -const data: Data[] = [ +interface TableData extends FormValues { + key: string; +} + +interface CustomModalFormProps { + customAttr: string; +} + +const data: TableData[] = [ { key: '1', name: 'UED', @@ -24,9 +31,12 @@ const data: Data[] = [ }, ]; -const ModalForm = Modal.Form((_props) => { +const ModalForm = Modal.Form((props) => { return ( <> + + + @@ -43,7 +53,7 @@ const ModalForm = Modal.Form((_props) => { export default () => { const [visible, setVisible] = useState(false); const [index, setIndex] = useState(0); - const [dataSource, setDataSource] = useState(data); + const [dataSource, setDataSource] = useState(data); const columns = [ { @@ -65,7 +75,7 @@ export default () => { title: '操作', dataIndex: 'operate', key: 'operate', - render: (_: void, record: Data, index: number) => { + render: (_: void, _record: TableData, index: number) => { return ( + setVisible((v) => !v)} + onSubmit={(value) => { + console.log(value); + }} + customAttr={'customAttr'} + /> + + ); +}; diff --git a/src/modal/form.tsx b/src/modal/form.tsx index e946c49fb..0621945ac 100644 --- a/src/modal/form.tsx +++ b/src/modal/form.tsx @@ -1,15 +1,12 @@ import React, { ReactElement, useMemo } from 'react'; -import { Modal, FormProps, ModalFuncProps } from 'antd'; +import { Modal, FormProps, ModalProps } from 'antd'; import { FORM_PROPS, MODAL_PROPS } from '../utils/antdProps'; import Utils from '../utils'; import Form from '../form'; -export interface IModalFormProps extends FormProps, ModalFuncProps { - /** - * modal title - * @param {string} - */ - title?: string; +export interface IModalFormProps + extends Omit, + Omit { /** * modal className * @param {string} @@ -22,7 +19,6 @@ export interface IModalFormProps extends FormProps, ModalFuncProps * @returns */ onSubmit?: (values: Values) => void; - [key: string]: any; } const ModalForm = (props: IModalFormProps) => { @@ -50,8 +46,8 @@ const ModalForm = (props: IModalFormProps) => { } catch (error) {} }; - const onCancel = () => { - props.onCancel?.(); + const onCancel = (e: React.MouseEvent) => { + props.onCancel?.(e); }; const afterClose = () => { @@ -76,11 +72,14 @@ const ModalForm = (props: IModalFormProps) => { ); }; -const InternalForm = (FormComponent: React.ComponentType) => { - return (props: IModalFormProps) => ( +function InternalForm

( + FormComponent: React.ComponentType & P> +): React.FC & P> { + return (props: IModalFormProps & P) => ( - + & P)} /> ); -}; +} + export default InternalForm; diff --git a/src/modal/index.md b/src/modal/index.md index 188ce3592..ca873541b 100644 --- a/src/modal/index.md +++ b/src/modal/index.md @@ -17,7 +17,8 @@ demo: 所用使用方式同 `Ant Design` 的 Modal 组件,新增 `Modal.Form` 组件 - + + ## API