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.
@@ -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, flattenChildren]);
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={`${prefixCls} ${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(() => {
@@ -367,8 +367,7 @@ const useForm = (
367
367
  ) {
368
368
  const fieldCallbacks = names.map(name =>
369
369
  subscribeToField(name, () => {
370
- const updatedValues = getFieldsValue(names);
371
- callback(updatedValues);
370
+ callback(getFieldsValue(names));
372
371
  })
373
372
  );
374
373
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-ui-design",
3
- "version": "0.6.21",
3
+ "version": "0.6.23",
4
4
  "license": "ISC",
5
5
  "author": "Gabriel Boyajyan",
6
6
  "main": "dist/index.js",
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
- form.setFieldsValue({ type: 'partial' })
1863
+ // setInterval(() => {
1864
+ // form.setFieldsValue({ email: Date.now().toString() })
1865
+ // }, 1000);
1864
1866
  }, [])
1865
1867
 
1866
1868
  const disableDate = useCallback(