@ballistix.digital/react-components 1.0.0 → 1.0.1

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
  //