@jswork/react-ant-form-schema 1.0.1
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.
- package/README.md +7 -0
- package/dist/main.cjs.js +157 -0
- package/dist/main.cjs.js.map +1 -0
- package/dist/main.d.mts +34 -0
- package/dist/main.d.ts +34 -0
- package/dist/main.esm.js +155 -0
- package/dist/main.esm.js.map +1 -0
- package/dist/style.css +2 -0
- package/dist/style.css.map +1 -0
- package/dist/style.scss +3 -0
- package/package.json +51 -0
- package/src/index.tsx +67 -0
- package/src/main.tsx +3 -0
- package/src/setup.ts +4 -0
- package/src/style.scss +3 -0
- package/src/utils.ts +19 -0
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"src/style.scss"}
|
package/dist/style.scss
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jswork/react-ant-form-schema",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"main": "dist/main.cjs.js",
|
|
5
|
+
"module": "dist/main.esm.js",
|
|
6
|
+
"types": "dist/main.d.ts",
|
|
7
|
+
"description": "Antd form builder for react.",
|
|
8
|
+
"homepage": "https://js.work",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"src"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsup",
|
|
16
|
+
"postbuild": "postsass -s src/style.scss -d dist/style.css -c",
|
|
17
|
+
"release": "release-it"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@swc/core": "^1.3.93",
|
|
21
|
+
"@types/react": "^18.2.28",
|
|
22
|
+
"@types/react-dom": "^18.2.13",
|
|
23
|
+
"antd": "^5.27.5",
|
|
24
|
+
"autoprefixer": "^10.4.16",
|
|
25
|
+
"classnames": "^2.5.1",
|
|
26
|
+
"cssnano": "^6.0.1",
|
|
27
|
+
"react": "^18.2.0",
|
|
28
|
+
"react-dom": "^18.2.0",
|
|
29
|
+
"tsup": "^8.2.4",
|
|
30
|
+
"typescript": "^5.2.2"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"classnames": "*",
|
|
34
|
+
"react": "*",
|
|
35
|
+
"react-dom": "*"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public",
|
|
39
|
+
"registry": "https://registry.npmjs.org"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@ebay/nice-form-react": "^2.0.3"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"form",
|
|
46
|
+
"schema",
|
|
47
|
+
"builder",
|
|
48
|
+
"ant",
|
|
49
|
+
"react"
|
|
50
|
+
]
|
|
51
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import cx from 'classnames';
|
|
2
|
+
import React, { FC, ReactNode } from 'react';
|
|
3
|
+
import { Form, FormProps, Spin } from 'antd';
|
|
4
|
+
import NiceForm, { NiceFormMeta } from '@ebay/nice-form-react';
|
|
5
|
+
import { deepMerge } from './utils';
|
|
6
|
+
|
|
7
|
+
const CLASS_NAME = 'react-ant-form-schema';
|
|
8
|
+
const DEFAULT_META = {
|
|
9
|
+
layout: 'vertical',
|
|
10
|
+
wrapperProps: {
|
|
11
|
+
labelCol: {
|
|
12
|
+
span: 4,
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type ReactAntdFormSchemaProps = {
|
|
18
|
+
/**
|
|
19
|
+
* The extended className for component.
|
|
20
|
+
* @default ''
|
|
21
|
+
*/
|
|
22
|
+
className?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The form schema meta data.
|
|
25
|
+
*/
|
|
26
|
+
meta: NiceFormMeta;
|
|
27
|
+
/**
|
|
28
|
+
* The header content.
|
|
29
|
+
*/
|
|
30
|
+
header?: ReactNode;
|
|
31
|
+
/**
|
|
32
|
+
* The footer content.
|
|
33
|
+
*/
|
|
34
|
+
footer?: ReactNode;
|
|
35
|
+
/**
|
|
36
|
+
* The form content.
|
|
37
|
+
*/
|
|
38
|
+
footerClassName?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Form loading status.
|
|
41
|
+
*/
|
|
42
|
+
loading?: boolean;
|
|
43
|
+
} & FormProps;
|
|
44
|
+
|
|
45
|
+
const ReactAntdFormSchema: FC<ReactAntdFormSchemaProps> = (props) => {
|
|
46
|
+
const { className, meta, header, footer, children, loading, footerClassName, ...rest } = props;
|
|
47
|
+
const footerNode = footer || (children as ReactNode);
|
|
48
|
+
const _meta = deepMerge(DEFAULT_META, meta);
|
|
49
|
+
const _offset = _meta?.wrapperProps?.labelCol?.span || 4;
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<Form data-component={CLASS_NAME} className={cx(CLASS_NAME, className)} {...rest}>
|
|
53
|
+
<Spin spinning={loading}>
|
|
54
|
+
{header}
|
|
55
|
+
<NiceForm meta={_meta} />
|
|
56
|
+
<Form.Item
|
|
57
|
+
wrapperCol={{ offset: _offset }}
|
|
58
|
+
className={footerClassName}
|
|
59
|
+
style={{ marginBottom: 0 }}>
|
|
60
|
+
{footerNode}
|
|
61
|
+
</Form.Item>
|
|
62
|
+
</Spin>
|
|
63
|
+
</Form>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export default ReactAntdFormSchema;
|
package/src/main.tsx
ADDED
package/src/setup.ts
ADDED
package/src/style.scss
ADDED
package/src/utils.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Author: aric 1290657123@qq.com
|
|
3
|
+
* @Date: 2025-10-18 21:20:55
|
|
4
|
+
* @LastEditors: aric 1290657123@qq.com
|
|
5
|
+
* @LastEditTime: 2025-10-18 21:21:09
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export function deepMerge(target, source) {
|
|
9
|
+
const result = { ...target };
|
|
10
|
+
for (const key in source) {
|
|
11
|
+
if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
|
|
12
|
+
result[key] = deepMerge(result[key] || {}, source[key]);
|
|
13
|
+
} else {
|
|
14
|
+
result[key] = source[key];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
|