revdev-components 0.21.0 → 0.23.0

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.
@@ -1,19 +1,17 @@
1
1
  import React from "react";
2
2
  import { FormInstance } from "antd/lib/form";
3
- import { Store } from "antd/es/form/interface";
4
3
  import { FieldData } from "../interfaces";
5
4
  export interface FormOptions {
6
5
  valid: boolean;
7
6
  }
8
- export interface AppFormProps {
7
+ export interface AppFormProps<T = any> {
9
8
  children?: React.ReactNode | ((options: FormOptions) => React.ReactNode);
10
9
  className?: string;
11
- onFinish?: (values: any) => void;
12
- onValuesChange?: (changedValues: any, values: any) => void;
13
- onChange?: (values: any) => void;
10
+ onFinish?: (values: T) => void;
11
+ onValuesChange?: (changedValues: Partial<T>, values: T) => void;
14
12
  onFieldsChange?: (changedFields: FieldData[], allFields: FieldData[]) => void;
15
13
  form?: FormInstance;
16
14
  onValid?: (valid: boolean) => void;
17
- initialValues?: Store;
15
+ initialValues?: Partial<T>;
18
16
  }
19
- export declare const AppForm: React.FC<AppFormProps>;
17
+ export declare function AppForm<T = any>({ form: propForm, children, className, onFinish, onValuesChange, onFieldsChange, onValid, initialValues, }: AppFormProps<T>): React.ReactElement<AppFormProps<T>>;
package/build/index.js CHANGED
@@ -4620,28 +4620,11 @@ function useForm(form) {
4620
4620
  var newForm = antd.Form.useForm()[0];
4621
4621
  return form ? form : newForm;
4622
4622
  }
4623
- var AppForm = function (_a) {
4624
- var propForm = _a.form, children = _a.children, className = _a.className, onFinish = _a.onFinish, onValuesChange = _a.onValuesChange, onChange = _a.onChange, onFieldsChange = _a.onFieldsChange, onValid = _a.onValid, initialValues = _a.initialValues;
4623
+ function AppForm(_a) {
4624
+ var propForm = _a.form, children = _a.children, className = _a.className, onFinish = _a.onFinish, onValuesChange = _a.onValuesChange, onFieldsChange = _a.onFieldsChange, onValid = _a.onValid, initialValues = _a.initialValues;
4625
4625
  var form = useForm(propForm);
4626
4626
  var _b = React.useState(false), valid = _b[0], setValid = _b[1];
4627
4627
  var values = antd.Form.useWatch([], form);
4628
- var handleValuesChange = React.useCallback(function (changedValues, values) {
4629
- if (onValuesChange) {
4630
- onValuesChange(changedValues, values);
4631
- }
4632
- }, [form, onValuesChange]);
4633
- var handleFieldsChange = React.useCallback(function (changedFields, allFields) {
4634
- if (onFieldsChange) {
4635
- onFieldsChange(changedFields, allFields);
4636
- }
4637
- if (onChange) {
4638
- var allValues_1 = {};
4639
- allFields.forEach(function (x) {
4640
- allValues_1[x.name] = x.value;
4641
- });
4642
- onChange(allValues_1);
4643
- }
4644
- }, [form, onFieldsChange, onChange]);
4645
4628
  React.useEffect(function () {
4646
4629
  form
4647
4630
  .validateFields({ validateOnly: true })
@@ -4651,8 +4634,8 @@ var AppForm = function (_a) {
4651
4634
  React.useEffect(function () {
4652
4635
  onValid === null || onValid === void 0 ? void 0 : onValid(valid);
4653
4636
  }, [onValid, valid]);
4654
- return (React.createElement(antd.Form, { form: form, onFinish: onFinish, className: classNames(s$g.root, className), layout: "vertical", onValuesChange: handleValuesChange, onFieldsChange: handleFieldsChange, initialValues: initialValues }, typeof children === "function" ? children({ valid: valid }) : children));
4655
- };
4637
+ return (React.createElement(antd.Form, { form: form, onFinish: onFinish, className: classNames(s$g.root, className), layout: "vertical", onValuesChange: onValuesChange, onFieldsChange: onFieldsChange, initialValues: initialValues }, typeof children === "function" ? children({ valid: valid }) : children));
4638
+ }
4656
4639
 
4657
4640
  var s$f = {"root":"index-module_root__2S1Jp"};
4658
4641
 
@@ -1,9 +1,9 @@
1
1
  export interface FieldData {
2
- touched: boolean;
3
- validating: boolean;
4
- errors: string[];
5
- warnings: string[];
2
+ touched?: boolean;
3
+ validating?: boolean;
4
+ errors?: string[];
5
+ warnings?: string[];
6
6
  name: string;
7
- validated: boolean;
7
+ validated?: boolean;
8
8
  value?: any;
9
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revdev-components",
3
- "version": "0.21.0",
3
+ "version": "0.23.0",
4
4
  "main": "build/index.js",
5
5
  "module": "build/index.esm.js",
6
6
  "scripts": {