dhre-ui-kit 0.0.258 → 0.0.259

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
@@ -3950,214 +3950,221 @@ const styles$5 = StyleSheet.create({
3950
3950
  }
3951
3951
  });
3952
3952
 
3953
- const OTPInputComponent = ({
3954
- length = 4,
3955
- onComplete,
3956
- resendOTP,
3957
- errorMessage,
3958
- testId = "",
3959
- otpContainerStyle,
3960
- otpHeaderTextStyle,
3961
- textInputStyle,
3962
- resendTextStyle,
3963
- resendOtpColor,
3964
- label = "OTP",
3965
- resendText = "Resend OTP",
3966
- mode,
3967
- disabled,
3968
- maxResendCount = 2,
3969
- timerToResend = 6e4,
3970
- timerIcon
3971
- }, ref) => {
3972
- const [otp, setOTP] = useState("");
3973
- const [isResendOtpEnable, setIsResendOtpEnable] = useState(false);
3974
- const [activeInput, setActiveInput] = useState(null);
3975
- const [resendOTPCount, setResendOTPCount] = useState(0);
3976
- const [errorMessageMaxReachCount, setErrorMessageMaxReachCount] = useState("");
3977
- const filteredTheme = mode ? theme[mode] : theme;
3978
- const { theme: theme$1 } = useTheme() || { theme: filteredTheme };
3979
- const [timeLeft, setTimeLeft] = useState(60);
3980
- useEffect(() => {
3981
- let timer;
3982
- if (!isResendOtpEnable && timeLeft > 0) {
3983
- timer = setInterval(() => {
3984
- setTimeLeft((prevTime) => prevTime - 1);
3985
- }, 1e3);
3986
- } else if (timeLeft === 0) {
3987
- clearInterval(timer);
3988
- }
3989
- return () => clearInterval(timer);
3990
- }, [timeLeft, isResendOtpEnable]);
3991
- const otpRefs = useRef(Array(length).fill(null));
3992
- useEffect(() => {
3993
- enableResendOtp();
3994
- }, []);
3995
- const onClickResendOTP = () => {
3996
- if (resendOTPCount > maxResendCount - 1) {
3997
- setErrorMessageMaxReachCount(
3998
- "You have exceeded the maximum number of attempts."
3999
- );
4000
- }
4001
- if (resendOTPCount < maxResendCount) {
4002
- setIsResendOtpEnable(false);
4003
- setResendOTPCount(resendOTPCount + 1);
3953
+ const OTPInput = React.forwardRef(
3954
+ ({
3955
+ length = 4,
3956
+ onComplete,
3957
+ resendOTP,
3958
+ errorMessage,
3959
+ testId = "",
3960
+ otpContainerStyle,
3961
+ otpHeaderTextStyle,
3962
+ textInputStyle,
3963
+ resendTextStyle,
3964
+ resendOtpColor,
3965
+ label = "OTP",
3966
+ resendText = "Resend OTP",
3967
+ mode,
3968
+ disabled,
3969
+ maxResendCount = 2,
3970
+ timerToResend = 6e4,
3971
+ timerIcon
3972
+ }, ref) => {
3973
+ const [otp, setOTP] = useState("");
3974
+ const [isResendOtpEnable, setIsResendOtpEnable] = useState(false);
3975
+ const [activeInput, setActiveInput] = useState(null);
3976
+ const [resendOTPCount, setResendOTPCount] = useState(0);
3977
+ const [errorMessageMaxReachCount, setErrorMessageMaxReachCount] = useState("");
3978
+ const filteredTheme = Object?.keys(theme)?.reduce(
3979
+ (acc, key) => {
3980
+ acc[key] = theme[key][mode];
3981
+ return acc;
3982
+ },
3983
+ {}
3984
+ );
3985
+ const { theme: theme$1 } = mode ? { theme: filteredTheme } : useTheme();
3986
+ const [timeLeft, setTimeLeft] = useState(60);
3987
+ useEffect(() => {
3988
+ let timer;
3989
+ if (!isResendOtpEnable && timeLeft > 0) {
3990
+ timer = setInterval(() => {
3991
+ setTimeLeft((prevTime) => prevTime - 1);
3992
+ }, 1e3);
3993
+ } else if (timeLeft === 0) {
3994
+ clearInterval(timer);
3995
+ }
3996
+ return () => clearInterval(timer);
3997
+ }, [timeLeft, isResendOtpEnable]);
3998
+ const otpRefs = useRef(Array(length).fill(null));
3999
+ useEffect(() => {
4004
4000
  enableResendOtp();
4005
- resendOTP?.();
4006
- setOTP("");
4007
- }
4008
- };
4009
- const disableResendButton = () => {
4010
- return disabled || resendOTPCount >= maxResendCount;
4011
- };
4012
- const enableResendOtp = () => {
4013
- setTimeout(() => {
4014
- setIsResendOtpEnable(true);
4015
- setTimeLeft(timerToResend / 1e3);
4016
- }, timerToResend);
4017
- };
4018
- useEffect(() => {
4019
- if (Platform.OS === "android") {
4020
- onStartListeningOtp();
4021
- }
4022
- return () => {
4001
+ }, []);
4002
+ const onClickResendOTP = () => {
4003
+ if (resendOTPCount > maxResendCount - 1) {
4004
+ setErrorMessageMaxReachCount(
4005
+ "You have exceeded the maximum number of attempts."
4006
+ );
4007
+ }
4008
+ if (resendOTPCount < maxResendCount) {
4009
+ setIsResendOtpEnable(false);
4010
+ setResendOTPCount(resendOTPCount + 1);
4011
+ enableResendOtp();
4012
+ resendOTP?.();
4013
+ setOTP("");
4014
+ }
4015
+ };
4016
+ const disableResendButton = () => {
4017
+ return disabled || resendOTPCount >= maxResendCount;
4018
+ };
4019
+ const enableResendOtp = () => {
4020
+ setTimeout(() => {
4021
+ setIsResendOtpEnable(true);
4022
+ setTimeLeft(timerToResend / 1e3);
4023
+ }, timerToResend);
4024
+ };
4025
+ useEffect(() => {
4023
4026
  if (Platform.OS === "android") {
4024
- OTPVerify.removeListener();
4025
- removeListener();
4027
+ onStartListeningOtp();
4026
4028
  }
4029
+ return () => {
4030
+ if (Platform.OS === "android") {
4031
+ OTPVerify.removeListener();
4032
+ removeListener();
4033
+ }
4034
+ };
4035
+ }, []);
4036
+ const onStartListeningOtp = async () => {
4037
+ await OTPVerify.getOtp();
4038
+ startOtpListener((message) => {
4039
+ const otpRegex = new RegExp(`(\\d{${length}})`, "g");
4040
+ const otp2 = otpRegex.exec(message)?.[1];
4041
+ setOTP(otp2 ?? "");
4042
+ if (otp2) {
4043
+ otpRefs.current[otp2?.length - 1]?.focus();
4044
+ }
4045
+ });
4027
4046
  };
4028
- }, []);
4029
- const onStartListeningOtp = async () => {
4030
- await OTPVerify.getOtp();
4031
- startOtpListener((message) => {
4032
- const otpRegex = new RegExp(`(\\d{${length}})`, "g");
4033
- const otp2 = otpRegex.exec(message)?.[1];
4034
- setOTP(otp2 ?? "");
4035
- if (otp2) {
4036
- otpRefs.current[otp2?.length - 1]?.focus();
4047
+ const reset = () => {
4048
+ setOTP("");
4049
+ otpRefs.current[0]?.focus();
4050
+ };
4051
+ React.useImperativeHandle(ref, () => ({
4052
+ reset
4053
+ }));
4054
+ const handleChange = (index, value) => {
4055
+ const regex = /^\d+$/;
4056
+ if (value.length === 1 && regex.test(value) && index >= 0 && index < length) {
4057
+ const newOTP = `${otp}${value}`;
4058
+ setOTP(newOTP);
4059
+ otpRefs.current[index + 1]?.focus();
4060
+ } else if (value.length === 0 && index > 0) {
4061
+ const newOTP = otp.slice(0, -1);
4062
+ setOTP(newOTP);
4063
+ otpRefs.current[index - 1]?.focus();
4064
+ } else if (value?.length === length) {
4065
+ setOTP(value);
4066
+ otpRefs.current[length - 1]?.focus();
4067
+ } else {
4068
+ const newOTP = otp.slice(0, -1);
4069
+ setOTP(newOTP);
4070
+ otpRefs.current[index]?.focus();
4037
4071
  }
4038
- });
4039
- };
4040
- const reset = () => {
4041
- setOTP("");
4042
- otpRefs.current[0]?.focus();
4043
- };
4044
- React.useImperativeHandle(ref, () => ({
4045
- reset
4046
- }));
4047
- const handleChange = (index, value) => {
4048
- const regex = /^\d+$/;
4049
- if (value.length === 1 && regex.test(value) && index >= 0 && index < length) {
4050
- const newOTP = `${otp}${value}`;
4051
- setOTP(newOTP);
4052
- otpRefs.current[index + 1]?.focus();
4053
- } else if (value.length === 0 && index > 0) {
4054
- const newOTP = otp.slice(0, -1);
4055
- setOTP(newOTP);
4056
- otpRefs.current[index - 1]?.focus();
4057
- } else if (value?.length === length) {
4058
- setOTP(value);
4059
- otpRefs.current[length - 1]?.focus();
4060
- } else {
4061
- const newOTP = otp.slice(0, -1);
4062
- setOTP(newOTP);
4063
- otpRefs.current[index]?.focus();
4064
- }
4065
- };
4066
- const handleKeyPress = (e, index) => {
4067
- if (e.nativeEvent.key === "Backspace" && index > 0) {
4068
- otpRefs.current[index - 1]?.focus();
4069
- }
4070
- };
4071
- useEffect(() => {
4072
- if (otp.length === length) {
4073
- onComplete?.(otp);
4074
- }
4075
- }, [otp]);
4076
- return /* @__PURE__ */ React.createElement(View, { style: { ...otpContainerStyle }, "data-testid": testId }, /* @__PURE__ */ React.createElement(
4077
- CustomTypography,
4078
- {
4079
- text: label,
4080
- variant: FontStyle.B4_REGULAR,
4081
- style: {
4082
- color: otp?.length ? theme$1.CONTENT_PRIMARY : theme$1.CONTENT_SECONDRY,
4083
- textAlign: "left",
4084
- ...otpHeaderTextStyle
4072
+ };
4073
+ const handleKeyPress = (e, index) => {
4074
+ if (e.nativeEvent.key === "Backspace" && index > 0) {
4075
+ otpRefs.current[index - 1]?.focus();
4085
4076
  }
4086
- }
4087
- ), /* @__PURE__ */ React.createElement(View, { style: { ...styles$5.textInputContainer } }, Array.from({ length }).map((_, index) => /* @__PURE__ */ React.createElement(
4088
- TextInput,
4089
- {
4090
- key: index?.toString(),
4091
- style: {
4092
- ...styles$5.textInputStyle,
4093
- color: theme$1.CONTENT_PRIMARY,
4094
- borderColor: errorMessage ? theme$1.ERROR : otp.length === length ? theme$1.SUCCESS : activeInput === index ? theme$1.BORDER_INVERTED : theme$1.BORDER_PRIMARY,
4095
- ...textInputStyle
4077
+ };
4078
+ useEffect(() => {
4079
+ if (otp.length === length) {
4080
+ onComplete?.(otp);
4081
+ }
4082
+ }, [otp]);
4083
+ return /* @__PURE__ */ React.createElement(ThemeProvider, null, /* @__PURE__ */ React.createElement(View, { style: { ...otpContainerStyle }, "data-testid": testId }, /* @__PURE__ */ React.createElement(
4084
+ CustomTypography,
4085
+ {
4086
+ text: label,
4087
+ variant: FontStyle.B4_REGULAR,
4088
+ style: {
4089
+ color: otp?.length ? theme$1.CONTENT_PRIMARY : theme$1.CONTENT_SECONDRY,
4090
+ textAlign: "left",
4091
+ ...otpHeaderTextStyle
4092
+ }
4093
+ }
4094
+ ), /* @__PURE__ */ React.createElement(View, { style: { ...styles$5.textInputContainer } }, Array.from({ length }).map((_, index) => /* @__PURE__ */ React.createElement(
4095
+ TextInput,
4096
+ {
4097
+ key: index?.toString(),
4098
+ style: {
4099
+ ...styles$5.textInputStyle,
4100
+ color: theme$1.CONTENT_PRIMARY,
4101
+ borderColor: errorMessage ? theme$1.ERROR : otp.length === length ? theme$1.SUCCESS : activeInput === index ? theme$1.BORDER_INVERTED : theme$1.BORDER_PRIMARY,
4102
+ ...textInputStyle
4103
+ },
4104
+ onFocus: () => setActiveInput(index),
4105
+ onBlur: () => setActiveInput(null),
4106
+ onKeyPress: (e) => handleKeyPress(e, index),
4107
+ onChangeText: (text) => handleChange(index, text),
4108
+ value: otp[index] ? "\u25CF" : "",
4109
+ placeholder: "",
4110
+ keyboardType: "numeric",
4111
+ ref: (el) => otpRefs.current[index] = el,
4112
+ returnKeyType: otp.length === length ? "done" : "next",
4113
+ importantForAutofill: "yes",
4114
+ textContentType: "oneTimeCode",
4115
+ autoComplete: "sms-otp",
4116
+ selectionColor: theme$1.CONTENT_PRIMARY
4117
+ }
4118
+ ))), !errorMessageMaxReachCount && /* @__PURE__ */ React.createElement(View, { style: styles$5.timerContainer }, (disableResendButton() || !isResendOtpEnable) && /* @__PURE__ */ React.createElement(View, { style: styles$5.timerIconContainer }, timerIcon, /* @__PURE__ */ React.createElement(
4119
+ CustomTypography,
4120
+ {
4121
+ text: `00:${timeLeft} secs`,
4122
+ variant: FontStyle.L1_REGULAR,
4123
+ style: { color: theme$1.INFO }
4124
+ }
4125
+ )), /* @__PURE__ */ React.createElement(
4126
+ Pressable,
4127
+ {
4128
+ onPress: onClickResendOTP,
4129
+ style: styles$5.resendOTPStyle,
4130
+ disabled: disableResendButton() || !isResendOtpEnable
4096
4131
  },
4097
- onFocus: () => setActiveInput(index),
4098
- onBlur: () => setActiveInput(null),
4099
- onKeyPress: (e) => handleKeyPress(e, index),
4100
- onChangeText: (text) => handleChange(index, text),
4101
- value: otp[index] ? "\u25CF" : "",
4102
- placeholder: "",
4103
- keyboardType: "numeric",
4104
- ref: (el) => otpRefs.current[index] = el,
4105
- returnKeyType: otp.length === length ? "done" : "next",
4106
- importantForAutofill: "yes",
4107
- textContentType: "oneTimeCode",
4108
- autoComplete: "sms-otp",
4109
- selectionColor: theme$1.CONTENT_PRIMARY
4110
- }
4111
- ))), !errorMessageMaxReachCount && /* @__PURE__ */ React.createElement(View, { style: styles$5.timerContainer }, (disableResendButton() || !isResendOtpEnable) && /* @__PURE__ */ React.createElement(View, { style: styles$5.timerIconContainer }, timerIcon, /* @__PURE__ */ React.createElement(
4112
- CustomTypography,
4113
- {
4114
- text: `00:${timeLeft} secs`,
4115
- variant: FontStyle.L1_REGULAR,
4116
- style: { color: theme$1.INFO }
4117
- }
4118
- )), /* @__PURE__ */ React.createElement(
4119
- Pressable,
4120
- {
4121
- onPress: onClickResendOTP,
4122
- style: styles$5.resendOTPStyle,
4123
- disabled: disableResendButton() || !isResendOtpEnable
4124
- },
4125
- /* @__PURE__ */ React.createElement(
4132
+ /* @__PURE__ */ React.createElement(
4133
+ CustomTypography,
4134
+ {
4135
+ text: resendText,
4136
+ variant: FontStyle.L2_REGULAR,
4137
+ style: {
4138
+ textDecorationLine: "underline",
4139
+ color: isResendOtpEnable ? resendOtpColor ?? theme$1.CONTENT_PRIMARY : theme$1.CONTENT_DISABLE,
4140
+ ...resendTextStyle
4141
+ }
4142
+ }
4143
+ )
4144
+ )), errorMessage ? /* @__PURE__ */ React.createElement(View, { style: styles$5.resendOtpContainer }, /* @__PURE__ */ React.createElement(
4126
4145
  CustomTypography,
4127
4146
  {
4128
- text: resendText,
4147
+ text: errorMessage,
4129
4148
  variant: FontStyle.L2_REGULAR,
4130
4149
  style: {
4131
- textDecorationLine: "underline",
4132
- color: isResendOtpEnable ? resendOtpColor ?? theme$1.CONTENT_PRIMARY : theme$1.CONTENT_DISABLE,
4133
- ...resendTextStyle
4150
+ alignSelf: "flex-start",
4151
+ color: theme$1.ERROR
4134
4152
  }
4135
4153
  }
4136
- )
4137
- )), errorMessage ? /* @__PURE__ */ React.createElement(View, { style: styles$5.resendOtpContainer }, /* @__PURE__ */ React.createElement(
4138
- CustomTypography,
4139
- {
4140
- text: errorMessage,
4141
- variant: FontStyle.L2_REGULAR,
4142
- style: {
4143
- alignSelf: "flex-start",
4144
- color: theme$1.ERROR
4145
- }
4146
- }
4147
- )) : null, errorMessageMaxReachCount ? /* @__PURE__ */ React.createElement(View, { style: styles$5.resendOtpContainer }, /* @__PURE__ */ React.createElement(
4148
- CustomTypography,
4149
- {
4150
- text: errorMessageMaxReachCount,
4151
- variant: FontStyle.L2_REGULAR,
4152
- style: {
4153
- alignSelf: "flex-start",
4154
- color: theme$1.ERROR
4154
+ )) : null, errorMessageMaxReachCount ? /* @__PURE__ */ React.createElement(View, { style: styles$5.resendOtpContainer }, /* @__PURE__ */ React.createElement(
4155
+ CustomTypography,
4156
+ {
4157
+ text: errorMessageMaxReachCount,
4158
+ variant: FontStyle.L2_REGULAR,
4159
+ style: {
4160
+ alignSelf: "flex-start",
4161
+ color: theme$1.ERROR
4162
+ }
4155
4163
  }
4156
- }
4157
- )) : null);
4158
- };
4159
- const OTPInput = withThemeProvider(OTPInputComponent);
4160
- var index$4 = React.forwardRef(OTPInput);
4164
+ )) : null));
4165
+ }
4166
+ );
4167
+ OTPInput.displayName = "OTPInput";
4161
4168
 
4162
4169
  const styles$4 = StyleSheet.create({
4163
4170
  stepperContainer: {
@@ -4897,5 +4904,5 @@ const RadioButtonGroup = ({ data, onSelect, containerStyle, labelStyle, optionCo
4897
4904
  )));
4898
4905
  };
4899
4906
 
4900
- export { Accordion$1 as Accordion, index$1 as AppointmentCard, Badge$1 as Badge, BottomDrawer, CustomButton$1 as Button, Cards, category as Category, Checkbox as CheckBox, ContactModel, CountryDropDown as CountryPicker, CustomDocumentPicker$1 as CustomDocumentPicker, CustomDropdown$1 as CustomDropdown, CustomHeader$1 as CustomHeader, CustomIcon, CustomLoader$1 as CustomLoader, CustomProgressBar, CustomSearchBar, index$2 as CustomSlideButton, CustomSwitchBtn, CustomText$1 as CustomText, CustomTextInput, CustomTooltip, CustomTypography, DHRE_COLORS_ALERT, DHRE_COLORS_BG, DHRE_COLORS_PRIMARY, DHRE_COLORS_SECONDARY, DHRE_COLORS_TEXT, DHRE_DEFAULT, DateRangePicker$1 as DateRangePicker, CustomDropdown as DropDown, FONT_STYLES, feedback as FeedbackForm, FileUpload, FontStyle, Line, NotificationBandge, index$4 as OTPInput, OurOffices as OurOfficesButton, PdfView, PopUp, index as PropertyDetails, RadioButtonGroup, ShapeType, TagSingleSelection as SingleSelectionTags, Star as StarRating, index$3 as Stepper, SwipableList$1 as SwipableList, Tabs$1 as Tabs, Tags, TextDirectType, CommonTextInput as TextInput, Theme, Toast, CustomSwitch as ToggleButton, ToggleButtonType, ToggleTextType, Topic$1 as Topic, copyToClipboard, theme as default, height, horizontalScale, moderateScale, toastService, verticalScale, width };
4907
+ export { Accordion$1 as Accordion, index$1 as AppointmentCard, Badge$1 as Badge, BottomDrawer, CustomButton$1 as Button, Cards, category as Category, Checkbox as CheckBox, ContactModel, CountryDropDown as CountryPicker, CustomDocumentPicker$1 as CustomDocumentPicker, CustomDropdown$1 as CustomDropdown, CustomHeader$1 as CustomHeader, CustomIcon, CustomLoader$1 as CustomLoader, CustomProgressBar, CustomSearchBar, index$2 as CustomSlideButton, CustomSwitchBtn, CustomText$1 as CustomText, CustomTextInput, CustomTooltip, CustomTypography, DHRE_COLORS_ALERT, DHRE_COLORS_BG, DHRE_COLORS_PRIMARY, DHRE_COLORS_SECONDARY, DHRE_COLORS_TEXT, DHRE_DEFAULT, DateRangePicker$1 as DateRangePicker, CustomDropdown as DropDown, FONT_STYLES, feedback as FeedbackForm, FileUpload, FontStyle, Line, NotificationBandge, OTPInput, OurOffices as OurOfficesButton, PdfView, PopUp, index as PropertyDetails, RadioButtonGroup, ShapeType, TagSingleSelection as SingleSelectionTags, Star as StarRating, index$3 as Stepper, SwipableList$1 as SwipableList, Tabs$1 as Tabs, Tags, TextDirectType, CommonTextInput as TextInput, Theme, Toast, CustomSwitch as ToggleButton, ToggleButtonType, ToggleTextType, Topic$1 as Topic, copyToClipboard, theme as default, height, horizontalScale, moderateScale, toastService, verticalScale, width };
4901
4908
  //# sourceMappingURL=index.mjs.map