@ballistix.digital/react-components 1.0.0 → 1.0.2

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/dist/index.js CHANGED
@@ -2678,13 +2678,14 @@ var DateMenuForm = function (props) {
2678
2678
  startDate: null,
2679
2679
  endDate: null,
2680
2680
  }), state = _p[0], setState = _p[1];
2681
- var handleValueChange = function (newValue) {
2681
+ var $datepickerInputRef = React.useRef(null);
2682
+ var handleValueChange = React.useCallback(function (newValue) {
2682
2683
  setState(newValue);
2683
2684
  onChange && onChange(newValue);
2684
2685
  setTimeout(function () {
2685
2686
  onBlur && onBlur();
2686
2687
  }, 50);
2687
- };
2688
+ }, [onBlur, onChange]);
2688
2689
  var handleGenerateStyle = function () {
2689
2690
  var result = deepCopyObject(styles$6.base);
2690
2691
  var keys = calculateNestedKeys(styles$6.base);
@@ -2707,7 +2708,40 @@ var DateMenuForm = function (props) {
2707
2708
  React.useEffect(function () {
2708
2709
  setState(defaultValue !== null && defaultValue !== void 0 ? defaultValue : { startDate: null, endDate: null });
2709
2710
  }, [defaultValue]);
2710
- return (jsxRuntime.jsxs("div", { className: styles.container, children: [jsxRuntime.jsxs("div", { className: styles.head, children: [label && (jsxRuntime.jsx("label", { htmlFor: name, className: styles.label, children: label })), !required && !isRequired && typeof label === 'string' && (jsxRuntime.jsx("span", { className: styles.hint, children: "Optional" })), required && required({ isRequired: isRequired })] }), jsxRuntime.jsxs("div", { className: styles.container, "data-cy": inputDataCy, children: [jsxRuntime.jsx(Datepicker, { inputName: name, inputId: name, i18n: i18n, useRange: size === 'expanded', placeholder: placeholder, asSingle: !isRanged, separator: separator, startFrom: startFrom, displayFormat: displayFormat, disabled: isDisabled, popoverDirection: direction, minDate: minDate, maxDate: maxDate, toggleIcon: icon,
2711
+ React.useEffect(function () {
2712
+ var _a;
2713
+ var input = (_a = $datepickerInputRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('input');
2714
+ var allowedCharacters = '0123456789';
2715
+ var separators = "./-".concat(separator);
2716
+ var callback = function (event) {
2717
+ if ((input === null || input === void 0 ? void 0 : input.value) === null ||
2718
+ (input === null || input === void 0 ? void 0 : input.value) === undefined ||
2719
+ lodash.intersection(input.value.split(''), separators.split('')).length > 0 ||
2720
+ isRanged) {
2721
+ return;
2722
+ }
2723
+ if (allowedCharacters.includes(event.key) && (input === null || input === void 0 ? void 0 : input.value.length) >= 7) {
2724
+ var newValue = input.value + event.key;
2725
+ var day = newValue.substring(0, 2);
2726
+ var month = newValue.substring(2, 4);
2727
+ var year = newValue.substring(4, 8);
2728
+ var newDate = new Date("".concat(year, "-").concat(month, "-").concat(day));
2729
+ if (isNaN(newDate.getTime()))
2730
+ return;
2731
+ input.blur();
2732
+ handleValueChange({
2733
+ startDate: "".concat(year, "-").concat(month, "-").concat(day),
2734
+ endDate: "".concat(year, "-").concat(month, "-").concat(day),
2735
+ });
2736
+ setTimeout(function () { return input.focus(); }, 100);
2737
+ }
2738
+ };
2739
+ if (input) {
2740
+ input.addEventListener('keydown', callback);
2741
+ }
2742
+ return function () { return removeEventListener('keydown', callback); };
2743
+ }, [handleValueChange, isRanged, separator]);
2744
+ return (jsxRuntime.jsxs("div", { className: styles.container, children: [jsxRuntime.jsxs("div", { className: styles.head, children: [label && (jsxRuntime.jsx("label", { htmlFor: name, className: styles.label, children: label })), !required && !isRequired && typeof label === 'string' && (jsxRuntime.jsx("span", { className: styles.hint, children: "Optional" })), required && required({ isRequired: isRequired })] }), jsxRuntime.jsxs("div", { className: styles.container, "data-cy": inputDataCy, ref: $datepickerInputRef, children: [jsxRuntime.jsx(Datepicker, { inputName: name, inputId: name, i18n: i18n, useRange: size === 'expanded', placeholder: placeholder, asSingle: !isRanged, separator: separator, startFrom: startFrom, displayFormat: displayFormat, disabled: isDisabled, popoverDirection: direction, minDate: minDate, maxDate: maxDate, toggleIcon: icon,
2711
2745
  //
2712
2746
  value: state,
2713
2747
  //
@@ -10747,6 +10781,26 @@ var AddressInputGroupForm = function (props) {
10747
10781
  var zipCode = handleExtractValueWithKey('postal_code');
10748
10782
  var houseNumber = handleExtractValueWithKey('street_number');
10749
10783
  var busNumber = handleExtractValueWithKey('post_box');
10784
+ if (
10785
+ // if busNumber is not found with the method above, try to find it in the user inputted label
10786
+ !busNumber &&
10787
+ (
10788
+ // if the label contains the houseNumber and city somewhere after the houseNumber
10789
+ e === null || e === void 0 ? void 0 : e.label.includes(houseNumber)) &&
10790
+ (e === null || e === void 0 ? void 0 : e.label.split(houseNumber)[1].includes(city))) {
10791
+ // split the label at the houseNumber and city
10792
+ var splitLabel = e === null || e === void 0 ? void 0 : e.label.split(houseNumber)[1].split(city)[0];
10793
+ // replace the zipCode from the label if it came before the city
10794
+ var replaceZipcode = splitLabel.replace(zipCode, '');
10795
+ // trim the label
10796
+ var trimmedLabel = lodash.trim(replaceZipcode);
10797
+ // if the trimmed label is shorter than 3 characters, it's probably the busNumber. Otherwise, something probably went wrong.
10798
+ if (trimmedLabel.length <= 3) {
10799
+ busNumber = trimmedLabel.includes(',')
10800
+ ? trimmedLabel.substring(0, lodash.lastIndexOf(trimmedLabel, ','))
10801
+ : trimmedLabel;
10802
+ }
10803
+ }
10750
10804
  var location = {
10751
10805
  street: street,
10752
10806
  city: city,