@itcase/forms 1.0.13 → 1.0.14

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.
@@ -2145,8 +2145,12 @@ TextareaField.propTypes = {
2145
2145
  inputProps: PropTypes__default.default.object
2146
2146
  };
2147
2147
 
2148
- function focusOnError(formElementsList, errors) {
2148
+ var focusOnError = function focusOnError(formElementsList, errors) {
2149
2149
  var selectsIds = Object.keys(errors).map(function (fieldName) {
2150
+ if (fieldName === finalForm.FORM_ERROR) {
2151
+ // TODO: get from somewhere
2152
+ return 'notification__item_status_error';
2153
+ }
2150
2154
  return "react-select-id_" + fieldName + "-input";
2151
2155
  });
2152
2156
  var errorFieldElement = formElementsList.find(function (element) {
@@ -2160,9 +2164,14 @@ function focusOnError(formElementsList, errors) {
2160
2164
  if (!errorFieldElement && errorsList.length) {
2161
2165
  var errorElement;
2162
2166
  try {
2163
- errorElement = document.querySelector("#" + errorsList[0] + "-error");
2164
- if (!errorElement) {
2165
- errorElement = document.querySelector("#id_" + errorsList[0]);
2167
+ var fieldName = errorsList[0];
2168
+ if (fieldName === finalForm.FORM_ERROR) {
2169
+ errorElement = document.querySelector('notification__item_status_error');
2170
+ } else {
2171
+ errorElement = document.querySelector("#" + fieldName + "-error");
2172
+ if (!errorElement) {
2173
+ errorElement = document.querySelector("#id_" + fieldName);
2174
+ }
2166
2175
  }
2167
2176
  } catch (err) {
2168
2177
  console.warn(err);
@@ -2182,31 +2191,42 @@ function focusOnError(formElementsList, errors) {
2182
2191
  });
2183
2192
  }
2184
2193
  return null;
2185
- }
2194
+ };
2186
2195
  var focusOnErrorDecorator = createDecorator__default.default(null, focusOnError);
2187
- function setErrorsMutator(args, state) {
2196
+ var setErrorsMutator = function setErrorsMutator(args, state) {
2188
2197
  var fieldName = args[0],
2189
2198
  data = args[1];
2190
- var fieldError = data.error || data.submitError;
2199
+ var submitError = data.submitError;
2200
+ var fieldError = data.error;
2191
2201
  if (fieldName === 'non_field_errors') {
2192
- state.formState.error = fieldError;
2193
2202
  // state.formState.invalid = true
2194
2203
  // state.formState.valid = false
2195
- state.formState.submitError = fieldError;
2196
- } else if (fieldName in state.fields && fieldError) {
2197
- var _Object$assign;
2198
- state.fields[fieldName].touched = true;
2199
- var errorsState = Object.assign({}, state.formState.errors, (_Object$assign = {}, _Object$assign[fieldName] = fieldError, _Object$assign));
2200
- state.formState.errors = errorsState;
2201
- state.formState.submitErrors = errorsState;
2202
- state.formState.lastSubmittedValues = state.formState.values;
2204
+ state.formState.error = fieldError;
2205
+ state.formState.submitError = submitError;
2206
+ } else if (fieldName in state.fields) {
2207
+ if (fieldError) {
2208
+ var _Object$assign;
2209
+ var errorsState = Object.assign({}, state.formState.errors, (_Object$assign = {}, _Object$assign[fieldName] = fieldError, _Object$assign));
2210
+ state.fields[fieldName].touched = true;
2211
+ state.fields[fieldName].error = fieldError;
2212
+ state.formState.errors = errorsState;
2213
+ }
2214
+ if (submitError) {
2215
+ var _Object$assign2;
2216
+ var submitErrorsState = Object.assign({}, state.formState.submitErrors, (_Object$assign2 = {}, _Object$assign2[fieldName] = submitError, _Object$assign2));
2217
+
2218
+ // state.fields[fieldName].submitFailed = true
2219
+ // state.fields[fieldName].submitSucceeded = false
2220
+ state.fields[fieldName].submitError = submitError;
2221
+ state.formState.submitErrors = submitErrorsState;
2222
+ state.formState.submitFailed = true;
2223
+ state.formState.submitSucceeded = false;
2224
+ state.formState.lastSubmittedValues = state.formState.values;
2225
+ }
2203
2226
  }
2204
- }
2205
- function sendFormDataToServer(_x, _x2) {
2206
- return _sendFormDataToServer.apply(this, arguments);
2207
- }
2208
- function _sendFormDataToServer() {
2209
- _sendFormDataToServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url, data) {
2227
+ };
2228
+ var sendFormDataToServer = /*#__PURE__*/function () {
2229
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url, data) {
2210
2230
  var response, _error$response, _error$response2, formErrors;
2211
2231
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2212
2232
  while (1) switch (_context.prev = _context.next) {
@@ -2232,9 +2252,9 @@ function _sendFormDataToServer() {
2232
2252
  formErrors[finalForm.FORM_ERROR] = 'Something went wrong';
2233
2253
  }
2234
2254
  if (typeof ((_error$response2 = _context.t0.response) == null ? void 0 : _error$response2.data) === 'object') {
2235
- Object.entries(_context.t0.response.data).forEach(function (_ref) {
2236
- var fieldName = _ref[0],
2237
- errorsList = _ref[1];
2255
+ Object.entries(_context.t0.response.data).forEach(function (_ref2) {
2256
+ var fieldName = _ref2[0],
2257
+ errorsList = _ref2[1];
2238
2258
  formErrors[fieldName] = errorsList[0];
2239
2259
  });
2240
2260
  }
@@ -2249,8 +2269,10 @@ function _sendFormDataToServer() {
2249
2269
  }
2250
2270
  }, _callee, null, [[0, 7]]);
2251
2271
  }));
2252
- return _sendFormDataToServer.apply(this, arguments);
2253
- }
2272
+ return function sendFormDataToServer(_x, _x2) {
2273
+ return _ref.apply(this, arguments);
2274
+ };
2275
+ }();
2254
2276
 
2255
2277
  var formTypes = {
2256
2278
  checkbox: 'checkbox',
@@ -2353,7 +2375,7 @@ function generateField(field, config, props) {
2353
2375
  }
2354
2376
  }
2355
2377
 
2356
- var FinalForm = /*#__PURE__*/React__default.default.forwardRef(function (props, ref) {
2378
+ var FinalForm = /*#__PURE__*/React__default.default.forwardRef(function FinalForm(props, ref) {
2357
2379
  var additionalProps = props.additionalProps,
2358
2380
  after = props.after,
2359
2381
  before = props.before,
@@ -2450,105 +2472,110 @@ var FinalForm = /*#__PURE__*/React__default.default.forwardRef(function (props,
2450
2472
  decorators: [focusOnErrorDecorator],
2451
2473
  initialValues: initialValues,
2452
2474
  initialValuesEqual: initialValuesEqual,
2475
+ mutators: mutators,
2476
+ render: function render(_ref) {
2477
+ var handleSubmit = _ref.handleSubmit,
2478
+ submitError = _ref.submitError,
2479
+ modifiedSinceLastSubmit = _ref.modifiedSinceLastSubmit,
2480
+ form = _ref.form;
2481
+ return /*#__PURE__*/React__default.default.createElement("form", {
2482
+ style: formStyles,
2483
+ className: clsx__default.default(className, 'form', set && "form_set_" + set, type && "form_type_" + type, directionClass, fillClass, shapeClass, elevationClass),
2484
+ name: formName,
2485
+ "data-tour": dataTour,
2486
+ ref: function ref() {
2487
+ return onRefFormInstance(form);
2488
+ },
2489
+ onSubmit: handleSubmit,
2490
+ autoComplete: disableFieldsAutoComplete ? 'off' : undefined,
2491
+ autoCorrect: disableFieldsAutoComplete ? 'off' : undefined,
2492
+ autoCapitalize: disableFieldsAutoComplete ? 'off' : undefined,
2493
+ spellCheck: disableFieldsAutoComplete ? 'false' : undefined
2494
+ }, before, title && /*#__PURE__*/React__default.default.createElement(Title.Title, {
2495
+ className: "form__title",
2496
+ size: titleTextSize,
2497
+ textColor: titleTextColor,
2498
+ textWeight: titleTextWeight
2499
+ }, title), description && /*#__PURE__*/React__default.default.createElement(Text.Text, {
2500
+ className: "form__description",
2501
+ size: descriptionSize,
2502
+ textColor: descriptionTextColor,
2503
+ textWeight: descriptionTextWeight
2504
+ }, description), submitError && !modifiedSinceLastSubmit && /*#__PURE__*/React__default.default.createElement(Notification.NotificationItem, {
2505
+ text: form.getState().submitError,
2506
+ status: "error"
2507
+ }), onChangeFormValues && /*#__PURE__*/React__default.default.createElement(reactFinalForm.FormSpy, {
2508
+ subscription: {
2509
+ values: true
2510
+ },
2511
+ onChange: onChangeFormValues
2512
+ }), Boolean(Object.keys(config).length) && /*#__PURE__*/React__default.default.createElement(Group$1.Group, {
2513
+ direction: "vertical",
2514
+ gap: fieldsGap || groupGap,
2515
+ className: "form__wrapper"
2516
+ }, Object.keys(config).map(function (key) {
2517
+ return generateField(config[key], {
2518
+ key: key
2519
+ }, additionalProps[config[key].name]);
2520
+ }), isLoading && (loader || /*#__PURE__*/React__default.default.createElement(Loader.Loader, {
2521
+ className: "form__loader",
2522
+ set: loaderSet,
2523
+ fill: loaderFill,
2524
+ itemFill: loaderItemFill,
2525
+ text: loaderText
2526
+ }))), (primaryButtonLabel || primaryButton || secondaryButtonLabel || secondaryButton || tertiaryButton || tertiaryButtonLabel) && /*#__PURE__*/React__default.default.createElement(Group$1.Group, {
2527
+ fill: buttonFill,
2528
+ justifyContent: buttonJustifyContent,
2529
+ direction: buttonDirection,
2530
+ padding: buttonPadding,
2531
+ gap: buttonGap,
2532
+ className: "form__button",
2533
+ dataTour: dataTourButtons
2534
+ }, primaryButtonLabel ? /*#__PURE__*/React__default.default.createElement(Button.Button, {
2535
+ width: "fill",
2536
+ className: "form__button-item",
2537
+ fill: primaryButtonFill,
2538
+ fillHover: primaryButtonFillHover,
2539
+ size: primaryButtonSize,
2540
+ labelTextColor: primaryButtonLabelTextColor,
2541
+ labelSize: primaryButtonLabelSize,
2542
+ labelTextWeight: primaryButtonLabelTextWeight,
2543
+ label: primaryButtonLabel,
2544
+ dataTour: dataTourPrimaryButton
2545
+ }) : primaryButton, secondaryButtonLabel ? /*#__PURE__*/React__default.default.createElement(Button.Button, {
2546
+ width: "fill",
2547
+ className: "form__button-item",
2548
+ fill: secondaryButtonFill,
2549
+ fillHover: secondaryButtonFillHover,
2550
+ size: secondaryButtonSize,
2551
+ labelTextColor: secondaryButtonLabelTextColor,
2552
+ labelSize: secondaryButtonLabelSize,
2553
+ labelTextWeight: secondaryButtonLabelTextWeight,
2554
+ label: secondaryButtonLabel,
2555
+ onClick: onClickSecondaryButton,
2556
+ dataTour: dataTourSecondaryButton
2557
+ }) : secondaryButton, tertiaryButtonLabel ? /*#__PURE__*/React__default.default.createElement(Button.Button, {
2558
+ width: "fill",
2559
+ className: "form__button-item",
2560
+ fill: tertiaryButtonFill,
2561
+ fillHover: tertiaryButtonFillHover,
2562
+ size: tertiaryButtonSize,
2563
+ labelTextColor: tertiaryButtonLabelTextColor,
2564
+ labelSize: tertiaryButtonLabelSize,
2565
+ labelTextWeight: tertiaryButtonLabelTextWeight,
2566
+ label: tertiaryButtonLabel,
2567
+ onClick: onClickTertiaryButton,
2568
+ dataTour: dataTourTertiaryButton
2569
+ }) : tertiaryButton), after);
2570
+ },
2453
2571
  subscription: {
2454
2572
  submitting: true,
2455
- pristine: true
2573
+ pristine: true,
2574
+ modifiedSinceLastSubmit: true,
2575
+ submitError: true
2456
2576
  },
2457
- mutators: mutators,
2458
2577
  validate: validate,
2459
2578
  onSubmit: onSubmit
2460
- }, function (_ref) {
2461
- var handleSubmit = _ref.handleSubmit,
2462
- form = _ref.form;
2463
- return /*#__PURE__*/React__default.default.createElement("form", {
2464
- style: formStyles,
2465
- className: clsx__default.default(className, 'form', set && "form_set_" + set, type && "form_type_" + type, directionClass, fillClass, shapeClass, elevationClass),
2466
- name: formName,
2467
- "data-tour": dataTour,
2468
- ref: function ref() {
2469
- return onRefFormInstance(form);
2470
- },
2471
- onSubmit: handleSubmit,
2472
- autoComplete: disableFieldsAutoComplete ? 'off' : undefined,
2473
- autoCorrect: disableFieldsAutoComplete ? 'off' : undefined,
2474
- autoCapitalize: disableFieldsAutoComplete ? 'off' : undefined,
2475
- spellCheck: disableFieldsAutoComplete ? 'false' : undefined
2476
- }, before, title && /*#__PURE__*/React__default.default.createElement(Title.Title, {
2477
- className: "form__title",
2478
- size: titleTextSize,
2479
- textColor: titleTextColor,
2480
- textWeight: titleTextWeight
2481
- }, title), description && /*#__PURE__*/React__default.default.createElement(Text.Text, {
2482
- className: "form__description",
2483
- size: descriptionSize,
2484
- textColor: descriptionTextColor,
2485
- textWeight: descriptionTextWeight
2486
- }, description), form.getState().submitError && /*#__PURE__*/React__default.default.createElement(Notification.NotificationItem, {
2487
- text: form.getState().submitError,
2488
- status: "error"
2489
- }), onChangeFormValues && /*#__PURE__*/React__default.default.createElement(reactFinalForm.FormSpy, {
2490
- subscription: {
2491
- values: true
2492
- },
2493
- onChange: onChangeFormValues
2494
- }), Boolean(Object.keys(config).length) && /*#__PURE__*/React__default.default.createElement(Group$1.Group, {
2495
- direction: "vertical",
2496
- gap: fieldsGap || groupGap,
2497
- className: "form__wrapper"
2498
- }, Object.keys(config).map(function (key) {
2499
- return generateField(config[key], {
2500
- key: key
2501
- }, additionalProps[config[key].name]);
2502
- }), isLoading && /*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, null, loader ? loader : /*#__PURE__*/React__default.default.createElement(Loader.Loader, {
2503
- className: "form__loader",
2504
- set: loaderSet,
2505
- fill: loaderFill,
2506
- itemFill: loaderItemFill,
2507
- text: loaderText
2508
- }))), (primaryButtonLabel || primaryButton || secondaryButtonLabel || secondaryButton || tertiaryButton || tertiaryButtonLabel) && /*#__PURE__*/React__default.default.createElement(Group$1.Group, {
2509
- fill: buttonFill,
2510
- justifyContent: buttonJustifyContent,
2511
- direction: buttonDirection,
2512
- padding: buttonPadding,
2513
- gap: buttonGap,
2514
- className: "form__button",
2515
- dataTour: dataTourButtons
2516
- }, primaryButtonLabel ? /*#__PURE__*/React__default.default.createElement(Button.Button, {
2517
- width: "fill",
2518
- className: "form__button-item",
2519
- fill: primaryButtonFill,
2520
- fillHover: primaryButtonFillHover,
2521
- size: primaryButtonSize,
2522
- labelTextColor: primaryButtonLabelTextColor,
2523
- labelSize: primaryButtonLabelSize,
2524
- labelTextWeight: primaryButtonLabelTextWeight,
2525
- label: primaryButtonLabel,
2526
- dataTour: dataTourPrimaryButton
2527
- }) : primaryButton, secondaryButtonLabel ? /*#__PURE__*/React__default.default.createElement(Button.Button, {
2528
- width: "fill",
2529
- className: "form__button-item",
2530
- fill: secondaryButtonFill,
2531
- fillHover: secondaryButtonFillHover,
2532
- size: secondaryButtonSize,
2533
- labelTextColor: secondaryButtonLabelTextColor,
2534
- labelSize: secondaryButtonLabelSize,
2535
- labelTextWeight: secondaryButtonLabelTextWeight,
2536
- label: secondaryButtonLabel,
2537
- onClick: onClickSecondaryButton,
2538
- dataTour: dataTourSecondaryButton
2539
- }) : secondaryButton, tertiaryButtonLabel ? /*#__PURE__*/React__default.default.createElement(Button.Button, {
2540
- width: "fill",
2541
- className: "form__button-item",
2542
- fill: tertiaryButtonFill,
2543
- fillHover: tertiaryButtonFillHover,
2544
- size: tertiaryButtonSize,
2545
- labelTextColor: tertiaryButtonLabelTextColor,
2546
- labelSize: tertiaryButtonLabelSize,
2547
- labelTextWeight: tertiaryButtonLabelTextWeight,
2548
- label: tertiaryButtonLabel,
2549
- onClick: onClickTertiaryButton,
2550
- dataTour: dataTourTertiaryButton
2551
- }) : tertiaryButton), after);
2552
2579
  });
2553
2580
  });
2554
2581
  FinalForm.propTypes = {
@@ -2599,7 +2626,6 @@ FinalForm.defaultProps = {
2599
2626
  direction: 'vertical',
2600
2627
  disableFieldsAutoComplete: false
2601
2628
  };
2602
- FinalForm.displayName = 'FinalForm';
2603
2629
 
2604
2630
  Object.defineProperty(exports, 'Field', {
2605
2631
  enumerable: true,
@@ -1,6 +1,6 @@
1
1
  import { isPossiblePhoneNumber } from 'libphonenumber-js';
2
2
  import React, { useMemo, useEffect, useCallback, useState } from 'react';
3
- import { setIn, getIn, FORM_ERROR } from 'final-form';
3
+ import { setIn, FORM_ERROR, getIn } from 'final-form';
4
4
  import { useForm, Field, Form, FormSpy } from 'react-final-form';
5
5
  export { Field, useForm, useFormState } from 'react-final-form';
6
6
  import PropTypes from 'prop-types';
@@ -2135,8 +2135,12 @@ TextareaField.propTypes = {
2135
2135
  inputProps: PropTypes.object
2136
2136
  };
2137
2137
 
2138
- function focusOnError(formElementsList, errors) {
2138
+ var focusOnError = function focusOnError(formElementsList, errors) {
2139
2139
  var selectsIds = Object.keys(errors).map(function (fieldName) {
2140
+ if (fieldName === FORM_ERROR) {
2141
+ // TODO: get from somewhere
2142
+ return 'notification__item_status_error';
2143
+ }
2140
2144
  return "react-select-id_" + fieldName + "-input";
2141
2145
  });
2142
2146
  var errorFieldElement = formElementsList.find(function (element) {
@@ -2150,9 +2154,14 @@ function focusOnError(formElementsList, errors) {
2150
2154
  if (!errorFieldElement && errorsList.length) {
2151
2155
  var errorElement;
2152
2156
  try {
2153
- errorElement = document.querySelector("#" + errorsList[0] + "-error");
2154
- if (!errorElement) {
2155
- errorElement = document.querySelector("#id_" + errorsList[0]);
2157
+ var fieldName = errorsList[0];
2158
+ if (fieldName === FORM_ERROR) {
2159
+ errorElement = document.querySelector('notification__item_status_error');
2160
+ } else {
2161
+ errorElement = document.querySelector("#" + fieldName + "-error");
2162
+ if (!errorElement) {
2163
+ errorElement = document.querySelector("#id_" + fieldName);
2164
+ }
2156
2165
  }
2157
2166
  } catch (err) {
2158
2167
  console.warn(err);
@@ -2172,31 +2181,42 @@ function focusOnError(formElementsList, errors) {
2172
2181
  });
2173
2182
  }
2174
2183
  return null;
2175
- }
2184
+ };
2176
2185
  var focusOnErrorDecorator = createDecorator(null, focusOnError);
2177
- function setErrorsMutator(args, state) {
2186
+ var setErrorsMutator = function setErrorsMutator(args, state) {
2178
2187
  var fieldName = args[0],
2179
2188
  data = args[1];
2180
- var fieldError = data.error || data.submitError;
2189
+ var submitError = data.submitError;
2190
+ var fieldError = data.error;
2181
2191
  if (fieldName === 'non_field_errors') {
2182
- state.formState.error = fieldError;
2183
2192
  // state.formState.invalid = true
2184
2193
  // state.formState.valid = false
2185
- state.formState.submitError = fieldError;
2186
- } else if (fieldName in state.fields && fieldError) {
2187
- var _Object$assign;
2188
- state.fields[fieldName].touched = true;
2189
- var errorsState = Object.assign({}, state.formState.errors, (_Object$assign = {}, _Object$assign[fieldName] = fieldError, _Object$assign));
2190
- state.formState.errors = errorsState;
2191
- state.formState.submitErrors = errorsState;
2192
- state.formState.lastSubmittedValues = state.formState.values;
2194
+ state.formState.error = fieldError;
2195
+ state.formState.submitError = submitError;
2196
+ } else if (fieldName in state.fields) {
2197
+ if (fieldError) {
2198
+ var _Object$assign;
2199
+ var errorsState = Object.assign({}, state.formState.errors, (_Object$assign = {}, _Object$assign[fieldName] = fieldError, _Object$assign));
2200
+ state.fields[fieldName].touched = true;
2201
+ state.fields[fieldName].error = fieldError;
2202
+ state.formState.errors = errorsState;
2203
+ }
2204
+ if (submitError) {
2205
+ var _Object$assign2;
2206
+ var submitErrorsState = Object.assign({}, state.formState.submitErrors, (_Object$assign2 = {}, _Object$assign2[fieldName] = submitError, _Object$assign2));
2207
+
2208
+ // state.fields[fieldName].submitFailed = true
2209
+ // state.fields[fieldName].submitSucceeded = false
2210
+ state.fields[fieldName].submitError = submitError;
2211
+ state.formState.submitErrors = submitErrorsState;
2212
+ state.formState.submitFailed = true;
2213
+ state.formState.submitSucceeded = false;
2214
+ state.formState.lastSubmittedValues = state.formState.values;
2215
+ }
2193
2216
  }
2194
- }
2195
- function sendFormDataToServer(_x, _x2) {
2196
- return _sendFormDataToServer.apply(this, arguments);
2197
- }
2198
- function _sendFormDataToServer() {
2199
- _sendFormDataToServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url, data) {
2217
+ };
2218
+ var sendFormDataToServer = /*#__PURE__*/function () {
2219
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url, data) {
2200
2220
  var response, _error$response, _error$response2, formErrors;
2201
2221
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2202
2222
  while (1) switch (_context.prev = _context.next) {
@@ -2222,9 +2242,9 @@ function _sendFormDataToServer() {
2222
2242
  formErrors[FORM_ERROR] = 'Something went wrong';
2223
2243
  }
2224
2244
  if (typeof ((_error$response2 = _context.t0.response) == null ? void 0 : _error$response2.data) === 'object') {
2225
- Object.entries(_context.t0.response.data).forEach(function (_ref) {
2226
- var fieldName = _ref[0],
2227
- errorsList = _ref[1];
2245
+ Object.entries(_context.t0.response.data).forEach(function (_ref2) {
2246
+ var fieldName = _ref2[0],
2247
+ errorsList = _ref2[1];
2228
2248
  formErrors[fieldName] = errorsList[0];
2229
2249
  });
2230
2250
  }
@@ -2239,8 +2259,10 @@ function _sendFormDataToServer() {
2239
2259
  }
2240
2260
  }, _callee, null, [[0, 7]]);
2241
2261
  }));
2242
- return _sendFormDataToServer.apply(this, arguments);
2243
- }
2262
+ return function sendFormDataToServer(_x, _x2) {
2263
+ return _ref.apply(this, arguments);
2264
+ };
2265
+ }();
2244
2266
 
2245
2267
  var formTypes = {
2246
2268
  checkbox: 'checkbox',
@@ -2343,7 +2365,7 @@ function generateField(field, config, props) {
2343
2365
  }
2344
2366
  }
2345
2367
 
2346
- var FinalForm = /*#__PURE__*/React.forwardRef(function (props, ref) {
2368
+ var FinalForm = /*#__PURE__*/React.forwardRef(function FinalForm(props, ref) {
2347
2369
  var additionalProps = props.additionalProps,
2348
2370
  after = props.after,
2349
2371
  before = props.before,
@@ -2440,105 +2462,110 @@ var FinalForm = /*#__PURE__*/React.forwardRef(function (props, ref) {
2440
2462
  decorators: [focusOnErrorDecorator],
2441
2463
  initialValues: initialValues,
2442
2464
  initialValuesEqual: initialValuesEqual,
2465
+ mutators: mutators,
2466
+ render: function render(_ref) {
2467
+ var handleSubmit = _ref.handleSubmit,
2468
+ submitError = _ref.submitError,
2469
+ modifiedSinceLastSubmit = _ref.modifiedSinceLastSubmit,
2470
+ form = _ref.form;
2471
+ return /*#__PURE__*/React.createElement("form", {
2472
+ style: formStyles,
2473
+ className: clsx(className, 'form', set && "form_set_" + set, type && "form_type_" + type, directionClass, fillClass, shapeClass, elevationClass),
2474
+ name: formName,
2475
+ "data-tour": dataTour,
2476
+ ref: function ref() {
2477
+ return onRefFormInstance(form);
2478
+ },
2479
+ onSubmit: handleSubmit,
2480
+ autoComplete: disableFieldsAutoComplete ? 'off' : undefined,
2481
+ autoCorrect: disableFieldsAutoComplete ? 'off' : undefined,
2482
+ autoCapitalize: disableFieldsAutoComplete ? 'off' : undefined,
2483
+ spellCheck: disableFieldsAutoComplete ? 'false' : undefined
2484
+ }, before, title && /*#__PURE__*/React.createElement(Title, {
2485
+ className: "form__title",
2486
+ size: titleTextSize,
2487
+ textColor: titleTextColor,
2488
+ textWeight: titleTextWeight
2489
+ }, title), description && /*#__PURE__*/React.createElement(Text, {
2490
+ className: "form__description",
2491
+ size: descriptionSize,
2492
+ textColor: descriptionTextColor,
2493
+ textWeight: descriptionTextWeight
2494
+ }, description), submitError && !modifiedSinceLastSubmit && /*#__PURE__*/React.createElement(NotificationItem, {
2495
+ text: form.getState().submitError,
2496
+ status: "error"
2497
+ }), onChangeFormValues && /*#__PURE__*/React.createElement(FormSpy, {
2498
+ subscription: {
2499
+ values: true
2500
+ },
2501
+ onChange: onChangeFormValues
2502
+ }), Boolean(Object.keys(config).length) && /*#__PURE__*/React.createElement(Group$1, {
2503
+ direction: "vertical",
2504
+ gap: fieldsGap || groupGap,
2505
+ className: "form__wrapper"
2506
+ }, Object.keys(config).map(function (key) {
2507
+ return generateField(config[key], {
2508
+ key: key
2509
+ }, additionalProps[config[key].name]);
2510
+ }), isLoading && (loader || /*#__PURE__*/React.createElement(Loader, {
2511
+ className: "form__loader",
2512
+ set: loaderSet,
2513
+ fill: loaderFill,
2514
+ itemFill: loaderItemFill,
2515
+ text: loaderText
2516
+ }))), (primaryButtonLabel || primaryButton || secondaryButtonLabel || secondaryButton || tertiaryButton || tertiaryButtonLabel) && /*#__PURE__*/React.createElement(Group$1, {
2517
+ fill: buttonFill,
2518
+ justifyContent: buttonJustifyContent,
2519
+ direction: buttonDirection,
2520
+ padding: buttonPadding,
2521
+ gap: buttonGap,
2522
+ className: "form__button",
2523
+ dataTour: dataTourButtons
2524
+ }, primaryButtonLabel ? /*#__PURE__*/React.createElement(Button, {
2525
+ width: "fill",
2526
+ className: "form__button-item",
2527
+ fill: primaryButtonFill,
2528
+ fillHover: primaryButtonFillHover,
2529
+ size: primaryButtonSize,
2530
+ labelTextColor: primaryButtonLabelTextColor,
2531
+ labelSize: primaryButtonLabelSize,
2532
+ labelTextWeight: primaryButtonLabelTextWeight,
2533
+ label: primaryButtonLabel,
2534
+ dataTour: dataTourPrimaryButton
2535
+ }) : primaryButton, secondaryButtonLabel ? /*#__PURE__*/React.createElement(Button, {
2536
+ width: "fill",
2537
+ className: "form__button-item",
2538
+ fill: secondaryButtonFill,
2539
+ fillHover: secondaryButtonFillHover,
2540
+ size: secondaryButtonSize,
2541
+ labelTextColor: secondaryButtonLabelTextColor,
2542
+ labelSize: secondaryButtonLabelSize,
2543
+ labelTextWeight: secondaryButtonLabelTextWeight,
2544
+ label: secondaryButtonLabel,
2545
+ onClick: onClickSecondaryButton,
2546
+ dataTour: dataTourSecondaryButton
2547
+ }) : secondaryButton, tertiaryButtonLabel ? /*#__PURE__*/React.createElement(Button, {
2548
+ width: "fill",
2549
+ className: "form__button-item",
2550
+ fill: tertiaryButtonFill,
2551
+ fillHover: tertiaryButtonFillHover,
2552
+ size: tertiaryButtonSize,
2553
+ labelTextColor: tertiaryButtonLabelTextColor,
2554
+ labelSize: tertiaryButtonLabelSize,
2555
+ labelTextWeight: tertiaryButtonLabelTextWeight,
2556
+ label: tertiaryButtonLabel,
2557
+ onClick: onClickTertiaryButton,
2558
+ dataTour: dataTourTertiaryButton
2559
+ }) : tertiaryButton), after);
2560
+ },
2443
2561
  subscription: {
2444
2562
  submitting: true,
2445
- pristine: true
2563
+ pristine: true,
2564
+ modifiedSinceLastSubmit: true,
2565
+ submitError: true
2446
2566
  },
2447
- mutators: mutators,
2448
2567
  validate: validate,
2449
2568
  onSubmit: onSubmit
2450
- }, function (_ref) {
2451
- var handleSubmit = _ref.handleSubmit,
2452
- form = _ref.form;
2453
- return /*#__PURE__*/React.createElement("form", {
2454
- style: formStyles,
2455
- className: clsx(className, 'form', set && "form_set_" + set, type && "form_type_" + type, directionClass, fillClass, shapeClass, elevationClass),
2456
- name: formName,
2457
- "data-tour": dataTour,
2458
- ref: function ref() {
2459
- return onRefFormInstance(form);
2460
- },
2461
- onSubmit: handleSubmit,
2462
- autoComplete: disableFieldsAutoComplete ? 'off' : undefined,
2463
- autoCorrect: disableFieldsAutoComplete ? 'off' : undefined,
2464
- autoCapitalize: disableFieldsAutoComplete ? 'off' : undefined,
2465
- spellCheck: disableFieldsAutoComplete ? 'false' : undefined
2466
- }, before, title && /*#__PURE__*/React.createElement(Title, {
2467
- className: "form__title",
2468
- size: titleTextSize,
2469
- textColor: titleTextColor,
2470
- textWeight: titleTextWeight
2471
- }, title), description && /*#__PURE__*/React.createElement(Text, {
2472
- className: "form__description",
2473
- size: descriptionSize,
2474
- textColor: descriptionTextColor,
2475
- textWeight: descriptionTextWeight
2476
- }, description), form.getState().submitError && /*#__PURE__*/React.createElement(NotificationItem, {
2477
- text: form.getState().submitError,
2478
- status: "error"
2479
- }), onChangeFormValues && /*#__PURE__*/React.createElement(FormSpy, {
2480
- subscription: {
2481
- values: true
2482
- },
2483
- onChange: onChangeFormValues
2484
- }), Boolean(Object.keys(config).length) && /*#__PURE__*/React.createElement(Group$1, {
2485
- direction: "vertical",
2486
- gap: fieldsGap || groupGap,
2487
- className: "form__wrapper"
2488
- }, Object.keys(config).map(function (key) {
2489
- return generateField(config[key], {
2490
- key: key
2491
- }, additionalProps[config[key].name]);
2492
- }), isLoading && /*#__PURE__*/React.createElement(React.Fragment, null, loader ? loader : /*#__PURE__*/React.createElement(Loader, {
2493
- className: "form__loader",
2494
- set: loaderSet,
2495
- fill: loaderFill,
2496
- itemFill: loaderItemFill,
2497
- text: loaderText
2498
- }))), (primaryButtonLabel || primaryButton || secondaryButtonLabel || secondaryButton || tertiaryButton || tertiaryButtonLabel) && /*#__PURE__*/React.createElement(Group$1, {
2499
- fill: buttonFill,
2500
- justifyContent: buttonJustifyContent,
2501
- direction: buttonDirection,
2502
- padding: buttonPadding,
2503
- gap: buttonGap,
2504
- className: "form__button",
2505
- dataTour: dataTourButtons
2506
- }, primaryButtonLabel ? /*#__PURE__*/React.createElement(Button, {
2507
- width: "fill",
2508
- className: "form__button-item",
2509
- fill: primaryButtonFill,
2510
- fillHover: primaryButtonFillHover,
2511
- size: primaryButtonSize,
2512
- labelTextColor: primaryButtonLabelTextColor,
2513
- labelSize: primaryButtonLabelSize,
2514
- labelTextWeight: primaryButtonLabelTextWeight,
2515
- label: primaryButtonLabel,
2516
- dataTour: dataTourPrimaryButton
2517
- }) : primaryButton, secondaryButtonLabel ? /*#__PURE__*/React.createElement(Button, {
2518
- width: "fill",
2519
- className: "form__button-item",
2520
- fill: secondaryButtonFill,
2521
- fillHover: secondaryButtonFillHover,
2522
- size: secondaryButtonSize,
2523
- labelTextColor: secondaryButtonLabelTextColor,
2524
- labelSize: secondaryButtonLabelSize,
2525
- labelTextWeight: secondaryButtonLabelTextWeight,
2526
- label: secondaryButtonLabel,
2527
- onClick: onClickSecondaryButton,
2528
- dataTour: dataTourSecondaryButton
2529
- }) : secondaryButton, tertiaryButtonLabel ? /*#__PURE__*/React.createElement(Button, {
2530
- width: "fill",
2531
- className: "form__button-item",
2532
- fill: tertiaryButtonFill,
2533
- fillHover: tertiaryButtonFillHover,
2534
- size: tertiaryButtonSize,
2535
- labelTextColor: tertiaryButtonLabelTextColor,
2536
- labelSize: tertiaryButtonLabelSize,
2537
- labelTextWeight: tertiaryButtonLabelTextWeight,
2538
- label: tertiaryButtonLabel,
2539
- onClick: onClickTertiaryButton,
2540
- dataTour: dataTourTertiaryButton
2541
- }) : tertiaryButton), after);
2542
2569
  });
2543
2570
  });
2544
2571
  FinalForm.propTypes = {
@@ -2589,6 +2616,5 @@ FinalForm.defaultProps = {
2589
2616
  direction: 'vertical',
2590
2617
  disableFieldsAutoComplete: false
2591
2618
  };
2592
- FinalForm.displayName = 'FinalForm';
2593
2619
 
2594
2620
  export { CheckboxField as Checkbox, ChoiceField, CustomField, DatePickerField, FieldWrapper, FieldWrapperBase, FileInput, FinalForm, Group, InputField, RadioGroup, SegmentedField, SelectField, SwitchField as Switch, TextareaField as Textarea, addRequiredFieldsParamToSchema, emailValidation, focusOnError, focusOnErrorDecorator, formTypes, generateField, phoneValidation, sendFormDataToServer, setErrorsMutator, useYupValidationSchema };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itcase/forms",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Forms fields, inputs, etc.",
5
5
  "keywords": [
6
6
  "forms",
@@ -35,15 +35,15 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@itcase/common": "^1.1.6",
38
- "@itcase/ui": "^1.0.18",
39
- "axios": "^1.4.0",
38
+ "@itcase/ui": "^1.0.25",
39
+ "axios": "^1.5.0",
40
40
  "clsx": "^2.0.0",
41
41
  "date-fns": "2.0.0-alpha.7",
42
42
  "final-form": "^4.20.10",
43
43
  "final-form-focus": "^1.1.2",
44
- "libphonenumber-js": "^1.10.41",
44
+ "libphonenumber-js": "^1.10.43",
45
45
  "lodash": "^4.17.21",
46
- "luxon": "^3.4.1",
46
+ "luxon": "^3.4.2",
47
47
  "prop-types": "^15.8.1",
48
48
  "react": "^18.2.0",
49
49
  "react-date-range": "^1.4.0",
@@ -67,7 +67,7 @@
67
67
  "@semantic-release/git": "^10.0.1",
68
68
  "babel-plugin-inline-react-svg": "^2.0.2",
69
69
  "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
70
- "eslint": "8.47.0",
70
+ "eslint": "8.48.0",
71
71
  "eslint-config-prettier": "^9.0.0",
72
72
  "eslint-config-standard": "^17.1.0",
73
73
  "eslint-plugin-import": "^2.28.1",
@@ -76,7 +76,7 @@
76
76
  "eslint-plugin-promise": "^6.1.1",
77
77
  "eslint-plugin-react": "^7.33.2",
78
78
  "eslint-plugin-standard": "^5.0.0",
79
- "husky": "^8.0.0",
79
+ "husky": "^8.0.3",
80
80
  "npm": "^9.8.1",
81
81
  "postcss-aspect-ratio-polyfill": "^2.0.0",
82
82
  "postcss-cli": "^10.1.0",
@@ -95,7 +95,7 @@
95
95
  "postcss-nested-ancestors": "^3.0.0",
96
96
  "postcss-normalize": "^10.0.1",
97
97
  "postcss-prepend-imports": "^1.0.1",
98
- "postcss-preset-env": "^9.1.1",
98
+ "postcss-preset-env": "^9.1.2",
99
99
  "postcss-pxtorem": "^6.0.0",
100
100
  "postcss-responsive-type": "github:ITCase/postcss-responsive-type",
101
101
  "postcss-sort-media-queries": "^5.2.0",