@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.d.cts CHANGED
@@ -113,7 +113,16 @@ interface PhoneInputProps extends Omit<TextInputProps, "style"> {
113
113
  errorClassName?: string;
114
114
  hintClassName?: string;
115
115
  }
116
- declare function PhoneInput({ label, countryCode, onCountryCodeChange, error, hint, height, containerStyle, style, className, labelClassName, labelStyles, inputClassName, errorClassName, hintClassName, editable, onFocus, onBlur, onChangeText, ...props }: PhoneInputProps): react.JSX.Element;
116
+ declare function PhoneInput({ label, countryCode, onCountryCodeChange, error, hint, height, containerStyle, style, className, labelClassName, labelStyles, inputClassName, errorClassName, hintClassName, editable, onFocus, onBlur, onChangeText, value, placeholder, ...props }: PhoneInputProps): react.JSX.Element;
117
+
118
+ declare const DEFAULT_PHONE_COUNTRY_CODE: string;
119
+ declare function getPhoneDigits(value: string): string;
120
+ /** Armenia mobile display while typing: (91) 44-55-66 */
121
+ declare function formatArmenianNationalNumber(digits: string): string;
122
+ declare function formatNationalPhoneDisplay(digits: string, countryCode?: string): string;
123
+ declare function sanitizeNationalPhoneDigits(value: string, countryCode?: string): string;
124
+ /** Placeholder mask shown for Armenia national numbers. */
125
+ declare const ARMENIAN_PHONE_PLACEHOLDER = "(00) 00-00-00";
117
126
 
118
127
  type Country = {
119
128
  code: string;
@@ -567,4 +576,4 @@ declare const shadows: {
567
576
  };
568
577
  };
569
578
 
570
- export { Button, type ButtonProps, type ButtonSize, type ButtonVariant, Calendar, CalendarIcon, type CalendarLabels, type CalendarLocale, CalendarLocaleProvider, type CalendarLocaleProviderProps, type CalendarProps, type CalendarRangeProps, type CalendarSingleProps, type CalendarTranslationKey$1 as CalendarTranslationKey, type CalendarTranslations, type Country, CountryCodeSelector, type CountryCodeSelectorProps, CountryFlag, type CountryFlagProps, DatePicker, type DatePickerProps, type DatePickerRangeProps, type DatePickerSingleProps, type DateRange, type EmeraldGreenStep, Input, type InputProps, Label, type LabelProps, LockIcon, type MultipleSelectProps, type NavyStep, PhoneInput, type PhoneInputProps, type RubyRedStep, Select, type SelectOption, type SelectProps, type SingleSelectProps, type StormGrayStep, announcementStatusBadge, brand, buttonTypography, calendarTranslations, colors, countries, countryCodeToFlagEmoji, defaultCountry, emeraldGreen, findCountry, fontSize, fontWeight, fonts, formatLocalizedCalendarMonthYear, getCalendarMonthLabels, getCalendarTranslations, getCountryFlagImageUri, labelTypography, navy, radii, resolveCalendarLocale, resolveWeekdayLabels, rubyRed, shadows, spacing, stormGray, typographyScale, useCalendarLocale };
579
+ export { ARMENIAN_PHONE_PLACEHOLDER, Button, type ButtonProps, type ButtonSize, type ButtonVariant, Calendar, CalendarIcon, type CalendarLabels, type CalendarLocale, CalendarLocaleProvider, type CalendarLocaleProviderProps, type CalendarProps, type CalendarRangeProps, type CalendarSingleProps, type CalendarTranslationKey$1 as CalendarTranslationKey, type CalendarTranslations, type Country, CountryCodeSelector, type CountryCodeSelectorProps, CountryFlag, type CountryFlagProps, DEFAULT_PHONE_COUNTRY_CODE, DatePicker, type DatePickerProps, type DatePickerRangeProps, type DatePickerSingleProps, type DateRange, type EmeraldGreenStep, Input, type InputProps, Label, type LabelProps, LockIcon, type MultipleSelectProps, type NavyStep, PhoneInput, type PhoneInputProps, type RubyRedStep, Select, type SelectOption, type SelectProps, type SingleSelectProps, type StormGrayStep, announcementStatusBadge, brand, buttonTypography, calendarTranslations, colors, countries, countryCodeToFlagEmoji, defaultCountry, emeraldGreen, findCountry, fontSize, fontWeight, fonts, formatArmenianNationalNumber, formatLocalizedCalendarMonthYear, formatNationalPhoneDisplay, getCalendarMonthLabels, getCalendarTranslations, getCountryFlagImageUri, getPhoneDigits, labelTypography, navy, radii, resolveCalendarLocale, resolveWeekdayLabels, rubyRed, sanitizeNationalPhoneDigits, shadows, spacing, stormGray, typographyScale, useCalendarLocale };
package/dist/index.d.ts CHANGED
@@ -113,7 +113,16 @@ interface PhoneInputProps extends Omit<TextInputProps, "style"> {
113
113
  errorClassName?: string;
114
114
  hintClassName?: string;
115
115
  }
