@alfalab/core-components-international-phone-input 2.7.0 → 2.7.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.
Files changed (69) hide show
  1. package/Component.responsive.d.ts +4 -4
  2. package/components/base-international-phone-input/Component.js +12 -2
  3. package/components/base-international-phone-input/index.css +6 -3
  4. package/components/country-select/Component.js +1 -1
  5. package/components/country-select/index.css +11 -8
  6. package/components/flag-icon/component.js +1 -1
  7. package/components/flag-icon/index.css +6 -3
  8. package/components/select-field/component.js +1 -1
  9. package/components/select-field/index.css +12 -9
  10. package/cssm/Component.responsive.d.ts +4 -4
  11. package/cssm/components/base-international-phone-input/Component.js +11 -1
  12. package/cssm/components/base-international-phone-input/index.module.css +4 -1
  13. package/cssm/components/country-select/index.module.css +3 -0
  14. package/cssm/components/flag-icon/index.module.css +3 -0
  15. package/cssm/components/select-field/index.module.css +3 -0
  16. package/cssm/index-464d40a4.d.ts +23 -0
  17. package/cssm/types.d.ts +1 -10
  18. package/cssm/typings-d515b24c.d.ts +1 -1
  19. package/cssm/use-skeleton-1328ead9.d.ts +7 -1
  20. package/cssm/utils/index.d.ts +3 -2
  21. package/cssm/utils/index.js +11 -5
  22. package/esm/Component.responsive.d.ts +4 -4
  23. package/esm/components/base-international-phone-input/Component.js +13 -3
  24. package/esm/components/base-international-phone-input/index.css +6 -3
  25. package/esm/components/country-select/Component.js +1 -1
  26. package/esm/components/country-select/index.css +11 -8
  27. package/esm/components/flag-icon/component.js +1 -1
  28. package/esm/components/flag-icon/index.css +6 -3
  29. package/esm/components/select-field/component.js +1 -1
  30. package/esm/components/select-field/index.css +12 -9
  31. package/esm/index-464d40a4.d.ts +23 -0
  32. package/esm/types.d.ts +1 -10
  33. package/esm/typings-d515b24c.d.ts +1 -1
  34. package/esm/use-skeleton-1328ead9.d.ts +7 -1
  35. package/esm/utils/index.d.ts +3 -2
  36. package/esm/utils/index.js +11 -5
  37. package/index-464d40a4.d.ts +23 -0
  38. package/modern/Component.responsive.d.ts +4 -4
  39. package/modern/components/base-international-phone-input/Component.js +11 -3
  40. package/modern/components/base-international-phone-input/index.css +6 -3
  41. package/modern/components/country-select/Component.js +1 -1
  42. package/modern/components/country-select/index.css +11 -8
  43. package/modern/components/flag-icon/component.js +1 -1
  44. package/modern/components/flag-icon/index.css +6 -3
  45. package/modern/components/select-field/component.js +1 -1
  46. package/modern/components/select-field/index.css +12 -9
  47. package/modern/index-464d40a4.d.ts +23 -0
  48. package/modern/types.d.ts +1 -10
  49. package/modern/typings-d515b24c.d.ts +1 -1
  50. package/modern/use-skeleton-1328ead9.d.ts +7 -1
  51. package/modern/utils/index.d.ts +3 -2
  52. package/modern/utils/index.js +9 -5
  53. package/moderncssm/Component.responsive.d.ts +4 -4
  54. package/moderncssm/components/base-international-phone-input/Component.js +10 -2
  55. package/moderncssm/index-464d40a4.d.ts +23 -0
  56. package/moderncssm/types.d.ts +1 -10
  57. package/moderncssm/typings-d515b24c.d.ts +1 -1
  58. package/moderncssm/use-skeleton-1328ead9.d.ts +7 -1
  59. package/moderncssm/utils/index.d.ts +3 -2
  60. package/moderncssm/utils/index.js +9 -5
  61. package/package.json +6 -6
  62. package/src/components/base-international-phone-input/Component.tsx +17 -1
  63. package/src/types.ts +3 -10
  64. package/src/utils/index.ts +16 -6
  65. package/types.d.ts +1 -10
  66. package/typings-d515b24c.d.ts +1 -1
  67. package/use-skeleton-1328ead9.d.ts +7 -1
  68. package/utils/index.d.ts +3 -2
  69. package/utils/index.js +11 -5
