ui-soxo-bootstrap-core 2.4.25-dev.47 → 2.4.25-dev.48

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.
@@ -6,79 +6,48 @@
6
6
  * Ensure to follow a minimal standard
7
7
  */
8
8
  import React, { useState, useEffect, useRef } from 'react';
9
-
10
9
  import PhoneInput from 'react-phone-input-2';
11
-
12
10
  import 'react-phone-input-2/lib/style.css';
13
-
14
- import PropTypes from "prop-types";
15
-
11
+ import PropTypes from 'prop-types';
16
12
  import './phone-input.scss';
17
13
 
14
+ export default function CountryPhoneInput({ value, onChange, disabled, disableCountryCode, required, defaultCountryCode, onBlur,className }) {
15
+ const inputRef = useRef();
16
+ const hasInitializedRef = useRef(false); // IMPORTANT
18
17
 
19
- export default function CountryPhoneInput({ value, onChange, disabled, disableCountryCode, required, defaultCountryCode, onBlur }) {
20
-
21
- let inputRef = useRef();
22
-
23
- const [phone, setPhone] = useState();
18
+ const [phone, setPhone] = useState('');
24
19
 
20
+ /**
21
+ * run ONLY ONCE when initial value has dial code
22
+ */
25
23
  useEffect(() => {
26
- if (value && value.code && value.code.dialCode !== null) {
27
- // To prepopulate phone number ,concat dialCode and phone number
24
+ if (
25
+ !hasInitializedRef.current &&
26
+ value?.code?.dialCode &&
27
+ value?.value
28
+ ) {
28
29
  setPhone(value.code.dialCode + value.value);
29
-
30
- // In case of update , to identify the country code that is getting selected
31
- // We are setting a timeout
32
- setTimeout(() => {
33
- // Using the reference , we get the internal state of the library component
34
- let selectedCountry = null;
35
-
36
- let selectedCode = null;
37
-
38
- if (
39
- inputRef.current &&
40
- inputRef.current.state &&
41
- inputRef.current.state.selectedCountry
42
- ) {
43
- selectedCountry = inputRef.current.state.selectedCountry;
44
-
45
- // Once we get the selected country ,we format it to the form that is received for normal onChange
46
- selectedCode = {
47
- countryCode: selectedCountry.iso2,
48
- dialCode: selectedCountry.dialCode,
49
- name: selectedCountry.name,
50
- };
51
- }
52
-
53
- // Below being the format expected , we trigger the onChange to manually update the form
54
- let updatedValue = {
55
- value: value.code.dialCode + value.value,
56
- code: selectedCode,
57
- };
58
-
59
- onChange(updatedValue);
60
- }, 0);
30
+ hasInitializedRef.current = true; // 👈 mark as done
61
31
  }
62
- }, []);
32
+ }, [value]);
63
33
 
64
34
  /**
65
- * To get value in parent component
66
- * @param {*} value
35
+ * handle user input
67
36
  */
68
- function handleInput(value, code) {
69
- if (code.dialCode) {
70
- value = value.substring(code.dialCode.length);
71
- }
72
- // To get country code with phone number in parent component
73
- value = {
74
- value,
37
+ function handleInput(inputValue, code) {
38
+ if (!code?.dialCode) return;
39
+
40
+ const phoneNumber = inputValue.slice(code.dialCode.length);
41
+
42
+ // remove autofill class when user edits field (if you use it)
43
+ onChange({
44
+ value: phoneNumber,
75
45
  code,
76
- };
77
- onChange(value);
46
+ });
78
47
  }
79
48
 
80
49
  return (
81
- <div className="phone-input">
50
+ <div className={`phone-input ${className || ''}`}>
82
51
  <PhoneInput
83
52
  ref={inputRef}
84
53
  country={defaultCountryCode || 'in'}
@@ -12,6 +12,20 @@
12
12
  // }
13
13
  }
14
14
 
15
+ .autofilled-field {
16
+ .react-tel-input {
17
+ .form-control {
18
+ border-color: #fa8c16 !important; // AntD warning orange
19
+ background-color: #fff7e6;
20
+ box-shadow: none;
21
+ }
22
+
23
+ .flag-dropdown {
24
+ border-color: #fa8c16 !important;
25
+ background-color: #fff7e6;
26
+ }
27
+ }
28
+ }
15
29
  // /* For tablets and smaller screens (max-width: 1024px) */
16
30
  // @media (max-width: 1024px) {
17
31
  // .phone-input {
@@ -241,39 +241,7 @@ export default function ProcessStepsPage({ match, CustomComponents = {}, ...prop
241
241
 
242
242
  return <Component {...step.config} {...props} step={step} params={urlParams} onStepComplete={() => setIsStepCompleted(true)} />;
243
243
  };
244
- /**
245
- * Keyboard Navigation
246
- * - Enables left and right arrow keys for step navigation.
247
- * - Prevents navigation beyond step boundaries.
248
- * - Cleans up event listeners on unmount.
249
- */
250
- // useEffect(() => {
251
- // const handleKeyDown = (event) => {
252
- // // Handle Left Arrow key press to go to the previous step
253
- // if (event.key === 'ArrowLeft') {
254
- // if (activeStep > 0) {
255
- // handlePrevious();
256
- // }
257
- // }
258
- // // Handle Right Arrow key press to go to the next step
259
- // else if (event.key === 'ArrowRight') {
260
- // if (activeStep < steps.length - 1) {
261
- // handleNext();
262
- // }
263
- // }
264
- // };
265
-
266
- // // externalWin?.addEventListener('keydown', handleKeyDown);
267
- // if (externalWin instanceof Window) {
268
- // console.log("********************************",externalWin.addEventListener)
269
- // externalWin.addEventListener('keydown', handleKeyDown);
270
- // }
271
244
 
272
- // // showExternalWindow.addEventListener('keydown', handleKeyDown);
273
- // console.log("LLLLLLLLLLLLLL",window.addEventListener)
274
- // window.addEventListener('keydown', handleKeyDown);
275
- // return () => window.removeEventListener('keydown', handleKeyDown);
276
- // }, [activeStep, steps, handlePrevious, handleNext, externalWin]);
277
245
  useEffect(() => {
278
246
  const handleKeyDown = (event) => {
279
247
  if (event.key === 'ArrowLeft' && activeStep > 0) {
@@ -355,7 +323,6 @@ export default function ProcessStepsPage({ match, CustomComponents = {}, ...prop
355
323
  <>
356
324
  <ExternalWindow
357
325
  onWindowReady={(win) => {
358
- console.log('>>>>>>>>>>>>>>>>>>>>>', win.addEventListener);
359
326
  setExternalWin(win);
360
327
  win.focus();
361
328
  }}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ui-soxo-bootstrap-core",
3
- "version": "2.4.25-dev.47",
3
+ "version": "2.4.25-dev.48",
4
4
  "description": "All the Core Components for you to start",
5
5
  "keywords": [
6
6
  "all in one"