@rh-support/components 2.0.5 → 2.0.7-beta.1

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 (212) hide show
  1. package/lib/cjs/AlertMessage/AlertMessage.js +5 -5
  2. package/lib/cjs/ConfirmationModal/ConfirmationContext.d.ts +0 -1
  3. package/lib/cjs/ConfirmationModal/ConfirmationContext.d.ts.map +1 -1
  4. package/lib/cjs/ConfirmationModal/ConfirmationContext.js +13 -41
  5. package/lib/cjs/ConfirmationModal/ConfirmationDialog.d.ts +4 -2
  6. package/lib/cjs/ConfirmationModal/ConfirmationDialog.d.ts.map +1 -1
  7. package/lib/cjs/ConfirmationModal/ConfirmationDialog.js +7 -6
  8. package/lib/cjs/CoverSpinner/CoverSpinner.d.ts +0 -1
  9. package/lib/cjs/CoverSpinner/CoverSpinner.d.ts.map +1 -1
  10. package/lib/cjs/CoverSpinner/CoverSpinner.js +1 -1
  11. package/lib/cjs/CustomContentLoader/CustomContentLoader.js +4 -4
  12. package/lib/cjs/CustomTextInput/CustomTextInput.d.ts +0 -1
  13. package/lib/cjs/CustomTextInput/CustomTextInput.d.ts.map +1 -1
  14. package/lib/cjs/CustomTextInput/CustomTextInput.js +8 -19
  15. package/lib/cjs/DropDownList/AsyncDropDownList.js +5 -5
  16. package/lib/cjs/DropDownList/DropDownList.d.ts +0 -1
  17. package/lib/cjs/DropDownList/DropDownList.d.ts.map +1 -1
  18. package/lib/cjs/DropDownList/DropDownList.js +45 -75
  19. package/lib/cjs/DropDownList/DropdownWrapper.js +7 -18
  20. package/lib/cjs/DropDownList/MultiSelectDropdownList.js +3 -3
  21. package/lib/cjs/DropDownList/SearchableList.d.ts +1 -0
  22. package/lib/cjs/DropDownList/SearchableList.d.ts.map +1 -1
  23. package/lib/cjs/DropDownList/SearchableList.js +44 -56
  24. package/lib/cjs/DropDownList/SelectList.js +15 -26
  25. package/lib/cjs/DropDownList/async.js +28 -38
  26. package/lib/cjs/DropDownList/dropdownList.css +1 -1
  27. package/lib/cjs/DropDownList/dropdownUtils.js +9 -20
  28. package/lib/cjs/DropDownList/types.d.ts +1 -0
  29. package/lib/cjs/DropDownList/types.d.ts.map +1 -1
  30. package/lib/cjs/DropDownList/withMulti.js +15 -26
  31. package/lib/cjs/ErrorBoundary/ErrorBoundary.js +18 -47
  32. package/lib/cjs/ErrorBoundary/ErrorBoundaryFallbackComponent.d.ts +0 -1
  33. package/lib/cjs/ErrorBoundary/ErrorBoundaryFallbackComponent.d.ts.map +1 -1
  34. package/lib/cjs/ErrorBoundary/ErrorBoundaryFallbackComponent.js +10 -10
  35. package/lib/cjs/ErrorPages/Generic403.d.ts +0 -1
  36. package/lib/cjs/ErrorPages/Generic403.d.ts.map +1 -1
  37. package/lib/cjs/ErrorPages/Generic403.js +2 -2
  38. package/lib/cjs/FeedbackForm/FeedbackForm.d.ts +0 -1
  39. package/lib/cjs/FeedbackForm/FeedbackForm.d.ts.map +1 -1
  40. package/lib/cjs/FeedbackForm/FeedbackForm.js +24 -52
  41. package/lib/cjs/Functional/CaseContactsSelectorExternal.d.ts.map +1 -1
  42. package/lib/cjs/Functional/CaseContactsSelectorExternal.js +81 -154
  43. package/lib/cjs/InlineEdit/InlineEdit.d.ts +1 -0
  44. package/lib/cjs/InlineEdit/InlineEdit.d.ts.map +1 -1
  45. package/lib/cjs/InlineEdit/InlineEdit.js +58 -144
  46. package/lib/cjs/InlineEdit/NewInlineEdit.d.ts +1 -0
  47. package/lib/cjs/InlineEdit/NewInlineEdit.d.ts.map +1 -1
  48. package/lib/cjs/InlineEdit/NewInlineEdit.js +62 -147
  49. package/lib/cjs/InlineEdit/inlineEdit.css +4 -0
  50. package/lib/cjs/InlineEdit/newInlineEdit.css +4 -0
  51. package/lib/cjs/LanguageSelector/LanguageSelector.d.ts +0 -1
  52. package/lib/cjs/LanguageSelector/LanguageSelector.d.ts.map +1 -1
  53. package/lib/cjs/LanguageSelector/LanguageSelector.js +10 -26
  54. package/lib/cjs/LoadingDots/LoadingDots.d.ts +0 -1
  55. package/lib/cjs/LoadingDots/LoadingDots.d.ts.map +1 -1
  56. package/lib/cjs/LoadingDots/LoadingDots.js +4 -4
  57. package/lib/cjs/LoadingIndicator/LoadingIndicator.d.ts +0 -1
  58. package/lib/cjs/LoadingIndicator/LoadingIndicator.d.ts.map +1 -1
  59. package/lib/cjs/LoadingIndicator/LoadingIndicator.js +3 -3
  60. package/lib/cjs/LoginModal/LoginModal.d.ts +0 -1
  61. package/lib/cjs/LoginModal/LoginModal.d.ts.map +1 -1
  62. package/lib/cjs/LoginModal/LoginModal.js +3 -3
  63. package/lib/cjs/MarkdownEditor/MarkdownEditor.js +113 -165
  64. package/lib/cjs/MoreOrLess/MoreOrLess.js +20 -40
  65. package/lib/cjs/PaginatedList/PaginatedList.js +15 -31
  66. package/lib/cjs/PaginationCompact/PaginationCompact.d.ts +0 -1
  67. package/lib/cjs/PaginationCompact/PaginationCompact.d.ts.map +1 -1
  68. package/lib/cjs/PaginationCompact/PaginationCompact.js +14 -31
  69. package/lib/cjs/PhoneInput/CountryData.d.ts +3 -0
  70. package/lib/cjs/PhoneInput/CountryData.d.ts.map +1 -0
  71. package/lib/cjs/PhoneInput/CountryData.js +583 -0
  72. package/lib/cjs/PhoneInput/PhoneInput.d.ts +19 -0
  73. package/lib/cjs/PhoneInput/PhoneInput.d.ts.map +1 -0
  74. package/lib/cjs/PhoneInput/PhoneInput.js +284 -0
  75. package/lib/cjs/PhoneInput/PhoneInput.scss +753 -0
  76. package/lib/cjs/PhoneInput/flags.png +0 -0
  77. package/lib/cjs/PhoneInput/index.d.ts +2 -0
  78. package/lib/cjs/PhoneInput/index.d.ts.map +1 -0
  79. package/lib/cjs/PhoneInput/index.js +13 -0
  80. package/lib/cjs/ProgressBar/CircularProgressBar/CircularProgressBar.d.ts +0 -1
  81. package/lib/cjs/ProgressBar/CircularProgressBar/CircularProgressBar.d.ts.map +1 -1
  82. package/lib/cjs/ProgressBar/CircularProgressBar/CircularProgressBar.js +14 -14
  83. package/lib/cjs/ProgressBar/CircularProgressBar/Path.js +20 -18
  84. package/lib/cjs/ProgressBar/ProgressBar.js +8 -19
  85. package/lib/cjs/PromisifyModal/PromisifyModal.js +19 -36
  86. package/lib/cjs/SubscriptionAbuse/SubscriptionAbuseModal.d.ts +0 -1
  87. package/lib/cjs/SubscriptionAbuse/SubscriptionAbuseModal.d.ts.map +1 -1
  88. package/lib/cjs/SubscriptionAbuse/SubscriptionAbuseModal.js +5 -5
  89. package/lib/cjs/SubscriptionAbuse/const.d.ts +0 -1
  90. package/lib/cjs/SubscriptionAbuse/const.d.ts.map +1 -1
  91. package/lib/cjs/SubscriptionAbuse/const.js +3 -3
  92. package/lib/cjs/SupportFeedbackForm/SupportFeedbackForm.d.ts +0 -1
  93. package/lib/cjs/SupportFeedbackForm/SupportFeedbackForm.d.ts.map +1 -1
  94. package/lib/cjs/SupportFeedbackForm/SupportFeedbackForm.js +8 -24
  95. package/lib/cjs/SupportFeedbackForm/SupportFeedbackModal.d.ts +0 -1
  96. package/lib/cjs/SupportFeedbackForm/SupportFeedbackModal.d.ts.map +1 -1
  97. package/lib/cjs/SupportFeedbackForm/SupportFeedbackModal.js +50 -120
  98. package/lib/cjs/Table/PFTable.js +52 -89
  99. package/lib/cjs/Table/Table.js +12 -29
  100. package/lib/cjs/Table/TableColumnSelector.d.ts +0 -1
  101. package/lib/cjs/Table/TableColumnSelector.d.ts.map +1 -1
  102. package/lib/cjs/Table/TableColumnSelector.js +14 -15
  103. package/lib/cjs/Table/TablePagination.d.ts +0 -1
  104. package/lib/cjs/Table/TablePagination.d.ts.map +1 -1
  105. package/lib/cjs/Table/TablePagination.js +8 -8
  106. package/lib/cjs/Table/TableProvider.js +6 -6
  107. package/lib/cjs/TermsAndConditions/AcceptTermsModal.d.ts +0 -1
  108. package/lib/cjs/TermsAndConditions/AcceptTermsModal.d.ts.map +1 -1
  109. package/lib/cjs/TermsAndConditions/AcceptTermsModal.js +46 -100
  110. package/lib/cjs/TextAreaAutosize/TextAreaAutosize.js +35 -62
  111. package/lib/cjs/TextAreaResizable/TextAreaResizable.js +9 -25
  112. package/lib/cjs/ToastNotification/ToastNotification.js +35 -70
  113. package/lib/cjs/TopContentSearch/TopContentSearch.js +48 -113
  114. package/lib/cjs/ValueChangedIcon/ValueChangedIcon.js +13 -29
  115. package/lib/cjs/helperFunctions/errorMessage.d.ts +0 -1
  116. package/lib/cjs/helperFunctions/errorMessage.d.ts.map +1 -1
  117. package/lib/cjs/helperFunctions/errorMessage.js +13 -13
  118. package/lib/cjs/hooks/useBreakpoint.js +26 -43
  119. package/lib/cjs/hooks/useCopyToClipboard.js +8 -24
  120. package/lib/cjs/hooks/useDebounce.js +13 -38
  121. package/lib/cjs/hooks/useFetch.js +47 -123
  122. package/lib/cjs/hooks/useForceUpdate.js +2 -18
  123. package/lib/cjs/hooks/useForkRef.js +3 -3
  124. package/lib/cjs/hooks/useIsMounted.js +4 -4
  125. package/lib/cjs/hooks/useLRUCache.js +11 -11
  126. package/lib/cjs/hooks/useLocalStorage.js +7 -23
  127. package/lib/cjs/hooks/useOnScreen.js +5 -24
  128. package/lib/cjs/hooks/usePolling.js +8 -30
  129. package/lib/cjs/hooks/usePrevious.js +3 -3
  130. package/lib/cjs/hooks/useTitle.js +4 -4
  131. package/lib/cjs/hooks/useUndo.js +49 -72
  132. package/lib/cjs/index.d.ts +1 -0
  133. package/lib/cjs/index.d.ts.map +1 -1
  134. package/lib/cjs/index.js +1 -0
  135. package/lib/esm/AlertMessage/AlertMessage.js +2 -2
  136. package/lib/esm/ConfirmationModal/ConfirmationContext.d.ts +0 -1
  137. package/lib/esm/ConfirmationModal/ConfirmationContext.d.ts.map +1 -1
  138. package/lib/esm/ConfirmationModal/ConfirmationDialog.d.ts +4 -2
  139. package/lib/esm/ConfirmationModal/ConfirmationDialog.d.ts.map +1 -1
  140. package/lib/esm/ConfirmationModal/ConfirmationDialog.js +3 -2
  141. package/lib/esm/CoverSpinner/CoverSpinner.d.ts +0 -1
  142. package/lib/esm/CoverSpinner/CoverSpinner.d.ts.map +1 -1
  143. package/lib/esm/CustomTextInput/CustomTextInput.d.ts +0 -1
  144. package/lib/esm/CustomTextInput/CustomTextInput.d.ts.map +1 -1
  145. package/lib/esm/DropDownList/DropDownList.d.ts +0 -1
  146. package/lib/esm/DropDownList/DropDownList.d.ts.map +1 -1
  147. package/lib/esm/DropDownList/SearchableList.d.ts +1 -0
  148. package/lib/esm/DropDownList/SearchableList.d.ts.map +1 -1
  149. package/lib/esm/DropDownList/SearchableList.js +4 -2
  150. package/lib/esm/DropDownList/dropdownList.css +1 -1
  151. package/lib/esm/DropDownList/types.d.ts +1 -0
  152. package/lib/esm/DropDownList/types.d.ts.map +1 -1
  153. package/lib/esm/ErrorBoundary/ErrorBoundaryFallbackComponent.d.ts +0 -1
  154. package/lib/esm/ErrorBoundary/ErrorBoundaryFallbackComponent.d.ts.map +1 -1
  155. package/lib/esm/ErrorPages/Generic403.d.ts +0 -1
  156. package/lib/esm/ErrorPages/Generic403.d.ts.map +1 -1
  157. package/lib/esm/FeedbackForm/FeedbackForm.d.ts +0 -1
  158. package/lib/esm/FeedbackForm/FeedbackForm.d.ts.map +1 -1
  159. package/lib/esm/Functional/CaseContactsSelectorExternal.d.ts.map +1 -1
  160. package/lib/esm/Functional/CaseContactsSelectorExternal.js +1 -1
  161. package/lib/esm/InlineEdit/InlineEdit.d.ts +1 -0
  162. package/lib/esm/InlineEdit/InlineEdit.d.ts.map +1 -1
  163. package/lib/esm/InlineEdit/InlineEdit.js +2 -2
  164. package/lib/esm/InlineEdit/NewInlineEdit.d.ts +1 -0
  165. package/lib/esm/InlineEdit/NewInlineEdit.d.ts.map +1 -1
  166. package/lib/esm/InlineEdit/NewInlineEdit.js +2 -2
  167. package/lib/esm/InlineEdit/inlineEdit.css +4 -0
  168. package/lib/esm/InlineEdit/newInlineEdit.css +4 -0
  169. package/lib/esm/LanguageSelector/LanguageSelector.d.ts +0 -1
  170. package/lib/esm/LanguageSelector/LanguageSelector.d.ts.map +1 -1
  171. package/lib/esm/LoadingDots/LoadingDots.d.ts +0 -1
  172. package/lib/esm/LoadingDots/LoadingDots.d.ts.map +1 -1
  173. package/lib/esm/LoadingDots/LoadingDots.js +1 -1
  174. package/lib/esm/LoadingIndicator/LoadingIndicator.d.ts +0 -1
  175. package/lib/esm/LoadingIndicator/LoadingIndicator.d.ts.map +1 -1
  176. package/lib/esm/LoginModal/LoginModal.d.ts +0 -1
  177. package/lib/esm/LoginModal/LoginModal.d.ts.map +1 -1
  178. package/lib/esm/PaginationCompact/PaginationCompact.d.ts +0 -1
  179. package/lib/esm/PaginationCompact/PaginationCompact.d.ts.map +1 -1
  180. package/lib/esm/PhoneInput/CountryData.d.ts +3 -0
  181. package/lib/esm/PhoneInput/CountryData.d.ts.map +1 -0
  182. package/lib/esm/PhoneInput/CountryData.js +580 -0
  183. package/lib/esm/PhoneInput/PhoneInput.d.ts +19 -0
  184. package/lib/esm/PhoneInput/PhoneInput.d.ts.map +1 -0
  185. package/lib/esm/PhoneInput/PhoneInput.js +257 -0
  186. package/lib/esm/PhoneInput/PhoneInput.scss +753 -0
  187. package/lib/esm/PhoneInput/flags.png +0 -0
  188. package/lib/esm/PhoneInput/index.d.ts +2 -0
  189. package/lib/esm/PhoneInput/index.d.ts.map +1 -0
  190. package/lib/esm/PhoneInput/index.js +1 -0
  191. package/lib/esm/ProgressBar/CircularProgressBar/CircularProgressBar.d.ts +0 -1
  192. package/lib/esm/ProgressBar/CircularProgressBar/CircularProgressBar.d.ts.map +1 -1
  193. package/lib/esm/SubscriptionAbuse/SubscriptionAbuseModal.d.ts +0 -1
  194. package/lib/esm/SubscriptionAbuse/SubscriptionAbuseModal.d.ts.map +1 -1
  195. package/lib/esm/SubscriptionAbuse/const.d.ts +0 -1
  196. package/lib/esm/SubscriptionAbuse/const.d.ts.map +1 -1
  197. package/lib/esm/SupportFeedbackForm/SupportFeedbackForm.d.ts +0 -1
  198. package/lib/esm/SupportFeedbackForm/SupportFeedbackForm.d.ts.map +1 -1
  199. package/lib/esm/SupportFeedbackForm/SupportFeedbackModal.d.ts +0 -1
  200. package/lib/esm/SupportFeedbackForm/SupportFeedbackModal.d.ts.map +1 -1
  201. package/lib/esm/Table/TableColumnSelector.d.ts +0 -1
  202. package/lib/esm/Table/TableColumnSelector.d.ts.map +1 -1
  203. package/lib/esm/Table/TablePagination.d.ts +0 -1
  204. package/lib/esm/Table/TablePagination.d.ts.map +1 -1
  205. package/lib/esm/TermsAndConditions/AcceptTermsModal.d.ts +0 -1
  206. package/lib/esm/TermsAndConditions/AcceptTermsModal.d.ts.map +1 -1
  207. package/lib/esm/helperFunctions/errorMessage.d.ts +0 -1
  208. package/lib/esm/helperFunctions/errorMessage.d.ts.map +1 -1
  209. package/lib/esm/index.d.ts +1 -0
  210. package/lib/esm/index.d.ts.map +1 -1
  211. package/lib/esm/index.js +1 -0
  212. package/package.json +15 -13
