@bigbinary/neeto-form-frontend 4.1.9 → 4.2.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.
Files changed (44) hide show
  1. package/app/javascript/src/translations/en.json +5 -1
  2. package/dist/BuildForm.js +103 -60
  3. package/dist/BuildForm.js.map +1 -1
  4. package/dist/ExternalForm.js +5 -4
  5. package/dist/ExternalForm.js.map +1 -1
  6. package/dist/Submission.js +2 -2
  7. package/dist/Submission.js.map +1 -1
  8. package/dist/UrlBuilder.js +3 -2
  9. package/dist/UrlBuilder.js.map +1 -1
  10. package/dist/{buildForm-BwhLCvEE.js → buildForm-CooylMLL.js} +3 -2
  11. package/dist/buildForm-CooylMLL.js.map +1 -0
  12. package/dist/{buildForm-CsVQHcC7.js → buildForm-DcE5kFvR.js} +3 -2
  13. package/dist/buildForm-DcE5kFvR.js.map +1 -0
  14. package/dist/cjs/BuildForm.js +103 -60
  15. package/dist/cjs/BuildForm.js.map +1 -1
  16. package/dist/cjs/ExternalForm.js +5 -4
  17. package/dist/cjs/ExternalForm.js.map +1 -1
  18. package/dist/cjs/Submission.js +2 -2
  19. package/dist/cjs/Submission.js.map +1 -1
  20. package/dist/cjs/UrlBuilder.js +3 -2
  21. package/dist/cjs/UrlBuilder.js.map +1 -1
  22. package/dist/cjs/hooks.js +1 -1
  23. package/dist/cjs/index.js +5 -3
  24. package/dist/cjs/index.js.map +1 -1
  25. package/dist/{constants-DXeRH2r2.js → constants-BjWWA3Oq.js} +11 -2
  26. package/dist/constants-BjWWA3Oq.js.map +1 -0
  27. package/dist/{constants-D0zli_cv.js → constants-QPLZ_r-D.js} +10 -3
  28. package/dist/constants-QPLZ_r-D.js.map +1 -0
  29. package/dist/hooks.js +1 -1
  30. package/dist/index.js +5 -3
  31. package/dist/index.js.map +1 -1
  32. package/dist/main.css +1 -1
  33. package/dist/main.css.map +1 -1
  34. package/dist/{utils-C-ermU02.js → utils-BwFLBXs2.js} +114 -39
  35. package/dist/utils-BwFLBXs2.js.map +1 -0
  36. package/dist/{utils-CdeIdZRi.js → utils-GRfGBny0.js} +114 -39
  37. package/dist/utils-GRfGBny0.js.map +1 -0
  38. package/package.json +17 -17
  39. package/dist/buildForm-BwhLCvEE.js.map +0 -1
  40. package/dist/buildForm-CsVQHcC7.js.map +0 -1
  41. package/dist/constants-D0zli_cv.js.map +0 -1
  42. package/dist/constants-DXeRH2r2.js.map +0 -1
  43. package/dist/utils-C-ermU02.js.map +0 -1
  44. package/dist/utils-CdeIdZRi.js.map +0 -1
@@ -22,7 +22,7 @@ import * as yup from 'yup';
22
22
  import i18next from 'i18next';
23
23
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
24
24
  import _toArray from '@babel/runtime/helpers/toArray';
25
- import { a as QUESTION_KIND, P as PARENTHESES_REGEX, E as EMAIL_REGEX, R as RATING_VALUES, S as SCHEMA_LESS_QUESTION_KINDS, c as SIX_DIGIT_NUMBER_REGEX, d as LABEL_FIELDS, e as RATING_OPTIONS, I as ICONS_MAP, g as generateArray } from './constants-D0zli_cv.js';
25
+ import { a as QUESTION_KIND, P as PARENTHESES_REGEX, E as EMAIL_REGEX, R as RATING_VALUES, S as SCHEMA_LESS_QUESTION_KINDS, c as SIX_DIGIT_NUMBER_REGEX, d as LABEL_FIELDS, D as DEFAULT_CHOICE_QUESTION_ATTRIBUTES, e as RATING_OPTIONS, I as ICONS_MAP, g as generateArray } from './constants-QPLZ_r-D.js';
26
26
  import classnames from 'classnames';
