@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.d.ts CHANGED
@@ -1135,7 +1135,7 @@ type TAddressInputGroupFormValue = {
1135
1135
  street: string;
1136
1136
  houseNumber: string;
1137
1137
  zipCode: string;
1138
- busNumber: string;
1138
+ busNumber?: string;
1139
1139
  lat: number;
1140
1140
  lng: number;
1141
1141
  info?: string;
package/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
2
2
  import { ArrowPathIcon, ChevronDownIcon, EllipsisVerticalIcon, ExclamationCircleIcon, ChevronDoubleLeftIcon, ChevronLeftIcon, ChevronRightIcon, ChevronDoubleRightIcon, ChevronUpIcon, ChevronUpDownIcon, HomeIcon, ArrowLongLeftIcon, ArrowLongRightIcon } from '@heroicons/react/20/solid';
3
- import { isArray, map, set, get, noop as noop$1, indexOf, toSafeInteger, pick, isEmpty, some, forEach, assign } from 'lodash';
3
+ import { isArray, map, set, get, noop as noop$1, indexOf, toSafeInteger, pick, isEmpty, some, forEach, assign, intersection, trim, lastIndexOf } from 'lodash';
4
4
  import get$1 from 'lodash/get';
5
5
  import React, { useState, useMemo, Children, Fragment, useEffect, useCallback, useRef, forwardRef, useImperativeHandle, useReducer, createElement, PureComponent, Component } from 'react';
6
6
  import { library } from '@fortawesome/fontawesome-svg-core';
@@ -2676,13 +2676,14 @@ var DateMenuForm = function (props) {
2676
2676
  startDate: null,
2677
2677
  endDate: null,
2678
2678
  }), state = _p[0], setState = _p[1];
2679
- var handleValueChange = function (newValue) {
2679
+ var $datepickerInputRef = useRef(null);
2680
+ var handleValueChange = useCallback(function (newValue) {
2680
2681
  setState(newValue);
2681
2682
  onChange && onChange(newValue);
2682
2683
  setTimeout(function () {
2683
2684
  onBlur && onBlur();
2684
2685
  }, 50);
2685
- };
2686
+ }, [onBlur, onChange]);
2686
2687
  var handleGenerateStyle = function () {
2687
2688
  var result = deepCopyObject(styles$6.base);
2688
2689
  var keys = calculateNestedKeys(styles$6.base);
@@ -2705,7 +2706,40 @@ var DateMenuForm = function (props) {
2705
2706
  useEffect(function () {
2706
2707
  setState(defaultValue !== null && defaultValue !== void 0 ? defaultValue : { startDate: null, endDate: null });
2707
2708
  }, [defaultValue]);
2708
- return (jsxs("div", { className: styles.container, children: [jsxs("div", { className: styles.head, children: [label && (jsx("label", { htmlFor: name, className: styles.label, children: label })), !required && !isRequired && typeof label === 'string' && (jsx("span", { className: styles.hint, children: "Optional" })), required && required({ isRequired: isRequired })] }), jsxs("div", { className: styles.container, "data-cy": inputDataCy, children: [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,
2709
+ useEffect(function () {
2710
+ var _a;
2711
+ var input = (_a = $datepickerInputRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('input');
2712
+ var allowedCharacters = '0123456789';
2713
+ var separators = "./-".concat(separator);
2714
+ var callback = function (event) {
2715
+ if ((input === null || input === void 0 ? void 0 : input.value) === null ||
2716
+ (input === null || input === void 0 ? void 0 : input.value) === undefined ||
2717
+ intersection(input.value.split(''), separators.split('')).length > 0 ||
2718
+ isRanged) {
2719
+ return;
2720
+ }
2721
+ if (allowedCharacters.includes(event.key) && (input === null || input === void 0 ? void 0 : input.value.length) >= 7) {
2722
+ var newValue = input.value + event.key;
2723
+ var day = newValue.substring(0, 2);
2724
+ var month = newValue.substring(2, 4);
2725
+ var year = newValue.substring(4, 8);
2726
+ var newDate = new Date("".concat(year, "-").concat(month, "-").concat(day));
2727
+ if (isNaN(newDate.getTime()))
2728
+ return;
2729
+ input.blur();
2730
+ handleValueChange({
2731
+ startDate: "".concat(year, "-").concat(month, "-").concat(day),
2732
+ endDate: "".concat(year, "-").concat(month, "-").concat(day),
2733
+ });
2734
+ setTimeout(function () { return input.focus(); }, 100);
2735
+ }
2736
+ };
2737
+ if (input) {
2738
+ input.addEventListener('keydown', callback);
2739
+ }
2740
+ return function () { return removeEventListener('keydown', callback); };
2741
+ }, [handleValueChange, isRanged, separator]);
2742
+ return (jsxs("div", { className: styles.container, children: [jsxs("div", { className: styles.head, children: [label && (jsx("label", { htmlFor: name, className: styles.label, children: label })), !required && !isRequired && typeof label === 'string' && (jsx("span", { className: styles.hint, children: "Optional" })), required && required({ isRequired: isRequired })] }), jsxs("div", { className: styles.container, "data-cy": inputDataCy, ref: $datepickerInputRef, children: [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,
2709
2743
  //
2710
2744
  value: state,
2711
2745
  //
@@ -10745,6 +10779,26 @@ var AddressInputGroupForm = function (props) {
10745
10779
  var zipCode = handleExtractValueWithKey('postal_code');
10746
10780
  var houseNumber = handleExtractValueWithKey('street_number');
10747
10781
  var busNumber = handleExtractValueWithKey('post_box');
10782
+ if (
10783
+ // if busNumber is not found with the method above, try to find it in the user inputted label
10784
+ !busNumber &&
10785
+ (
10786
+ // if the label contains the houseNumber and city somewhere after the houseNumber
10787
+ e === null || e === void 0 ? void 0 : e.label.includes(houseNumber)) &&
10788
+ (e === null || e === void 0 ? void 0 : e.label.split(houseNumber)[1].includes(city))) {
10789
+ // split the label at the houseNumber and city
10790
+ var splitLabel = e === null || e === void 0 ? void 0 : e.label.split(houseNumber)[1].split(city)[0];
10791
+ // replace the zipCode from the label if it came before the city
10792
+ var replaceZipcode = splitLabel.replace(zipCode, '');
10793
+ // trim the label
10794
+ var trimmedLabel = trim(replaceZipcode);
10795
+ // if the trimmed label is shorter than 3 characters, it's probably the busNumber. Otherwise, something probably went wrong.
10796
+ if (trimmedLabel.length <= 3) {
10797
+ busNumber = trimmedLabel.includes(',')
10798
+ ? trimmedLabel.substring(0, lastIndexOf(trimmedLabel, ','))
10799
+ : trimmedLabel;
10800
+ }
10801
+ }
10748
10802
  var location = {
10749
10803
  street: street,
10750
10804
  city: city,