zy-react-library 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import type { FormInstance, FormProps } from "antd/es/form";
2
2
  import type { Gutter } from "antd/es/grid/row";
3
- import type { FC } from "react";
3
+ import type { FC, ReactNode } from "react";
4
4
  import type { FormOption, FormValues } from "./FormItemsRenderer";
5
5
 
6
6
  /**
@@ -16,11 +16,23 @@ export interface FormBuilderProps extends Omit<FormProps, "form"> {
16
16
  /** 占据栅格列数,默认 12 */
17
17
  span?: number | string;
18
18
  /** 表单实例(通过 Form.useForm() 创建) */
19
- form: FormInstance;
19
+ form?: FormInstance;
20
20
  /** 自动生成必填规则,默认 true */
21
21
  useAutoGenerateRequired?: boolean;
22
22
  /** 表单提交回调 */
23
- onFinish?: (values: any) => void;
23
+ onFinish?: (values: FormValues) => void;
24
+ /** 是否显示操作按钮区域,默认 true */
25
+ showActionButtons?: boolean;
26
+ /** 提交按钮文字,默认为"提交" */
27
+ submitButtonText?: string;
28
+ /** 重置按钮文字,默认为"重置" */
29
+ resetButtonText?: string;
30
+ /** 是否显示提交按钮,默认 true */
31
+ showSubmitButton?: boolean;
32
+ /** 是否显示重置按钮,默认 true */
33
+ showResetButton?: boolean;
34
+ /** 自定义操作按钮组 */
35
+ customActionButtons?: ReactNode;
24
36
  }
25
37
 
26
38
  /**
@@ -1,4 +1,4 @@
1
- import { Form, Row } from "antd";
1
+ import { Button, Col, Form, Row, Space } from "antd";
2
2
  import FormItemsRenderer from "./FormItemsRenderer";
3
3
 
4
4
  /**
@@ -13,9 +13,23 @@ const FormBuilder = (props) => {
13
13
  labelCol = { span: 4 },
14
14
  onFinish,
15
15
  useAutoGenerateRequired = true,
16
+ showActionButtons = true,
17
+ submitButtonText = "提交",
18
+ resetButtonText = "重置",
19
+ showSubmitButton = true,
20
+ showResetButton = true,
21
+ customActionButtons,
22
+ form: externalForm,
16
23
  ...restProps
17
24
  } = props;
18
25
 
26
+ const [internalForm] = Form.useForm();
27
+ const form = externalForm || internalForm;
28
+
29
+ const handleReset = () => {
30
+ form.resetFields();
31
+ };
32
+
19
33
  return (
20
34
  <Form
21
35
  labelCol={labelCol}
@@ -23,6 +37,7 @@ const FormBuilder = (props) => {
23
37
  wrapperCol={{ span: 24 - labelCol.span }}
24
38
  onFinish={onFinish}
25
39
  initialValues={values}
40
+ form={form}
26
41
  {...restProps}
27
42
  >
28
43
  <Row gutter={gutter}>
@@ -32,6 +47,26 @@ const FormBuilder = (props) => {
32
47
  useAutoGenerateRequired={useAutoGenerateRequired}
33
48
  />
34
49
  </Row>
50
+ {showActionButtons && (
51
+ <Row gutter={gutter} style={{ marginTop: 24 }}>
52
+ <Col span={24} style={{ textAlign: "center" }}>
53
+ {customActionButtons || (
54
+ <Space>
55
+ {showSubmitButton && (
56
+ <Button type="primary" htmlType="submit">
57
+ {submitButtonText}
58
+ </Button>
59
+ )}
60
+ {showResetButton && (
61
+ <Button onClick={handleReset} style={{ marginRight: 8 }}>
62
+ {resetButtonText}
63
+ </Button>
64
+ )}
65
+ </Space>
66
+ )}
67
+ </Col>
68
+ </Row>
69
+ )}
35
70
  </Form>
36
71
  );
37
72
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zy-react-library",
3
3
  "private": false,
4
- "version": "1.0.2",
4
+ "version": "1.0.3",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",