116
- declare function PhoneInput({ label, countryCode, onCountryCodeChange, error, hint, height, containerStyle, style, className, labelClassName, labelStyles, inputClassName, errorClassName, hintClassName, editable, onFocus, onBlur, onChangeText, ...props }: PhoneInputProps): react.JSX.Element;
116
+ declare function PhoneInput({ label, countryCode, onCountryCodeChange, error, hint, height, containerStyle, style, className, labelClassName, labelStyles, inputClassName, errorClassName, hintClassName, editable, onFocus, onBlur, onChangeText, value, placeholder, ...props }: PhoneInputProps): react.JSX.Element;
117
+
118
+ declare const DEFAULT_PHONE_COUNTRY_CODE: string;
119
+ declare function getPhoneDigits(value: string): string;
120
+ /** Armenia mobile display while typing: (91) 44-55-66 */
121
+ declare function formatArmenianNationalNumber(digits: string): string;
122
+ declare function formatNationalPhoneDisplay(digits: string, countryCode?: string): string;
123
+ declare function sanitizeNationalPhoneDigits(value: string, countryCode?: string): string;
124
+ /** Placeholder mask shown for Armenia national numbers. */
125
+ declare const ARMENIAN_PHONE_PLACEHOLDER = "(00) 00-00-00";
117
126
 
118
127
  type Country = {
119
128
  code: string;
@@ -567,4 +576,4 @@ declare const shadows: {
567
576
  };
568
577
  };
569
578
 
