@siamf/otp-timer 4.5.0 → 5.0.3
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/README.md +13 -69
- package/dist/cjs/components/OtpTimers.d.ts +15 -0
- package/dist/cjs/components/OtpTimers.js +38 -0
- package/dist/cjs/components/OtpTimers.js.map +1 -0
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/components/OtpTimers.d.ts +15 -0
- package/dist/esm/components/OtpTimers.js +36 -0
- package/dist/esm/components/OtpTimers.js.map +1 -0
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/components/Otptimer.d.ts +0 -23
- package/dist/cjs/components/Otptimer.js +0 -51
- package/dist/cjs/components/Otptimer.js.map +0 -1
- package/dist/esm/components/Otptimer.d.ts +0 -23
- package/dist/esm/components/Otptimer.js +0 -46
- package/dist/esm/components/Otptimer.js.map +0 -1
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ $ npm i @siamf/otp-timer
|
|
|
35
35
|
### `OtpTimer` Component
|
|
36
36
|
|
|
37
37
|
```javascript
|
|
38
|
-
import {
|
|
38
|
+
import { OtpTimer } from "@siamf/otp-timer";
|
|
39
39
|
|
|
40
40
|
const MyComponent = () => {
|
|
41
41
|
|
|
@@ -45,7 +45,15 @@ const MyComponent = () => {
|
|
|
45
45
|
|
|
46
46
|
return (
|
|
47
47
|
<div>
|
|
48
|
-
<
|
|
48
|
+
<OtpTimer
|
|
49
|
+
minutes={0}
|
|
50
|
+
seconds={30}
|
|
51
|
+
onResend={handleResend}
|
|
52
|
+
renderText={(props) => <p>You can resend code in {props.minutes} minutes and {props.seconds} seconds</p>}
|
|
53
|
+
renderButton={(props) => <button {...props}>
|
|
54
|
+
Send Code Again
|
|
55
|
+
</button>}
|
|
56
|
+
/>
|
|
49
57
|
</div>
|
|
50
58
|
);
|
|
51
59
|
};
|
|
@@ -85,72 +93,8 @@ export default function App() {
|
|
|
85
93
|
|seconds|number of seconds for which timer must be set|30|
|
|
86
94
|
|minutes|number of minutes for which the timer must be set|0|
|
|
87
95
|
|onResend|function that would get triggered on clicking the resend button|n/a|
|
|
88
|
-
|
|
|
89
|
-
|
|
|
90
|
-
|showSpinner|If you want to show any button loading|false|
|
|
91
|
-
|fetching|If you want to show any button loading icon with fetching state|false|
|
|
92
|
-
|spinnerComponent|Your custom spinner component for render|null|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
### Styling
|
|
96
|
-
|
|
97
|
-
<table>
|
|
98
|
-
<tr>
|
|
99
|
-
<th> Name </th>
|
|
100
|
-
<th> Type </th>
|
|
101
|
-
<th> Description </th>
|
|
102
|
-
</tr>
|
|
103
|
-
<tr>
|
|
104
|
-
<td> containerClass </td>
|
|
105
|
-
<td> string </td>
|
|
106
|
-
<td> timer Container class name </td>
|
|
107
|
-
</tr>
|
|
108
|
-
<tr>
|
|
109
|
-
<td> textClass </td>
|
|
110
|
-
<td> string </td>
|
|
111
|
-
<td> text class name </td>
|
|
112
|
-
</tr>
|
|
113
|
-
<tr>
|
|
114
|
-
<td> timerClass </td>
|
|
115
|
-
<td> string </td>
|
|
116
|
-
<td> timer class name </td>
|
|
117
|
-
</tr>
|
|
118
|
-
<tr>
|
|
119
|
-
<td> buttonContainerClass </td>
|
|
120
|
-
<td> string </td>
|
|
121
|
-
<td> button container class </td>
|
|
122
|
-
</tr>
|
|
123
|
-
<tr>
|
|
124
|
-
<td> buttonClass </td>
|
|
125
|
-
<td> string </td>
|
|
126
|
-
<td> button class </td>
|
|
127
|
-
</tr>
|
|
128
|
-
<tr>
|
|
129
|
-
<td> buttonStyle </td>
|
|
130
|
-
<td> CSSProperties </td>
|
|
131
|
-
<td> styles for resend button </td>
|
|
132
|
-
</tr>
|
|
133
|
-
<tr>
|
|
134
|
-
<td> buttonContainerStyle </td>
|
|
135
|
-
<td> CSSProperties </td>
|
|
136
|
-
<td> styles for resend button container </td>
|
|
137
|
-
</tr>
|
|
138
|
-
<tr>
|
|
139
|
-
<td> textStyle </td>
|
|
140
|
-
<td> CSSProperties </td>
|
|
141
|
-
<td> styles for text </td>
|
|
142
|
-
</tr>
|
|
143
|
-
<tr>
|
|
144
|
-
<td> timerStyle </td>
|
|
145
|
-
<td> CSSProperties </td>
|
|
146
|
-
<td> styles for timer </td>
|
|
147
|
-
</tr>
|
|
148
|
-
<tr>
|
|
149
|
-
<td> textContainerStyle </td>
|
|
150
|
-
<td> CSSProperties </td>
|
|
151
|
-
<td> styles for timer text container </td>
|
|
152
|
-
</tr>
|
|
153
|
-
</table>
|
|
96
|
+
|renderText|Customizable text content(See Example Code)|Required|
|
|
97
|
+
|renderButton|Customizable button content(See Example Code)|Required|
|
|
154
98
|
|
|
155
99
|
## `OtpInput` component
|
|
156
100
|
|
|
@@ -267,4 +211,4 @@ You are welcome to create an issue.
|
|
|
267
211
|
|
|
268
212
|
- Author - [Siam Ahnaf](https://www.siamahnaf.com/)
|
|
269
213
|
- Website - [https://www.siamahnaf.com/](https://www.siamahnaf.com/)
|
|
270
|
-
- Github - [https://github.com/siamahnaf](https://github.com/siamahnaf)
|
|
214
|
+
- Github - [https://github.com/siamahnaf](https://github.com/siamahnaf)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface OtpTimerProps {
|
|
3
|
+
minutes?: number;
|
|
4
|
+
seconds?: number;
|
|
5
|
+
onResend: () => void;
|
|
6
|
+
renderText: (props: {
|
|
7
|
+
minutes: number;
|
|
8
|
+
seconds: number;
|
|
9
|
+
}) => React.ReactNode;
|
|
10
|
+
renderButton: (props: {
|
|
11
|
+
onClick: () => void;
|
|
12
|
+
}) => React.ReactElement<HTMLButtonElement>;
|
|
13
|
+
}
|
|
14
|
+
declare const OtpTimer: ({ minutes: initialMinutes, seconds: initialSeconds, onResend, renderText, renderButton, }: OtpTimerProps) => import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export default OtpTimer;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const OtpTimer = ({ minutes: initialMinutes = 0, seconds: initialSeconds = 30, onResend, renderText, renderButton, }) => {
|
|
6
|
+
//Error Throwing
|
|
7
|
+
if (initialSeconds > 59)
|
|
8
|
+
throw new Error("Seconds cannot be greater than 59");
|
|
9
|
+
if (initialMinutes > 59)
|
|
10
|
+
throw new Error("Minutes cannot be greater than 59");
|
|
11
|
+
//State
|
|
12
|
+
const [minutes, setMinutes] = (0, react_1.useState)(initialMinutes);
|
|
13
|
+
const [seconds, setSeconds] = (0, react_1.useState)(initialSeconds);
|
|
14
|
+
(0, react_1.useEffect)(() => {
|
|
15
|
+
if (minutes === 0 && seconds === 0)
|
|
16
|
+
return;
|
|
17
|
+
const interval = setInterval(() => {
|
|
18
|
+
if (seconds > 0) {
|
|
19
|
+
setSeconds((prev) => prev - 1);
|
|
20
|
+
}
|
|
21
|
+
else if (minutes > 0) {
|
|
22
|
+
setMinutes((prev) => prev - 1);
|
|
23
|
+
setSeconds(59);
|
|
24
|
+
}
|
|
25
|
+
}, 1000);
|
|
26
|
+
return () => clearInterval(interval);
|
|
27
|
+
}, [minutes, seconds]);
|
|
28
|
+
const handleResend = () => {
|
|
29
|
+
setMinutes(initialMinutes);
|
|
30
|
+
setSeconds(initialSeconds);
|
|
31
|
+
onResend();
|
|
32
|
+
};
|
|
33
|
+
return ((0, jsx_runtime_1.jsx)(react_1.Fragment, { children: minutes === 0 && seconds === 0
|
|
34
|
+
? renderButton({ onClick: handleResend })
|
|
35
|
+
: renderText({ minutes, seconds }) }));
|
|
36
|
+
};
|
|
37
|
+
exports.default = OtpTimer;
|
|
38
|
+
//# sourceMappingURL=Ot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AE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAEvB,MAAM,YAAY,GAAG,GAAG,EAAE;QACtB,UAAU,CAAC,cAAc,CAAC,CAAC;QAC3B,UAAU,CAAC,cAAc,CAAC,CAAC;QAC3B,QAAQ,EAAE,CAAC;IACf,CAAC,CAAC;IAEF,OAAO,CACH,uBAAC,gBAAQ,cACJ,OAAO,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC;YAC3B,CAAC,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;YACzC,CAAC,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,GAC/B,CACd,CAAC;AACN,CAAC,CAAC;AAEF,kBAAe,QAAQ,CAAC"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default as
|
|
1
|
+
export { default as OtpTimer } from "./components/OtpTimers";
|
|
2
2
|
export { default as OtpInput } from "./components/OtpInput";
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.OtpInput = exports.
|
|
7
|
-
var
|
|
8
|
-
Object.defineProperty(exports, "
|
|
6
|
+
exports.OtpInput = exports.OtpTimer = void 0;
|
|
7
|
+
var OtpTimers_1 = require("./components/OtpTimers");
|
|
8
|
+
Object.defineProperty(exports, "OtpTimer", { enumerable: true, get: function () { return __importDefault(OtpTimers_1).default; } });
|
|
9
9
|
var OtpInput_1 = require("./components/OtpInput");
|
|
10
10
|
Object.defineProperty(exports, "OtpInput", { enumerable: true, get: function () { return __importDefault(OtpInput_1).default; } });
|
|
11
11
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA6D;AAApD,sHAAA,OAAO,OAAY;AAC5B,kDAA4D;AAAnD,qHAAA,OAAO,OAAY"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface OtpTimerProps {
|
|
3
|
+
minutes?: number;
|
|
4
|
+
seconds?: number;
|
|
5
|
+
onResend: () => void;
|
|
6
|
+
renderText: (props: {
|
|
7
|
+
minutes: number;
|
|
8
|
+
seconds: number;
|
|
9
|
+
}) => React.ReactNode;
|
|
10
|
+
renderButton: (props: {
|
|
11
|
+
onClick: () => void;
|
|
12
|
+
}) => React.ReactElement<HTMLButtonElement>;
|
|
13
|
+
}
|
|
14
|
+
declare const OtpTimer: ({ minutes: initialMinutes, seconds: initialSeconds, onResend, renderText, renderButton, }: OtpTimerProps) => import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export default OtpTimer;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState, Fragment } from "react";
|
|
3
|
+
const OtpTimer = ({ minutes: initialMinutes = 0, seconds: initialSeconds = 30, onResend, renderText, renderButton, }) => {
|
|
4
|
+
//Error Throwing
|
|
5
|
+
if (initialSeconds > 59)
|
|
6
|
+
throw new Error("Seconds cannot be greater than 59");
|
|
7
|
+
if (initialMinutes > 59)
|
|
8
|
+
throw new Error("Minutes cannot be greater than 59");
|
|
9
|
+
//State
|
|
10
|
+
const [minutes, setMinutes] = useState(initialMinutes);
|
|
11
|
+
const [seconds, setSeconds] = useState(initialSeconds);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (minutes === 0 && seconds === 0)
|
|
14
|
+
return;
|
|
15
|
+
const interval = setInterval(() => {
|
|
16
|
+
if (seconds > 0) {
|
|
17
|
+
setSeconds((prev) => prev - 1);
|
|
18
|
+
}
|
|
19
|
+
else if (minutes > 0) {
|
|
20
|
+
setMinutes((prev) => prev - 1);
|
|
21
|
+
setSeconds(59);
|
|
22
|
+
}
|
|
23
|
+
}, 1000);
|
|
24
|
+
return () => clearInterval(interval);
|
|
25
|
+
}, [minutes, seconds]);
|
|
26
|
+
const handleResend = () => {
|
|
27
|
+
setMinutes(initialMinutes);
|
|
28
|
+
setSeconds(initialSeconds);
|
|
29
|
+
onResend();
|
|
30
|
+
};
|
|
31
|
+
return (_jsx(Fragment, { children: minutes === 0 && seconds === 0
|
|
32
|
+
? renderButton({ onClick: handleResend })
|
|
33
|
+
: renderText({ minutes, seconds }) }));
|
|
34
|
+
};
|
|
35
|
+
export default OtpTimer;
|
|
36
|
+
//# sourceMappingURL=OtpTimers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OtpTimers.js","sourceRoot":"","sources":["../../../src/components/OtpTimers.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAU7D,MAAM,QAAQ,GAAG,CAAC,EAAE,OAAO,EAAE,cAAc,GAAG,CAAC,EAAE,OAAO,EAAE,cAAc,GAAG,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,YAAY,GAAkB,EAAE,EAAE;IACnI,gBAAgB;IAChB,IAAI,cAAc,GAAG,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IAC9E,IAAI,cAAc,GAAG,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IAE9E,OAAO;IACP,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC;IACvD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC;IAEvD,SAAS,CAAC,GAAG,EAAE;QACX,IAAI,OAAO,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC;YAAE,OAAO;QAE3C,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE;YAC9B,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;gBACd,UAAU,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;YACnC,CAAC;iBAAM,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;gBACrB,UAAU,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;gBAC/B,UAAU,CAAC,EAAE,CAAC,CAAC;YACnB,CAAC;QACL,CAAC,EAAE,IAAI,CAAC,CAAC;QAET,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAEvB,MAAM,YAAY,GAAG,GAAG,EAAE;QACtB,UAAU,CAAC,cAAc,CAAC,CAAC;QAC3B,UAAU,CAAC,cAAc,CAAC,CAAC;QAC3B,QAAQ,EAAE,CAAC;IACf,CAAC,CAAC;IAEF,OAAO,CACH,KAAC,QAAQ,cACJ,OAAO,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC;YAC3B,CAAC,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;YACzC,CAAC,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,GAC/B,CACd,CAAC;AACN,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default as
|
|
1
|
+
export { default as OtpTimer } from "./components/OtpTimers";
|
|
2
2
|
export { default as OtpInput } from "./components/OtpInput";
|
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,uBAAuB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
interface Props {
|
|
3
|
-
seconds?: number;
|
|
4
|
-
minutes?: number;
|
|
5
|
-
text?: string;
|
|
6
|
-
buttonText?: string;
|
|
7
|
-
containerClass?: string;
|
|
8
|
-
buttonContainerClass?: string;
|
|
9
|
-
textClass?: string;
|
|
10
|
-
timerClass?: string;
|
|
11
|
-
buttonStyle?: React.CSSProperties;
|
|
12
|
-
buttonClass?: string;
|
|
13
|
-
textStyle?: React.CSSProperties;
|
|
14
|
-
timerStyle?: React.CSSProperties;
|
|
15
|
-
buttonContainerStyle?: React.CSSProperties;
|
|
16
|
-
textContainerStyle?: React.CSSProperties;
|
|
17
|
-
onResend: () => void;
|
|
18
|
-
fetching?: boolean;
|
|
19
|
-
showSpinner?: boolean;
|
|
20
|
-
spinnerComponent?: React.ReactNode;
|
|
21
|
-
}
|
|
22
|
-
declare const Otptimer: (props: Props) => import("react/jsx-runtime").JSX.Element;
|
|
23
|
-
export default Otptimer;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const Otptimer = (props) => {
|
|
9
|
-
//From props
|
|
10
|
-
const { text = "Resend otp in", containerClass = "otp-timer-container", buttonText = "Resend", textClass = "otp-text", buttonContainerClass = "button-container", timerClass = "otp-timer", buttonStyle, buttonContainerStyle, timerStyle, textStyle, textContainerStyle, onResend, fetching = false, buttonClass, showSpinner = false, spinnerComponent } = props;
|
|
11
|
-
//State
|
|
12
|
-
const [minutes, setMinutes] = react_1.default.useState(props.minutes ? props.minutes : 0);
|
|
13
|
-
const [seconds, setSeconds] = react_1.default.useState(props.seconds ? props.seconds : 30);
|
|
14
|
-
//Handler
|
|
15
|
-
let myInterval;
|
|
16
|
-
const onTimeHandler = () => {
|
|
17
|
-
myInterval = setInterval(() => {
|
|
18
|
-
if (seconds > 0) {
|
|
19
|
-
setSeconds(seconds - 1);
|
|
20
|
-
}
|
|
21
|
-
if (seconds === 0) {
|
|
22
|
-
if (minutes === 0) {
|
|
23
|
-
clearInterval(myInterval);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
setMinutes(minutes - 1);
|
|
27
|
-
setSeconds(59);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}, 1000);
|
|
31
|
-
};
|
|
32
|
-
//Effect
|
|
33
|
-
react_1.default.useEffect(() => {
|
|
34
|
-
onTimeHandler();
|
|
35
|
-
return () => clearInterval(myInterval);
|
|
36
|
-
});
|
|
37
|
-
//Handler
|
|
38
|
-
const resendHandler = () => {
|
|
39
|
-
setSeconds(props.seconds ? props.seconds : 30);
|
|
40
|
-
setMinutes(props.minutes ? props.minutes : 0);
|
|
41
|
-
onTimeHandler();
|
|
42
|
-
onResend();
|
|
43
|
-
};
|
|
44
|
-
//Styling
|
|
45
|
-
const ButtonStyles = Object.assign({ border: "none", background: "none", cursor: "pointer", padding: 0, margin: 0 }, buttonStyle);
|
|
46
|
-
const textContainerStyles = Object.assign({ fontSize: "15px" }, textContainerStyle);
|
|
47
|
-
return ((0, jsx_runtime_1.jsx)("div", { children: minutes === 0 && seconds === 0 ? ((0, jsx_runtime_1.jsx)("div", { className: buttonContainerClass, style: buttonContainerStyle, children: (0, jsx_runtime_1.jsxs)("button", { onClick: resendHandler, className: buttonClass, style: ButtonStyles, children: [(0, jsx_runtime_1.jsx)("span", { children: buttonText }), showSpinner && fetching &&
|
|
48
|
-
spinnerComponent] }) })) : ((0, jsx_runtime_1.jsxs)("div", { className: containerClass, style: textContainerStyles, children: [(0, jsx_runtime_1.jsx)("span", { className: textClass, style: textStyle, children: text }), " ", (0, jsx_runtime_1.jsxs)("span", { className: timerClass, style: timerStyle, children: [(0, jsx_runtime_1.jsx)("span", { children: minutes < 10 ? `0${minutes}` : minutes }), ":", (0, jsx_runtime_1.jsx)("span", { children: seconds < 10 ? `0${seconds}` : seconds })] })] })) }));
|
|
49
|
-
};
|
|
50
|
-
exports.default = Otptimer;
|
|
51
|
-
//# sourceMappingURL=Otptimer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Otptimer.js","sourceRoot":"","sources":["../../../src/components/Otptimer.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAwB1B,MAAM,QAAQ,GAAG,CAAC,KAAY,EAAE,EAAE;IAC9B,YAAY;IACZ,MAAM,EAAE,IAAI,GAAG,eAAe,EAAE,cAAc,GAAG,qBAAqB,EAAE,UAAU,GAAG,QAAQ,EAAE,SAAS,GAAG,UAAU,EAAE,oBAAoB,GAAG,kBAAkB,EAAE,UAAU,GAAG,WAAW,EAAE,WAAW,EAAE,oBAAoB,EAAE,UAAU,EAAE,SAAS,EAAE,kBAAkB,EAAE,QAAQ,EAAE,QAAQ,GAAG,KAAK,EAAE,WAAW,EAAE,WAAW,GAAG,KAAK,EAAE,gBAAgB,EAAE,GAAG,KAAK,CAAC;IACnW,OAAO;IACP,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,eAAK,CAAC,Q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6
|
-
buttonText?: string;
|
|
7
|
-
containerClass?: string;
|
|
8
|
-
buttonContainerClass?: string;
|
|
9
|
-
textClass?: string;
|
|
10
|
-
timerClass?: string;
|
|
11
|
-
buttonStyle?: React.CSSProperties;
|
|
12
|
-
buttonClass?: string;
|
|
13
|
-
textStyle?: React.CSSProperties;
|
|
14
|
-
timerStyle?: React.CSSProperties;
|
|
15
|
-
buttonContainerStyle?: React.CSSProperties;
|
|
16
|
-
textContainerStyle?: React.CSSProperties;
|
|
17
|
-
onResend: () => void;
|
|
18
|
-
fetching?: boolean;
|
|
19
|
-
showSpinner?: boolean;
|
|
20
|
-
spinnerComponent?: React.ReactNode;
|
|
21
|
-
}
|
|
22
|
-
declare const Otptimer: (props: Props) => import("react/jsx-runtime").JSX.Element;
|
|
23
|
-
export default Otptimer;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import React from 'react';
|
|
3
|
-
const Otptimer = (props) => {
|
|
4
|
-
//From props
|
|
5
|
-
const { text = "Resend otp in", containerClass = "otp-timer-container", buttonText = "Resend", textClass = "otp-text", buttonContainerClass = "button-container", timerClass = "otp-timer", buttonStyle, buttonContainerStyle, timerStyle, textStyle, textContainerStyle, onResend, fetching = false, buttonClass, showSpinner = false, spinnerComponent } = props;
|
|
6
|
-
//State
|
|
7
|
-
const [minutes, setMinutes] = React.useState(props.minutes ? props.minutes : 0);
|
|
8
|
-
const [seconds, setSeconds] = React.useState(props.seconds ? props.seconds : 30);
|
|
9
|
-
//Handler
|
|
10
|
-
let myInterval;
|
|
11
|
-
const onTimeHandler = () => {
|
|
12
|
-
myInterval = setInterval(() => {
|
|
13
|
-
if (seconds > 0) {
|
|
14
|
-
setSeconds(seconds - 1);
|
|
15
|
-
}
|
|
16
|
-
if (seconds === 0) {
|
|
17
|
-
if (minutes === 0) {
|
|
18
|
-
clearInterval(myInterval);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
setMinutes(minutes - 1);
|
|
22
|
-
setSeconds(59);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}, 1000);
|
|
26
|
-
};
|
|
27
|
-
//Effect
|
|
28
|
-
React.useEffect(() => {
|
|
29
|
-
onTimeHandler();
|
|
30
|
-
return () => clearInterval(myInterval);
|
|
31
|
-
});
|
|
32
|
-
//Handler
|
|
33
|
-
const resendHandler = () => {
|
|
34
|
-
setSeconds(props.seconds ? props.seconds : 30);
|
|
35
|
-
setMinutes(props.minutes ? props.minutes : 0);
|
|
36
|
-
onTimeHandler();
|
|
37
|
-
onResend();
|
|
38
|
-
};
|
|
39
|
-
//Styling
|
|
40
|
-
const ButtonStyles = Object.assign({ border: "none", background: "none", cursor: "pointer", padding: 0, margin: 0 }, buttonStyle);
|
|
41
|
-
const textContainerStyles = Object.assign({ fontSize: "15px" }, textContainerStyle);
|
|
42
|
-
return (_jsx("div", { children: minutes === 0 && seconds === 0 ? (_jsx("div", { className: buttonContainerClass, style: buttonContainerStyle, children: _jsxs("button", { onClick: resendHandler, className: buttonClass, style: ButtonStyles, children: [_jsx("span", { children: buttonText }), showSpinner && fetching &&
|
|
43
|
-
spinnerComponent] }) })) : (_jsxs("div", { className: containerClass, style: textContainerStyles, children: [_jsx("span", { className: textClass, style: textStyle, children: text }), " ", _jsxs("span", { className: timerClass, style: timerStyle, children: [_jsx("span", { children: minutes < 10 ? `0${minutes}` : minutes }), ":", _jsx("span", { children: seconds < 10 ? `0${seconds}` : seconds })] })] })) }));
|
|
44
|
-
};
|
|
45
|
-
export default Otptimer;
|
|
46
|
-
//# sourceMappingURL=Otptimer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Otptimer.js","sourceRoot":"","sources":["../../../src/components/Otptimer.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAwB1B,MAAM,QAAQ,GAAG,CAAC,KAAY,EAAE,EAAE;IAC9B,YA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