27
27
  import { useUpdateEffect, useStateWithDependency, useDebounce } from '@bigbinary/neeto-commons-frontend/react-utils';
28
28
  import Refresh from '@bigbinary/neeto-icons/Refresh';
@@ -42,6 +42,7 @@ import { FileUpload } from '@bigbinary/neeto-molecules/FileUpload';
42
42
  import Label from '@bigbinary/neetoui/Label';
43
43
  import Select from '@bigbinary/neetoui/Select';
44
44
  import Radio from '@bigbinary/neetoui/Radio';
45
+ import Image from '@bigbinary/neeto-icons/Image';
45
46
  import NeetoEditor from '@bigbinary/neeto-editor/Editor';
46
47
  import Textarea from '@bigbinary/neetoui/Textarea';
47
48
 
@@ -911,7 +912,7 @@ var MultipleEmailInput = function MultipleEmailInput(_ref) {
911
912
  className: "flex flex-col gap-2 items-end",
912
913
  children: [/*#__PURE__*/jsx(Button, _defineProperty(_defineProperty(_defineProperty({
913
914
  label: label,
914
- "data-cy": "add-guest-button",
915
+ "data-testid": "add-guest-button",
915
916
  disabled: isReadOnly,
916
917
  icon: Plus,
917
918
  iconPosition: "left"
@@ -981,7 +982,7 @@ var CaptchaField = function CaptchaField(_ref) {
981
982
  })
982
983
  }), touched && error && /*#__PURE__*/jsx("p", {
983
984
  className: "neeto-form-engine-input__error",
984
- "data-cy": "neeto-form-engine-captcha-error",
985
+ "data-testid": "neeto-form-engine-captcha-error",
985
986
  children: error
986
987
  })]
987
988
  });
@@ -1047,7 +1048,7 @@ var MathCaptcha = function MathCaptcha(_ref) {
1047
1048
  }, [userInput]);
