dhre-ui-kit 0.0.258 → 0.0.260

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,229 @@ 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 refs = useRef([]);
3999
+ refs.current = Array(length).fill(0).map((_, index) => refs.current[index] || null);
4000
+ useEffect(() => {
4004
4001
  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 () => {
4002
+ }, []);
4003
+ const onClickResendOTP = () => {
4004
+ if (resendOTPCount > maxResendCount - 1) {
4005
+ setErrorMessageMaxReachCount(
4006
+ "You have exceeded the maximum number of attempts."
4007
+ );
4008
+ }
4009
+ if (resendOTPCount < maxResendCount) {
4010
+ setIsResendOtpEnable(false);
4011
+ setResendOTPCount(resendOTPCount + 1);
4012
+ enableResendOtp();
4013
+ resendOTP?.();
4014
+ setOTP("");
4015
+ }
4016
+ };
4017
+ const disableResendButton = () => {
4018
+ if (disabled === true && resendOTPCount >= maxResendCount) {
4019
+ return true;
4020
+ } else {
4021
+ return false;
4022
+ }
4023
+ };
4024
+ const enableResendOtp = () => {
4025
+ setTimeout(() => {
4026
+ setIsResendOtpEnable(true);
4027
+ setTimeLeft(timerToResend / 1e3);
4028
+ }, timerToResend);
4029
+ };
4030
+ useEffect(() => {
4023
4031
  if (Platform.OS === "android") {
4024
- OTPVerify.removeListener();
4025
- removeListener();
4032
+ onStartListeningOtp();
4026
4033
  }
4034
+ return () => {
4035
+ if (Platform.OS === "android") {
4036
+ OTPVerify.removeListener();
4037
+ removeListener();
4038
+ }
4039
+ };
4040
+ }, []);
4041
+ const onStartListeningOtp = async () => {
4042
+ await OTPVerify.getOtp();
4043
+ startOtpListener((message) => {
4044
+ const otpRegex = new RegExp(`(\\d{${length}})`, "g");
4045
+ const otp2 = otpRegex.exec(message)?.[1];
4046
+ setOTP(otp2 ?? "");
4047
+ if (otp2) {
4048
+ refs.current[otp2?.length - 1]?.focus();
4049
+ }
4050
+ });
4027
4051
  };
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();
4052
+ React.useImperativeHandle(ref, () => ({
4053
+ reset() {
4054
+ setOTP("");
4055
+ refs.current[0]?.focus();
4056
+ },
4057
+ set(newOtp) {
4058
+ setOTP(newOtp);
4059
+ refs.current[newOtp?.length - 1]?.focus();
4037
4060
  }
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
4061
+ }));
4062
+ const handleChange = (index, value) => {
4063
+ const regex = /^\d+$/;
4064
+ if (value.length === 1 && regex.test(value) && index >= 0 && index < length) {
4065
+ const newOTP = `${otp}${value}`;
4066
+ setOTP(newOTP);
4067
+ refs.current[index + 1]?.focus();
4068
+ } else if (value.length === 0 && index > 0) {
4069
+ const newOTP = otp.slice(0, -1);
4070
+ setOTP(newOTP);
4071
+ refs.current[index - 1]?.focus();
4072
+ } else if (value?.length === length) {
4073
+ setOTP(value);
4074
+ refs.current[length - 1]?.focus();
4075
+ } else {
4076
+ const newOTP = otp.slice(0, -1);
4077
+ setOTP(newOTP);
4078
+ refs.current[index]?.focus();
4085
4079
  }
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
4080
+ };
4081
+ const handleKeyPress = (e, index) => {
4082
+ if (e.nativeEvent.key === "Backspace" && index > 0) {
4083
+ refs.current[index - 1]?.focus();
4084
+ }
4085
+ };
4086
+ useEffect(() => {
4087
+ if (otp.length === length) {
4088
+ onComplete?.(otp);
4089
+ }
4090
+ }, [otp]);
4091
+ return /* @__PURE__ */ React.createElement(ThemeProvider, null, /* @__PURE__ */ React.createElement(View, { style: { ...otpContainerStyle }, "data-testid": testId }, /* @__PURE__ */ React.createElement(
4092
+ CustomTypography,
4093
+ {
4094
+ text: label,
4095
+ variant: FontStyle.B4_REGULAR,
4096
+ style: {
4097
+ color: otp?.length ? theme$1.CONTENT_PRIMARY : theme$1.CONTENT_SECONDRY,
4098
+ textAlign: "left",
4099
+ ...otpHeaderTextStyle
4100
+ }
4101
+ }
4102
+ ), /* @__PURE__ */ React.createElement(View, { style: { ...styles$5.textInputContainer } }, Array.from({ length }).map((_, index) => /* @__PURE__ */ React.createElement(
4103
+ TextInput,
4104
+ {
4105
+ key: index?.toString(),
4106
+ style: {
4107
+ ...styles$5.textInputStyle,
4108
+ color: theme$1.CONTENT_PRIMARY,
4109
+ borderColor: errorMessage ? theme$1.ERROR : otp.length === length ? theme$1.SUCCESS : activeInput === index ? theme$1.BORDER_INVERTED : theme$1.BORDER_PRIMARY,
4110
+ ...textInputStyle
4111
+ },
4112
+ onFocus: () => setActiveInput(index),
4113
+ onBlur: () => setActiveInput(null),
4114
+ onKeyPress: (e) => handleKeyPress(e, index),
4115
+ onChangeText: (text) => handleChange(index, text),
4116
+ value: otp[index] ? "\u25CF" : "",
4117
+ placeholder: "",
4118
+ keyboardType: "numeric",
4119
+ ref: (el) => refs.current[index] = el,
4120
+ returnKeyType: otp.length === length ? "done" : "next",
4121
+ importantForAutofill: "yes",
4122
+ textContentType: "oneTimeCode",
4123
+ autoComplete: "sms-otp",
4124
+ selectionColor: theme$1.CONTENT_PRIMARY
4125
+ }
4126
+ ))), !errorMessageMaxReachCount && /* @__PURE__ */ React.createElement(View, { style: styles$5.timerContainer }, (disableResendButton() || !isResendOtpEnable) && /* @__PURE__ */ React.createElement(View, { style: styles$5.timerIconContainer }, timerIcon, /* @__PURE__ */ React.createElement(
4127
+ CustomTypography,
4128
+ {
4129
+ text: `00:${timeLeft} secs`,
4130
+ variant: FontStyle.L1_REGULAR,
4131
+ style: { color: theme$1.INFO }
4132
+ }
4133
+ )), /* @__PURE__ */ React.createElement(
4134
+ Pressable,
4135
+ {
4136
+ onPress: onClickResendOTP,
4137
+ style: styles$5.resendOTPStyle,
4138
+ disabled: disableResendButton() || !isResendOtpEnable
4096
4139
  },
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(
4140
+ /* @__PURE__ */ React.createElement(
4141
+ CustomTypography,
4142
+ {
4143
+ text: resendText,
4144
+ variant: FontStyle.L2_REGULAR,
4145
+ style: {
4146
+ textDecorationLine: "underline",
4147
+ color: isResendOtpEnable ? resendOtpColor ?? theme$1.CONTENT_PRIMARY : theme$1.CONTENT_DISABLE,
4148
+ ...resendTextStyle
4149
+ }
4150
+ }
4151
+ )
4152
+ )), errorMessage ? /* @__PURE__ */ React.createElement(View, { style: styles$5.resendOtpContainer }, /* @__PURE__ */ React.createElement(
4126
4153
  CustomTypography,
4127
4154
  {
4128
- text: resendText,
4155
+ text: errorMessage,
4129
4156
  variant: FontStyle.L2_REGULAR,
4130
4157
  style: {
4131
- textDecorationLine: "underline",
4132
- color: isResendOtpEnable ? resendOtpColor ?? theme$1.CONTENT_PRIMARY : theme$1.CONTENT_DISABLE,
4133
- ...resendTextStyle
4158
+ alignSelf: "flex-start",
4159
+ color: theme$1.ERROR
4134
4160
  }
4135
4161
  }
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
4162
+ )) : null, errorMessageMaxReachCount ? /* @__PURE__ */ React.createElement(View, { style: styles$5.resendOtpContainer }, /* @__PURE__ */ React.createElement(
4163
+ CustomTypography,
4164
+ {
4165
+ text: errorMessageMaxReachCount,
4166
+ variant: FontStyle.L2_REGULAR,
4167
+ style: {
4168
+ alignSelf: "flex-start",
4169
+ color: theme$1.ERROR
4170
+ }
4155
4171
  }
4156
- }
4157
- )) : null);
4158
- };
4159
- const OTPInput = withThemeProvider(OTPInputComponent);
4160
- var index$4 = React.forwardRef(OTPInput);
4172
+ )) : null));
4173
+ }
4174
+ );
4175
+ OTPInput.displayName = "OTPInput";
4161
4176
 
4162
4177
  const styles$4 = StyleSheet.create({
4163
4178
  stepperContainer: {
@@ -4897,5 +4912,5 @@ const RadioButtonGroup = ({ data, onSelect, containerStyle, labelStyle, optionCo
4897
4912
  )));
4898
4913
  };
4899
4914
 
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 };
4915
+ 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
4916
  //# sourceMappingURL=index.mjs.map