x-ui-design 0.6.21 → 0.6.22

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,7 +38,7 @@ const Form: FC<FormProps> & { Item: FC<FormItemProps> } = ({
38
38
  scrollToFirstError = false,
39
39
  ...rest
40
40
  }) => {
41
- const internalForm = useForm(initialValues, onFieldsChange, onValuesChange);
41
+ const internalForm = useForm(initialValues, onFieldsChange, onValuesChange);
42
42
  const formInstance = form || internalForm;
43
43
  const formRef = useRef<HTMLFormElement>(null);
44
44
 
@@ -55,6 +55,8 @@ const Form: FC<FormProps> & { Item: FC<FormItemProps> } = ({
55
55
 
56
56
  const childrenList = useMemo(() => flattenChildren(children), [children]);
57
57
 
58
+ const formClassName = useMemo(() => `${prefixCls} ${className}`.trim(), [prefixCls, className]);
59
+
58
60
  useEffect(() => {
59
61
  if (onFieldsChange) {
60
62
  formInstance.setOnFieldsChange?.(onFieldsChange);
@@ -110,16 +112,27 @@ const Form: FC<FormProps> & { Item: FC<FormItemProps> } = ({
110
112
  size={childProps.size || rest.size}
111
113
  layout={childProps.layout || layout}
112
114
  />
113
- }, [rest.size, layout, flattenChildren]);
115
+ }, [rest.size, layout]);
116
+
117
+ console.info({
118
+ children,
119
+ form,
120
+ style,
121
+ prefixCls,
122
+ className,
123
+ initialValues,
124
+ layout,
125
+ scrollToFirstError,
126
+ ...rest
127
+ });
114
128
 
115
- console.info(1)
116
129
  return (
117
130
  <FormContext.Provider value={formInstance}>
118
131
  <form
119
132
  style={style}
120
133
  ref={formRef}
121
134
  onSubmit={handleSubmit}
122
- className={`${prefixCls} ${className}`}
135
+ className={formClassName}
123
136
  >
124
137
  {Children.map(childrenList, child => injectPropsIntoFinalLeaf(child))}
125
138
  </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.22",
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(