1048
1049
  return /*#__PURE__*/jsxs("div", {
1049
1050
  className: "neeto-form-nano-math-captcha",
1050
- "data-cy": "math-captcha",
1051
+ "data-testid": "math-captcha",
1051
1052
  ref: captchaRef,
1052
1053
  children: [/*#__PURE__*/jsx("button", {
1053
1054
  className: "neeto-form-nano-math-captcha__button",
@@ -1057,13 +1058,13 @@ var MathCaptcha = function MathCaptcha(_ref) {
1057
1058
  }), /*#__PURE__*/jsxs("div", {
1058
1059
  className: "neeto-form-nano-math-captcha__equation",
1059
1060
  children: [/*#__PURE__*/jsx("span", {
1060
- "data-cy": "first-number",
1061
+ "data-testid": "first-number",
1061
1062
  children: firstNumber
1062
1063
  }), /*#__PURE__*/jsx("span", {
1063
- "data-cy": "operator",
1064
+ "data-testid": "operator",
1064
1065
  children: operator
1065
1066
  }), /*#__PURE__*/jsx("span", {
1066
- "data-cy": "second-number",
1067
+ "data-testid": "second-number",
1067
1068
  children: secondNumber
1068
1069
  }), /*#__PURE__*/jsx("span", {
1069
1070
  children: "="
@@ -1071,7 +1072,7 @@ var MathCaptcha = function MathCaptcha(_ref) {
1071
1072
  }), /*#__PURE__*/jsx(Input, {
1072
1073
  required: true,
1073
1074
  className: "neeto-form-nano-math-captcha__input",
1074
- "data-cy": "math-captcha-input",
1075
+ "data-testid": "math-captcha-input",
1075
1076
  value: userInput,
1076
1077
  onBlur: handleBlur,
1077
1078
  onChange: withEventTargetValue(setUserInput)
@@ -1156,7 +1157,7 @@ var DateField = function DateField(_ref) {
1156
1157
  className: "neeto-form-engine-input__label-wrapper",
1157
1158
  children: label && /*#__PURE__*/jsx("label", {
1158
1159
  className: "neeto-form-engine-label",
1159
- "data-cy": "".concat(hyphenate(label), "-input-label"),
1160
+ "data-testid": "".concat(hyphenate(label), "-input-label"),
1160
1161
  children: getLabel(label, isRequired)
1161
1162
  })
1162
1163
  }), /*#__PURE__*/jsx("div", {
@@ -1178,7 +1179,7 @@ var DateField = function DateField(_ref) {
1178
1179
  return /*#__PURE__*/jsx(DatePicker, _objectSpread$e(_objectSpread$e({}, _objectSpread$e(_objectSpread$e({}, field), {}, {
1179
1180
  type: type
1180
1181
  })), {}, {
1181
- "data-cy": "".concat(hyphenate(label), "-input-field"),
1182
+ "data-testid": "".concat(hyphenate(label), "-input-field"),
1182
1183
  dateFormat: "MMM D, YYYY",
1183
1184
  disabled: isReadOnly,
1184
1185
  error: meta.touched ? meta.error : "",
@@ -1285,7 +1286,7 @@ var SendCodeButton = function SendCodeButton(_ref) {
1285
1286
  return /*#__PURE__*/jsx(CheckCircle, {});
1286
1287
  }
1287
1288
  return /*#__PURE__*/jsx(Button, {
1288
- "data-cy": "send-code-button",
1289
+ "data-testid": "send-code-button",
1289
1290
  disabled: isDisabled,
1290
1291
  size: "small",
1291
1292
  style: "secondary",
@@ -1329,7 +1330,7 @@ var ResendVerificationCode = function ResendVerificationCode(_ref) {
1329
1330
  i18nKey: "neetoForm.emailVerification.resendCode",
1330
1331
  components: {
1331
1332
  button: /*#__PURE__*/jsx(Button, {
1332
- "data-cy": "otp-resend-button",
1333
+ "data-testid": "otp-resend-button",
1333
1334
  disabled: isResendDisabled,
1334
1335
  size: "small",
1335
1336
  style: "link",
@@ -1409,7 +1410,7 @@ var VerifyCode = function VerifyCode(_ref) {
1409
1410
  }, [code, hasError]);
1410
1411
  return /*#__PURE__*/jsxs(Fragment, {
1411
1412
  children: [/*#__PURE__*/jsx(Input, _objectSpread$c(_objectSpread$c({}, _objectSpread$c({}, field)), {}, {
1412
- "data-cy": "otp-input-field",
1413
+ "data-testid": "otp-input-field",
1413
1414
  disabled: isVerifyingCode,
1414
1415
  error: touched ? error : "",
1415
1416
  loading: isVerifyingCode,
@@ -1725,6 +1726,56 @@ var NameField = function NameField(props) {
1725
1726
  }));
1726
1727
  };
1727
1728
 
1729
+ var ChoiceImage = function ChoiceImage(_ref) {
1730
+ var src = _ref.src,
1731
+ alt = _ref.alt,
1732
+ height = _ref.height,
1733
+ shouldFitImages = _ref.shouldFitImages;
1734
+ var _useState = useState(false),
1735
+ _useState2 = _slicedToArray(_useState, 2),
1736
+ hasError = _useState2[0],
1737
+ setHasError = _useState2[1];
1738
+ var _useState3 = useState(true),
1739
+ _useState4 = _slicedToArray(_useState3, 2),
1740
+ isLoading = _useState4[0],
1741
+ setIsLoading = _useState4[1];
1742
+ var handleLoad = function handleLoad() {
1743
+ return setIsLoading(false);
1744
+ };
1745
+ var handleError = function handleError() {
1746
+ setHasError(true);
1747
+ setIsLoading(false);
1748
+ };
1749
+ if (hasError || !src) {
1750
+ return /*#__PURE__*/jsx("div", {
1751
+ className: "neeto-form-engine-choice__image-placeholder neeto-ui-bg-gray-100",
1752
+ style: {
1753
+ height: height
1754
+ },
1755
+ children: /*#__PURE__*/jsx(Image, {
1756
+ size: 32
1757
+ })
1758
+ });
1759
+ }
1760
+ return /*#__PURE__*/jsx("div", {
1761
+ style: {
1762
+ height: height
1763
+ },
1764
+ className: classnames("neeto-form-engine-choice__image-wrapper", {
1765
+ "neeto-form-engine-choice__image-wrapper--loading": isLoading
1766
+ }),
1767
+ children: /*#__PURE__*/jsx("img", {
1768
+ alt: alt,
1769
+ src: src,
1770
+ className: classnames("neeto-form-engine-choice__image", {
1771
+ "neeto-form-engine-choice__image--fit": shouldFitImages
1772
+ }),
1773
+ onError: handleError,
1774
+ onLoad: handleLoad
1775
+ })
1776
+ });
1777
+ };
1778
+
1728
1779
  var Choices = function Choices(_ref) {
1729
1780
  var label = _ref.label,
1730
1781
  options = _ref.options,
@@ -1733,51 +1784,66 @@ var Choices = function Choices(_ref) {
1733
1784
  value = _ref.value,
1734
1785
  onChange = _ref.onChange,
1735
1786
  error = _ref.error,
1736
- disabled = _ref.isDisabled;
1787
+ disabled = _ref.isDisabled,
1788
+ _ref$isPictureChoice = _ref.isPictureChoice,
1789
+ isPictureChoice = _ref$isPictureChoice === void 0 ? DEFAULT_CHOICE_QUESTION_ATTRIBUTES.isPictureChoice : _ref$isPictureChoice,
1790
+ _ref$imageHeight = _ref.imageHeight,
1791
+ imageHeight = _ref$imageHeight === void 0 ? DEFAULT_CHOICE_QUESTION_ATTRIBUTES.imageHeight : _ref$imageHeight,
1792
+ _ref$shouldFitImages = _ref.shouldFitImages,
1793
+ shouldFitImages = _ref$shouldFitImages === void 0 ? DEFAULT_CHOICE_QUESTION_ATTRIBUTES.shouldFitImages : _ref$shouldFitImages;
1737
1794
  var isCheckBox = type === "checkbox";
1738
1795
  var ChoiceWrapper = isCheckBox ? "div" : Radio;
1739
1796
  var Component = isCheckBox ? Checkbox : Radio.Item;
1740
1797
  return /*#__PURE__*/jsxs("div", {
1741
1798
  className: "neeto-form-engine-choices__wrapper",
1742
- "data-cy": "".concat(hyphenate(label), "-select-container-wrapper"),
1799
+ "data-testid": "".concat(hyphenate(label), "-select-container-wrapper"),
1743
1800
  children: [/*#__PURE__*/jsx("label", {
1744
1801
  className: "neeto-form-engine-label",
1745
- "data-cy": "".concat(hyphenate(label), "-input-label"),
1802
+ "data-testid": "".concat(hyphenate(label), "-input-label"),
1746
1803
  children: label
1747
1804
  }), /*#__PURE__*/jsx(ChoiceWrapper, {
1748
- className: "neeto-form-engine-choices",
1749
1805
  stacked: !isCheckBox,
1806
+ className: classnames("neeto-form-engine-choices", {
1807
+ "neeto-form-engine-choices--picture": isPictureChoice
1808
+ }),
1750
1809
  children: options.map(function (option, index) {
1751
- var _value$index;
1752
- return /*#__PURE__*/jsx("label", {
1810
+ var _value$index, _option$image;
1811
+ var isChecked = isCheckBox ? (_value$index = value === null || value === void 0 ? void 0 : value[index]) !== null && _value$index !== void 0 ? _value$index : false : value === option.id;
1812
+ return /*#__PURE__*/jsxs("label", {
1753
1813
  htmlFor: option.id,
1754
1814
  className: classnames("neeto-form-engine-choice", {
1755
- active: false,
1815
+ "neeto-form-engine-choice--picture": isPictureChoice,
1816
+ "neeto-form-engine-choice--selected": isChecked,
1756
1817
  "cursor-not-allowed": disabled
1757
1818
  }),
1758
- children: /*#__PURE__*/jsx(Component, {
1819
+ children: [isPictureChoice && /*#__PURE__*/jsx(ChoiceImage, {
1820
+ shouldFitImages: shouldFitImages,
1821
+ alt: option.label,
1822
+ height: imageHeight,
1823
+ src: (_option$image = option.image) === null || _option$image === void 0 ? void 0 : _option$image.url
1824
+ }), /*#__PURE__*/jsx(Component, {
1759
1825
  disabled: disabled,
1760
1826
  onChange: onChange,
1761
1827
  type: type,
1828
+ checked: isChecked,
1762
1829
  className: classnames({
1763
1830
  "cursor-not-allowed": disabled
1764
1831
  }),
1765
1832
  id: option.id,
1833
+ label: option.label,
1834
+ name: isCheckBox ? "".concat(name, ".").concat(index) : name,
1835
+ value: option.id,
1766
1836
  labelProps: {
1767
1837
  className: classnames({
1768
1838
  "cursor-not-allowed": disabled
1769
1839
  })
1770
- },
1771
- label: option.label,
1772
- name: isCheckBox ? "".concat(name, ".").concat(index) : name,
1773
- value: option.id,
1774
- checked: isCheckBox ? (_value$index = value === null || value === void 0 ? void 0 : value[index]) !== null && _value$index !== void 0 ? _value$index : false : value === option.id
1775
- })
1840
+ }
1841
+ })]
1776
1842
  }, option.id);
1777
1843
  })
1778
1844
  }), !!error && typeof error === "string" && /*#__PURE__*/jsx("p", {
1779
1845
  className: "neeto-form-engine-input__error",
1780
- "data-cy": "neeto-form-engine-".concat(type, "-error"),
1846
+ "data-testid": "neeto-form-engine-".concat(type, "-error"),
1781
1847
  children: error
1782
1848
  })]
1783
1849
  });
@@ -1798,8 +1864,12 @@ var OptionsField = function OptionsField(_ref) {
1798
1864
  kind = question.kind,
1799
1865
  isRequired = question.isRequired,
1800
1866
  isReadOnly = question.isReadOnly,
1867
+ isPictureChoiceFromQuestion = question.isPictureChoice,
1868
+ imageHeight = question.imageHeight,
1869
+ shouldFitImages = question.shouldFitImages,
1801
1870
  _question$optionsAttr = question.optionsAttributes,
1802
1871
  options = _question$optionsAttr === void 0 ? [] : _question$optionsAttr;
1872
+ var isPictureChoice = isPictureChoiceFromQuestion;
1803
1873
  var isDropdown = kind === QUESTION_KIND.DROPDOWN.value;
1804
1874
  var label = fieldWithFallback(question, "label");
1805
1875
  var Component = isDropdown ? Select : Choices$1;
@@ -1839,17 +1909,22 @@ var OptionsField = function OptionsField(_ref) {
1839
1909
  var onChange = field.onChange,
1840
1910
  value = field.value;
1841
1911
  return /*#__PURE__*/jsx(Component, _objectSpread$8(_objectSpread$8({
1842
- isRequired: isRequired,
1843
- name: name,
1844
1912
  error: getError(meta),
1845
1913
  isDisabled: isReadOnly,
1846
1914
  label: getLabel(label, isRequired),
1847
1915
  options: transformedOptions,
1848
1916
  strategy: "fixed",
1849
1917
  type: kind
1918
+ }, _objectSpread$8(_objectSpread$8({
1919
+ isRequired: isRequired,
1920
+ name: name
1850
1921
  }, isDropdown && {
1851
1922
  filterOption: customFilter
1852
- }), {}, {
1923
+ }), !isDropdown && {
1924
+ imageHeight: imageHeight,
1925
+ isPictureChoice: isPictureChoice,
1926
+ shouldFitImages: shouldFitImages
1927
+ })), {}, {
1853
1928
  value: isDropdown ? findBy({
1854
1929
  value: value
1855
1930
  }, transformedOptions) || null : value,
@@ -1962,15 +2037,15 @@ var Rating = function Rating(_ref) {
1962
2037
  className: "neeto-form-engine-rating",
1963
2038
  children: [/*#__PURE__*/jsx("label", {
1964
2039
  className: "neeto-form-engine-label",
1965
- "data-cy": "rating-input-label",
2040
+ "data-testid": "rating-input-label",
1966
2041
  children: label
1967
2042
  }), /*#__PURE__*/jsx("div", {
1968
2043
  className: "neeto-form-engine-rating__row",
1969
- "data-cy": "rating-input-field",
2044
+ "data-testid": "rating-input-field",
1970
2045
  children: render()
1971
2046
  }), !!error && typeof error === "string" && /*#__PURE__*/jsx("p", {
1972
2047
  className: "neeto-form-engine-input__error",
1973
- "data-cy": "neeto-form-engine-rating-error",
2048
+ "data-testid": "neeto-form-engine-rating-error",
1974
2049
  children: error
1975
2050
  })]
1976
2051
  });
@@ -2038,7 +2113,7 @@ var RichTextEditor = function RichTextEditor(_ref) {
2038
2113
  className: "neeto-form-engine-input__label-wrapper",
2039
2114
  children: label && /*#__PURE__*/jsx("label", {
2040
2115
  className: "neeto-form-engine-label",
2041
- "data-cy": "".concat(hyphenate(label), "-input-label"),
2116
+ "data-testid": "".concat(hyphenate(label), "-input-label"),
2042
2117
  children: getLabel(label, isRequired)
2043
2118
  })
2044
2119
  }), /*#__PURE__*/jsx(FastField, {
@@ -2137,12 +2212,12 @@ var StarRating = function StarRating(_ref) {
2137
2212
  className: "neeto-form-engine-input__label-wrapper",
2138
2213
  children: /*#__PURE__*/jsx("label", {
2139
2214
  className: "neeto-form-engine-label",
2140
- "data-cy": "star-rating-input-label",
2215
+ "data-testid": "star-rating-input-label",
2141
2216
  children: label
2142
2217
  })
2143
2218
  }), /*#__PURE__*/jsx("div", {
2144
2219
  className: "neeto-form-engine-star-rating__row",
2145
- "data-cy": "star-rating-input-field",
2220
+ "data-testid": "star-rating-input-field",
2146
2221
  children: generateArray(minValue, maxValue).map(function (index) {
2147
2222
  return /*#__PURE__*/jsx(RatingButton$1, _objectSpread$3({
2148
2223
  label: index,
@@ -2151,7 +2226,7 @@ var StarRating = function StarRating(_ref) {
2151
2226
  })
2152
2227
  }), !!error && typeof error === "string" && /*#__PURE__*/jsx("p", {
2153
2228
  className: "neeto-form-engine-input__error",
2154
- "data-cy": "neeto-form-engine-star-rating-error",
2229
+ "data-testid": "neeto-form-engine-star-rating-error",
2155
2230
  children: error
2156
2231
  })]
2157
2232
  });
@@ -2325,4 +2400,4 @@ var containsIgnoreCase = function containsIgnoreCase(string, substring) {
2325
2400
  };
2326
2401
 
2327
2402
  export { FormikWrap as F, getFieldComponent as a, buildAutoCompleteAttribute as b, clientI18nInstance as c, getWithExpiry as d, clearEmailVerificationDetails as e, generateFormResponse as f, generateInitValues as g, clearLocalStorageValues as h, mergeRefs as m, renderButtonsInOrder as r };
2328
- //# sourceMappingURL=utils-CdeIdZRi.js.map
2403
+ //# sourceMappingURL=utils-GRfGBny0.js.map