@rh-support/components 2.0.10 → 2.0.12-beta.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/lib/cjs/ConfirmationModal/ConfirmationDialog.d.ts +4 -1
- package/lib/cjs/ConfirmationModal/ConfirmationDialog.d.ts.map +1 -1
- package/lib/cjs/ConfirmationModal/ConfirmationDialog.js +2 -1
- package/lib/cjs/LoadingDots/LoadingDots.js +1 -1
- package/lib/cjs/PhoneInput/CountryData.d.ts +3 -0
- package/lib/cjs/PhoneInput/CountryData.d.ts.map +1 -0
- package/lib/cjs/PhoneInput/CountryData.js +590 -0
- package/lib/cjs/PhoneInput/PhoneInput.d.ts +14 -0
- package/lib/cjs/PhoneInput/PhoneInput.d.ts.map +1 -0
- package/lib/cjs/PhoneInput/PhoneInput.js +199 -0
- package/lib/cjs/PhoneInput/PhoneInput.scss +744 -0
- package/lib/cjs/PhoneInput/flags.png +0 -0
- package/lib/cjs/PhoneInput/index.d.ts +2 -0
- package/lib/cjs/PhoneInput/index.d.ts.map +1 -0
- package/lib/cjs/PhoneInput/index.js +13 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +1 -0
- package/lib/esm/ConfirmationModal/ConfirmationDialog.d.ts +4 -1
- package/lib/esm/ConfirmationModal/ConfirmationDialog.d.ts.map +1 -1
- package/lib/esm/ConfirmationModal/ConfirmationDialog.js +3 -2
- package/lib/esm/LoadingDots/LoadingDots.js +1 -1
- package/lib/esm/PhoneInput/CountryData.d.ts +3 -0
- package/lib/esm/PhoneInput/CountryData.d.ts.map +1 -0
- package/lib/esm/PhoneInput/CountryData.js +588 -0
- package/lib/esm/PhoneInput/PhoneInput.d.ts +14 -0
- package/lib/esm/PhoneInput/PhoneInput.d.ts.map +1 -0
- package/lib/esm/PhoneInput/PhoneInput.js +173 -0
- package/lib/esm/PhoneInput/PhoneInput.scss +744 -0
- package/lib/esm/PhoneInput/flags.png +0 -0
- package/lib/esm/PhoneInput/index.d.ts +2 -0
- package/lib/esm/PhoneInput/index.d.ts.map +1 -0
- package/lib/esm/PhoneInput/index.js +1 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +1 -0
- package/package.json +12 -9
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import './PhoneInput.scss';
|
|
3
|
+
interface IProps {
|
|
4
|
+
phoneValue: string;
|
|
5
|
+
countryCode?: string;
|
|
6
|
+
onPhoneValue?: (string: any) => void;
|
|
7
|
+
validations?: 'default' | 'success' | 'warning' | 'error' | undefined;
|
|
8
|
+
onCountryCode?: (string: any) => void;
|
|
9
|
+
invalid?: boolean;
|
|
10
|
+
setInvalid: (boolean: any) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function PhoneInput(props: IProps): JSX.Element;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=PhoneInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PhoneInput.d.ts","sourceRoot":"","sources":["../../../src/PhoneInput/PhoneInput.tsx"],"names":[],"mappings":";AAAA,OAAO,mBAAmB,CAAC;AAS3B,UAAU,MAAM;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,CAAC,MAAM,KAAA,KAAK,IAAI,CAAC;IAChC,WAAW,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IACtE,aAAa,CAAC,EAAE,CAAC,MAAM,KAAA,KAAK,IAAI,CAAC;IACjC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,CAAC,OAAO,KAAA,KAAK,IAAI,CAAC;CACjC;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,eAyNvC"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.PhoneInput = void 0;
|
|
26
|
+
require("./PhoneInput.scss");
|
|
27
|
+
const react_core_1 = require("@patternfly/react-core");
|
|
28
|
+
const lodash_1 = require("lodash");
|
|
29
|
+
const react_1 = __importStar(require("react"));
|
|
30
|
+
const react_i18next_1 = require("react-i18next");
|
|
31
|
+
const CountryData_1 = __importDefault(require("./CountryData"));
|
|
32
|
+
function PhoneInput(props) {
|
|
33
|
+
const { phoneValue, countryCode, onCountryCode, onPhoneValue, validations, setInvalid } = props;
|
|
34
|
+
const { t } = react_i18next_1.useTranslation();
|
|
35
|
+
const [isOpen, setIsOpen] = react_1.useState(false);
|
|
36
|
+
const [iso2, setIso2] = react_1.useState('');
|
|
37
|
+
const [formattedNumber, setFormattedNumber] = react_1.useState('');
|
|
38
|
+
const [format, setFormat] = react_1.useState('');
|
|
39
|
+
const prefix = '+';
|
|
40
|
+
const defaultMask = '... ... ... ... ..';
|
|
41
|
+
const alwaysDefaultMask = false;
|
|
42
|
+
const [selected, setSelected] = react_1.useState({
|
|
43
|
+
name: '',
|
|
44
|
+
regions: [''],
|
|
45
|
+
iso2: '',
|
|
46
|
+
countryCode: '',
|
|
47
|
+
dialCode: '',
|
|
48
|
+
format: '', // Number Format (For US, '(...) ...-....' )
|
|
49
|
+
});
|
|
50
|
+
react_1.useEffect(() => {
|
|
51
|
+
if (lodash_1.isEmpty(iso2) && !lodash_1.isEmpty(phoneValue)) {
|
|
52
|
+
let localCountryCode = countryCode === null || countryCode === void 0 ? void 0 : countryCode.replace(prefix, '');
|
|
53
|
+
const exactCountry = initializedCountries.filter((country) => country.dialCode.toString() === localCountryCode);
|
|
54
|
+
let localFormat = exactCountry[0].format.toString();
|
|
55
|
+
setFormat(localFormat);
|
|
56
|
+
formatNumber(countryCode + phoneValue);
|
|
57
|
+
}
|
|
58
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
59
|
+
}, []);
|
|
60
|
+
react_1.useEffect(() => {
|
|
61
|
+
if (!lodash_1.isEmpty(selected.iso2) && `${prefix}${selected.dialCode}` !== countryCode) {
|
|
62
|
+
setIso2(selected.iso2);
|
|
63
|
+
setFormat(selected.format);
|
|
64
|
+
onPhoneValue && onPhoneValue(`${prefix}${selected.dialCode}`);
|
|
65
|
+
setFormattedNumber(`${prefix}${selected.dialCode}`);
|
|
66
|
+
}
|
|
67
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
68
|
+
}, [selected]);
|
|
69
|
+
react_1.useEffect(() => {
|
|
70
|
+
if (lodash_1.isEmpty(phoneValue)) {
|
|
71
|
+
setIso2('');
|
|
72
|
+
setInvalid(false);
|
|
73
|
+
setFormattedNumber('');
|
|
74
|
+
}
|
|
75
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
76
|
+
}, [phoneValue]);
|
|
77
|
+
// Getting Country phone format
|
|
78
|
+
function getMask(prefix, dialCode, predefinedMask, defaultMask, alwaysDefaultMask) {
|
|
79
|
+
if (!predefinedMask || alwaysDefaultMask) {
|
|
80
|
+
return prefix + ''.padEnd(dialCode.length, '.') + ' ' + defaultMask;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return prefix + ''.padEnd(dialCode.length, '.') + ' ' + predefinedMask;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const initializedCountries = CountryData_1.default.map((country) => {
|
|
87
|
+
const countryItem = {
|
|
88
|
+
name: country[0],
|
|
89
|
+
regions: country[1],
|
|
90
|
+
iso2: country[2],
|
|
91
|
+
countryCode: country[3],
|
|
92
|
+
dialCode: country[3],
|
|
93
|
+
format: getMask(prefix, country[3], country[4], defaultMask, alwaysDefaultMask),
|
|
94
|
+
priority: country[5] || 0,
|
|
95
|
+
};
|
|
96
|
+
return countryItem;
|
|
97
|
+
});
|
|
98
|
+
const onChange = (phone) => {
|
|
99
|
+
if (lodash_1.isEmpty(phone)) {
|
|
100
|
+
setFormattedNumber('');
|
|
101
|
+
}
|
|
102
|
+
const regex = /^[\d ()+-]+$/;
|
|
103
|
+
regex.test(phone) ? setInvalid(false) : setInvalid(true);
|
|
104
|
+
formatNumber(phone);
|
|
105
|
+
if (!phoneValue.startsWith(prefix) && regex.test(phone) && !lodash_1.isEqual(phone, '-')) {
|
|
106
|
+
onPhoneValue && onPhoneValue(prefix + phone);
|
|
107
|
+
}
|
|
108
|
+
else if (phone.length <= formattedNumber.length) {
|
|
109
|
+
onPhoneValue && onPhoneValue(phone);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const onToggle = (isOpen) => {
|
|
113
|
+
setIsOpen(isOpen);
|
|
114
|
+
};
|
|
115
|
+
const onSelect = (event, selection) => {
|
|
116
|
+
setSelected(selection);
|
|
117
|
+
setIsOpen(!isOpen);
|
|
118
|
+
};
|
|
119
|
+
const getOptions = (options) => {
|
|
120
|
+
return options.map((country) => (react_1.default.createElement(react_core_1.SelectOption, { key: country.iso2, value: country },
|
|
121
|
+
react_1.default.createElement("div", { className: "pf-u-display-inline-flex" },
|
|
122
|
+
react_1.default.createElement("div", { className: `flag ${country.iso2}`, style: { marginRight: '8px' } }),
|
|
123
|
+
country.name,
|
|
124
|
+
" (+",
|
|
125
|
+
country.dialCode,
|
|
126
|
+
")"))));
|
|
127
|
+
};
|
|
128
|
+
const onFilter = (_, value) => {
|
|
129
|
+
if (!value)
|
|
130
|
+
return getOptions(initializedCountries);
|
|
131
|
+
const input = new RegExp(value, 'i');
|
|
132
|
+
const newOptions = initializedCountries.filter((country) => input.test(country.name.toString()));
|
|
133
|
+
return getOptions(newOptions);
|
|
134
|
+
};
|
|
135
|
+
// Formatting phone numbers according to country
|
|
136
|
+
const formatNumber = (phoneNumber) => {
|
|
137
|
+
if (lodash_1.isEmpty(phoneNumber)) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
let localPhone = phoneNumber.replace(prefix, '');
|
|
141
|
+
if (lodash_1.isEmpty(localPhone)) {
|
|
142
|
+
setFormattedNumber('');
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
// Guessing countries according to user input
|
|
146
|
+
const possibleCountries = initializedCountries.filter((country) => localPhone.startsWith(country.dialCode.toString()));
|
|
147
|
+
const exactCountry = initializedCountries.filter((country) => country.dialCode.toString() === localPhone);
|
|
148
|
+
let localFormat;
|
|
149
|
+
if (!lodash_1.isEmpty(exactCountry)) {
|
|
150
|
+
setIso2(exactCountry[0].iso2.toString());
|
|
151
|
+
localFormat = exactCountry[0].format.toString();
|
|
152
|
+
setFormat(localFormat);
|
|
153
|
+
onCountryCode && onCountryCode(prefix + exactCountry[0].dialCode.toString());
|
|
154
|
+
}
|
|
155
|
+
else if (!lodash_1.isEmpty(possibleCountries)) {
|
|
156
|
+
setIso2(possibleCountries[0].iso2.toString());
|
|
157
|
+
localFormat = possibleCountries[0].format.toString();
|
|
158
|
+
setFormat(localFormat);
|
|
159
|
+
onCountryCode && onCountryCode(prefix + possibleCountries[0].dialCode.toString());
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
setIso2('');
|
|
163
|
+
localFormat = format;
|
|
164
|
+
}
|
|
165
|
+
if (lodash_1.isEmpty(localFormat)) {
|
|
166
|
+
setFormattedNumber('');
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
// Formatting inputted number
|
|
170
|
+
let phone = '';
|
|
171
|
+
[...phoneNumber].forEach((ele) => {
|
|
172
|
+
if (ele >= '0' && ele <= '9') {
|
|
173
|
+
phone = phone.concat(ele);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
let pattern = '';
|
|
177
|
+
let i = 0;
|
|
178
|
+
for (let j = 0; j < localFormat.length && i < phone.length; j++) {
|
|
179
|
+
if (localFormat[j] === '.') {
|
|
180
|
+
pattern += phone[i];
|
|
181
|
+
i++;
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
pattern += localFormat[j];
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
setFormattedNumber(pattern);
|
|
188
|
+
};
|
|
189
|
+
const placeholder = (react_1.default.createElement("div", { className: "phone-number-select-placeholder" },
|
|
190
|
+
react_1.default.createElement("div", { className: "pf-u-display-inline-flex" },
|
|
191
|
+
react_1.default.createElement("div", { className: `flag ${iso2}`, style: { marginRight: '5px' } }),
|
|
192
|
+
iso2.toUpperCase())));
|
|
193
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
194
|
+
react_1.default.createElement(react_core_1.InputGroup, { className: "phone-number-input" },
|
|
195
|
+
react_1.default.createElement("div", null,
|
|
196
|
+
react_1.default.createElement(react_core_1.Select, { variant: react_core_1.SelectVariant.single, "data-tracking-id": "case-phone-number-country-code", className: "phone-number-select", onToggle: onToggle, onSelect: onSelect, isOpen: isOpen, placeholderText: iso2 && phoneValue !== '' ? placeholder : 'Country Code', onFilter: onFilter, hasInlineFilter: true, inlineFilterPlaceholderText: t('Search') }, getOptions(initializedCountries))),
|
|
197
|
+
react_1.default.createElement(react_core_1.TextInput, { id: "case-phone-number", "data-tracking-id": "case-phone-number", placeholder: "55-555-5555", value: formattedNumber ? formattedNumber : phoneValue, onChange: onChange, validated: validations }))));
|
|
198
|
+
}
|
|
199
|
+
exports.PhoneInput = PhoneInput;
|