dhre-ui-kit 0.0.232 → 0.0.234
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.d.ts +1 -0
- package/lib/index.js +38 -9
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +38 -9
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
package/lib/index.mjs
CHANGED
|
@@ -3988,11 +3988,14 @@ const OTPInput = React.forwardRef(
|
|
|
3988
3988
|
resendOtpColor,
|
|
3989
3989
|
label = "OTP",
|
|
3990
3990
|
resendText = "Resend OTP",
|
|
3991
|
-
mode
|
|
3991
|
+
mode,
|
|
3992
|
+
disabled
|
|
3992
3993
|
}, ref) => {
|
|
3993
3994
|
const [otp, setOTP] = useState("");
|
|
3994
3995
|
const [isResendOtpEnable, setIsResendOtpEnable] = useState(false);
|
|
3995
3996
|
const [activeInput, setActiveInput] = useState(null);
|
|
3997
|
+
const [resendOTPCount, setResendOTPCount] = useState(0);
|
|
3998
|
+
const [errorMessageMaxReachCount, setErrorMessageMaxReachCount] = useState("");
|
|
3996
3999
|
const filteredTheme = Object?.keys(theme)?.reduce(
|
|
3997
4000
|
(acc, key) => {
|
|
3998
4001
|
acc[key] = theme[key][mode];
|
|
@@ -4007,16 +4010,32 @@ const OTPInput = React.forwardRef(
|
|
|
4007
4010
|
enableResendOtp();
|
|
4008
4011
|
}, []);
|
|
4009
4012
|
const onClickResendOTP = () => {
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4013
|
+
if (resendOTPCount >= 3) {
|
|
4014
|
+
setErrorMessageMaxReachCount("You have exceeded the maximum number of attempts.");
|
|
4015
|
+
return;
|
|
4016
|
+
}
|
|
4017
|
+
if (resendOTPCount < 3) {
|
|
4018
|
+
setIsResendOtpEnable(false);
|
|
4019
|
+
setResendOTPCount(resendOTPCount + 1);
|
|
4020
|
+
enableResendOtp();
|
|
4021
|
+
resendOTP?.();
|
|
4022
|
+
setOTP("");
|
|
4023
|
+
}
|
|
4014
4024
|
};
|
|
4015
4025
|
const enableResendOtp = () => {
|
|
4016
4026
|
setTimeout(() => {
|
|
4017
4027
|
setIsResendOtpEnable(true);
|
|
4018
4028
|
}, 5e3);
|
|
4019
4029
|
};
|
|
4030
|
+
const disableResendButton = () => {
|
|
4031
|
+
if (disabled === true && resendOTPCount >= 3) {
|
|
4032
|
+
setIsResendOtpEnable(true);
|
|
4033
|
+
return true;
|
|
4034
|
+
} else {
|
|
4035
|
+
setIsResendOtpEnable(false);
|
|
4036
|
+
return false;
|
|
4037
|
+
}
|
|
4038
|
+
};
|
|
4020
4039
|
useEffect(() => {
|
|
4021
4040
|
if (Platform.OS === "android") {
|
|
4022
4041
|
onStartListeningOtp();
|
|
@@ -4096,7 +4115,7 @@ const OTPInput = React.forwardRef(
|
|
|
4096
4115
|
style: {
|
|
4097
4116
|
...styles$5.textInputStyle,
|
|
4098
4117
|
color: theme$1.CONTENT_PRIMARY,
|
|
4099
|
-
borderColor: errorMessage ? theme$1.ERROR : otp.length === length ? theme$1.SUCCESS : activeInput === index ? theme$1.BORDER_INVERTED : theme$1.BORDER_PRIMARY,
|
|
4118
|
+
borderColor: errorMessage || errorMessageMaxReachCount ? theme$1.ERROR : otp.length === length ? theme$1.SUCCESS : activeInput === index ? theme$1.BORDER_INVERTED : theme$1.BORDER_PRIMARY,
|
|
4100
4119
|
...textInputStyle
|
|
4101
4120
|
},
|
|
4102
4121
|
onFocus: () => setActiveInput(index),
|
|
@@ -4118,7 +4137,7 @@ const OTPInput = React.forwardRef(
|
|
|
4118
4137
|
{
|
|
4119
4138
|
onPress: onClickResendOTP,
|
|
4120
4139
|
style: styles$5.resendOTPStyle,
|
|
4121
|
-
disabled: !isResendOtpEnable
|
|
4140
|
+
disabled: disableResendButton() || !isResendOtpEnable
|
|
4122
4141
|
},
|
|
4123
4142
|
/* @__PURE__ */ React.createElement(
|
|
4124
4143
|
CustomTypography,
|
|
@@ -4132,7 +4151,7 @@ const OTPInput = React.forwardRef(
|
|
|
4132
4151
|
}
|
|
4133
4152
|
}
|
|
4134
4153
|
)
|
|
4135
|
-
), /* @__PURE__ */ React.createElement(View, { style: styles$5.resendOtpContainer },
|
|
4154
|
+
), errorMessage ? /* @__PURE__ */ React.createElement(View, { style: styles$5.resendOtpContainer }, /* @__PURE__ */ React.createElement(
|
|
4136
4155
|
CustomTypography,
|
|
4137
4156
|
{
|
|
4138
4157
|
text: errorMessage,
|
|
@@ -4142,7 +4161,17 @@ const OTPInput = React.forwardRef(
|
|
|
4142
4161
|
color: theme$1.ERROR
|
|
4143
4162
|
}
|
|
4144
4163
|
}
|
|
4145
|
-
) : /* @__PURE__ */ React.createElement(View,
|
|
4164
|
+
)) : null, errorMessageMaxReachCount ? /* @__PURE__ */ React.createElement(View, { style: styles$5.resendOtpContainer }, /* @__PURE__ */ React.createElement(
|
|
4165
|
+
CustomTypography,
|
|
4166
|
+
{
|
|
4167
|
+
text: errorMessageMaxReachCount,
|
|
4168
|
+
variant: FontStyle.L2_REGULAR,
|
|
4169
|
+
style: {
|
|
4170
|
+
alignSelf: "flex-start",
|
|
4171
|
+
color: theme$1.ERROR
|
|
4172
|
+
}
|
|
4173
|
+
}
|
|
4174
|
+
)) : null);
|
|
4146
4175
|
}
|
|
4147
4176
|
);
|
|
4148
4177
|
var index$4 = withThemeProvider(OTPInput);
|