elseware-ui 2.19.0 → 2.19.1

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,10 +1,13 @@
1
1
  import React from "react";
2
2
  export interface FormProps {
3
- initialValues?: object;
3
+ initialValues?: Record<string, any>;
4
4
  validationSchema?: object;
5
5
  enableReinitialize?: boolean;
6
6
  children?: React.ReactNode;
7
7
  styles?: string;
8
- onSubmit: any;
8
+ onSubmit: (values: any) => void;
9
+ onChange?: (values: Record<string, any>, meta?: {
10
+ changed: Record<string, any>;
11
+ }) => void;
9
12
  }
10
- export declare const Form: ({ initialValues, validationSchema, enableReinitialize, children, styles, onSubmit, }: FormProps) => import("react/jsx-runtime").JSX.Element;
13
+ export declare const Form: ({ initialValues, validationSchema, enableReinitialize, children, styles, onSubmit, onChange, }: FormProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { FormikProps } from "formik";
2
+ interface FormObserverProps {
3
+ formik: FormikProps<Record<string, any>>;
4
+ onChange?: (values: Record<string, any>, meta?: {
5
+ changed: Record<string, any>;
6
+ }) => void;
7
+ }
8
+ declare const FormObserver: ({ formik, onChange }: FormObserverProps) => null;
9
+ export default FormObserver;
package/build/index.es.js CHANGED
@@ -36283,14 +36283,31 @@ var ErrorMessageImpl = /*#__PURE__*/function (_React$Component) {
36283
36283
 
36284
36284
  var ErrorMessage = /*#__PURE__*/connect$1(ErrorMessageImpl);
36285
36285
 
36286
+ var FormObserver = function (_a) {
36287
+ var formik = _a.formik, onChange = _a.onChange;
36288
+ var prevValuesRef = useRef(formik.values);
36289
+ useEffect(function () {
36290
+ if (!onChange)
36291
+ return;
36292
+ var currentValues = formik.values;
36293
+ var prevValues = prevValuesRef.current;
36294
+ var changed = {};
36295
+ Object.keys(currentValues).forEach(function (key) {
36296
+ if (currentValues[key] !== prevValues[key]) {
36297
+ changed[key] = currentValues[key];
36298
+ }
36299
+ });
36300
+ if (Object.keys(changed).length > 0) {
36301
+ onChange(currentValues, { changed: changed });
36302
+ }
36303
+ prevValuesRef.current = currentValues;
36304
+ }, [formik.values, onChange]);
36305
+ return null;
36306
+ };
36307
+
36286
36308
  var Form = function (_a) {
36287
- var _b = _a.initialValues, initialValues = _b === void 0 ? {} : _b, validationSchema = _a.validationSchema, enableReinitialize = _a.enableReinitialize, children = _a.children, styles = _a.styles, onSubmit = _a.onSubmit;
36288
- return (jsx(Formik, __assign$1({ initialValues: initialValues, validationSchema: validationSchema, enableReinitialize: enableReinitialize, onSubmit: onSubmit }, { children: function (formik) {
36289
- var _a;
36290
- return (jsx(Form$1, { children: jsx("div", __assign$1({ className: classnames((_a = {},
36291
- _a["".concat(styles)] = styles,
36292
- _a)) }, { children: children })) }));
36293
- } })));
36309
+ var _b = _a.initialValues, initialValues = _b === void 0 ? {} : _b, validationSchema = _a.validationSchema, enableReinitialize = _a.enableReinitialize, children = _a.children, styles = _a.styles, onSubmit = _a.onSubmit, onChange = _a.onChange;
36310
+ return (jsx(Formik, __assign$1({ initialValues: initialValues, validationSchema: validationSchema, enableReinitialize: enableReinitialize, onSubmit: onSubmit }, { children: function (formik) { return (jsxs(Form$1, { children: [jsx(FormObserver, { formik: formik, onChange: onChange }), jsx("div", __assign$1({ className: classnames(styles) }, { children: children }))] })); } })));
36294
36311
  };
36295
36312
 
36296
36313
  var Backdrop = function (_a) {
package/build/index.js CHANGED
@@ -36310,14 +36310,31 @@ var ErrorMessageImpl = /*#__PURE__*/function (_React$Component) {
36310
36310
 
36311
36311
  var ErrorMessage = /*#__PURE__*/connect$1(ErrorMessageImpl);
36312
36312
 
36313
+ var FormObserver = function (_a) {
36314
+ var formik = _a.formik, onChange = _a.onChange;
36315
+ var prevValuesRef = React.useRef(formik.values);
36316
+ React.useEffect(function () {
36317
+ if (!onChange)
36318
+ return;
36319
+ var currentValues = formik.values;
36320
+ var prevValues = prevValuesRef.current;
36321
+ var changed = {};
36322
+ Object.keys(currentValues).forEach(function (key) {
36323
+ if (currentValues[key] !== prevValues[key]) {
36324
+ changed[key] = currentValues[key];
36325
+ }
36326
+ });
36327
+ if (Object.keys(changed).length > 0) {
36328
+ onChange(currentValues, { changed: changed });
36329
+ }
36330
+ prevValuesRef.current = currentValues;
36331
+ }, [formik.values, onChange]);
36332
+ return null;
36333
+ };
36334
+
36313
36335
  var Form = function (_a) {
36314
- var _b = _a.initialValues, initialValues = _b === void 0 ? {} : _b, validationSchema = _a.validationSchema, enableReinitialize = _a.enableReinitialize, children = _a.children, styles = _a.styles, onSubmit = _a.onSubmit;
36315
- return (jsxRuntime.jsx(Formik, __assign$1({ initialValues: initialValues, validationSchema: validationSchema, enableReinitialize: enableReinitialize, onSubmit: onSubmit }, { children: function (formik) {
36316
- var _a;
36317
- return (jsxRuntime.jsx(Form$1, { children: jsxRuntime.jsx("div", __assign$1({ className: classnames((_a = {},
36318
- _a["".concat(styles)] = styles,
36319
- _a)) }, { children: children })) }));
36320
- } })));
36336
+ var _b = _a.initialValues, initialValues = _b === void 0 ? {} : _b, validationSchema = _a.validationSchema, enableReinitialize = _a.enableReinitialize, children = _a.children, styles = _a.styles, onSubmit = _a.onSubmit, onChange = _a.onChange;
36337
+ return (jsxRuntime.jsx(Formik, __assign$1({ initialValues: initialValues, validationSchema: validationSchema, enableReinitialize: enableReinitialize, onSubmit: onSubmit }, { children: function (formik) { return (jsxRuntime.jsxs(Form$1, { children: [jsxRuntime.jsx(FormObserver, { formik: formik, onChange: onChange }), jsxRuntime.jsx("div", __assign$1({ className: classnames(styles) }, { children: children }))] })); } })));
36321
36338
  };
36322
36339
 
36323
36340
  var Backdrop = function (_a) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elseware-ui",
3
- "version": "2.19.0",
3
+ "version": "2.19.1",
4
4
  "private": false,
5
5
  "description": "A modern and customizable React UI component library by elseware Technology.",
6
6
  "keywords": [