@@ -0,0 +1,257 @@
1
+ import './PhoneInput.scss';
2
+ import { InputGroup, Select, SelectOption, SelectVariant, Spinner, TextInput } from '@patternfly/react-core';
3
+ import isEmpty from 'lodash/isEmpty';
4
+ import isEqual from 'lodash/isEqual';
5
+ import React, { useEffect, useState } from 'react';
6
+ import { useTranslation } from 'react-i18next';
7
+ import { canadaAreaCodes, COUNTRY_DATA } from './CountryData';
8
+ const PREFIX = '+';
9
+ const DEFAULT_MASK = '... ... ... ... ..';
10
+ const ALWAYS_DEFAULT_MASK = false;
11
+ // Getting Country phone format
12
+ function getMask(prefix, dialCode, predefinedMask, defaultMask, alwaysDefaultMask) {
13
+ if (!predefinedMask || alwaysDefaultMask) {
14
+ return prefix + ''.padEnd(dialCode.length, '.') + ' ' + defaultMask;
15
+ }
16
+ else {
17
+ return prefix + ''.padEnd(dialCode.length, '.') + ' ' + predefinedMask;
18
+ }
19
+ }
20
+ const initializedCountries = COUNTRY_DATA.map((country) => {
21
+ const countryItem = {
22
+ name: country[0],
23
+ regions: country[1],
24
+ iso2: country[2],
25
+ countryCode: country[3],
26
+ dialCode: country[3],
27
+ format: getMask(PREFIX, country[3], country[4], DEFAULT_MASK, ALWAYS_DEFAULT_MASK),
28
+ priority: country[5] || 0,
29
+ areaCode: country[6] || [],
30
+ };
31
+ return countryItem;
32
+ });
33
+ // Formatting phone numbers according to country
34
+ const formatNumber = (fullPhoneNumber, localFormat) => {
35
+ if (isEmpty(fullPhoneNumber))
36
+ return '';
37
+ let localPhone = fullPhoneNumber.replace(PREFIX, '');
38
+ if (isEmpty(localPhone))
39
+ return '';
40
+ // Formatting inputted number
41
+ let phone = '';
42
+ [...fullPhoneNumber].forEach((ele) => {
43
+ if (ele >= '0' && ele <= '9') {
44
+ phone = phone.concat(ele);
45
+ }
46
+ });
47
+ let pattern = '';
48
+ let i = 0;
49
+ for (let j = 0; j < (localFormat === null || localFormat === void 0 ? void 0 : localFormat.length) && i < phone.length; j++) {
50
+ if (localFormat[j] === '.') {
51
+ pattern += phone[i];
52
+ i++;
53
+ }
54
+ else {
55
+ pattern += localFormat[j];
56
+ }
57
+ }
58
+ return pattern;
59
+ };
60
+ // return phoneline and countrycode for any given phone
61
+ export const getPhoneObj = (phoneNumber) => {
62
+ let localPhone = phoneNumber.replace(/[^0-9]/g, '');
63
+ let countryCode = '';
64
+ // Guessing countries according to user input
65
+ const possibleCountries = initializedCountries.filter((country) => localPhone === null || localPhone === void 0 ? void 0 : localPhone.startsWith(country.dialCode.toString()));
66
+ const exactCountry = initializedCountries.filter((country) => country.dialCode.toString() === localPhone);
67
+ if (!isEmpty(exactCountry)) {
68
+ countryCode = exactCountry[0].dialCode.toString();
69
+ }
70
+ else if (!isEmpty(possibleCountries)) {
71
+ countryCode = possibleCountries[0].dialCode.toString();
72
+ }
73
+ return {
74
+ countryCode: PREFIX + countryCode,
75
+ phoneLine: localPhone.substring(countryCode.length, localPhone.length),
76
+ };
77
+ };
78
+ export function PhoneInput(props) {
79
+ const { phoneValue, countryCode, onCountryCodeChange, onPhoneValueChange, validations, setInvalid } = props;
80
+ const { t } = useTranslation();
81
+ const [isOpen, setIsOpen] = useState(false);
82
+ const [iso2, setIso2] = useState('');
83
+ const [formattedNumber, setFormattedNumber] = useState('');
84
+ const [format, setFormat] = useState('');
85
+ const [countryObj, setCountryObj] = useState({
86
+ name: '',
87
+ regions: [''],
88
+ iso2: '',
89
+ countryCode: '',
90
+ dialCode: '',
91
+ format: '',
92
+ priority: 0,
93
+ areaCode: [''], // Area codes of a country
94
+ });
95
+ const setLocalFormat = (phoneNumber) => {
96
+ let localPhone = phoneNumber.replace(PREFIX, '').trim();
97
+ localPhone = localPhone.replace('(', '').trim();
98
+ localPhone = localPhone.replace(/ +/g, '');
99
+ // if the user selects a value from the dropdown and the country code is the same as prev, iso2 values shouldn't override
100
+ if (!isEmpty(countryObj) && isEqual(localPhone, countryObj.dialCode)) {
101
+ return countryObj.format;
102
+ }
103
+ let localFormat;
104
+ // Guessing countries according to user input
105
+ const possibleCountries = initializedCountries.filter((country) => localPhone === null || localPhone === void 0 ? void 0 : localPhone.startsWith(country.dialCode.toString()));
106
+ const canadaDialCode = '1';
107
+ const canadaCountryPhone = canadaAreaCodes.map((areaCode) => canadaDialCode + areaCode);
108
+ const isCountryCanada = canadaCountryPhone.filter((phone) => localPhone.startsWith(phone)); // checks if phone is Canadian
109
+ const exactCountry = initializedCountries.filter((country) => country.dialCode.toString() === localPhone);
110
+ if (!isEmpty(isCountryCanada)) {
111
+ const canadaCountryObj = initializedCountries.filter((country) => country.iso2.toString() === 'ca');
112
+ setIso2(canadaCountryObj[0].iso2.toString());
113
+ localFormat = canadaCountryObj[0].format.toString();
114
+ onCountryCodeChange && onCountryCodeChange(PREFIX + canadaCountryObj[0].dialCode.toString());
115
+ setFormat(localFormat);
116
+ }
117
+ else if (!isEmpty(exactCountry)) {
118
+ const localExactCountry = exactCountry.filter((country) => isEqual(country.priority, 0));
119
+ if (isEqual(localExactCountry[0].dialCode.toString(), countryObj.dialCode)) {
120
+ setIso2(countryObj.iso2);
121
+ onCountryCodeChange && onCountryCodeChange(PREFIX + countryObj.countryCode);
122
+ return countryObj.format;
123
+ }
124
+ setIso2(localExactCountry[0].iso2.toString());
125
+ localFormat = localExactCountry[0].format.toString();
126
+ onCountryCodeChange && onCountryCodeChange(PREFIX + localExactCountry[0].dialCode.toString());
127
+ setFormat(localFormat);
128
+ }
129
+ else if (!isEmpty(possibleCountries)) {
130
+ const localPossibleCountry = possibleCountries.filter((country) => isEqual(country.priority, 0));
131
+ if (isEqual(localPossibleCountry[0].dialCode.toString(), countryObj.dialCode)) {
132
+ setIso2(countryObj.iso2);
133
+ onCountryCodeChange && onCountryCodeChange(PREFIX + countryObj.countryCode);
134
+ return countryObj.format;
135
+ }
136
+ setIso2(localPossibleCountry[0].iso2.toString());
137
+ localFormat = localPossibleCountry[0].format.toString();
138
+ onCountryCodeChange && onCountryCodeChange(PREFIX + localPossibleCountry[0].dialCode.toString());
139
+ setFormat(localFormat);
140
+ }
141
+ else {
142
+ // if the exact and possible are not the
143
+ setIso2('');
144
+ localFormat = format;
145
+ onCountryCodeChange && onCountryCodeChange('');
146
+ }
147
+ return localFormat;
148
+ };
149
+ const onPhoneChange = (phone) => {
150
+ if (isEmpty(phone.trim()) || isEmpty(phone.replace(PREFIX, '').trim())) {
151
+ setFormattedNumber('');
152
+ onPhoneValueChange('');
153
+ setInvalid && setInvalid(false);
154
+ }
155
+ const regex = /^[\d ()+-]+$/;
156
+ if (setInvalid)
157
+ regex.test(phone) ? setInvalid(false) : setInvalid(true);
158
+ const localFormat = setLocalFormat(phone);
159
+ const _formattedNumber = formatNumber(phone, localFormat);
160
+ setFormattedNumber(_formattedNumber);
161
+ if (!phone.trim().startsWith(PREFIX) && regex.test(phone) && !isEqual(phone, '-')) {
162
+ onPhoneValueChange(PREFIX + phone.trim());
163
+ }
164
+ else {
165
+ // to allow users to edit phone from between but not from right end, 5 is max length of any country code used when local format is empty
166
+ onPhoneValueChange(phone.slice(0, localFormat.length || 5));
167
+ }
168
+ };
169
+ const onToggle = (isOpen) => {
170
+ setIsOpen(isOpen);
171
+ };
172
+ const onCountrySelect = (event, selection) => {
173
+ setCountryObj(selection);
174
+ setIsOpen(!isOpen);
175
+ };
176
+ const getOptions = (options) => {
177
+ return options.map((country) => (React.createElement(SelectOption, { key: country.iso2, value: country },
178
+ React.createElement("div", { className: "pf-u-display-inline-flex" },
179
+ React.createElement("div", { className: `flag ${country.iso2}`, style: { marginRight: '8px' } }),
180
+ country.name,
181
+ " (+",
182
+ country.dialCode,
183
+ ")"))));
184
+ };
185
+ const onFilter = (_, value) => {
186
+ if (!value)
187
+ return getOptions(initializedCountries);
188
+ const newOptions = initializedCountries.filter((country) => {
189
+ const countryStr = `${country.name.toString()} (+${country.countryCode.toString()})`.toLowerCase();
190
+ return countryStr.includes(value.toLowerCase());
191
+ });
192
+ return getOptions(newOptions);
193
+ };
194
+ const placeholder = (React.createElement("div", { className: "phone-number-select-placeholder" },
195
+ React.createElement("div", { className: "pf-u-display-inline-flex" },
196
+ React.createElement("div", { className: `flag ${iso2}`, style: { marginRight: '5px' } }),
197
+ iso2.toUpperCase())));
198
+ useEffect(() => {
199
+ if (isEmpty(phoneValue)) {
200
+ setInvalid && setInvalid(false);
201
+ return;
202
+ }
203
+ if (isEmpty(iso2)) {
204
+ const localFormat = setLocalFormat(phoneValue);
205
+ const _formattedNumber = formatNumber(phoneValue, localFormat);
206
+ setFormattedNumber(_formattedNumber);
207
+ }
208
+ // eslint-disable-next-line react-hooks/exhaustive-deps
209
+ }, []);
210
+ useEffect(() => {
211
+ if (!isEmpty(countryObj.iso2) && `${PREFIX}${countryObj.dialCode}` !== countryCode) {
212
+ setIso2(countryObj.iso2);
213
+ setFormat(countryObj.format);
214
+ onPhoneValueChange(`${PREFIX}${countryObj.dialCode}`);
215
+ setFormattedNumber(`${PREFIX}${countryObj.dialCode}`);
216
+ }
217
+ // eslint-disable-next-line react-hooks/exhaustive-deps
218
+ }, [countryObj]);
219
+ useEffect(() => {
220
+ // when user types +, it will be replaced by empty string
221
+ if (isEqual(phoneValue.trim(), PREFIX) && isEmpty(iso2)) {
222
+ onPhoneValueChange('');
223
+ setFormattedNumber('');
224
+ return;
225
+ }
226
+ if (isEmpty(phoneValue) && isEmpty(iso2)) {
227
+ setCountryObj({
228
+ name: '',
229
+ regions: [''],
230
+ iso2: '',
231
+ countryCode: '',
232
+ dialCode: '',
233
+ format: '',
234
+ priority: 0,
235
+ areaCode: [''],
236
+ });
237
+ }
238
+ if (isEmpty(phoneValue)) {
239
+ setIso2('');
240
+ setInvalid && setInvalid(false);
241
+ setFormattedNumber('');
242
+ onPhoneValueChange('');
243
+ }
244
+ else {
245
+ onPhoneValueChange(phoneValue);
246
+ const localFormat = setLocalFormat(phoneValue);
247
+ const _formattedNumber = formatNumber(phoneValue, localFormat);
248
+ setFormattedNumber(_formattedNumber);
249
+ }
250
+ // eslint-disable-next-line react-hooks/exhaustive-deps
251
+ }, [phoneValue]);
252
+ return (React.createElement(InputGroup, { className: "phone-number-input" },
253
+ React.createElement("div", null,
254
+ React.createElement(Select, { variant: SelectVariant.single, "data-tracking-id": "case-phone-number-country-code", className: "phone-number-select", onToggle: onToggle, onSelect: onCountrySelect, isOpen: isOpen, placeholderText: iso2 && phoneValue !== '' ? placeholder : 'Country Code', onFilter: onFilter, hasInlineFilter: true, inlineFilterPlaceholderText: t('Search'), isDisabled: props.isDisabled }, getOptions(initializedCountries))),
255
+ React.createElement(TextInput, { id: "case-phone-number", "data-tracking-id": "case-phone-number", placeholder: "55-555-5555", value: formattedNumber ? formattedNumber : phoneValue, onChange: onPhoneChange, validated: validations, isDisabled: props.isDisabled }),
256
+ props.isLoading && React.createElement(Spinner, { isSVG: true, size: "lg", className: "pf-u-ml-2xl pf-u-mr-xl phone-spinner" })));
257
+ }