@admin-layout/tailwind-ui 10.0.9-alpha.71

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.
Files changed (129) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +297 -0
  3. package/lib/components/ErrorHandlers/ApplicationErrorHandler.d.ts +2 -0
  4. package/lib/components/ErrorHandlers/ApplicationErrorHandler.d.ts.map +1 -0
  5. package/lib/components/ErrorHandlers/ApplicationErrorHandler.js +24 -0
  6. package/lib/components/ErrorHandlers/ApplicationErrorHandler.js.map +1 -0
  7. package/lib/components/ErrorHandlers/ErrorBoundary.d.ts +2 -0
  8. package/lib/components/ErrorHandlers/ErrorBoundary.d.ts.map +1 -0
  9. package/lib/components/ErrorHandlers/ErrorBoundary.js +48 -0
  10. package/lib/components/ErrorHandlers/ErrorBoundary.js.map +1 -0
  11. package/lib/components/ErrorHandlers/LayoutErrorBoundary.d.ts +2 -0
  12. package/lib/components/ErrorHandlers/LayoutErrorBoundary.d.ts.map +1 -0
  13. package/lib/components/ErrorHandlers/LayoutErrorBoundary.js +34 -0
  14. package/lib/components/ErrorHandlers/LayoutErrorBoundary.js.map +1 -0
  15. package/lib/components/ErrorHandlers/index.d.ts +4 -0
  16. package/lib/components/ErrorHandlers/index.d.ts.map +1 -0
  17. package/lib/components/ErrorPages/403.d.ts +2 -0
  18. package/lib/components/ErrorPages/403.d.ts.map +1 -0
  19. package/lib/components/ErrorPages/403.js +29 -0
  20. package/lib/components/ErrorPages/403.js.map +1 -0
  21. package/lib/components/ErrorPages/404.d.ts +2 -0
  22. package/lib/components/ErrorPages/404.d.ts.map +1 -0
  23. package/lib/components/ErrorPages/404.js +29 -0
  24. package/lib/components/ErrorPages/404.js.map +1 -0
  25. package/lib/components/ErrorPages/500.d.ts +2 -0
  26. package/lib/components/ErrorPages/500.d.ts.map +1 -0
  27. package/lib/components/ErrorPages/500.js +29 -0
  28. package/lib/components/ErrorPages/500.js.map +1 -0
  29. package/lib/components/ErrorPages/index.d.ts +4 -0
  30. package/lib/components/ErrorPages/index.d.ts.map +1 -0
  31. package/lib/components/OTP/OTPInput.d.ts +4 -0
  32. package/lib/components/OTP/OTPInput.d.ts.map +1 -0
  33. package/lib/components/OTP/OTPInput.js +82 -0
  34. package/lib/components/OTP/OTPInput.js.map +1 -0
  35. package/lib/components/OTP/OTPVerification.d.ts +4 -0
  36. package/lib/components/OTP/OTPVerification.d.ts.map +1 -0
  37. package/lib/components/OTP/OTPVerification.js +155 -0
  38. package/lib/components/OTP/OTPVerification.js.map +1 -0
  39. package/lib/components/OTP/SingleInput.d.ts +10 -0
  40. package/lib/components/OTP/SingleInput.d.ts.map +1 -0
  41. package/lib/components/OTP/SingleInput.js +43 -0
  42. package/lib/components/OTP/SingleInput.js.map +1 -0
  43. package/lib/components/OTP/hooks.d.ts +3 -0
  44. package/lib/components/OTP/hooks.d.ts.map +1 -0
  45. package/lib/components/OTP/hooks.js +95 -0
  46. package/lib/components/OTP/hooks.js.map +1 -0
  47. package/lib/components/OTP/index.d.ts +6 -0
  48. package/lib/components/OTP/index.d.ts.map +1 -0
  49. package/lib/components/OTP/types.d.ts +110 -0
  50. package/lib/components/OTP/types.d.ts.map +1 -0
  51. package/lib/components/OTP/utils.d.ts +26 -0
  52. package/lib/components/OTP/utils.d.ts.map +1 -0
  53. package/lib/components/OTP/utils.js +36 -0
  54. package/lib/components/OTP/utils.js.map +1 -0
  55. package/lib/components/PageContainer/PageContainer.d.ts +4 -0
  56. package/lib/components/PageContainer/PageContainer.d.ts.map +1 -0
  57. package/lib/components/PageContainer/PageContainer.js +57 -0
  58. package/lib/components/PageContainer/PageContainer.js.map +1 -0
  59. package/lib/components/PageContainer/index.d.ts +2 -0
  60. package/lib/components/PageContainer/index.d.ts.map +1 -0
  61. package/lib/components/PageContainer/types.d.ts +51 -0
  62. package/lib/components/PageContainer/types.d.ts.map +1 -0
  63. package/lib/components/PageLoading/index.d.ts +6 -0
  64. package/lib/components/PageLoading/index.d.ts.map +1 -0
  65. package/lib/components/PageLoading/index.js +9 -0
  66. package/lib/components/PageLoading/index.js.map +1 -0
  67. package/lib/components/ReactTable/Table.d.ts +18 -0
  68. package/lib/components/ReactTable/Table.d.ts.map +1 -0
  69. package/lib/components/ReactTable/Table.js +151 -0
  70. package/lib/components/ReactTable/Table.js.map +1 -0
  71. package/lib/components/ReactTable/TableFilters.d.ts +8 -0
  72. package/lib/components/ReactTable/TableFilters.d.ts.map +1 -0
  73. package/lib/components/ReactTable/TableFilters.js +58 -0
  74. package/lib/components/ReactTable/TableFilters.js.map +1 -0
  75. package/lib/components/ReactTable/index.d.ts +3 -0
  76. package/lib/components/ReactTable/index.d.ts.map +1 -0
  77. package/lib/components/Spin/index.d.ts +10 -0
  78. package/lib/components/Spin/index.d.ts.map +1 -0
  79. package/lib/components/Spin/index.js +31 -0
  80. package/lib/components/Spin/index.js.map +1 -0
  81. package/lib/components/index.d.ts +9 -0
  82. package/lib/components/index.d.ts.map +1 -0
  83. package/lib/hooks/useToast.d.ts +17 -0
  84. package/lib/hooks/useToast.d.ts.map +1 -0
  85. package/lib/hooks/useToast.js +163 -0
  86. package/lib/hooks/useToast.js.map +1 -0
  87. package/lib/icons/index.d.ts +15 -0
  88. package/lib/icons/index.d.ts.map +1 -0
  89. package/lib/icons/index.js +14 -0
  90. package/lib/icons/index.js.map +1 -0
  91. package/lib/index.d.ts +3 -0
  92. package/lib/index.d.ts.map +1 -0
  93. package/lib/index.js +1 -0
  94. package/lib/index.js.map +1 -0
  95. package/lib/machines/otpMachine.d.ts +3 -0
  96. package/lib/machines/otpMachine.d.ts.map +1 -0
  97. package/lib/machines/otpMachine.js +131 -0
  98. package/lib/machines/otpMachine.js.map +1 -0
  99. package/lib/utils/hooks/useDebounceFn/index.d.ts +8 -0
  100. package/lib/utils/hooks/useDebounceFn/index.d.ts.map +1 -0
  101. package/lib/utils/hooks/useDeepCompareEffect/index.d.ts +5 -0
  102. package/lib/utils/hooks/useDeepCompareEffect/index.d.ts.map +1 -0
  103. package/lib/utils/hooks/useDocumentTitle/index.d.ts +7 -0
  104. package/lib/utils/hooks/useDocumentTitle/index.d.ts.map +1 -0
  105. package/lib/utils/hooks/usePrevious/index.d.ts +3 -0
  106. package/lib/utils/hooks/usePrevious/index.d.ts.map +1 -0
  107. package/lib/utils/hooks/useWindowDimensions/index.d.ts +5 -0
  108. package/lib/utils/hooks/useWindowDimensions/index.d.ts.map +1 -0
  109. package/lib/utils/hooks/useWindowDimensions/index.js +21 -0
  110. package/lib/utils/hooks/useWindowDimensions/index.js.map +1 -0
  111. package/lib/utils/index.d.ts +21 -0
  112. package/lib/utils/index.d.ts.map +1 -0
  113. package/lib/utils/isBrowser/index.d.ts +3 -0
  114. package/lib/utils/isBrowser/index.d.ts.map +1 -0
  115. package/lib/utils/isDropdownValueType/index.d.ts +3 -0
  116. package/lib/utils/isDropdownValueType/index.d.ts.map +1 -0
  117. package/lib/utils/isImg/index.d.ts +4 -0
  118. package/lib/utils/isImg/index.d.ts.map +1 -0
  119. package/lib/utils/isNil/index.d.ts +3 -0
  120. package/lib/utils/isNil/index.d.ts.map +1 -0
  121. package/lib/utils/isUrl/index.d.ts +3 -0
  122. package/lib/utils/isUrl/index.d.ts.map +1 -0
  123. package/lib/utils/omitUndefined/index.d.ts +3 -0
  124. package/lib/utils/omitUndefined/index.d.ts.map +1 -0
  125. package/lib/utils/omitUndefinedAndEmptyArr/index.d.ts +3 -0
  126. package/lib/utils/omitUndefinedAndEmptyArr/index.d.ts.map +1 -0
  127. package/lib/utils/typing.d.ts +142 -0
  128. package/lib/utils/typing.d.ts.map +1 -0
  129. package/package.json +38 -0
