@sprinklrjs/spaceweb 14.12.0 → 14.12.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.
- package/asyncSelect/hooks/useAsyncOptionHandlers.js +3 -2
- package/baseui/layer/tether.js +5 -5
- package/esm/asyncSelect/hooks/useAsyncOptionHandlers.js +4 -3
- package/esm/baseui/layer/tether.js +5 -5
- package/esm/input/base-input.js +1 -1
- package/esm/list/divider.js +3 -1
- package/esm/list/list.js +11 -14
- package/esm/list/utils.d.ts +8 -0
- package/esm/list/utils.js +28 -1
- package/esm/phone-input/constants.d.ts +476 -0
- package/esm/phone-input/constants.js +397 -105
- package/esm/phone-input/country-select.js +7 -4
- package/esm/phone-input/types.d.ts +24 -1
- package/esm/phone-input/useStatefulPhoneInput.d.ts +1 -1
- package/esm/phone-input/utils.d.ts +25 -1
- package/esm/phone-input/utils.js +49 -0
- package/input/base-input.js +1 -1
- package/list/divider.js +3 -1
- package/list/list.js +10 -13
- package/list/utils.d.ts +8 -0
- package/list/utils.js +31 -1
- package/package.json +2 -2
- package/phone-input/constants.d.ts +476 -0
- package/phone-input/constants.js +397 -105
- package/phone-input/country-select.js +5 -2
- package/phone-input/types.d.ts +24 -1
- package/phone-input/useStatefulPhoneInput.d.ts +1 -1
- package/phone-input/utils.d.ts +25 -1
- package/phone-input/utils.js +52 -1
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -8,6 +8,7 @@ var pick_1 = tslib_1.__importDefault(require("lodash/pick"));
|
|
|
8
8
|
var select_1 = require("../select");
|
|
9
9
|
var list_1 = require("../list");
|
|
10
10
|
var typography_1 = require("../typography");
|
|
11
|
+
var box_1 = require("../box");
|
|
11
12
|
var flag_container_1 = tslib_1.__importDefault(require("./flag-container"));
|
|
12
13
|
var locale_1 = require("../locale");
|
|
13
14
|
var overrides_1 = require("../overrides");
|
|
@@ -15,8 +16,10 @@ var utils_1 = require("./utils");
|
|
|
15
16
|
var constants_1 = require("./constants");
|
|
16
17
|
var types_1 = require("../popover/types");
|
|
17
18
|
var SelectListItem = React.forwardRef(function (_a, ref) {
|
|
18
|
-
var mapIsoToLabel = _a.mapIsoToLabel,
|
|
19
|
-
|
|
19
|
+
var mapIsoToLabel = _a.mapIsoToLabel, country = _a.$item, rest = tslib_1.__rest(_a, ["mapIsoToLabel", "$item"]);
|
|
20
|
+
var id = country.id, dialCode = country.dialCode;
|
|
21
|
+
var _b = (0, utils_1.resolveCountryLabelParts)(country, mapIsoToLabel), primaryName = _b.primaryName, nativeName = _b.nativeName, nativeLang = _b.nativeLang;
|
|
22
|
+
return ((0, jsx_runtime_1.jsxs)(list_1.ListItem, tslib_1.__assign({}, rest, { startEnhancer: (0, utils_1.iso2FlagEmoji)(id), ref: ref }, { children: [dialCode, (0, jsx_runtime_1.jsxs)(typography_1.Typography, tslib_1.__assign({ "data-testid": id, "data-entity-type": "country-label", className: "spr-text-03 ml-1" }, { children: ["(", primaryName, nativeName && nativeLang ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [' (', (0, jsx_runtime_1.jsx)(box_1.Box, tslib_1.__assign({ "$as": "span", lang: nativeLang }, { children: nativeName })), ")"] })) : null, (0, jsx_runtime_1.jsx)(box_1.Box, tslib_1.__assign({ "$as": "span" }, { children: ")" }))] }))] })));
|
|
20
23
|
});
|
|
21
24
|
var CountrySelect = function (props) {
|
|
22
25
|
var size = props.size, disabled = props.disabled, inputRef = props.inputRef, onChange = props.onChange, countries = props.countries, value = props.value, mapIsoToLabel = props.mapIsoToLabel, maxDropdownHeight = props.maxDropdownHeight, maxDropdownWidth = props.maxDropdownWidth, overrides = props.overrides;
|
package/phone-input/types.d.ts
CHANGED
|
@@ -7,6 +7,14 @@ export type Country = {
|
|
|
7
7
|
id: keyof typeof COUNTRIES;
|
|
8
8
|
label: string;
|
|
9
9
|
dialCode: string;
|
|
10
|
+
/**
|
|
11
|
+
* The portion of `label` (without the wrapping parentheses) that is rendered in a language
|
|
12
|
+
* other than the component's default (English), e.g. `'भारत'` for India. Used to apply the
|
|
13
|
+
* correct `lang` attribute to that segment for screen reader pronunciation (WCAG 3.1.2).
|
|
14
|
+
*/
|
|
15
|
+
nativeName?: string;
|
|
16
|
+
/** BCP 47 language tag for `nativeName`, e.g. `'hi'` for Hindi. */
|
|
17
|
+
nativeLang?: string;
|
|
10
18
|
};
|
|
11
19
|
export type State = {
|
|
12
20
|
country: Country;
|
|
@@ -22,11 +30,26 @@ export type PhoneInputOverrides = {
|
|
|
22
30
|
FlagContainer?: Override<SharedProps & Record<string, any>>;
|
|
23
31
|
DialCode?: Override<SharedProps & Record<string, any>>;
|
|
24
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Custom country label for `mapIsoToLabel`. Provide both `nativeName` and `nativeLang` when a
|
|
35
|
+
* native-language segment should be marked with `lang` (WCAG 3.1.2); otherwise only `label` is used.
|
|
36
|
+
*/
|
|
37
|
+
export type CustomCountryLabel = {
|
|
38
|
+
label: string;
|
|
39
|
+
nativeName?: string;
|
|
40
|
+
nativeLang?: string;
|
|
41
|
+
};
|
|
25
42
|
export type PhoneInputProps = Omit<InputProps, 'value' | 'onChange'> & {
|
|
26
43
|
onInputChange?: (event: React.SyntheticEvent<HTMLInputElement>) => unknown;
|
|
27
44
|
onChange?: (value: Value) => void;
|
|
28
45
|
value?: Value;
|
|
29
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Maps an ISO country code to the dropdown label. Return a `string` to replace the whole label
|
|
48
|
+
* (legacy behavior), or a `CustomCountryLabel` with both `nativeName` and `nativeLang` to mark
|
|
49
|
+
* a native-language segment with `lang` (WCAG 3.1.2). Object results missing either native field
|
|
50
|
+
* are flattened into a single label string.
|
|
51
|
+
*/
|
|
52
|
+
mapIsoToLabel?: (iso: string) => string | CustomCountryLabel;
|
|
30
53
|
maxDropdownHeight?: string;
|
|
31
54
|
countries?: Array<Country>;
|
|
32
55
|
maxDropdownWidth?: string;
|
|
@@ -9,7 +9,7 @@ declare const useStatefulPhoneInput: ({ clearable, disabled, id, initialState, i
|
|
|
9
9
|
intent: import("..").Intent | undefined;
|
|
10
10
|
maxDropdownHeight: string;
|
|
11
11
|
maxDropdownWidth: string;
|
|
12
|
-
mapIsoToLabel: ((iso: string) => string) | undefined;
|
|
12
|
+
mapIsoToLabel: ((iso: string) => string | import("./types").CustomCountryLabel) | undefined;
|
|
13
13
|
name: string | undefined;
|
|
14
14
|
overrides: import("../input").BaseInputOverrides & {
|
|
15
15
|
Root?: import("../overrides").Override<import("../input").SharedProps & Record<string, any>> | undefined;
|
package/phone-input/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Value as ValueT } from '../select/types';
|
|
2
|
-
import type { Value, Country } from './types';
|
|
2
|
+
import type { Value, Country, CustomCountryLabel } from './types';
|
|
3
3
|
export declare const iso2FlagEmoji: (iso: string) => string | undefined;
|
|
4
4
|
export declare const sanitize: (value?: string) => string;
|
|
5
5
|
export declare const getPhoneNumberWithCountryDialCode: (value: Value) => string | undefined;
|
|
@@ -11,3 +11,27 @@ export declare const getDefaultValue: (countries?: Country[]) => {
|
|
|
11
11
|
country: Country;
|
|
12
12
|
phoneNumber: string;
|
|
13
13
|
};
|
|
14
|
+
export type CountryLabelParts = {
|
|
15
|
+
primaryName: string;
|
|
16
|
+
nativeName?: string;
|
|
17
|
+
nativeLang?: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Splits a country's `label` (e.g. `'India (भारत)'`) into the default-language name and the
|
|
21
|
+
* trailing native-language segment (if any), so the native segment can be given its own `lang`
|
|
22
|
+
* attribute for correct screen reader pronunciation (WCAG 3.1.2 - Language of Parts).
|
|
23
|
+
*
|
|
24
|
+
* Requires both `nativeName` and `nativeLang`. Falls back to the whole `label` as `primaryName`
|
|
25
|
+
* if either is missing or `nativeName` is not actually a trailing `label` suffix, so incomplete
|
|
26
|
+
* data never breaks rendering or ships a native segment without a language tag.
|
|
27
|
+
*/
|
|
28
|
+
export declare const getCountryLabelParts: ({ label, nativeName, nativeLang }: Country) => CountryLabelParts;
|
|
29
|
+
/**
|
|
30
|
+
* Resolves the label parts to render for a country option, honoring an optional `mapIsoToLabel`
|
|
31
|
+
* override (string or `{ label, nativeName?, nativeLang? }`).
|
|
32
|
+
*
|
|
33
|
+
* String overrides replace the whole label (legacy behavior). Object overrides only split out a
|
|
34
|
+
* `lang`-tagged native segment when both `nativeName` and `nativeLang` are provided; otherwise the
|
|
35
|
+
* visible text is flattened into `primaryName` so display stays correct without invalid markup.
|
|
36
|
+
*/
|
|
37
|
+
export declare const resolveCountryLabelParts: (country: Country, mapIsoToLabel?: ((iso: string) => string | CustomCountryLabel) | undefined) => CountryLabelParts;
|
package/phone-input/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDefaultValue = exports.countrySelectFilterOptions = exports.getPhoneNumberWithCountryDialCode = exports.sanitize = exports.iso2FlagEmoji = void 0;
|
|
3
|
+
exports.resolveCountryLabelParts = exports.getCountryLabelParts = exports.getDefaultValue = exports.countrySelectFilterOptions = exports.getPhoneNumberWithCountryDialCode = exports.sanitize = exports.iso2FlagEmoji = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
|
|
6
6
|
var default_filter_options_1 = require("../select/utils/default-filter-options");
|
|
@@ -38,3 +38,54 @@ var getDefaultValue = function (countries) {
|
|
|
38
38
|
return countries && !(0, isEmpty_1.default)(countries) ? { country: constants_1.COUNTRIES[countries[0].id], phoneNumber: '' } : default_props_1.defaultValue;
|
|
39
39
|
};
|
|
40
40
|
exports.getDefaultValue = getDefaultValue;
|
|
41
|
+
/**
|
|
42
|
+
* Splits a country's `label` (e.g. `'India (भारत)'`) into the default-language name and the
|
|
43
|
+
* trailing native-language segment (if any), so the native segment can be given its own `lang`
|
|
44
|
+
* attribute for correct screen reader pronunciation (WCAG 3.1.2 - Language of Parts).
|
|
45
|
+
*
|
|
46
|
+
* Requires both `nativeName` and `nativeLang`. Falls back to the whole `label` as `primaryName`
|
|
47
|
+
* if either is missing or `nativeName` is not actually a trailing `label` suffix, so incomplete
|
|
48
|
+
* data never breaks rendering or ships a native segment without a language tag.
|
|
49
|
+
*/
|
|
50
|
+
var getCountryLabelParts = function (_a) {
|
|
51
|
+
var label = _a.label, nativeName = _a.nativeName, nativeLang = _a.nativeLang;
|
|
52
|
+
if (!nativeName || !nativeLang) {
|
|
53
|
+
return { primaryName: label };
|
|
54
|
+
}
|
|
55
|
+
var nativeNameSuffix = "(".concat(nativeName, ")");
|
|
56
|
+
var suffixStartIndex = label.lastIndexOf(nativeNameSuffix);
|
|
57
|
+
var isSuffixAtEnd = suffixStartIndex !== -1 && suffixStartIndex + nativeNameSuffix.length === label.length;
|
|
58
|
+
if (!isSuffixAtEnd) {
|
|
59
|
+
return { primaryName: label };
|
|
60
|
+
}
|
|
61
|
+
return { primaryName: label.slice(0, suffixStartIndex).trimEnd(), nativeName: nativeName, nativeLang: nativeLang };
|
|
62
|
+
};
|
|
63
|
+
exports.getCountryLabelParts = getCountryLabelParts;
|
|
64
|
+
/**
|
|
65
|
+
* Resolves the label parts to render for a country option, honoring an optional `mapIsoToLabel`
|
|
66
|
+
* override (string or `{ label, nativeName?, nativeLang? }`).
|
|
67
|
+
*
|
|
68
|
+
* String overrides replace the whole label (legacy behavior). Object overrides only split out a
|
|
69
|
+
* `lang`-tagged native segment when both `nativeName` and `nativeLang` are provided; otherwise the
|
|
70
|
+
* visible text is flattened into `primaryName` so display stays correct without invalid markup.
|
|
71
|
+
*/
|
|
72
|
+
var resolveCountryLabelParts = function (country, mapIsoToLabel) {
|
|
73
|
+
if (!mapIsoToLabel) {
|
|
74
|
+
return (0, exports.getCountryLabelParts)(country);
|
|
75
|
+
}
|
|
76
|
+
var mapped = mapIsoToLabel(country.id);
|
|
77
|
+
if (typeof mapped === 'string') {
|
|
78
|
+
return { primaryName: mapped };
|
|
79
|
+
}
|
|
80
|
+
if (!mapped.nativeName || !mapped.nativeLang) {
|
|
81
|
+
return {
|
|
82
|
+
primaryName: mapped.nativeName ? "".concat(mapped.label, " (").concat(mapped.nativeName, ")") : mapped.label,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
primaryName: mapped.label,
|
|
87
|
+
nativeName: mapped.nativeName,
|
|
88
|
+
nativeLang: mapped.nativeLang,
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
exports.resolveCountryLabelParts = resolveCountryLabelParts;
|