@scripso-homepad/ui 0.4.39 → 0.4.40
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.cjs +52 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +47 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/PhoneInput.stories.tsx +1 -2
- package/src/components/PhoneInput.tsx +24 -8
- package/src/index.ts +9 -0
- package/src/utils/phoneFormat.test.ts +34 -0
- package/src/utils/phoneFormat.ts +57 -0
package/dist/index.cjs
CHANGED
|
@@ -2091,6 +2091,42 @@ var styles6 = reactNative.StyleSheet.create({
|
|
|
2091
2091
|
color: colors.slateBlue
|
|
2092
2092
|
}
|
|
2093
2093
|
});
|
|
2094
|
+
|
|
2095
|
+
// src/utils/phoneFormat.ts
|
|
2096
|
+
var DEFAULT_PHONE_COUNTRY_CODE = defaultCountry.code;
|
|
2097
|
+
var AM_NATIONAL_MAX_DIGITS = 8;
|
|
2098
|
+
var MAX_NATIONAL_DIGITS = 15;
|
|
2099
|
+
function getPhoneDigits(value) {
|
|
2100
|
+
return value.replace(/\D/g, "");
|
|
2101
|
+
}
|
|
2102
|
+
function formatArmenianNationalNumber(digits) {
|
|
2103
|
+
const national = getPhoneDigits(digits).slice(0, AM_NATIONAL_MAX_DIGITS);
|
|
2104
|
+
if (national.length === 0) {
|
|
2105
|
+
return "";
|
|
2106
|
+
}
|
|
2107
|
+
if (national.length <= 2) {
|
|
2108
|
+
return `(${national}`;
|
|
2109
|
+
}
|
|
2110
|
+
const head = national.slice(0, 2);
|
|
2111
|
+
const rest = national.slice(2);
|
|
2112
|
+
const groups = rest.match(/.{1,2}/g) ?? [];
|
|
2113
|
+
return `(${head}) ${groups.join("-")}`;
|
|
2114
|
+
}
|
|
2115
|
+
function formatNationalPhoneDisplay(digits, countryCode = DEFAULT_PHONE_COUNTRY_CODE) {
|
|
2116
|
+
const national = getPhoneDigits(digits).slice(0, MAX_NATIONAL_DIGITS);
|
|
2117
|
+
if (countryCode === DEFAULT_PHONE_COUNTRY_CODE) {
|
|
2118
|
+
return formatArmenianNationalNumber(national);
|
|
2119
|
+
}
|
|
2120
|
+
return national;
|
|
2121
|
+
}
|
|
2122
|
+
function sanitizeNationalPhoneDigits(value, countryCode = DEFAULT_PHONE_COUNTRY_CODE) {
|
|
2123
|
+
const digits = getPhoneDigits(value);
|
|
2124
|
+
if (countryCode === DEFAULT_PHONE_COUNTRY_CODE) {
|
|
2125
|
+
return digits.slice(0, AM_NATIONAL_MAX_DIGITS);
|
|
2126
|
+
}
|
|
2127
|
+
return digits.slice(0, MAX_NATIONAL_DIGITS);
|
|
2128
|
+
}
|
|
2129
|
+
var ARMENIAN_PHONE_PLACEHOLDER = "(00) 00-00-00";
|
|
2094
2130
|
var countryOutlineSlot = {
|
|
2095
2131
|
borderRadius: radii.lg + INPUT_OUTLINE_WIDTH,
|
|
2096
2132
|
borderWidth: INPUT_OUTLINE_WIDTH,
|
|
@@ -2098,12 +2134,9 @@ var countryOutlineSlot = {
|
|
|
2098
2134
|
padding: 0,
|
|
2099
2135
|
backgroundColor: colors.transparent
|
|
2100
2136
|
};
|
|
2101
|
-
function sanitizePhoneDigits(value) {
|
|
2102
|
-
return value.replace(/\D/g, "");
|
|
2103
|
-
}
|
|
2104
2137
|
function PhoneInput({
|
|
2105
2138
|
label,
|
|
2106
|
-
countryCode,
|
|
2139
|
+
countryCode = defaultCountry.code,
|
|
2107
2140
|
onCountryCodeChange,
|
|
2108
2141
|
error,
|
|
2109
2142
|
hint,
|
|
@@ -2120,6 +2153,8 @@ function PhoneInput({
|
|
|
2120
2153
|
onFocus,
|
|
2121
2154
|
onBlur,
|
|
2122
2155
|
onChangeText,
|
|
2156
|
+
value,
|
|
2157
|
+
placeholder,
|
|
2123
2158
|
...props
|
|
2124
2159
|
}) {
|
|
2125
2160
|
const wrapperRef = react.useRef(null);
|
|
@@ -2136,6 +2171,9 @@ function PhoneInput({
|
|
|
2136
2171
|
disabled: isDisabled
|
|
2137
2172
|
});
|
|
2138
2173
|
const phoneFieldStyles = getInputFieldStyles(phoneVisualState);
|
|
2174
|
+
const resolvedCountryCode = countryCode || DEFAULT_PHONE_COUNTRY_CODE;
|
|
2175
|
+
const displayValue = typeof value === "string" || typeof value === "number" ? formatNationalPhoneDisplay(String(value), resolvedCountryCode) : value;
|
|
2176
|
+
const resolvedPlaceholder = placeholder ?? (resolvedCountryCode === DEFAULT_PHONE_COUNTRY_CODE ? ARMENIAN_PHONE_PLACEHOLDER : void 0);
|
|
2139
2177
|
function handleFocus(event) {
|
|
2140
2178
|
setFocused(true);
|
|
2141
2179
|
onFocus?.(event);
|
|
@@ -2144,8 +2182,8 @@ function PhoneInput({
|
|
|
2144
2182
|
setFocused(false);
|
|
2145
2183
|
onBlur?.(event);
|
|
2146
2184
|
}
|
|
2147
|
-
function handleChangeText(
|
|
2148
|
-
onChangeText?.(
|
|
2185
|
+
function handleChangeText(nextValue) {
|
|
2186
|
+
onChangeText?.(sanitizeNationalPhoneDigits(nextValue, resolvedCountryCode));
|
|
2149
2187
|
}
|
|
2150
2188
|
const helperMessage = error ?? hint;
|
|
2151
2189
|
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: wrapperRef, style: [styles7.wrapper, containerStyle], children: [
|
|
@@ -2195,6 +2233,8 @@ function PhoneInput({
|
|
|
2195
2233
|
onBlur: handleBlur,
|
|
2196
2234
|
accessibilityState: { disabled: isDisabled },
|
|
2197
2235
|
...props,
|
|
2236
|
+
value: displayValue,
|
|
2237
|
+
placeholder: resolvedPlaceholder,
|
|
2198
2238
|
onChangeText: handleChangeText
|
|
2199
2239
|
}
|
|
2200
2240
|
)
|
|
@@ -3606,12 +3646,14 @@ function LockIcon({
|
|
|
3606
3646
|
) });
|
|
3607
3647
|
}
|
|
3608
3648
|
|
|
3649
|
+
exports.ARMENIAN_PHONE_PLACEHOLDER = ARMENIAN_PHONE_PLACEHOLDER;
|
|
3609
3650
|
exports.Button = Button;
|
|
3610
3651
|
exports.Calendar = Calendar;
|
|
3611
3652
|
exports.CalendarIcon = CalendarIcon;
|
|
3612
3653
|
exports.CalendarLocaleProvider = CalendarLocaleProvider;
|
|
3613
3654
|
exports.CountryCodeSelector = CountryCodeSelector;
|
|
3614
3655
|
exports.CountryFlag = CountryFlag;
|
|
3656
|
+
exports.DEFAULT_PHONE_COUNTRY_CODE = DEFAULT_PHONE_COUNTRY_CODE;
|
|
3615
3657
|
exports.DatePicker = DatePicker;
|
|
3616
3658
|
exports.Input = Input;
|
|
3617
3659
|
exports.Label = Label;
|
|
@@ -3631,16 +3673,20 @@ exports.findCountry = findCountry;
|
|
|
3631
3673
|
exports.fontSize = fontSize;
|
|
3632
3674
|
exports.fontWeight = fontWeight;
|
|
3633
3675
|
exports.fonts = fonts;
|
|
3676
|
+
exports.formatArmenianNationalNumber = formatArmenianNationalNumber;
|
|
3634
3677
|
exports.formatLocalizedCalendarMonthYear = formatLocalizedCalendarMonthYear;
|
|
3678
|
+
exports.formatNationalPhoneDisplay = formatNationalPhoneDisplay;
|
|
3635
3679
|
exports.getCalendarMonthLabels = getCalendarMonthLabels;
|
|
3636
3680
|
exports.getCalendarTranslations = getCalendarTranslations;
|
|
3637
3681
|
exports.getCountryFlagImageUri = getCountryFlagImageUri;
|
|
3682
|
+
exports.getPhoneDigits = getPhoneDigits;
|
|
3638
3683
|
exports.labelTypography = labelTypography;
|
|
3639
3684
|
exports.navy = navy;
|
|
3640
3685
|
exports.radii = radii;
|
|
3641
3686
|
exports.resolveCalendarLocale = resolveCalendarLocale;
|
|
3642
3687
|
exports.resolveWeekdayLabels = resolveWeekdayLabels;
|
|
3643
3688
|
exports.rubyRed = rubyRed;
|
|
3689
|
+
exports.sanitizeNationalPhoneDigits = sanitizeNationalPhoneDigits;
|
|
3644
3690
|
exports.shadows = shadows;
|
|
3645
3691
|
exports.spacing = spacing;
|
|
3646
3692
|
exports.stormGray = stormGray;
|