@justfixnyc/component-library 0.53.9 → 0.54.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.
- package/dist/src/index.es.js +30 -2
- package/dist/src/index.js +29 -1
- package/package.json +1 -1
package/dist/src/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from '@babel/runtime/helpers/extends';
|
|
2
2
|
import classNames from 'classnames';
|
|
3
|
-
import React, { forwardRef, useId } from 'react';
|
|
3
|
+
import React, { forwardRef, useId, useState } from 'react';
|
|
4
4
|
import { faBan, faXmark, faDownload as faDownload$1, faBuildingColumns, faAddressCard, faBuilding, faMapLocationDot, faMemoPad, faLocationDot, faHouse, faGlobe, faUser, faSpinner, faBars, faEnvelope as faEnvelope$1, faCommentSms, faCopy, faCirclePlus, faCircleInfo, faCircleExclamation as faCircleExclamation$1, faChevronRight, faChevronLeft, faChevronDown, faChevronUp, faCheckDouble, faCheck, faCaretDown, faCaretRight, faBookmark as faBookmark$1, faSquareArrowUpRight, faArrowsRotateReverse, faArrowDownWideShort, faArrowUpShortWide, faArrowUpArrowDown, faArrowDownLong, faArrowUpLong, faArrowDown, faArrowUp, faArrowRight, faArrowLeft } from '@awesome.me/kit-dd32553919/icons/classic/solid';
|
|
5
5
|
import { faPrint, faEyeSlash, faEye, faDownload, faEnvelope, faCircleExclamation, faBookmark } from '@awesome.me/kit-dd32553919/icons/classic/regular';
|
|
6
6
|
import { faXTwitter, faTwitter, faFacebookF } from '@awesome.me/kit-dd32553919/icons/classic/brands';
|
|
@@ -581,6 +581,32 @@ const TextInput = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
581
581
|
const textInputClassNames = classNames('jfcl-text-input__input', {
|
|
582
582
|
["jfcl-text-input--size-".concat(size)]: size
|
|
583
583
|
});
|
|
584
|
+
const formatPhoneNumber = value => {
|
|
585
|
+
// remove all non-digit characters
|
|
586
|
+
const cleaned = value.replace(/\D/g, '');
|
|
587
|
+
// limit to 10 characters
|
|
588
|
+
const limited = cleaned.slice(0, 10);
|
|
589
|
+
|
|
590
|
+
// format with parentheses and dashes e.g. (555) 666-7777
|
|
591
|
+
const match = limited.match(/^(\d{0,3})(\d{0,3})(\d{0,4})$/);
|
|
592
|
+
if (match) {
|
|
593
|
+
const [, part1, part2, part3] = match;
|
|
594
|
+
const formatted = [part1 ? "(".concat(part1) : '', part2 ? ") ".concat(part2) : '', part3 ? "-".concat(part3) : ''].join('').trim();
|
|
595
|
+
return formatted;
|
|
596
|
+
}
|
|
597
|
+
return value;
|
|
598
|
+
};
|
|
599
|
+
const [inputValue, setInputValue] = useState('');
|
|
600
|
+
const handleChange = e => {
|
|
601
|
+
let formattedValue = e.target.value;
|
|
602
|
+
if (type === 'tel') {
|
|
603
|
+
formattedValue = formatPhoneNumber(e.target.value);
|
|
604
|
+
}
|
|
605
|
+
setInputValue(formattedValue);
|
|
606
|
+
if (props.onChange) {
|
|
607
|
+
props.onChange(e); // call original onChange if provided
|
|
608
|
+
}
|
|
609
|
+
};
|
|
584
610
|
return /*#__PURE__*/React.createElement("div", {
|
|
585
611
|
className: textInputWrapperClassNames,
|
|
586
612
|
"data-testid": "jfcl-text-input"
|
|
@@ -600,7 +626,9 @@ const TextInput = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
600
626
|
}, props, {
|
|
601
627
|
id: id,
|
|
602
628
|
className: textInputClassNames,
|
|
603
|
-
type: inputType
|
|
629
|
+
type: inputType,
|
|
630
|
+
value: inputValue,
|
|
631
|
+
onChange: handleChange
|
|
604
632
|
}))));
|
|
605
633
|
});
|
|
606
634
|
TextInput.displayName = 'TextInput';
|
package/dist/src/index.js
CHANGED
|
@@ -592,6 +592,32 @@ const TextInput = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref)
|
|
|
592
592
|
const textInputClassNames = classNames__default["default"]('jfcl-text-input__input', {
|
|
593
593
|
["jfcl-text-input--size-".concat(size)]: size
|
|
594
594
|
});
|
|
595
|
+
const formatPhoneNumber = value => {
|
|
596
|
+
// remove all non-digit characters
|
|
597
|
+
const cleaned = value.replace(/\D/g, '');
|
|
598
|
+
// limit to 10 characters
|
|
599
|
+
const limited = cleaned.slice(0, 10);
|
|
600
|
+
|
|
601
|
+
// format with parentheses and dashes e.g. (555) 666-7777
|
|
602
|
+
const match = limited.match(/^(\d{0,3})(\d{0,3})(\d{0,4})$/);
|
|
603
|
+
if (match) {
|
|
604
|
+
const [, part1, part2, part3] = match;
|
|
605
|
+
const formatted = [part1 ? "(".concat(part1) : '', part2 ? ") ".concat(part2) : '', part3 ? "-".concat(part3) : ''].join('').trim();
|
|
606
|
+
return formatted;
|
|
607
|
+
}
|
|
608
|
+
return value;
|
|
609
|
+
};
|
|
610
|
+
const [inputValue, setInputValue] = React.useState('');
|
|
611
|
+
const handleChange = e => {
|
|
612
|
+
let formattedValue = e.target.value;
|
|
613
|
+
if (type === 'tel') {
|
|
614
|
+
formattedValue = formatPhoneNumber(e.target.value);
|
|
615
|
+
}
|
|
616
|
+
setInputValue(formattedValue);
|
|
617
|
+
if (props.onChange) {
|
|
618
|
+
props.onChange(e); // call original onChange if provided
|
|
619
|
+
}
|
|
620
|
+
};
|
|
595
621
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
596
622
|
className: textInputWrapperClassNames,
|
|
597
623
|
"data-testid": "jfcl-text-input"
|
|
@@ -611,7 +637,9 @@ const TextInput = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref)
|
|
|
611
637
|
}, props, {
|
|
612
638
|
id: id,
|
|
613
639
|
className: textInputClassNames,
|
|
614
|
-
type: inputType
|
|
640
|
+
type: inputType,
|
|
641
|
+
value: inputValue,
|
|
642
|
+
onChange: handleChange
|
|
615
643
|
}))));
|
|
616
644
|
});
|
|
617
645
|
TextInput.displayName = 'TextInput';
|