570
- export { Button, type ButtonProps, type ButtonSize, type ButtonVariant, Calendar, CalendarIcon, type CalendarLabels, type CalendarLocale, CalendarLocaleProvider, type CalendarLocaleProviderProps, type CalendarProps, type CalendarRangeProps, type CalendarSingleProps, type CalendarTranslationKey$1 as CalendarTranslationKey, type CalendarTranslations, type Country, CountryCodeSelector, type CountryCodeSelectorProps, CountryFlag, type CountryFlagProps, DatePicker, type DatePickerProps, type DatePickerRangeProps, type DatePickerSingleProps, type DateRange, type EmeraldGreenStep, Input, type InputProps, Label, type LabelProps, LockIcon, type MultipleSelectProps, type NavyStep, PhoneInput, type PhoneInputProps, type RubyRedStep, Select, type SelectOption, type SelectProps, type SingleSelectProps, type StormGrayStep, announcementStatusBadge, brand, buttonTypography, calendarTranslations, colors, countries, countryCodeToFlagEmoji, defaultCountry, emeraldGreen, findCountry, fontSize, fontWeight, fonts, formatLocalizedCalendarMonthYear, getCalendarMonthLabels, getCalendarTranslations, getCountryFlagImageUri, labelTypography, navy, radii, resolveCalendarLocale, resolveWeekdayLabels, rubyRed, shadows, spacing, stormGray, typographyScale, useCalendarLocale };
579
+ export { ARMENIAN_PHONE_PLACEHOLDER, Button, type ButtonProps, type ButtonSize, type ButtonVariant, Calendar, CalendarIcon, type CalendarLabels, type CalendarLocale, CalendarLocaleProvider, type CalendarLocaleProviderProps, type CalendarProps, type CalendarRangeProps, type CalendarSingleProps, type CalendarTranslationKey$1 as CalendarTranslationKey, type CalendarTranslations, type Country, CountryCodeSelector, type CountryCodeSelectorProps, CountryFlag, type CountryFlagProps, DEFAULT_PHONE_COUNTRY_CODE, DatePicker, type DatePickerProps, type DatePickerRangeProps, type DatePickerSingleProps, type DateRange, type EmeraldGreenStep, Input, type InputProps, Label, type LabelProps, LockIcon, type MultipleSelectProps, type NavyStep, PhoneInput, type PhoneInputProps, type RubyRedStep, Select, type SelectOption, type SelectProps, type SingleSelectProps, type StormGrayStep, announcementStatusBadge, brand, buttonTypography, calendarTranslations, colors, countries, countryCodeToFlagEmoji, defaultCountry, emeraldGreen, findCountry, fontSize, fontWeight, fonts, formatArmenianNationalNumber, formatLocalizedCalendarMonthYear, formatNationalPhoneDisplay, getCalendarMonthLabels, getCalendarTranslations, getCountryFlagImageUri, getPhoneDigits, labelTypography, navy, radii, resolveCalendarLocale, resolveWeekdayLabels, rubyRed, sanitizeNationalPhoneDigits, shadows, spacing, stormGray, typographyScale, useCalendarLocale };
package/dist/index.js CHANGED
@@ -1147,6 +1147,42 @@ var styles3 = StyleSheet.create({
1147
1147
  color: colors.slateBlue
1148
1148
  }
1149
1149
  });