@@ -2,6 +2,7 @@
2
2
  import React from "react";
3
3
  import { ReactNode } from "react";
4
4
  import { TextSkeletonProps } from "./types-1328ead9";
5
+ type BorderRadiusSize = 0 | 2 | 4 | 6 | 8 | 10 | 12 | 16 | 20 | 24 | 32 | 36 | 64 | "pill";
5
6
  type SkeletonProps = {
6
7
  /**
7
8
  * Флаг, явно задающий состояние, при котором контент закрывается прелоадером
@@ -36,6 +37,11 @@ type SkeletonProps = {
36
37
  * @default default
37
38
  */
38
39
  colors?: "default" | "inverted";
40
+ /**
41
+ * Скругление углов
42
+ * @default 8
43
+ */
44
+ borderRadius?: BorderRadiusSize;
39
45
  };
40
46
  declare const Skeleton: React.FC<SkeletonProps>;
41
47
  type SkeletonProps$0 = {
@@ -46,4 +52,4 @@ declare function useSkeleton(showSkeleton?: boolean, skeletonProps?: TextSkeleto
46
52
  renderSkeleton: (props: SkeletonProps$0) => React.JSX.Element | null;
47
53
  textRef: React.RefObject<HTMLElement>;
48
54
  };
49
- export { SkeletonProps, Skeleton, useSkeleton };
55
+ export { BorderRadiusSize, SkeletonProps, Skeleton, useSkeleton };
@@ -1,14 +1,15 @@
1
+ import { RefObject } from 'react';
1
2
  import { MaskitoOptions } from '@maskito/core';
2
3
  import { InputAutocompleteDesktopProps } from "@alfalab/core-components-input-autocomplete/desktop";
3
4
  import { GroupShape, OptionShape } from "@alfalab/core-components-select/shared";
4
5
  import { CountriesData } from "../data/country-data";
5
6
  import { Country } from "../types";
6
7
  declare function initCountries(iso2s?: string[], customCountriesList?: CountriesData[]): Country[][];
7
- declare function findCountry(countries: Country[][], value?: string, iso2?: string, country?: Country): Country | undefined;
8
+ declare function findCountry(countries: Country[][], value: string | undefined, iso2: string | undefined, country?: Country): Country | undefined;
8
9
  declare function guessCountry(inputNumber: string, data: Country[][]): Country | undefined;
9
10
  declare function clearMask(value: string): string;
10
11
  declare function createPhoneMaskExpression(country: Country | undefined, clearableCountryCode: boolean): Array<RegExp | string>;
11
- declare function createMaskOptions(country: Country | undefined, clearableCountryCode: boolean, preserveCountryCode: boolean): MaskitoOptions;
12
+ declare function createMaskOptions(country: Country | undefined, clearableCountryCode: boolean, preserveCountryCode: boolean, lastCountryRef: RefObject<Country | null>): MaskitoOptions;
12
13
  declare function defaultFilterFn(value: string | undefined, option: OptionShape): boolean;
13
14
  declare const filterPhones: (value?: string, options?: InputAutocompleteDesktopProps['options'], filterFn?: typeof defaultFilterFn) => (OptionShape | GroupShape)[];
14
15
  declare function getPhoneData(phone: string, countries: Country[][], defaultIso2?: string): {
@@ -115,17 +115,21 @@ function createPhoneMaskExpression(country, clearableCountryCode) {
115
115
  ...format.split('').map(itemToMask),
116
116
  ];
117
117
  }
118
- function createMaskOptions(country, clearableCountryCode, preserveCountryCode) {
118
+ function createMaskOptions(country, clearableCountryCode, preserveCountryCode, lastCountryRef) {
119
119
  const countryCode = country?.countryCode;
120
120
  const prefix = countryCode ? getInitialValueFromCountry(countryCode) : '';
121
121
  const prefixLen = !clearableCountryCode && prefix ? prefix.length : 0;
122
122
  const mask = createPhoneMaskExpression(country, clearableCountryCode);
123
+ const preprocessors = [
124
+ maskUtils.insertionPhonePreprocessor(mask, countryCode, clearableCountryCode),
125
+ ];
126
+ if (preserveCountryCode) {
127
+ const createMask = (lastCountry) => createPhoneMaskExpression(lastCountry, clearableCountryCode);
128
+ preprocessors.push(maskUtils.preserveCountryCodePreprocessor(lastCountryRef, createMask));
129
+ }
123
130
  return {
124
131
  mask,
125
- preprocessors: [
126
- maskUtils.insertionPhonePreprocessor(mask, countryCode, clearableCountryCode),
127
- maskUtils.preserveCountryCodePreprocessor(countryCode, preserveCountryCode),
128
- ],
132
+ preprocessors,
129
133
  postprocessors: [maskUtils.prefixPostprocessor(prefixLen > 0 ? prefix : '')],
130
134
  plugins: [
131
135
  maskUtils.caretGuard((value, [from, to]) => [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfalab/core-components-international-phone-input",
3
- "version": "2.7.0",
3
+ "version": "2.7.2",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -15,10 +15,10 @@
15
15
  "react": "^16.9.0 || ^17.0.1 || ^18.0.0"
16
16
  },
17
17
  "dependencies": {
18
- "@alfalab/core-components-input-autocomplete": "12.7.2",
19
- "@alfalab/core-components-input": "^15.5.0",
20
- "@alfalab/core-components-select": "^17.20.1",
21
- "@alfalab/core-components-shared": "^0.14.1",
18
+ "@alfalab/core-components-input-autocomplete": "12.8.0",
19
+ "@alfalab/core-components-input": "^15.5.1",
20
+ "@alfalab/core-components-select": "^17.20.3",
21
+ "@alfalab/core-components-shared": "^0.15.0",
22
22
  "@alfalab/core-components-mq": "^4.4.1",
23
23
  "@alfalab/hooks": "^1.13.1",
24
24
  "@alfalab/icons-glyph": "^2.210.0",
@@ -29,5 +29,5 @@
29
29
  "tslib": "^2.4.0"
30
30
  },
31
31
  "themesVersion": "13.7.0",
32
- "varsVersion": "9.16.0"
32
+ "varsVersion": "9.18.0"
33
33
  }
@@ -14,6 +14,7 @@ import { useMaskito } from '@maskito/react';
14
14
  import type { InputAutocompleteProps } from '@alfalab/core-components-input-autocomplete';
15
15
  import { AnyObject, BaseOption } from '@alfalab/core-components-select/shared';
16
16
  import type { BaseSelectChangePayload } from '@alfalab/core-components-select/typings';
17
+ import { isNullable } from '@alfalab/core-components-shared';
17
18
 
18
19
  import type { BaseInternationalPhoneInputProps, Country } from '../../types';
19
20
  import {
@@ -59,6 +60,7 @@ export const BaseInternationalPhoneInput = forwardRef<
59
60
  },
60
61
  ref,
61
62
  ) => {
63
+ const lastCountryRef = useRef<Country | null>(null);
62
64
  const countriesData = useMemo(
63
65
  () => initCountries(countries, customCountriesList),
64
66
  [countries, customCountriesList],
@@ -84,7 +86,13 @@ export const BaseInternationalPhoneInput = forwardRef<
84
86
  const preserveCountryCode = clearableCountryCodeFromProps === 'preserve';
85
87
  const clearableCountryCode = preserveCountryCode || clearableCountryCodeFromProps;
86
88
  const maskOptions = useMemo(
87
- () => createMaskOptions(country, clearableCountryCode, preserveCountryCode),
89
+ () =>
90
+ createMaskOptions(
91
+ country,
92
+ clearableCountryCode,
93
+ preserveCountryCode,
94
+ lastCountryRef,
95
+ ),
88
96
  [country, clearableCountryCode, preserveCountryCode],
89
97
  );
90
98
 
@@ -206,6 +214,14 @@ export const BaseInternationalPhoneInput = forwardRef<
206
214
  ...restProps.inputProps,
207
215
  } as const;
208
216
 
217
+ useEffect(() => {
218
+ if (!preserveCountryCode || isNullable(country)) {
219
+ return;
220
+ }
221
+
222
+ lastCountryRef.current = country;
223
+ }, [country, preserveCountryCode]);
224
+
209
225
  return Array.isArray(options) ? (
210
226
  <InputAutocomplete
211
227
  closeOnSelect={true}
package/src/types.ts CHANGED
@@ -9,19 +9,12 @@ import type { InputAutocompleteDesktopProps } from '@alfalab/core-components-inp
9
9
  import type { InputAutocompleteMobileProps } from '@alfalab/core-components-input-autocomplete/mobile';
10
10
  import { OptionShape } from '@alfalab/core-components-select/typings';
11
11
 
12
+ import { Country } from '../../types';
13
+
12
14
  import type { SharedCountrySelectProps } from './components/country-select';
13
15
  import { CountriesData } from './data/country-data';
14
16
 
15
- export type Country = {
16
- name: string;
17
- regions?: string[];
18
- iso2: string;
19
- countryCode: string;
20
- dialCode: string;
21
- format?: string;
22
- priority: number;
23
- mainCode?: boolean;
24
- };
17
+ export { Country };
25
18
 
26
19
  export type AreaItem = Country & {
27
20
  isAreaCode: boolean;
@@ -1,3 +1,4 @@
1
+ import { RefObject } from 'react';
1
2
  import type { MaskitoOptions } from '@maskito/core';
2
3
 
3
4
  import type { InputAutocompleteDesktopProps } from '@alfalab/core-components-input-autocomplete/desktop';
@@ -51,8 +52,8 @@ export function initCountries(iso2s?: string[], customCountriesList?: CountriesD
51
52
 
52
53
  export function findCountry(
53
54
  countries: Country[][],
54
- value?: string,
55
- iso2?: string,
55
+ value: string | undefined,
56
+ iso2: string | undefined,
56
57
  country?: Country,
57
58
  ) {
58
59
  if (country) return country;
@@ -163,18 +164,27 @@ export function createMaskOptions(
163
164
  country: Country | undefined,
164
165
  clearableCountryCode: boolean,
165
166
  preserveCountryCode: boolean,
167
+ lastCountryRef: RefObject<Country | null>,
166
168
  ): MaskitoOptions {
167
169
  const countryCode = country?.countryCode;
168
170
  const prefix = countryCode ? getInitialValueFromCountry(countryCode) : '';
169
171
  const prefixLen = !clearableCountryCode && prefix ? prefix.length : 0;
170
172
  const mask = createPhoneMaskExpression(country, clearableCountryCode);
171
173
 
174
+ const preprocessors = [
175
+ maskUtils.insertionPhonePreprocessor(mask, countryCode, clearableCountryCode),
176
+ ];
177
+
178
+ if (preserveCountryCode) {
179
+ const createMask = (lastCountry: Country) =>
180
+ createPhoneMaskExpression(lastCountry, clearableCountryCode);
181
+
182
+ preprocessors.push(maskUtils.preserveCountryCodePreprocessor(lastCountryRef, createMask));
183
+ }
184
+
172
185
  return {
173
186
  mask,
174
- preprocessors: [
175
- maskUtils.insertionPhonePreprocessor(mask, countryCode, clearableCountryCode),
176
- maskUtils.preserveCountryCodePreprocessor(countryCode, preserveCountryCode),
177
- ],
187
+ preprocessors,
178
188
  postprocessors: [maskUtils.prefixPostprocessor(prefixLen > 0 ? prefix : '')],
179
189
  plugins: [
180
190
  maskUtils.caretGuard((value, [from, to]) => [
package/types.d.ts CHANGED
@@ -6,18 +6,9 @@ import { InputAutocompleteProps } from "@alfalab/core-components-input-autocompl
6
6
  import { InputAutocompleteDesktopProps } from "@alfalab/core-components-input-autocomplete/desktop";
7
7
  import { InputAutocompleteMobileProps } from "@alfalab/core-components-input-autocomplete/mobile";
8
8
  import { OptionShape } from "./typings-d515b24c";
9
+ import { Country } from "./index-464d40a4";
9
10
  import { SharedCountrySelectProps } from "./components/country-select/index";
10
11
  import { CountriesData } from "./data/country-data";
11
- type Country = {
12
- name: string;
13
- regions?: string[];
14
- iso2: string;
15
- countryCode: string;
16
- dialCode: string;
17
- format?: string;
18
- priority: number;
19
- mainCode?: boolean;
20
- };
21
12
  type AreaItem = Country & {
22
13
  isAreaCode: boolean;
23
14
  areaCodeLength: number;
@@ -5,6 +5,7 @@ import { HTMLAttributes, ReactElement, ReactNode, RefObject, ButtonHTMLAttribute
5
5
  import { HandledEvents } from "react-swipeable/es/types";
6
6
  import { TransitionProps } from "react-transition-group/Transition";
7
7
  import { BaseModalProps, BaseModalContext } from "./index-11f20b2e";
8
+ import { BackgroundColorType } from "./index-464d40a4";
8
9
  import { BaseFormControlProps, BackdropProps } from "./index-ebda875c";
9
10
  import { ContentProps } from "./typings-4b7234ef";
10
11
  import { ModalResponsiveProps as ModalProps } from "./typings-4b7234ef";
@@ -175,7 +176,6 @@ type NavigationBarPrivateProps = {
175
176
  scrollableParentRef?: React.RefObject<HTMLDivElement>;
176
177
  };
177
178
  type NavigationBarProps = NavigationBarPrivateProps;
178
- type BackgroundColorType = "accent" | "info" | "attention-muted" | "positive-muted" | "negative-muted" | "primary" | "primary-inverted" | "secondary" | "secondary-inverted" | "tertiary" | "tertiary-inverted" | "quaternary" | "quaternary-inverted" | "specialbg-component" | "specialbg-component-inverted" | "specialbg-primary-grouped" | "specialbg-secondary-grouped" | "specialbg-tertiary-grouped" | "specialbg-secondary-transparent" | "specialbg-secondary-transparent-inverted" | "specialbg-tertiary-transparent" | "specialbg-tertiary-transparent-inverted";
179
179
  type BottomSheetTitleAlign = "center" | "left";
180
180
  type BottomSheetProps = {
181
181
  /**
@@ -2,6 +2,7 @@
2
2
  import React from "react";
3
3
  import { ReactNode } from "react";
4
4
  import { TextSkeletonProps } from "./types-1328ead9";
5
+ type BorderRadiusSize = 0 | 2 | 4 | 6 | 8 | 10 | 12 | 16 | 20 | 24 | 32 | 36 | 64 | "pill";
5
6
  type SkeletonProps = {
6
7
  /**
7
8
  * Флаг, явно задающий состояние, при котором контент закрывается прелоадером
@@ -36,6 +37,11 @@ type SkeletonProps = {
36
37
  * @default default
37
38
  */
38
39
  colors?: "default" | "inverted";
40
+ /**
41
+ * Скругление углов
42
+ * @default 8
43
+ */
44
+ borderRadius?: BorderRadiusSize;
39
45
  };
40
46
  declare const Skeleton: React.FC<SkeletonProps>;
41
47
  type SkeletonProps$0 = {
@@ -46,4 +52,4 @@ declare function useSkeleton(showSkeleton?: boolean, skeletonProps?: TextSkeleto
46
52
  renderSkeleton: (props: SkeletonProps$0) => React.JSX.Element | null;
47
53
  textRef: React.RefObject<HTMLElement>;
48
54
  };
49
- export { SkeletonProps, Skeleton, useSkeleton };
55
+ export { BorderRadiusSize, SkeletonProps, Skeleton, useSkeleton };
package/utils/index.d.ts CHANGED
@@ -1,14 +1,15 @@
1
+ import { RefObject } from 'react';
1
2
  import { MaskitoOptions } from '@maskito/core';
2
3
  import { InputAutocompleteDesktopProps } from "@alfalab/core-components-input-autocomplete/desktop";
3
4
  import { GroupShape, OptionShape } from "@alfalab/core-components-select/shared";
4
5
  import { CountriesData } from "../data/country-data";
5
6
  import { Country } from "../types";
6
7
  declare function initCountries(iso2s?: string[], customCountriesList?: CountriesData[]): Country[][];
7
- declare function findCountry(countries: Country[][], value?: string, iso2?: string, country?: Country): Country | undefined;
8
+ declare function findCountry(countries: Country[][], value: string | undefined, iso2: string | undefined, country?: Country): Country | undefined;
8
9
  declare function guessCountry(inputNumber: string, data: Country[][]): Country | undefined;
9
10
  declare function clearMask(value: string): string;
10
11
  declare function createPhoneMaskExpression(country: Country | undefined, clearableCountryCode: boolean): Array<RegExp | string>;
11
- declare function createMaskOptions(country: Country | undefined, clearableCountryCode: boolean, preserveCountryCode: boolean): MaskitoOptions;
12
+ declare function createMaskOptions(country: Country | undefined, clearableCountryCode: boolean, preserveCountryCode: boolean, lastCountryRef: RefObject<Country | null>): MaskitoOptions;
12
13
  declare function defaultFilterFn(value: string | undefined, option: OptionShape): boolean;
13
14
  declare const filterPhones: (value?: string, options?: InputAutocompleteDesktopProps['options'], filterFn?: typeof defaultFilterFn) => (OptionShape | GroupShape)[];
14
15
  declare function getPhoneData(phone: string, countries: Country[][], defaultIso2?: string): {
package/utils/index.js CHANGED
@@ -120,17 +120,23 @@ function createPhoneMaskExpression(country, clearableCountryCode) {
120
120
  ' '
121
121
  ], false), format.split('').map(itemToMask), true);
122
122
  }
123
- function createMaskOptions(country, clearableCountryCode, preserveCountryCode) {
123
+ function createMaskOptions(country, clearableCountryCode, preserveCountryCode, lastCountryRef) {
124
124
  var countryCode = country === null || country === void 0 ? void 0 : country.countryCode;
125
125
  var prefix = countryCode ? getInitialValueFromCountry(countryCode) : '';
126
126
  var prefixLen = !clearableCountryCode && prefix ? prefix.length : 0;
127
127
  var mask = createPhoneMaskExpression(country, clearableCountryCode);
128
+ var preprocessors = [
129
+ coreComponentsShared.maskUtils.insertionPhonePreprocessor(mask, countryCode, clearableCountryCode),
130
+ ];
131
+ if (preserveCountryCode) {
132
+ var createMask = function (lastCountry) {
133
+ return createPhoneMaskExpression(lastCountry, clearableCountryCode);
134
+ };
135
+ preprocessors.push(coreComponentsShared.maskUtils.preserveCountryCodePreprocessor(lastCountryRef, createMask));
136
+ }
128
137
  return {
129
138
  mask: mask,
130
- preprocessors: [
131
- coreComponentsShared.maskUtils.insertionPhonePreprocessor(mask, countryCode, clearableCountryCode),
132
- coreComponentsShared.maskUtils.preserveCountryCodePreprocessor(countryCode, preserveCountryCode),
133
- ],
139
+ preprocessors: preprocessors,
134
140
  postprocessors: [coreComponentsShared.maskUtils.prefixPostprocessor(prefixLen > 0 ? prefix : '')],
135
141
  plugins: [
136
142
  coreComponentsShared.maskUtils.caretGuard(function (value, _a) {