@hw-component/form 1.2.2 → 1.2.4
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/es/Form/FormItem/BasicItem.js +3 -2
- package/es/Form/FormItem/hooks.d.ts +3 -0
- package/es/Form/FormItem/hooks.js +4 -1
- package/es/Form/modal.d.ts +3 -2
- package/lib/Form/FormItem/BasicItem.js +2 -1
- package/lib/Form/FormItem/hooks.d.ts +3 -0
- package/lib/Form/FormItem/hooks.js +4 -0
- package/lib/Form/modal.d.ts +3 -2
- package/package.json +1 -1
- package/src/components/Form/FormItem/BasicItem.tsx +3 -2
- package/src/components/Form/FormItem/hooks.tsx +6 -1
- package/src/components/Form/modal.ts +3 -2
- package/src/pages/Form/index.tsx +7 -1
|
@@ -15,7 +15,7 @@ import { Col, Form, Space } from 'antd';
|
|
|
15
15
|
import React from 'react';
|
|
16
16
|
import Index$2 from './Helper.js';
|
|
17
17
|
import { useClassName } from '../../hooks/index.js';
|
|
18
|
-
import { usePositionClassName, useHide } from './hooks.js';
|
|
18
|
+
import { usePositionClassName, useHide, useFormItemLabel } from './hooks.js';
|
|
19
19
|
import { useFormContext } from '../Context/index.js';
|
|
20
20
|
import { useDefaultRender } from '../hooks/useDefaultRender.js';
|
|
21
21
|
import { useDefaultComponents } from '../hooks/index.js';
|
|
@@ -92,6 +92,7 @@ var Index = function Index(props) {
|
|
|
92
92
|
hide: hide,
|
|
93
93
|
form: form
|
|
94
94
|
});
|
|
95
|
+
var formItemLabel = useFormItemLabel(form, label);
|
|
95
96
|
if (hideItem) {
|
|
96
97
|
return null;
|
|
97
98
|
}
|
|
@@ -104,7 +105,7 @@ var Index = function Index(props) {
|
|
|
104
105
|
labelWidth: labelWidth,
|
|
105
106
|
required: required,
|
|
106
107
|
colon: colon,
|
|
107
|
-
children:
|
|
108
|
+
children: formItemLabel
|
|
108
109
|
})
|
|
109
110
|
}, oProps), {}, {
|
|
110
111
|
style: style || formItemStyle,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import React from "react";
|
|
1
2
|
import type { HFormInstance, HItemProps } from "../modal";
|
|
2
3
|
import type { LabelAlignModal } from "../modal";
|
|
4
|
+
import { HelperModal } from "../modal";
|
|
3
5
|
export declare const useFormItemDomControl: ({ shouldUpdate, hide, dependencies, }: HItemProps) => ({ shouldUpdate, dependencies, hide, itemSpan, ...props }: import("../modal").HFormItemProps) => JSX.Element;
|
|
4
6
|
interface UseHideUpItemModal extends Omit<HItemProps, "name"> {
|
|
5
7
|
form: HFormInstance;
|
|
@@ -7,4 +9,5 @@ interface UseHideUpItemModal extends Omit<HItemProps, "name"> {
|
|
|
7
9
|
export declare const useShouldUpdate: ({ hide, shouldUpdate, }: Omit<HItemProps, "name">) => import("rc-field-form/lib/Field").ShouldUpdate<any> | undefined;
|
|
8
10
|
export declare const useHide: ({ hide, form }: UseHideUpItemModal) => boolean;
|
|
9
11
|
export declare const usePositionClassName: (position: LabelAlignModal) => string;
|
|
12
|
+
export declare const useFormItemLabel: (form: HFormInstance, label?: React.ReactNode | HelperModal) => any;
|
|
10
13
|
export {};
|
|
@@ -45,6 +45,9 @@ var usePositionClassName = function usePositionClassName(position) {
|
|
|
45
45
|
var className = classNameData[position];
|
|
46
46
|
return useClassName(className);
|
|
47
47
|
};
|
|
48
|
+
var useFormItemLabel = function useFormItemLabel(form, label) {
|
|
49
|
+
return typeof label === "function" ? label(form) : label;
|
|
50
|
+
};
|
|
48
51
|
|
|
49
|
-
export { useFormItemDomControl, useHide, usePositionClassName, useShouldUpdate };
|
|
52
|
+
export { useFormItemDomControl, useFormItemLabel, useHide, usePositionClassName, useShouldUpdate };
|
|
50
53
|
// powered by hdj
|
package/es/Form/modal.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface HoverModal {
|
|
|
22
22
|
text?: string;
|
|
23
23
|
icon?: React.ReactNode;
|
|
24
24
|
}
|
|
25
|
-
type HelperModal = (form: HFormInstance) => React.ReactNode | string;
|
|
25
|
+
export type HelperModal = (form: HFormInstance) => React.ReactNode | string;
|
|
26
26
|
export type HideModal = (form: HFormInstance) => boolean;
|
|
27
27
|
export type AddDispatchListenerFn = (action: ActionModal, fn: argsFn) => void;
|
|
28
28
|
export type DispatchSourceDataModal = Record<string, Record<string, DispatchModal>>;
|
|
@@ -33,7 +33,7 @@ export interface DispatchModal<T = string | string[]> {
|
|
|
33
33
|
reset?: boolean;
|
|
34
34
|
}
|
|
35
35
|
export type LabelAlignModal = "left" | "right" | "topLeft" | "topRight" | "top";
|
|
36
|
-
export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign"> {
|
|
36
|
+
export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign" | "label"> {
|
|
37
37
|
type?: string;
|
|
38
38
|
itemProps?: ItemPropsType;
|
|
39
39
|
render?: RenderFun;
|
|
@@ -47,6 +47,7 @@ export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign"> {
|
|
|
47
47
|
itemSpan?: ColProps;
|
|
48
48
|
hideLabel?: boolean;
|
|
49
49
|
labelAlign?: LabelAlignModal;
|
|
50
|
+
label?: React.ReactNode | HelperModal;
|
|
50
51
|
}
|
|
51
52
|
export interface HFormProps<T = any, R = any> extends Omit<FormProps, "form" | "onFinish" | "labelAlign"> {
|
|
52
53
|
configData: HItemProps[];
|
|
@@ -95,6 +95,7 @@ var Index = function Index(props) {
|
|
|
95
95
|
hide: hide,
|
|
96
96
|
form: form
|
|
97
97
|
});
|
|
98
|
+
var formItemLabel = hooks.useFormItemLabel(form, label);
|
|
98
99
|
if (hideItem) {
|
|
99
100
|
return null;
|
|
100
101
|
}
|
|
@@ -107,7 +108,7 @@ var Index = function Index(props) {
|
|
|
107
108
|
labelWidth: labelWidth,
|
|
108
109
|
required: required,
|
|
109
110
|
colon: colon,
|
|
110
|
-
children:
|
|
111
|
+
children: formItemLabel
|
|
111
112
|
})
|
|
112
113
|
}, oProps), {}, {
|
|
113
114
|
style: style || formItemStyle,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import React from "react";
|
|
1
2
|
import type { HFormInstance, HItemProps } from "../modal";
|
|
2
3
|
import type { LabelAlignModal } from "../modal";
|
|
4
|
+
import { HelperModal } from "../modal";
|
|
3
5
|
export declare const useFormItemDomControl: ({ shouldUpdate, hide, dependencies, }: HItemProps) => ({ shouldUpdate, dependencies, hide, itemSpan, ...props }: import("../modal").HFormItemProps) => JSX.Element;
|
|
4
6
|
interface UseHideUpItemModal extends Omit<HItemProps, "name"> {
|
|
5
7
|
form: HFormInstance;
|
|
@@ -7,4 +9,5 @@ interface UseHideUpItemModal extends Omit<HItemProps, "name"> {
|
|
|
7
9
|
export declare const useShouldUpdate: ({ hide, shouldUpdate, }: Omit<HItemProps, "name">) => import("rc-field-form/lib/Field").ShouldUpdate<any> | undefined;
|
|
8
10
|
export declare const useHide: ({ hide, form }: UseHideUpItemModal) => boolean;
|
|
9
11
|
export declare const usePositionClassName: (position: LabelAlignModal) => string;
|
|
12
|
+
export declare const useFormItemLabel: (form: HFormInstance, label?: React.ReactNode | HelperModal) => any;
|
|
10
13
|
export {};
|
|
@@ -46,8 +46,12 @@ var usePositionClassName = function usePositionClassName(position) {
|
|
|
46
46
|
var className = classNameData[position];
|
|
47
47
|
return index.useClassName(className);
|
|
48
48
|
};
|
|
49
|
+
var useFormItemLabel = function useFormItemLabel(form, label) {
|
|
50
|
+
return typeof label === "function" ? label(form) : label;
|
|
51
|
+
};
|
|
49
52
|
|
|
50
53
|
exports.useFormItemDomControl = useFormItemDomControl;
|
|
54
|
+
exports.useFormItemLabel = useFormItemLabel;
|
|
51
55
|
exports.useHide = useHide;
|
|
52
56
|
exports.usePositionClassName = usePositionClassName;
|
|
53
57
|
exports.useShouldUpdate = useShouldUpdate;
|
package/lib/Form/modal.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface HoverModal {
|
|
|
22
22
|
text?: string;
|
|
23
23
|
icon?: React.ReactNode;
|
|
24
24
|
}
|
|
25
|
-
type HelperModal = (form: HFormInstance) => React.ReactNode | string;
|
|
25
|
+
export type HelperModal = (form: HFormInstance) => React.ReactNode | string;
|
|
26
26
|
export type HideModal = (form: HFormInstance) => boolean;
|
|
27
27
|
export type AddDispatchListenerFn = (action: ActionModal, fn: argsFn) => void;
|
|
28
28
|
export type DispatchSourceDataModal = Record<string, Record<string, DispatchModal>>;
|
|
@@ -33,7 +33,7 @@ export interface DispatchModal<T = string | string[]> {
|
|
|
33
33
|
reset?: boolean;
|
|
34
34
|
}
|
|
35
35
|
export type LabelAlignModal = "left" | "right" | "topLeft" | "topRight" | "top";
|
|
36
|
-
export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign"> {
|
|
36
|
+
export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign" | "label"> {
|
|
37
37
|
type?: string;
|
|
38
38
|
itemProps?: ItemPropsType;
|
|
39
39
|
render?: RenderFun;
|
|
@@ -47,6 +47,7 @@ export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign"> {
|
|
|
47
47
|
itemSpan?: ColProps;
|
|
48
48
|
hideLabel?: boolean;
|
|
49
49
|
labelAlign?: LabelAlignModal;
|
|
50
|
+
label?: React.ReactNode | HelperModal;
|
|
50
51
|
}
|
|
51
52
|
export interface HFormProps<T = any, R = any> extends Omit<FormProps, "form" | "onFinish" | "labelAlign"> {
|
|
52
53
|
configData: HItemProps[];
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@ import { Form, Space, Col } from "antd";
|
|
|
3
3
|
import React from "react";
|
|
4
4
|
import Helper from "./Helper";
|
|
5
5
|
import { useClassName } from "../../hooks";
|
|
6
|
-
import { useHide, usePositionClassName
|
|
6
|
+
import {useFormItemLabel, useHide, usePositionClassName} from "./hooks";
|
|
7
7
|
import { useFormContext } from "../Context";
|
|
8
8
|
import type { HItemProps } from "../modal";
|
|
9
9
|
import { useDefaultRender } from "../hooks/useDefaultRender";
|
|
@@ -67,6 +67,7 @@ const Index: React.FC<HFormItemProps> = (props) => {
|
|
|
67
67
|
);
|
|
68
68
|
const className = usePositionClassName(align);
|
|
69
69
|
const hideItem = useHide({ hide, form });
|
|
70
|
+
const formItemLabel=useFormItemLabel(form,label);
|
|
70
71
|
if (hideItem) {
|
|
71
72
|
return null;
|
|
72
73
|
}
|
|
@@ -82,7 +83,7 @@ const Index: React.FC<HFormItemProps> = (props) => {
|
|
|
82
83
|
required={required}
|
|
83
84
|
colon={colon}
|
|
84
85
|
>
|
|
85
|
-
{
|
|
86
|
+
{formItemLabel}
|
|
86
87
|
</Label>
|
|
87
88
|
)
|
|
88
89
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import UpFormItem from "./UpFormItem";
|
|
2
2
|
import RegularFormItem from "./RegularFormItem";
|
|
3
|
-
import { useMemo } from "react";
|
|
3
|
+
import React, { useMemo } from "react";
|
|
4
4
|
import type { HFormInstance, HItemProps } from "../modal";
|
|
5
5
|
import type { LabelAlignModal } from "../modal";
|
|
6
6
|
import { useClassName } from "../../hooks";
|
|
7
|
+
import {HelperModal} from "../modal";
|
|
7
8
|
|
|
8
9
|
export const useFormItemDomControl = ({
|
|
9
10
|
shouldUpdate,
|
|
@@ -52,3 +53,7 @@ export const usePositionClassName = (position: LabelAlignModal) => {
|
|
|
52
53
|
const className = classNameData[position];
|
|
53
54
|
return useClassName(className);
|
|
54
55
|
};
|
|
56
|
+
|
|
57
|
+
export const useFormItemLabel=(form:HFormInstance,label?:React.ReactNode|HelperModal,)=>{
|
|
58
|
+
return typeof label==="function"?label(form):label;
|
|
59
|
+
}
|
|
@@ -60,7 +60,7 @@ export interface HoverModal {
|
|
|
60
60
|
text?: string;
|
|
61
61
|
icon?: React.ReactNode;
|
|
62
62
|
}
|
|
63
|
-
type HelperModal = (form: HFormInstance) => React.ReactNode | string;
|
|
63
|
+
export type HelperModal = (form: HFormInstance) => React.ReactNode | string;
|
|
64
64
|
|
|
65
65
|
export type HideModal = (form: HFormInstance) => boolean;
|
|
66
66
|
|
|
@@ -77,7 +77,7 @@ export interface DispatchModal<T = string | string[]> {
|
|
|
77
77
|
}
|
|
78
78
|
export type LabelAlignModal = "left" | "right" | "topLeft" | "topRight" | "top";
|
|
79
79
|
|
|
80
|
-
export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign"> {
|
|
80
|
+
export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign"|"label"> {
|
|
81
81
|
type?: string;
|
|
82
82
|
itemProps?: ItemPropsType;
|
|
83
83
|
render?: RenderFun;
|
|
@@ -93,6 +93,7 @@ export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign"> {
|
|
|
93
93
|
itemSpan?: ColProps;
|
|
94
94
|
hideLabel?: boolean;
|
|
95
95
|
labelAlign?: LabelAlignModal;
|
|
96
|
+
label?:React.ReactNode|HelperModal;
|
|
96
97
|
}
|
|
97
98
|
export interface HFormProps<T = any, R = any>
|
|
98
99
|
extends Omit<FormProps, "form" | "onFinish" | "labelAlign"> {
|
package/src/pages/Form/index.tsx
CHANGED
|
@@ -35,10 +35,16 @@ const formData = () => {
|
|
|
35
35
|
},
|
|
36
36
|
},
|
|
37
37
|
{
|
|
38
|
-
label:
|
|
38
|
+
label:(form)=>{
|
|
39
|
+
const nameTest=form.getFieldValue("nameTest")
|
|
40
|
+
return nameTest;
|
|
41
|
+
},
|
|
39
42
|
name: "checkboxGroup",
|
|
40
43
|
type: "checkboxGroup",
|
|
41
44
|
rules: [{ required: true }],
|
|
45
|
+
shouldUpdate:()=>{
|
|
46
|
+
return true;
|
|
47
|
+
},
|
|
42
48
|
helper: "帮助我",
|
|
43
49
|
options: [
|
|
44
50
|
{ value: "选择1", key: "check1" },
|