@@ -0,0 +1,82 @@
1
+ import {jsx,jsxs}from'react/jsx-runtime';import React__default from'react';import {useOTPInput}from'./hooks.js';import {SingleInput}from'./SingleInput.js';import {getPlaceholderValue,isInputNumeric}from'./utils.js';const OTPInput = ({
2
+ value = '',
3
+ numInputs = 4,
4
+ onChange,
5
+ onPaste,
6
+ renderInput,
7
+ shouldAutoFocus = false,
8
+ inputType = 'text',
9
+ renderSeparator,
10
+ placeholder,
11
+ containerClassName,
12
+ inputClassName,
13
+ skipDefaultStyles = false
14
+ }) => {
15
+ const [{
16
+ activeInput,
17
+ otp,
18
+ handleChange,
19
+ handleInputChange,
20
+ handleFocus,
21
+ handleBlur,
22
+ handleKeyDown,
23
+ handlePaste
24
+ }, inputRefs] = useOTPInput(value, numInputs, onChange, inputType, shouldAutoFocus);
25
+ // Create default input renderer if not provided
26
+ const defaultRenderInput = (props, index) => jsx(SingleInput, {
27
+ ...props,
28
+ focused: activeInput === index
29
+ });
30
+ // Use provided input renderer or default
31
+ const inputRenderer = renderInput || defaultRenderInput;
32
+ const placeholderValue = getPlaceholderValue(placeholder, numInputs);
33
+ const isInputNum = isInputNumeric(inputType);
34
+ // Handle paste across the whole component
35
+ const handleComponentPaste = e => {
36
+ if (onPaste) {
37
+ onPaste(e);
38
+ return;
39
+ }
40
+ // Default paste behavior
41
+ e.preventDefault();
42
+ const pastedData = e.clipboardData.getData('text/plain');
43
+ // Prevent pasting if the clipboard data contains non-numeric values for number inputs
44
+ if (isInputNum && pastedData.split('').some(value => isNaN(Number(value)))) {
45
+ return;
46
+ }
47
+ // Let the hook handle the paste logic
48
+ handlePaste(e);
49
+ };
50
+ return jsx("div", {
51
+ className: `flex items-center justify-center space-x-2 md:space-x-4 ${containerClassName || ''}`,
52
+ onPaste: handleComponentPaste,
53
+ "data-testid": "otp-input-container",
54
+ children: Array.from({
55
+ length: numInputs
56
+ }, (_, index) => jsxs(React__default.Fragment, {
57
+ children: [inputRenderer({
58
+ value: otp[index] || '',
59
+ placeholder: placeholderValue?.[index],
60
+ ref: element => {
61
+ if (inputRefs.current) {
62
+ inputRefs.current[index] = element;
63
+ }
64
+ },
65
+ onChange: handleChange,
66
+ onFocus: event => handleFocus(event)(index),
67
+ onBlur: handleBlur,
68
+ onKeyDown: handleKeyDown,
69
+ onPaste: handlePaste,
70
+ autoComplete: 'off',
71
+ 'aria-label': `Please enter OTP character ${index + 1}`,
72
+ className: skipDefaultStyles ? inputClassName || '' : `${inputClassName || ''}`,
73
+ type: inputType,
74
+ inputMode: isInputNum ? 'numeric' : 'text',
75
+ onInput: handleInputChange
76
+ }, index), index < numInputs - 1 && (typeof renderSeparator === 'function' ? renderSeparator(index) : renderSeparator || jsx("span", {
77
+ className: "text-gray-400",
78
+ children: "-"
79
+ }))]
80
+ }, index))
81
+ });
82
+ };export{OTPInput};//# sourceMappingURL=OTPInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OTPInput.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { OTPVerificationProps } from './types';
3
+ export declare const OTPVerification: React.FC<OTPVerificationProps>;
4
+ //# sourceMappingURL=OTPVerification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OTPVerification.d.ts","sourceRoot":"","sources":["../../../src/components/OTP/OTPVerification.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAG/C,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CA2K1D,CAAC"}
@@ -0,0 +1,155 @@
1
+ import {jsxs,jsx,Fragment}from'react/jsx-runtime';import {useState,useEffect}from'react';import {OTPInput}from'./OTPInput.js';import {icons}from'../../icons/index.js';const OTPVerification = ({
2
+ length = 4,
3
+ onVerificationSuccess,
4
+ onVerificationFailed,
5
+ onOtpChange,
6
+ onContinue,
7
+ onResendCode,
8
+ validCode = '1234',
9
+ title = 'Verification Required',
10
+ description = 'Please enter the code sent to your device to continue.',
11
+ successMessage = 'Thank you! Your identity has been verified successfully.',
12
+ errorMessage = 'Invalid code. Please try again.',
13
+ continueButtonText = 'Continue to Dashboard',
14
+ resendCodeText = 'Resend Code',
15
+ verificationDelay = 500,
16
+ resetDelay = 1000,
17
+ showFooter = true
18
+ }) => {
19
+ const [otp, setOtp] = useState('');
20
+ const [isVerified, setIsVerified] = useState(false);
21
+ const [isInvalid, setIsInvalid] = useState(false);
22
+ const {
23
+ CheckIcon,
24
+ AlertIcon,
25
+ LockIcon,
26
+ KeyIcon
27
+ } = icons;
28
+ // Reset component when validCode changes
29
+ useEffect(() => {
30
+ setOtp('');
31
+ setIsVerified(false);
32
+ setIsInvalid(false);
33
+ }, [validCode]);
34
+ const handleChange = value => {
35
+ setOtp(value);
36
+ setIsInvalid(false);
37
+ // Call the external onChange handler if provided
38
+ if (onOtpChange) {
39
+ onOtpChange(value);
40
+ }
41
+ // Verify when the OTP is fully entered
42
+ if (value.length === length) {
43
+ if (value === validCode) {
44
+ setTimeout(() => {
45
+ setIsVerified(true);
46
+ setIsInvalid(false);
47
+ if (onVerificationSuccess) {
48
+ onVerificationSuccess();
49
+ }
50
+ }, verificationDelay);
51
+ } else {
52
+ setIsInvalid(true);
53
+ if (onVerificationFailed) {
54
+ onVerificationFailed();
55
+ }
56
+ // Reset after delay if incorrect
57
+ setTimeout(() => {
58
+ setOtp('');
59
+ setIsInvalid(false);
60
+ }, resetDelay);
61
+ }
62
+ } else {
63
+ setIsVerified(false);
64
+ }
65
+ };
66
+ const handleContinue = () => {
67
+ if (onContinue) {
68
+ onContinue();
69
+ } else {
70
+ setIsVerified(false);
71
+ setOtp('');
72
+ }
73
+ };
74
+ const handleResendCode = () => {
75
+ if (onResendCode) {
76
+ onResendCode();
77
+ } else {
78
+ alert('Code resent!');
79
+ }
80
+ };
81
+ return jsxs("div", {
82
+ className: "max-w-fit w-full bg-white rounded-2xl shadow-xl overflow-hidden",
83
+ children: [jsxs("div", {
84
+ className: "p-8",
85
+ children: [jsx("div", {
86
+ className: `flex items-center justify-center w-16 h-16 rounded-full mx-auto mb-6 transition-colors duration-300 ${isVerified ? 'bg-green-100' : isInvalid ? 'bg-red-100' : 'bg-blue-100'}`,
87
+ children: isVerified ? jsx(CheckIcon, {
88
+ className: "w-8 h-8 text-green-600"
89
+ }) : isInvalid ? jsx(AlertIcon, {
90
+ className: "w-8 h-8 text-red-600"
91
+ }) : jsx(LockIcon, {
92
+ className: "w-8 h-8 text-blue-600"
93
+ })
94
+ }), jsx("h1", {
95
+ className: `text-2xl font-bold text-center mb-2 ${isVerified ? 'text-green-800' : isInvalid ? 'text-red-800' : 'text-gray-800'}`,
96
+ children: isVerified ? 'Verification Complete' : title
97
+ }), jsx("p", {
98
+ className: `text-center mb-8 ${isVerified ? 'text-green-600' : isInvalid ? 'text-red-600' : 'text-gray-600'}`,
99
+ children: isVerified ? successMessage : isInvalid ? errorMessage : description
100
+ }), !isVerified ? jsxs(Fragment, {
101
+ children: [jsx("div", {
102
+ className: "mb-6",
103
+ children: jsx(OTPInput, {
104
+ value: otp,
105
+ onChange: handleChange,
106
+ numInputs: length,
107
+ shouldAutoFocus: true,
108
+ inputType: "number",
109
+ renderSeparator: jsx("span", {
110
+ className: "text-gray-300",
111
+ children: "\u2022"
112
+ }),
113
+ containerClassName: `justify-center ${isInvalid ? 'animate-shake' : ''}`,
114
+ inputClassName: isInvalid ? 'border-red-500 text-red-500' : ''
115
+ })
116
+ }), jsxs("div", {
117
+ className: "text-center mb-6",
118
+ children: [jsx("p", {
119
+ className: "text-sm text-gray-500",
120
+ children: "Didn't receive a code?"
121
+ }), jsx("button", {
122
+ className: "text-blue-600 font-medium text-sm hover:text-blue-800 transition-colors mt-1",
123
+ onClick: handleResendCode,
124
+ children: resendCodeText
125
+ })]
126
+ }), jsxs("div", {
127
+ className: "flex items-center justify-center text-sm text-gray-600",
128
+ children: [jsx(KeyIcon, {
129
+ className: "w-4 h-4 mr-2"
130
+ }), jsx("span", {
131
+ children: "Secured with end-to-end encryption"
132
+ })]
133
+ })]
134
+ }) : jsx("button", {
135
+ className: "w-full py-3 bg-green-600 text-white rounded-lg font-medium hover:bg-green-700 transition-colors",
136
+ onClick: handleContinue,
137
+ children: continueButtonText
138
+ })]
139
+ }), showFooter && jsx("div", {
140
+ className: "bg-gray-50 py-4 px-8 border-t border-gray-100",
141
+ children: jsxs("p", {
142
+ className: "text-xs text-center text-gray-500",
143
+ children: ["By continuing, you agree to our", ' ', jsx("a", {
144
+ href: "#",
145
+ className: "text-blue-600",
146
+ children: "Terms of Service"
147
+ }), ' ', "and", ' ', jsx("a", {
148
+ href: "#",
149
+ className: "text-blue-600",
150
+ children: "Privacy Policy"
151
+ })]
152
+ })
153
+ })]
154
+ });
155
+ };export{OTPVerification};//# sourceMappingURL=OTPVerification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OTPVerification.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ export declare const SingleInput: React.ForwardRefExoticComponent<Omit<Required<Pick<React.InputHTMLAttributes<HTMLInputElement>, "value" | "onChange" | "onFocus" | "onBlur" | "onKeyDown" | "onPaste" | "aria-label" | "autoComplete" | "inputMode" | "onInput"> & {
3
+ ref: React.RefCallback<HTMLInputElement>;
4
+ placeholder: string | undefined;
5
+ className: string;
6
+ type: import("./types").AllowedInputTypes;
7
+ }>, "ref"> & {
8
+ focused: boolean;
9
+ } & React.RefAttributes<HTMLInputElement>>;
10
+ //# sourceMappingURL=SingleInput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SingleInput.d.ts","sourceRoot":"","sources":["../../../src/components/OTP/SingleInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAG1C,eAAO,MAAM,WAAW;SAcZ,MAAA,WAAQ;;;;;aAdyE,OAAO;0CAgDnG,CAAC"}
@@ -0,0 +1,43 @@
1
+ import {jsx}from'react/jsx-runtime';import {forwardRef}from'react';const SingleInput = forwardRef(({
2
+ value,
3
+ focused,
4
+ type,
5
+ inputMode,
6
+ onFocus,
7
+ onBlur,
8
+ onChange,
9
+ onKeyDown,
10
+ onPaste,
11
+ placeholder,
12
+ onInput,
13
+ className,
14
+ ...props
15
+ }, ref) => {
16
+ return jsx("input", {
17
+ ref: ref,
18
+ className: `
19
+ w-12 h-12 md:w-14 md:h-14
20
+ text-center text-xl font-medium
21
+ bg-white border rounded-md
22
+ transition-all duration-200 ease-in-out
23
+ focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500
24
+ ${focused ? 'border-blue-500 ring-2 ring-blue-500' : 'border-gray-300'}
25
+ ${value ? 'text-gray-900' : 'text-gray-400'}
26
+ ${className}
27
+ `,
28
+ value: value,
29
+ placeholder: placeholder,
30
+ type: type,
31
+ inputMode: inputMode,
32
+ onFocus: onFocus,
33
+ onBlur: onBlur,
34
+ onChange: onChange,
35
+ onKeyDown: onKeyDown,
36
+ onPaste: onPaste,
37
+ onInput: onInput,
38
+ "aria-label": props['aria-label'],
39
+ autoComplete: props.autoComplete,
40
+ maxLength: 1
41
+ });
42
+ });
43
+ SingleInput.displayName = 'SingleInput';export{SingleInput};//# sourceMappingURL=SingleInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SingleInput.js","sources":["../../../src/components/OTP/SingleInput.tsx"],"sourcesContent":[null],"names":[],"mappings":"mEAiBY,MAAA,WAAQ,GAAA,UAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,3 @@
1
+ import { AllowedInputTypes, OTPContextValue } from './types';
2
+ export declare const useOTPInput: (value: string, numInputs: number, onChange: (otp: string) => void, inputType?: AllowedInputTypes, shouldAutoFocus?: boolean) => [OTPContextValue, React.RefObject<(HTMLInputElement | null)[]>];
3
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/components/OTP/hooks.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG7D,eAAO,MAAM,WAAW,UACb,MAAM,aACF,MAAM,YACP,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,cACpB,iBAAiB,oBACX,OAAO,KACzB,CAAC,eAAe,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,gBAAgB,GAAG,IAAI,CAAC,EAAE,CAAC,CA2GhE,CAAC"}
@@ -0,0 +1,95 @@
1
+ import {useRef,useState,useMemo,useEffect}from'react';import {createOTPInputMachine}from'../../machines/otpMachine.js';import {useMachine}from'@xstate/react';import {otpStringToArray}from'./utils.js';const useOTPInput = (value = '', numInputs = 4, onChange, inputType = 'text', shouldAutoFocus = false) => {
2
+ const inputRefs = useRef([]);
3
+ const [prevOtp, setPrevOtp] = useState(value);
4
+ const otpMachine = useMemo(() => createOTPInputMachine(numInputs, inputType), [numInputs, inputType]);
5
+ const [state, send] = useMachine(otpMachine);
6
+ const {
7
+ otp,
8
+ activeInput
9
+ } = state.context;
10
+ useEffect(() => {
11
+ inputRefs.current = inputRefs.current.slice(0, numInputs);
12
+ }, [numInputs]);
13
+ useEffect(() => {
14
+ if (shouldAutoFocus) {
15
+ inputRefs.current[0]?.focus();
16
+ }
17
+ }, [shouldAutoFocus]);
18
+ useEffect(() => {
19
+ if (value !== prevOtp) {
20
+ setPrevOtp(value);
21
+ send({
22
+ type: 'SET_OTP',
23
+ otp: otpStringToArray(value, numInputs)
24
+ });
25
+ }
26
+ }, [value, numInputs, prevOtp, send]);
27
+ useEffect(() => {
28
+ inputRefs.current[activeInput]?.focus();
29
+ inputRefs.current[activeInput]?.select();
30
+ }, [activeInput]);
31
+ useEffect(() => {
32
+ const otpValue = otp.join('');
33
+ if (otpValue !== prevOtp) {
34
+ setPrevOtp(otpValue);
35
+ onChange(otpValue);
36
+ }
37
+ }, [otp, onChange, prevOtp]);
38
+ const handleChange = e => {
39
+ send({
40
+ type: 'CHANGE',
41
+ value: e.target.value
42
+ });
43
+ };
44
+ const handleInputChange = e => {
45
+ send({
46
+ type: 'INPUT_CHANGE',
47
+ value: e.target.value
48
+ });
49
+ const nativeEvent = e.nativeEvent;
50
+ if (nativeEvent.data === null && nativeEvent.inputType === 'deleteContentBackward') {
51
+ e.preventDefault();
52
+ send({
53
+ type: 'KEY_DOWN',
54
+ key: 'Backspace',
55
+ code: 'Backspace'
56
+ });
57
+ }
58
+ };
59
+ const handleFocus = e => index => {
60
+ send({
61
+ type: 'FOCUS',
62
+ index
63
+ });
64
+ e.target.select();
65
+ };
66
+ const handleBlur = () => {
67
+ send({
68
+ type: 'BLUR'
69
+ });
70
+ };
71
+ const handleKeyDown = e => {
72
+ send({
73
+ type: 'KEY_DOWN',
74
+ key: e.key,
75
+ code: e.code
76
+ });
77
+ };
78
+ const handlePaste = e => {
79
+ e.preventDefault();
80
+ send({
81
+ type: 'PASTE',
82
+ pastedData: e.clipboardData.getData('text/plain')
83
+ });
84
+ };
85
+ return [{
86
+ activeInput,
87
+ otp,
88
+ handleChange,
89
+ handleInputChange,
90
+ handleFocus,
91
+ handleBlur,
92
+ handleKeyDown,
93
+ handlePaste
94
+ }, inputRefs];
95
+ };export{useOTPInput};//# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,6 @@
1
+ export { OTPInput } from './OTPInput';
2
+ export { SingleInput } from './SingleInput';
3
+ export type { OTPInputProps, InputProps, AllowedInputTypes } from './types';
4
+ export { useOTPInput } from './hooks';
5
+ export { OTPVerification } from './OTPVerification';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/OTP/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,110 @@
1
+ import { ReactNode } from 'react';
2
+ export type AllowedInputTypes = 'password' | 'text' | 'number' | 'tel';
3
+ export type InputProps = Required<Pick<React.InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange' | 'onFocus' | 'onBlur' | 'onKeyDown' | 'onPaste' | 'aria-label' | 'autoComplete' | 'inputMode' | 'onInput'> & {
4
+ ref: React.RefCallback<HTMLInputElement>;
5
+ placeholder: string | undefined;
6
+ className: string;
7
+ type: AllowedInputTypes;
8
+ }>;
9
+ export type OTPInputProps = {
10
+ /** Value of the OTP input */
11
+ value?: string;
12
+ /** Number of OTP inputs to be rendered */
13
+ numInputs?: number;
14
+ /** Callback to be called when the OTP value changes */
15
+ onChange: (otp: string) => void;
16
+ /** Callback to be called when pasting content into the component */
17
+ onPaste?: (event: React.ClipboardEvent<HTMLDivElement>) => void;
18
+ /** Function to render the input */
19
+ renderInput?: (inputProps: InputProps, index: number) => ReactNode;
20
+ /** Whether the first input should be auto focused */
21
+ shouldAutoFocus?: boolean;
22
+ /** Placeholder for the inputs */
23
+ placeholder?: string;
24
+ /** Function to render the separator */
25
+ renderSeparator?: ((index: number) => ReactNode) | ReactNode;
26
+ /** Additional classes for the container */
27
+ containerClassName?: string;
28
+ /** Additional classes for the input */
29
+ inputClassName?: string;
30
+ /** The type that will be passed to the input being rendered */
31
+ inputType?: AllowedInputTypes;
32
+ /** Set to true to use a custom input renderer without default styling */
33
+ skipDefaultStyles?: boolean;
34
+ };
35
+ export type OTPContextValue = {
36
+ activeInput: number;
37
+ otp: string[];
38
+ handleChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
39
+ handleInputChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
40
+ handleFocus: (e: React.FocusEvent<HTMLInputElement>) => (index: number) => void;
41
+ handleBlur: () => void;
42
+ handleKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void;
43
+ handlePaste: (e: React.ClipboardEvent<HTMLInputElement>) => void;
44
+ };
45
+ export type OTPInputMachineContext = {
46
+ otp: string[];
47
+ activeInput: number;
48
+ numInputs: number;
49
+ inputType: AllowedInputTypes;
50
+ };
51
+ export type OTPInputMachineEvent = {
52
+ type: 'CHANGE';
53
+ value: string;
54
+ } | {
55
+ type: 'INPUT_CHANGE';
56
+ value: string;
57
+ } | {
58
+ type: 'FOCUS';
59
+ index: number;
60
+ } | {
61
+ type: 'BLUR';
62
+ } | {
63
+ type: 'KEY_DOWN';
64
+ key: string;
65
+ code: string;
66
+ } | {
67
+ type: 'PASTE';
68
+ pastedData: string;
69
+ } | {
70
+ type: 'SET_OTP';
71
+ otp: string[];
72
+ };
73
+ /**
74
+ * OTP Verification Component Props
75
+ */
76
+ export interface OTPVerificationProps {
77
+ /** Number of OTP input fields */
78
+ length?: number;
79
+ /** Function to call when OTP is verified successfully */
80
+ onVerificationSuccess?: () => void;
81
+ /** Function to call when verification fails */
82
+ onVerificationFailed?: () => void;
83
+ /** Function to handle OTP change */
84
+ onOtpChange?: (value: string) => void;
85
+ /** Function to call when continue button is clicked after successful verification */
86
+ onContinue?: () => void;
87
+ /** Function to call when resend code is clicked */
88
+ onResendCode?: () => void;
89
+ /** Valid OTP code for verification (for demo purposes - in production this would come from a backend) */
90
+ validCode?: string;
91
+ /** Title text displayed above the OTP input */
92
+ title?: string;
93
+ /** Description text below the title */
94
+ description?: string;
95
+ /** Success message shown after verification */
96
+ successMessage?: string;
97
+ /** Error message shown for invalid OTP */
98
+ errorMessage?: string;
99
+ /** Text for continue button after verification */
100
+ continueButtonText?: string;
101
+ /** Text for resend code */
102
+ resendCodeText?: string;
103
+ /** Verification delay in milliseconds */
104
+ verificationDelay?: number;
105
+ /** Reset delay after invalid code in milliseconds */
106
+ resetDelay?: number;
107
+ /** Whether to show the footer with Terms and Privacy links */
108
+ showFooter?: boolean;
109
+ }
110
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/OTP/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;AAEvE,MAAM,MAAM,UAAU,GAAG,QAAQ,CAC7B,IAAI,CACA,KAAK,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,EACzC,OAAO,GACP,UAAU,GACV,SAAS,GACT,QAAQ,GACR,WAAW,GACX,SAAS,GACT,YAAY,GACZ,cAAc,GACd,WAAW,GACX,SAAS,CACd,GAAG;IACA,GAAG,EAAE,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;IACzC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,iBAAiB,CAAC;CAC3B,CACJ,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IACxB,6BAA6B;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uDAAuD;IACvD,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,oEAAoE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+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+CAA+C;IAC/C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,0CAA0C;IAC1C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kDAAkD;IAClD,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,2BAA2B;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,yCAAyC;IACzC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,qDAAqD;IACrD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB"}
@@ -0,0 +1,26 @@
1
+ import { AllowedInputTypes } from './types';
2
+ /**
3
+ * Checks if an object is a style object (not null and is an object)
4
+ */
5
+ export declare const isStyleObject: (obj: unknown) => obj is Record<string, unknown>;
6
+ /**
7
+ * Checks if the input value is valid based on the input type
8
+ */
9
+ export declare const isInputValueValid: (value: string, isInputNum: boolean) => boolean;
10
+ /**
11
+ * Determines if the input is numeric based on the input type
12
+ */
13
+ export declare const isInputNumeric: (inputType: AllowedInputTypes) => boolean;
14
+ /**
15
+ * Converts the OTP string to an array of characters
16
+ */
17
+ export declare const otpStringToArray: (value?: string, length?: number) => string[];
18
+ /**
19
+ * Gets the placeholder value for the OTP input
20
+ */
21
+ export declare const getPlaceholderValue: (placeholder?: string, numInputs?: number) => string | undefined;
22
+ /**
23
+ * Calculates the next input index to focus
24
+ */
25
+ export declare const getNextInputIndex: (currentIndex: number, direction: 1 | -1, maxIndex: number) => number;
26
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/OTP/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5C;;GAEG;AACH,eAAO,MAAM,aAAa,QAAS,OAAO,KAAG,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAA4C,CAAC;AAEvH;;GAEG;AACH,eAAO,MAAM,iBAAiB,UAAW,MAAM,cAAc,OAAO,KAAG,OAGtE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,cAAe,iBAAiB,KAAG,OAAwD,CAAC;AAEvH;;GAEG;AACH,eAAO,MAAM,gBAAgB,WAAY,MAAM,sBAAe,MAAM,EACY,CAAC;AAEjF;;GAEG;AACH,eAAO,MAAM,mBAAmB,iBAAkB,MAAM,cAAc,MAAM,KAAG,MAAM,GAAG,SAWvF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,iBAAkB,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC,YAAY,MAAM,KAAG,MACjC,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Checks if an object is a style object (not null and is an object)
3
+ */
4
+ /**
5
+ * Checks if the input value is valid based on the input type
6
+ */
7
+ const isInputValueValid = (value, isInputNum) => {
8
+ const isTypeValid = isInputNum ? !isNaN(Number(value)) : typeof value === 'string';
9
+ return isTypeValid && value.trim().length === 1;
10
+ };
11
+ /**
12
+ * Determines if the input is numeric based on the input type
13
+ */
14
+ const isInputNumeric = inputType => inputType === 'number' || inputType === 'tel';
15
+ /**
16
+ * Converts the OTP string to an array of characters
17
+ */
18
+ const otpStringToArray = (value, length = 0) => value ? value.toString().split('').slice(0, length) : Array(length).fill('');
19
+ /**
20
+ * Gets the placeholder value for the OTP input
21
+ */
22
+ const getPlaceholderValue = (placeholder, numInputs) => {
23
+ if (typeof placeholder === 'string') {
24
+ if (placeholder.length === numInputs) {
25
+ return placeholder;
26
+ }
27
+ if (placeholder.length > 0) {
28
+ console.error('Length of the placeholder should be equal to the number of inputs.');
29
+ }
30
+ }
31
+ return undefined;
32
+ };
33
+ /**
34
+ * Calculates the next input index to focus
35
+ */
36
+ const getNextInputIndex = (currentIndex, direction, maxIndex) => Math.max(Math.min(maxIndex, currentIndex + direction), 0);export{getNextInputIndex,getPlaceholderValue,isInputNumeric,isInputValueValid,otpStringToArray};//# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":["../../../src/components/OTP/utils.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;AAEA;;AAGA;AAEA;;AAEG,MAAA,iBAAA,GAAA,CAAA,KAAA,EAAA,UAAA,KAAA;AACH,EAAO,MAAA,WAAA,sBAAkC,CAAA,MAAA,CAAA,KAAM,iBAAqB,KAAA;AAKpE,EAAA,OAAA,WAAA,IAAA,KAAA,CAAA,IAAA,EAAA,CAAA,MAAA,KAAA,CAAA;;AAEG;AACH;AAEA;;AAEG;AACH;AAGA;;AAEG;AACH;AAaA;;AAEG,EAAA,IAAA,OAAA,WAAA,KAAA,QAAA,EAAA;AACH,IAAA,IAAA,WAAa,CAAA,MAAA,KAAA,SAAmC,EAAA;;;;;;;;;;;;"}
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import type { PageContainerProps } from './types';
3
+ export declare const PageContainer: React.FC<PageContainerProps>;
4
+ //# sourceMappingURL=PageContainer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PageContainer.d.ts","sourceRoot":"","sources":["../../../src/components/PageContainer/PageContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGlD,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CA0DtD,CAAC"}