Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed Modal.Form ts problems #350

Merged
merged 3 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/modal/demos/advance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import React, { useState } from 'react';
import { Button, Form, Input, InputNumber, Table } from 'antd';
import { Modal } from 'dt-react-component';

interface Data {
key: string;
interface FormData {
name: string;
age: number;
address: string;
}

interface Data extends FormData {
Zaoei marked this conversation as resolved.
Show resolved Hide resolved
key: string;
}

const data: Data[] = [
{
key: '1',
Expand All @@ -24,7 +27,7 @@ const data: Data[] = [
},
];

const ModalForm = Modal.Form((_props) => {
const ModalForm = Modal.Form<FormData>((_props) => {
return (
<>
<Form.Item label="name" name={'name'}>
Expand Down Expand Up @@ -81,7 +84,7 @@ export default () => {
},
];

const onSubmit = (values: Data) => {
const onSubmit = (values: FormData) => {
dataSource.splice(index, 0, { ...values, key: new Date() + '' });
setDataSource([...dataSource]);

Expand Down
6 changes: 5 additions & 1 deletion src/modal/demos/basics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import React, { useState } from 'react';
import { Button, Form, Input } from 'antd';
import { Modal } from 'dt-react-component';

const ModalForm = Modal.Form((_props) => {
interface FormData {
username: string;
}

const ModalForm = Modal.Form<FormData>((_props) => {
return (
<Form.Item label="username" name={'username'} rules={[{ max: 10 }]}>
<Input />
Expand Down
9 changes: 6 additions & 3 deletions src/modal/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,14 @@ const ModalForm = (props: IModalFormProps) => {
);
};

const InternalForm = (FormComponent: React.ComponentType) => {
return (props: IModalFormProps) => (
function InternalForm<V = any>(
FormComponent: React.ComponentType<IModalFormProps<V>>
): React.FC<IModalFormProps<V>> {
return (props: IModalFormProps<V>) => (
<ModalForm {...props}>
<FormComponent />
</ModalForm>
);
};
}

export default InternalForm;