@bigbinary/neetoui 5.0.9 → 5.0.11

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/formik.d.ts CHANGED
@@ -24,8 +24,9 @@ export interface BlockNavigationProps {
24
24
  export interface Form {
25
25
  className?: string;
26
26
  children: React.ReactNode | ((props: FormikProps<any>) => React.ReactNode);
27
- formikProps: {[key: string]: any};
28
- formProps?: {[key: string]: any};
27
+ formikProps: { [key: string]: any };
28
+ formProps?: { [key: string]: any };
29
+ scrollToErrorField?: boolean;
29
30
  }
30
31
 
31
32
  export const ActionBlock: React.FC<ActionBlockProps>;
package/formik.js CHANGED
@@ -1506,6 +1506,37 @@ function _objectAssign(target) {
1506
1506
 
1507
1507
  var _objectAssign$1 = typeof Object.assign === 'function' ? Object.assign : _objectAssign;
1508
1508
 
1509
+ /**
1510
+ * See if an object (i.e. `val`) is an instance of the supplied constructor. This
1511
+ * function will check up the inheritance chain, if any.
1512
+ * If `val` was created using `Object.create`, `R.is(Object, val) === true`.
1513
+ *
1514
+ * @func
1515
+ * @memberOf R
1516
+ * @since v0.3.0
1517
+ * @category Type
1518
+ * @sig (* -> {*}) -> a -> Boolean
1519
+ * @param {Object} ctor A constructor
1520
+ * @param {*} val The value to test
1521
+ * @return {Boolean}
1522
+ * @example
1523
+ *
1524
+ * R.is(Object, {}); //=> true
1525
+ * R.is(Number, 1); //=> true
1526
+ * R.is(Object, 1); //=> false
1527
+ * R.is(String, 's'); //=> true
1528
+ * R.is(String, new String('')); //=> true
1529
+ * R.is(Object, new String('')); //=> true
1530
+ * R.is(Object, 's'); //=> false
1531
+ * R.is(Number, {}); //=> false
1532
+ */
1533
+
1534
+ var is =
1535
+ /*#__PURE__*/
1536
+ _curry2(function is(Ctor, val) {
1537
+ return val instanceof Ctor || val != null && (val.constructor === Ctor || Ctor.name === 'Object' && typeof val === 'object');
1538
+ });
1539
+
1509
1540
  /**
1510
1541
  * Returns `true` if the given value is its type's empty value; `false`
1511
1542
  * otherwise.
@@ -14035,7 +14066,7 @@ var FormikButton = /*#__PURE__*/forwardRef$1(function (_ref, ref) {
14035
14066
  values = _useFormikContext.values,
14036
14067
  initialValues = _useFormikContext.initialValues,
14037
14068
  isValid = _useFormikContext.isValid;
14038
- var isDisabled = disabled !== null && disabled !== void 0 ? disabled : isSubmitting || !isValid || equals(values, initialValues);
14069
+ var isDisabled = disabled !== null && disabled !== void 0 ? disabled : isSubmitting || equals(values, initialValues);
14039
14070
  return /*#__PURE__*/React__default.createElement(Button, _extends$2({
14040
14071
  disabled: isDisabled,
14041
14072
  loading: isSubmitting && isValid,
@@ -17477,8 +17508,9 @@ var BlockNavigation = function BlockNavigation(_ref) {
17477
17508
  };
17478
17509
  return /*#__PURE__*/React__default.createElement(Alert, {
17479
17510
  isOpen: isBlocked,
17480
- message: "Are you sure you want to continue? All of your unsaved changes will be lost.",
17481
- title: "You have unsaved changes!",
17511
+ message: "All of your unsaved changes will be lost. This can't be undone.",
17512
+ submitButtonLabel: "Discard changes",
17513
+ title: "You have unsaved changes",
17482
17514
  onClose: hidePrompt,
17483
17515
  onSubmit: continueAction
17484
17516
  });
@@ -18092,12 +18124,76 @@ try {
18092
18124
  }
18093
18125
  }
18094
18126
 
18127
+ function _arrayWithoutHoles$1(arr) {
18128
+ if (Array.isArray(arr)) return _arrayLikeToArray$1(arr);
18129
+ }
18130
+
18131
+ function _iterableToArray$1(iter) {
18132
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
18133
+ }
18134
+
18135
+ function _nonIterableSpread$1() {
18136
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
18137
+ }
18138
+
18139
+ function _toConsumableArray$1(arr) {
18140
+ return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _unsupportedIterableToArray$1(arr) || _nonIterableSpread$1();
18141
+ }
18142
+
18143
+ var transformObjectToDotNotation = function transformObjectToDotNotation(object) {
18144
+ var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
18145
+ var result = [];
18146
+ Object.entries(object).forEach(function (_ref) {
18147
+ var _ref2 = _slicedToArray$1(_ref, 2),
18148
+ key = _ref2[0],
18149
+ value = _ref2[1];
18150
+ if (value) {
18151
+ var nextKey = prefix ? "".concat(prefix, ".").concat(key) : key;
18152
+ if (is(Object, value)) {
18153
+ result.push.apply(result, _toConsumableArray$1(transformObjectToDotNotation(value, nextKey)));
18154
+ } else {
18155
+ result.push(nextKey);
18156
+ }
18157
+ }
18158
+ });
18159
+ return result;
18160
+ };
18161
+ var getErrorFieldName = function getErrorFieldName(formikErrors) {
18162
+ var _transformObjectToDot;
18163
+ return (_transformObjectToDot = transformObjectToDotNotation(formikErrors)) === null || _transformObjectToDot === void 0 ? void 0 : _transformObjectToDot[0];
18164
+ };
18165
+
18166
+ var ScrollToErrorField = function ScrollToErrorField(_ref) {
18167
+ var formRef = _ref.formRef;
18168
+ var _useFormikContext = useFormikContext(),
18169
+ submitCount = _useFormikContext.submitCount,
18170
+ isValid = _useFormikContext.isValid,
18171
+ errors = _useFormikContext.errors;
18172
+ var isValidatedReference = useRef(false);
18173
+ useEffect(function () {
18174
+ isValidatedReference.current = false;
18175
+ }, [submitCount]);
18176
+ useEffect(function () {
18177
+ if (!formRef.current || isValidatedReference.current || isValid) return;
18178
+ isValidatedReference.current = true;
18179
+ var fieldErrorName = getErrorFieldName(errors);
18180
+ if (!fieldErrorName) return;
18181
+ var errorFormElement = formRef.current.querySelector("[name=".concat(fieldErrorName, "]"));
18182
+ errorFormElement === null || errorFormElement === void 0 ? void 0 : errorFormElement.scrollIntoView({
18183
+ behavior: "smooth",
18184
+ block: "center"
18185
+ });
18186
+ }, [submitCount, errors]);
18187
+ return null;
18188
+ };
18189
+
18095
18190
  var _excluded$j = ["values", "validateForm", "setErrors", "setTouched"];
18096
18191
  var FormWrapper = /*#__PURE__*/forwardRef$1(function (_ref, formRef) {
18097
18192
  var className = _ref.className,
18098
18193
  formProps = _ref.formProps,
18099
18194
  children = _ref.children,
18100
- onSubmit = _ref.onSubmit;
18195
+ onSubmit = _ref.onSubmit,
18196
+ scrollToErrorField = _ref.scrollToErrorField;
18101
18197
  var _useFormikContext = useFormikContext(),
18102
18198
  values = _useFormikContext.values,
18103
18199
  validateForm = _useFormikContext.validateForm,
@@ -18106,6 +18202,7 @@ var FormWrapper = /*#__PURE__*/forwardRef$1(function (_ref, formRef) {
18106
18202
  formikBag = _objectWithoutProperties$1(_useFormikContext, _excluded$j);
18107
18203
  var isFormDirty = formikBag.dirty,
18108
18204
  isSubmitting = formikBag.isSubmitting;
18205
+ var formRefForScrollToErrorFiled = useRef();
18109
18206
  var handleKeyDown = useCallback( /*#__PURE__*/function () {
18110
18207
  var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(event) {
18111
18208
  var isEventFromEditorOrTextarea, errors;
@@ -18170,9 +18267,11 @@ var FormWrapper = /*#__PURE__*/forwardRef$1(function (_ref, formRef) {
18170
18267
  noValidate: true,
18171
18268
  className: className,
18172
18269
  "data-testid": "neeto-ui-form-wrapper",
18173
- ref: formRef,
18270
+ ref: formRef || formRefForScrollToErrorFiled,
18174
18271
  onKeyDown: handleKeyDown
18175
- }, formProps), children);
18272
+ }, formProps), scrollToErrorField && /*#__PURE__*/React__default.createElement(ScrollToErrorField, {
18273
+ formRef: formRef || formRefForScrollToErrorFiled
18274
+ }), children);
18176
18275
  });
18177
18276
  FormWrapper.displayName = "FormWrapper";
18178
18277
 
@@ -18180,12 +18279,15 @@ var Form = /*#__PURE__*/forwardRef$1(function (_ref, ref) {
18180
18279
  var className = _ref.className,
18181
18280
  children = _ref.children,
18182
18281
  formikProps = _ref.formikProps,
18183
- formProps = _ref.formProps;
18282
+ formProps = _ref.formProps,
18283
+ _ref$scrollToErrorFie = _ref.scrollToErrorField,
18284
+ scrollToErrorField = _ref$scrollToErrorFie === void 0 ? true : _ref$scrollToErrorFie;
18184
18285
  return /*#__PURE__*/React__default.createElement(Formik, formikProps, function (props) {
18185
18286
  return /*#__PURE__*/React__default.createElement(FormWrapper, {
18186
18287
  className: className,
18187
18288
  formProps: formProps,
18188
18289
  ref: ref,
18290
+ scrollToErrorField: scrollToErrorField,
18189
18291
  onSubmit: formikProps === null || formikProps === void 0 ? void 0 : formikProps.onSubmit
18190
18292
  }, typeof children === "function" ? children(props) : children);
18191
18293
  });
@@ -18211,7 +18313,11 @@ Form.propTypes = {
18211
18313
  * Refer to the Formik docs for more details
18212
18314
  * https://formik.org/docs/api/form
18213
18315
  **/
18214
- formProps: propTypes.exports.object
18316
+ formProps: propTypes.exports.object,
18317
+ /**
18318
+ * Props to be passed for scrolling to error field on submit button click.
18319
+ **/
18320
+ scrollToErrorField: propTypes.exports.bool
18215
18321
  };
18216
18322
 
18217
18323
  var _excluded$i = ["size", "type", "label", "error", "suffix", "prefix", "disabled", "helpText", "className", "nakedInput", "contentSize", "required", "maxLength", "unlimitedChars", "labelProps"];
@@ -18346,22 +18452,6 @@ FormikInput.propTypes = {
18346
18452
  name: propTypes.exports.string
18347
18453
  };
18348
18454
 
18349
- function _arrayWithoutHoles$1(arr) {
18350
- if (Array.isArray(arr)) return _arrayLikeToArray$1(arr);
18351
- }
18352
-
18353
- function _iterableToArray$1(iter) {
18354
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
18355
- }
18356
-
18357
- function _nonIterableSpread$1() {
18358
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
18359
- }
18360
-
18361
- function _toConsumableArray$1(arr) {
18362
- return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _unsupportedIterableToArray$1(arr) || _nonIterableSpread$1();
18363
- }
18364
-
18365
18455
  function _extends() {
18366
18456
  _extends = Object.assign ? Object.assign.bind() : function (target) {
18367
18457
  for (var i = 1; i < arguments.length; i++) {