Skip to content

Commit

Permalink
Merge pull request #1478 from leshalv/master
Browse files Browse the repository at this point in the history
支持 footer 透传dom元素
  • Loading branch information
lhbxs authored Feb 21, 2024
2 parents f692511 + 084aefc commit f5fa160
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
25 changes: 24 additions & 1 deletion docs/form-render/advanced-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,27 @@ export default () => {
/>
);
}
```
```

- `footer` dom 元素透传
```jsx
import React, { useState } from 'react';
import { Button, Space, Form, Radio } from 'antd';
import FormRender, { useForm } from 'form-render';
import schema from './schema/simple';

export default () => {
const form = useForm();

return (
<FormRender
schema={schema}
form={form}
maxWidth={360}
footer={(dom) => (
<Space>{dom}</Space>
)}
/>
);
}
```
43 changes: 21 additions & 22 deletions packages/form-render/src/form-core/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,23 @@ const FormCore:FC<FRProps> = (props) => {
};

const operlabelCol = getFormItemLayout(column, {}, { labelWidth })?.labelCol;

const footerDom: React.JSX.Element[] = [];
if (!footer?.reset?.hide) {
footerDom.push(
<Button {...footer?.reset} onClick={() => form.resetFields()}>
{footer?.reset?.text || t('reset')}
</Button>
);
}
if (!footer?.submit?.hide) {
footerDom.push(
<Button type="primary" onClick={form.submit} {...footer?.submit}>
{footer?.submit?.text || t('submit')}
</Button>
);
}

return (
<Form
className={classNames('fr-form', { [className]: !!className } )}
Expand All @@ -218,28 +235,10 @@ const FormCore:FC<FRProps> = (props) => {
labelCol={operlabelCol}
className='fr-hide-label'
>
{isFunction(footer) ? (
<Space>{footer()}</Space>
): (
<Space>
{!footer?.reset?.hide && (
<Button
{...footer?.reset}
onClick={() => form.resetFields()}
>
{footer?.reset?.text || t('reset')}
</Button>
)}
{!footer?.submit?.hide && (
<Button
type='primary'
onClick={form.submit}
{...footer?.submit}
>
{footer?.submit?.text || t('submit')}
</Button>
)}
</Space>
{isFunction(footer) ? (
<Space>{footer(footerDom)}</Space>
) : (
<Space>{footerDom}</Space>
)}
</Form.Item>
</Col>
Expand Down
2 changes: 1 addition & 1 deletion packages/form-render/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ export interface FRProps extends Omit<AntdFormProps, 'form'> {
methods?: Record<string, Function>;
operateExtra?: React.ReactNode;
maxWidth?: number | string;
footer?: boolean | (() => React.ReactNode) | Partial<ActionProps> ;
footer?: boolean | ((dom: React.JSX.Element[]) => React.ReactNode) | Partial<ActionProps> ;
}

export interface SearchProps<RecordType> extends Omit<FRProps, 'form'> {
Expand Down

0 comments on commit f5fa160

Please sign in to comment.