x-ui-design 0.6.21 → 0.6.23
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/dist/index.esm.js +24 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +24 -7
- package/dist/index.js.map +1 -1
- package/lib/components/Form/Form.tsx +19 -5
- package/lib/components/Form/Item/Item.tsx +10 -1
- package/lib/hooks/useForm.ts +1 -2
- package/package.json +1 -1
- package/src/app/page.tsx +3 -1
|
@@ -38,9 +38,10 @@ const Form: FC<FormProps> & { Item: FC<FormItemProps> } = ({
|
|
|
38
38
|
scrollToFirstError = false,
|
|
39
39
|
...rest
|
|
40
40
|
}) => {
|
|
41
|
-
const internalForm = useForm(initialValues, onFieldsChange, onValuesChange);
|
|
42
|
-
const formInstance = form || internalForm;
|
|
41
|
+
const internalForm = useForm(initialValues, onFieldsChange, onValuesChange);
|
|
43
42
|
const formRef = useRef<HTMLFormElement>(null);
|
|
43
|
+
|
|
44
|
+
const formInstance = useMemo(() => form || internalForm, [form, internalForm]);
|
|
44
45
|
|
|
45
46
|
const handleSubmit = async (e: SyntheticEvent) => {
|
|
46
47
|
e.preventDefault();
|
|
@@ -55,6 +56,8 @@ const Form: FC<FormProps> & { Item: FC<FormItemProps> } = ({
|
|
|
55
56
|
|
|
56
57
|
const childrenList = useMemo(() => flattenChildren(children), [children]);
|
|
57
58
|
|
|
59
|
+
const formClassName = useMemo(() => `${prefixCls} ${className}`.trim(), [prefixCls, className]);
|
|
60
|
+
|
|
58
61
|
useEffect(() => {
|
|
59
62
|
if (onFieldsChange) {
|
|
60
63
|
formInstance.setOnFieldsChange?.(onFieldsChange);
|
|
@@ -110,16 +113,27 @@ const Form: FC<FormProps> & { Item: FC<FormItemProps> } = ({
|
|
|
110
113
|
size={childProps.size || rest.size}
|
|
111
114
|
layout={childProps.layout || layout}
|
|
112
115
|
/>
|
|
113
|
-
}, [rest.size, layout
|
|
116
|
+
}, [rest.size, layout]);
|
|
117
|
+
|
|
118
|
+
console.info({
|
|
119
|
+
children,
|
|
120
|
+
form,
|
|
121
|
+
style,
|
|
122
|
+
prefixCls,
|
|
123
|
+
className,
|
|
124
|
+
initialValues,
|
|
125
|
+
layout,
|
|
126
|
+
scrollToFirstError,
|
|
127
|
+
...rest
|
|
128
|
+
});
|
|
114
129
|
|
|
115
|
-
console.info(1)
|
|
116
130
|
return (
|
|
117
131
|
<FormContext.Provider value={formInstance}>
|
|
118
132
|
<form
|
|
119
133
|
style={style}
|
|
120
134
|
ref={formRef}
|
|
121
135
|
onSubmit={handleSubmit}
|
|
122
|
-
className={
|
|
136
|
+
className={formClassName}
|
|
123
137
|
>
|
|
124
138
|
{Children.map(childrenList, child => injectPropsIntoFinalLeaf(child))}
|
|
125
139
|
</form>
|
|
@@ -160,6 +160,7 @@ const FormItemChildComponent = memo(({
|
|
|
160
160
|
getFieldsValue,
|
|
161
161
|
getFieldValue,
|
|
162
162
|
setFieldValue,
|
|
163
|
+
subscribeToField,
|
|
163
164
|
subscribeToFields,
|
|
164
165
|
validateFields
|
|
165
166
|
} = formContext || {};
|
|
@@ -167,12 +168,20 @@ const FormItemChildComponent = memo(({
|
|
|
167
168
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
168
169
|
// @ts-expect-error
|
|
169
170
|
const { onChange, value } = child.props;
|
|
170
|
-
const fieldValue = value ?? getFieldValue?.(name) ?? initialValue;
|
|
171
|
+
const [fieldValue, _setFieldValue] = useState(value ?? getFieldValue?.(name) ?? initialValue);
|
|
171
172
|
|
|
172
173
|
useEffect(() => {
|
|
173
174
|
if (initialValue) {
|
|
174
175
|
setFieldValue?.(name, initialValue);
|
|
175
176
|
}
|
|
177
|
+
|
|
178
|
+
const unsubscribe = subscribeToField?.(name, (value) => {
|
|
179
|
+
_setFieldValue(value);
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
return () => {
|
|
183
|
+
unsubscribe?.();
|
|
184
|
+
}
|
|
176
185
|
}, []);
|
|
177
186
|
|
|
178
187
|
useEffect(() => {
|
package/lib/hooks/useForm.ts
CHANGED
package/package.json
CHANGED
package/src/app/page.tsx
CHANGED
|
@@ -1860,7 +1860,9 @@ export default function Home() {
|
|
|
1860
1860
|
const [type, setType] = useState('full');
|
|
1861
1861
|
|
|
1862
1862
|
useEffect(() => {
|
|
1863
|
-
|
|
1863
|
+
// setInterval(() => {
|
|
1864
|
+
// form.setFieldsValue({ email: Date.now().toString() })
|
|
1865
|
+
// }, 1000);
|
|
1864
1866
|
}, [])
|
|
1865
1867
|
|
|
1866
1868
|
const disableDate = useCallback(
|