@akinon/pz-otp 2.0.0-beta.10 → 2.0.0-beta.12
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/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/readme.md +100 -0
- package/src/views/Otp.tsx +31 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @akinon/pz-otp
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.12
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 1d79e32: ZERO-3540: Next.js Upgrade to 15.4.5
|
|
8
|
+
|
|
9
|
+
## 2.0.0-beta.11
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- ac783d6: ZERO-3482: Update tailwindcss to version 4.1.11 and enhance button cursor styles
|
|
14
|
+
|
|
3
15
|
## 2.0.0-beta.10
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -9,3 +9,103 @@ You can use the following command to install the extension with the latest plugi
|
|
|
9
9
|
npx @akinon/projectzero@latest --plugins
|
|
10
10
|
|
|
11
11
|
```
|
|
12
|
+
|
|
13
|
+
### Props
|
|
14
|
+
|
|
15
|
+
| Property | Type | Description |
|
|
16
|
+
| --- | --- | --- |
|
|
17
|
+
| `customUIRender` | `React.ReactNode` | Optional function to fully customize the otp. Receives closeHandler, resendHandler, otp, setOtp, hasError, error, canResend, time, codeLength, setHasError and onSubmit props. |
|
|
18
|
+
|
|
19
|
+
### Customizing OTP
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
import PluginModule, { Component } from '@akinon/next/components/plugin-module';
|
|
23
|
+
|
|
24
|
+
<PluginModule
|
|
25
|
+
component={Component.Otp}
|
|
26
|
+
props={{
|
|
27
|
+
data: getValues(),
|
|
28
|
+
submitAction: registerHandler,
|
|
29
|
+
customUIRender: ({
|
|
30
|
+
closeHandler,
|
|
31
|
+
resendHandler,
|
|
32
|
+
onSubmit,
|
|
33
|
+
otp,
|
|
34
|
+
setOtp,
|
|
35
|
+
hasError,
|
|
36
|
+
error,
|
|
37
|
+
canResend,
|
|
38
|
+
time,
|
|
39
|
+
codeLength,
|
|
40
|
+
setHasError
|
|
41
|
+
}) => {
|
|
42
|
+
return (
|
|
43
|
+
<div className="fixed left-0 top-0 z-50 flex h-screen w-screen items-end md:items-center md:justify-center md:bg-black/10">
|
|
44
|
+
<div className="h-[calc(100vh-48px)] w-screen flex md:h-auto md:max-w-lg flex-col items-center rounded-sm bg-white p-8 shadow-xl">
|
|
45
|
+
<div className="w-full flex items-center justify-end">
|
|
46
|
+
<div className="cursor-pointer" onClick={closeHandler}>
|
|
47
|
+
<svg
|
|
48
|
+
width="14"
|
|
49
|
+
height="14"
|
|
50
|
+
viewBox="0 0 14 14"
|
|
51
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
52
|
+
>
|
|
53
|
+
<g fill="#000" fillRule="nonzero">
|
|
54
|
+
<path d="M.684 14A.684.684 0 0 1 .2 12.833L12.833.2a.684.684 0 1 1 .967.967L1.167 13.8a.682.682 0 0 1-.483.2z" />
|
|
55
|
+
<path d="M13.316 14a.682.682 0 0 1-.483-.2L.2 1.167A.684.684 0 0 1 1.167.2L13.8 12.833A.684.684 0 0 1 13.316 14z" />
|
|
56
|
+
</g>
|
|
57
|
+
</svg>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
<div className="flex flex-col items-center px-14 mt-5">
|
|
61
|
+
<div className="text-2xl font-medium">OTP Verification</div>
|
|
62
|
+
<div className={twMerge('mt-2.5 text-center text-gray-700')}>
|
|
63
|
+
{`Please enter the ${codeLength}-digit sms code sent to your registered number and email address`}
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
<form
|
|
67
|
+
onSubmit={onSubmit}
|
|
68
|
+
className="flex flex-col items-center w-full"
|
|
69
|
+
>
|
|
70
|
+
<OtpInput
|
|
71
|
+
value={otp}
|
|
72
|
+
onChange={(otp) => {
|
|
73
|
+
setOtp(otp);
|
|
74
|
+
setHasError(false);
|
|
75
|
+
}}
|
|
76
|
+
numInputs={codeLength}
|
|
77
|
+
containerStyle="mt-12 gap-2 flex-wrap"
|
|
78
|
+
inputStyle={twMerge(
|
|
79
|
+
'h-12 w-8 md:h-16 md:w-12 rounded-md border border-gray-600 text-center text-lg',
|
|
80
|
+
hasError && 'border-error'
|
|
81
|
+
)}
|
|
82
|
+
renderInput={({ ...props }) => <input {...props} />}
|
|
83
|
+
skipDefaultStyles={true}
|
|
84
|
+
/>
|
|
85
|
+
{error && <p className="text-xs text-error mt-2">{error}</p>}
|
|
86
|
+
<Button
|
|
87
|
+
type="submit"
|
|
88
|
+
className="mt-5 h-auto w-full py-4 text-lg font-medium uppercase"
|
|
89
|
+
>
|
|
90
|
+
Verify
|
|
91
|
+
</Button>
|
|
92
|
+
</form>
|
|
93
|
+
<div className="mt-6 flex flex-col items-center">
|
|
94
|
+
<span className="text-gray-700">I didn`t receive a code</span>
|
|
95
|
+
<div
|
|
96
|
+
className={twMerge(
|
|
97
|
+
' font-medium underline cursor-pointer',
|
|
98
|
+
!canResend && 'cursor-not-allowed text-gray-700'
|
|
99
|
+
)}
|
|
100
|
+
onClick={resendHandler}
|
|
101
|
+
>
|
|
102
|
+
RESEND
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}}
|
|
110
|
+
/>;
|
|
111
|
+
```
|
package/src/views/Otp.tsx
CHANGED
|
@@ -43,6 +43,19 @@ type OtpProps = {
|
|
|
43
43
|
[c in ComponentClasses]?: string;
|
|
44
44
|
};
|
|
45
45
|
error?: string;
|
|
46
|
+
customUIRender?: (props: {
|
|
47
|
+
closeHandler?: () => void;
|
|
48
|
+
resendHandler?: () => void;
|
|
49
|
+
onSubmit?: (event: FormEvent<HTMLFormElement>) => Promise<void>;
|
|
50
|
+
otp?: string;
|
|
51
|
+
setOtp?: (otp: string) => void;
|
|
52
|
+
hasError?: boolean;
|
|
53
|
+
error?: string;
|
|
54
|
+
canResend?: boolean;
|
|
55
|
+
time?: number;
|
|
56
|
+
codeLength?: number;
|
|
57
|
+
setHasError?: (hasError: boolean) => void;
|
|
58
|
+
}) => ReactNode;
|
|
46
59
|
};
|
|
47
60
|
|
|
48
61
|
export const Otp = ({
|
|
@@ -52,7 +65,8 @@ export const Otp = ({
|
|
|
52
65
|
timer = 60,
|
|
53
66
|
texts,
|
|
54
67
|
classes,
|
|
55
|
-
error
|
|
68
|
+
error,
|
|
69
|
+
customUIRender
|
|
56
70
|
}: OtpProps) => {
|
|
57
71
|
const { phone } = data;
|
|
58
72
|
const [otp, setOtp] = useState('');
|
|
@@ -129,6 +143,22 @@ export const Otp = ({
|
|
|
129
143
|
|
|
130
144
|
if (!isPopupVisible) return null;
|
|
131
145
|
|
|
146
|
+
if (customUIRender) {
|
|
147
|
+
return customUIRender({
|
|
148
|
+
closeHandler,
|
|
149
|
+
resendHandler,
|
|
150
|
+
onSubmit,
|
|
151
|
+
otp,
|
|
152
|
+
setOtp,
|
|
153
|
+
hasError,
|
|
154
|
+
error,
|
|
155
|
+
canResend,
|
|
156
|
+
time,
|
|
157
|
+
codeLength,
|
|
158
|
+
setHasError
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
132
162
|
return (
|
|
133
163
|
<div className="fixed left-0 top-0 z-50 flex h-screen w-screen items-end md:items-center md:justify-center md:bg-black/10">
|
|
134
164
|
<div className="h-[calc(100vh-48px)] w-screen flex md:h-auto md:max-w-lg flex-col items-center rounded-xs bg-white p-8 shadow-xl">
|