1150
+
1151
+ // src/utils/phoneFormat.ts
1152
+ var DEFAULT_PHONE_COUNTRY_CODE = defaultCountry.code;
1153
+ var AM_NATIONAL_MAX_DIGITS = 8;
1154
+ var MAX_NATIONAL_DIGITS = 15;
1155
+ function getPhoneDigits(value) {
1156
+ return value.replace(/\D/g, "");
1157
+ }
1158
+ function formatArmenianNationalNumber(digits) {
1159
+ const national = getPhoneDigits(digits).slice(0, AM_NATIONAL_MAX_DIGITS);
1160
+ if (national.length === 0) {
1161
+ return "";
1162
+ }
1163
+ if (national.length <= 2) {
1164
+ return `(${national}`;
1165
+ }
1166
+ const head = national.slice(0, 2);
1167
+ const rest = national.slice(2);
1168
+ const groups = rest.match(/.{1,2}/g) ?? [];
1169
+ return `(${head}) ${groups.join("-")}`;
1170
+ }
1171
+ function formatNationalPhoneDisplay(digits, countryCode = DEFAULT_PHONE_COUNTRY_CODE) {
1172
+ const national = getPhoneDigits(digits).slice(0, MAX_NATIONAL_DIGITS);
1173
+ if (countryCode === DEFAULT_PHONE_COUNTRY_CODE) {
1174
+ return formatArmenianNationalNumber(national);
1175
+ }
1176
+ return national;
1177
+ }
1178
+ function sanitizeNationalPhoneDigits(value, countryCode = DEFAULT_PHONE_COUNTRY_CODE) {
1179
+ const digits = getPhoneDigits(value);
1180
+ if (countryCode === DEFAULT_PHONE_COUNTRY_CODE) {
1181
+ return digits.slice(0, AM_NATIONAL_MAX_DIGITS);
1182
+ }
1183
+ return digits.slice(0, MAX_NATIONAL_DIGITS);
1184
+ }
1185
+ var ARMENIAN_PHONE_PLACEHOLDER = "(00) 00-00-00";
1150
1186
  var countryOutlineSlot = {
1151
1187
  borderRadius: radii.lg + INPUT_OUTLINE_WIDTH,
1152
1188
  borderWidth: INPUT_OUTLINE_WIDTH,
@@ -1154,12 +1190,9 @@ var countryOutlineSlot = {
1154
1190
  padding: 0,
1155
1191
  backgroundColor: colors.transparent
1156
1192
  };
1157
- function sanitizePhoneDigits(value) {
1158
- return value.replace(/\D/g, "");
1159
- }
1160
1193
  function PhoneInput({
1161
1194
  label,
1162
- countryCode,
1195
+ countryCode = defaultCountry.code,
1163
1196
  onCountryCodeChange,
1164
1197
  error,
1165
1198
  hint,
@@ -1176,6 +1209,8 @@ function PhoneInput({
1176
1209
  onFocus,
1177
1210
  onBlur,
1178
1211
  onChangeText,
1212
+ value,
1213
+ placeholder,
1179
1214
  ...props
1180
1215
  }) {
1181
1216
  const wrapperRef = useRef(null);
@@ -1192,6 +1227,9 @@ function PhoneInput({
1192
1227
  disabled: isDisabled
1193
1228
  });
1194
1229
  const phoneFieldStyles = getInputFieldStyles(phoneVisualState);
1230
+ const resolvedCountryCode = countryCode || DEFAULT_PHONE_COUNTRY_CODE;
1231
+ const displayValue = typeof value === "string" || typeof value === "number" ? formatNationalPhoneDisplay(String(value), resolvedCountryCode) : value;
1232
+ const resolvedPlaceholder = placeholder ?? (resolvedCountryCode === DEFAULT_PHONE_COUNTRY_CODE ? ARMENIAN_PHONE_PLACEHOLDER : void 0);
1195
1233
  function handleFocus(event) {
1196
1234
  setFocused(true);
1197
1235
  onFocus?.(event);
@@ -1200,8 +1238,8 @@ function PhoneInput({
1200
1238
  setFocused(false);
1201
1239
  onBlur?.(event);
1202
1240
  }
1203
- function handleChangeText(value) {
1204
- onChangeText?.(sanitizePhoneDigits(value));
1241
+ function handleChangeText(nextValue) {
1242
+ onChangeText?.(sanitizeNationalPhoneDigits(nextValue, resolvedCountryCode));
1205
1243
  }
1206
1244
  const helperMessage = error ?? hint;
1207
1245
  return /* @__PURE__ */ jsxs(View, { ref: wrapperRef, style: [styles4.wrapper, containerStyle], children: [
@@ -1251,6 +1289,8 @@ function PhoneInput({
1251
1289
  onBlur: handleBlur,
1252
1290
  accessibilityState: { disabled: isDisabled },
1253
1291
  ...props,
1292
+ value: displayValue,
1293
+ placeholder: resolvedPlaceholder,
1254
1294
  onChangeText: handleChangeText
1255
1295
  }
1256
1296
  )
@@ -2662,6 +2702,6 @@ function LockIcon({
2662
2702
  ) });
2663
2703
  }
2664
2704
 
2665
- export { Calendar, CalendarIcon, CalendarLocaleProvider, CountryCodeSelector, CountryFlag, DatePicker, LockIcon, PhoneInput, Select, calendarTranslations, countries, countryCodeToFlagEmoji, defaultCountry, findCountry, formatLocalizedCalendarMonthYear, getCalendarMonthLabels, getCalendarTranslations, getCountryFlagImageUri, resolveCalendarLocale, resolveWeekdayLabels, useCalendarLocale };
2705
+ export { ARMENIAN_PHONE_PLACEHOLDER, Calendar, CalendarIcon, CalendarLocaleProvider, CountryCodeSelector, CountryFlag, DEFAULT_PHONE_COUNTRY_CODE, DatePicker, LockIcon, PhoneInput, Select, calendarTranslations, countries, countryCodeToFlagEmoji, defaultCountry, findCountry, formatArmenianNationalNumber, formatLocalizedCalendarMonthYear, formatNationalPhoneDisplay, getCalendarMonthLabels, getCalendarTranslations, getCountryFlagImageUri, getPhoneDigits, resolveCalendarLocale, resolveWeekdayLabels, sanitizeNationalPhoneDigits, useCalendarLocale };
2666
2706
  //# sourceMappingURL=index.js.map
2667
2707
  //# sourceMappingURL=index.js.map