dhre-ui-kit 0.0.252 → 0.0.254

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/index.mjs CHANGED
@@ -3995,7 +3995,7 @@ const OTPInput = React.forwardRef(
3995
3995
  }
3996
3996
  return () => clearInterval(timer);
3997
3997
  }, [timeLeft, isResendOtpEnable]);
3998
- const refs = useRef(Array(length).fill(null));
3998
+ const otpRefs = useRef(Array(length).fill(null));
3999
3999
  useEffect(() => {
4000
4000
  enableResendOtp();
4001
4001
  }, []);
@@ -4014,11 +4014,7 @@ const OTPInput = React.forwardRef(
4014
4014
  }
4015
4015
  };
4016
4016
  const disableResendButton = () => {
4017
- if (disabled === true && resendOTPCount >= maxResendCount) {
4018
- return true;
4019
- } else {
4020
- return false;
4021
- }
4017
+ return disabled || resendOTPCount >= maxResendCount;
4022
4018
  };
4023
4019
  const enableResendOtp = () => {
4024
4020
  setTimeout(() => {
@@ -4044,39 +4040,41 @@ const OTPInput = React.forwardRef(
4044
4040
  const otp2 = otpRegex.exec(message)?.[1];
4045
4041
  setOTP(otp2 ?? "");
4046
4042
  if (otp2) {
4047
- refs.current[otp2?.length - 1]?.focus();
4043
+ otpRefs.current[otp2?.length - 1]?.focus();
4048
4044
  }
4049
4045
  });
4050
4046
  };
4051
4047
  const reset = () => {
4052
4048
  setOTP("");
4053
- refs?.current?.[0]?.focus();
4049
+ otpRefs.current[0]?.focus();
4054
4050
  };
4055
- React.useImperativeHandle(ref, () => ({
4056
- reset
4057
- }));
4051
+ useEffect(() => {
4052
+ React.useImperativeHandle(ref, () => ({
4053
+ reset
4054
+ }));
4055
+ }, []);
4058
4056
  const handleChange = (index, value) => {
4059
4057
  const regex = /^\d+$/;
4060
4058
  if (value.length === 1 && regex.test(value) && index >= 0 && index < length) {
4061
4059
  const newOTP = `${otp}${value}`;
4062
4060
  setOTP(newOTP);
4063
- refs.current[index + 1]?.focus();
4061
+ otpRefs.current[index + 1]?.focus();
4064
4062
  } else if (value.length === 0 && index > 0) {
4065
4063
  const newOTP = otp.slice(0, -1);
4066
4064
  setOTP(newOTP);
4067
- refs.current[index - 1]?.focus();
4065
+ otpRefs.current[index - 1]?.focus();
4068
4066
  } else if (value?.length === length) {
4069
4067
  setOTP(value);
4070
- refs.current[length - 1]?.focus();
4068
+ otpRefs.current[length - 1]?.focus();
4071
4069
  } else {
4072
4070
  const newOTP = otp.slice(0, -1);
4073
4071
  setOTP(newOTP);
4074
- refs.current[index]?.focus();
4072
+ otpRefs.current[index]?.focus();
4075
4073
  }
4076
4074
  };
4077
4075
  const handleKeyPress = (e, index) => {
4078
4076
  if (e.nativeEvent.key === "Backspace" && index > 0) {
4079
- refs.current[index - 1]?.focus();
4077
+ otpRefs.current[index - 1]?.focus();
4080
4078
  }
4081
4079
  };
4082
4080
  useEffect(() => {
@@ -4112,7 +4110,7 @@ const OTPInput = React.forwardRef(
4112
4110
  value: otp[index] ? "\u25CF" : "",
4113
4111
  placeholder: "",
4114
4112
  keyboardType: "numeric",
4115
- ref: (el) => refs.current[index] = el,
4113
+ ref: (el) => otpRefs.current[index] = el,
4116
4114
  returnKeyType: otp.length === length ? "done" : "next",
4117
4115
  importantForAutofill: "yes",
4118
4116
  textContentType: "oneTimeCode",