otp-timer 1.1.5 → 2.0.0
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 +9 -5
- package/example/index.css +3 -0
- package/example/index.js +4 -0
- package/example/webpack.config.js +5 -1
- package/lib/timer.js +47 -69
- package/package.json +15 -13
- package/src/timer.js +3 -2
package/README.md
CHANGED
|
@@ -45,10 +45,14 @@ Functionality:
|
|
|
45
45
|
|
|
46
46
|
Styling:
|
|
47
47
|
|
|
48
|
-
| Prop name
|
|
49
|
-
|
|
|
50
|
-
| textColor
|
|
51
|
-
| buttonColor
|
|
52
|
-
| background
|
|
48
|
+
| Prop name | Description | Default Value | Example |
|
|
49
|
+
| :-------------- | :-----------------------------------------: | :-----------: | ------------------------------: |
|
|
50
|
+
| textColor | describes the timer's text color | "#000000" | textColor={"#000000"} |
|
|
51
|
+
| buttonColor | describes the button's text color | "#fff" | buttonColor={"#fff"} |
|
|
52
|
+
| background | describe the background color of the button | "#0033cc" | background={"#0033cc"} |
|
|
53
|
+
| buttonClassName | describe custom classname for button | n/a | buttonClassName="btnClass" |
|
|
54
|
+
| buttonStyle | describe custome styles for button | - | buttonStyle={{color:"#fff"}} |
|
|
55
|
+
| timerSpanClass | describe custom classname for timerspan | - | timerSpanClass="timerClass" |
|
|
56
|
+
| timerSpanStyle | describe custom styles for timerspan | - | timerSpanStyle={{font:"Inter"}} |
|
|
53
57
|
|
|
54
58
|
---
|
package/example/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import OtpTimer from "../lib/timer";
|
|
2
2
|
import ReactDOM from "react-dom";
|
|
3
3
|
import React, { Component, PropTypes } from "react";
|
|
4
|
+
import './index.css'
|
|
4
5
|
|
|
5
6
|
class Example extends Component {
|
|
6
7
|
submit() {
|
|
@@ -15,6 +16,9 @@ class Example extends Component {
|
|
|
15
16
|
resend={this.submit.bind(this)}
|
|
16
17
|
text="Time:"
|
|
17
18
|
ButtonText="Resend"
|
|
19
|
+
timerSpanClass= "btn"
|
|
20
|
+
timerSpanStyle={{ fontSize: "16px" }}
|
|
21
|
+
buttonStyle={{ backgroundColor: "lightBlue" }}
|
|
18
22
|
/>
|
|
19
23
|
</div>
|
|
20
24
|
);
|
|
@@ -10,7 +10,11 @@ module.exports = {
|
|
|
10
10
|
test: /\.js$/,
|
|
11
11
|
use: [ { loader: 'babel-loader', options: { presets: ['@babel/preset-env', '@babel/react'] } } ],
|
|
12
12
|
exclude: /node_modules/,
|
|
13
|
-
}
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
test: /\.css$/,
|
|
16
|
+
use: ["style-loader", "css-loader"],
|
|
17
|
+
},
|
|
14
18
|
]
|
|
15
19
|
},
|
|
16
20
|
plugins: [
|
package/lib/timer.js
CHANGED
|
@@ -1,72 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
7
|
+
exports["default"] = void 0;
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
9
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
function _setPrototypeOf(
|
|
29
|
-
|
|
30
|
-
function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
31
|
-
|
|
32
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
33
|
-
|
|
34
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
35
|
-
|
|
36
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
37
|
-
|
|
38
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
39
|
-
|
|
40
|
-
var Otp = /*#__PURE__*/function (_Component) {
|
|
41
|
-
_inherits(Otp, _Component);
|
|
42
|
-
|
|
43
|
-
var _super = _createSuper(Otp);
|
|
44
|
-
|
|
45
|
-
_createClass(Otp, null, [{
|
|
46
|
-
key: "propTypes",
|
|
47
|
-
get: function get() {
|
|
48
|
-
return {
|
|
49
|
-
options: _propTypes.default.object
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
}]);
|
|
53
|
-
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
13
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
15
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
16
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
17
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
18
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
19
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
20
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
21
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
22
|
+
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
23
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
24
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
25
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
26
|
+
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
27
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
28
|
+
var Otp = exports["default"] = /*#__PURE__*/function (_Component) {
|
|
54
29
|
function Otp(props) {
|
|
55
30
|
var _this;
|
|
56
|
-
|
|
57
31
|
_classCallCheck(this, Otp);
|
|
58
|
-
|
|
59
|
-
_this = _super.call(this, props);
|
|
32
|
+
_this = _callSuper(this, Otp, [props]);
|
|
60
33
|
_this.state = {
|
|
61
34
|
showfield: false,
|
|
62
35
|
minutes: _this.props.minutes ? _this.props.minutes : 0,
|
|
63
36
|
seconds: _this.props.seconds ? _this.props.seconds : 30
|
|
64
37
|
};
|
|
65
|
-
_this.handleClick = _this.handleClick.bind(
|
|
38
|
+
_this.handleClick = _this.handleClick.bind(_this);
|
|
66
39
|
return _this;
|
|
67
40
|
}
|
|
68
|
-
|
|
69
|
-
_createClass(Otp, [{
|
|
41
|
+
_inherits(Otp, _Component);
|
|
42
|
+
return _createClass(Otp, [{
|
|
70
43
|
key: "componentDidMount",
|
|
71
44
|
value: function componentDidMount() {
|
|
72
45
|
clearInterval(this.myInterval);
|
|
@@ -76,13 +49,11 @@ var Otp = /*#__PURE__*/function (_Component) {
|
|
|
76
49
|
key: "otptimer",
|
|
77
50
|
value: function otptimer() {
|
|
78
51
|
var _this2 = this;
|
|
79
|
-
|
|
80
52
|
clearInterval(this.myInterval);
|
|
81
53
|
this.myInterval = setInterval(function () {
|
|
82
54
|
var _this2$state = _this2.state,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
55
|
+
seconds = _this2$state.seconds,
|
|
56
|
+
minutes = _this2$state.minutes;
|
|
86
57
|
if (seconds > 0) {
|
|
87
58
|
_this2.setState(function (_ref) {
|
|
88
59
|
var seconds = _ref.seconds;
|
|
@@ -91,7 +62,6 @@ var Otp = /*#__PURE__*/function (_Component) {
|
|
|
91
62
|
};
|
|
92
63
|
});
|
|
93
64
|
}
|
|
94
|
-
|
|
95
65
|
if (seconds === 0) {
|
|
96
66
|
if (minutes === 0) {
|
|
97
67
|
clearInterval(_this2.myInterval);
|
|
@@ -122,11 +92,11 @@ var Otp = /*#__PURE__*/function (_Component) {
|
|
|
122
92
|
this.props.resend();
|
|
123
93
|
this.otptimer();
|
|
124
94
|
event.preventDefault();
|
|
125
|
-
}
|
|
95
|
+
}
|
|
96
|
+
// wrapperFunction(e){
|
|
126
97
|
// this.props.resend;
|
|
127
98
|
// this.handleClick.bind(this);
|
|
128
99
|
// }
|
|
129
|
-
|
|
130
100
|
}, {
|
|
131
101
|
key: "render",
|
|
132
102
|
value: function render() {
|
|
@@ -138,21 +108,29 @@ var Otp = /*#__PURE__*/function (_Component) {
|
|
|
138
108
|
};
|
|
139
109
|
var buttonStyling = {
|
|
140
110
|
border: "none",
|
|
111
|
+
cursor: "pointer",
|
|
141
112
|
background: this.props.background ? this.props.background : "#0033cc",
|
|
142
113
|
color: this.props.buttonColor ? this.props.buttonColor : "#fff",
|
|
143
114
|
fontSize: "16px",
|
|
144
115
|
lineHeight: "22px"
|
|
145
116
|
};
|
|
146
|
-
return /*#__PURE__*/_react
|
|
117
|
+
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
147
118
|
style: textStyle
|
|
148
|
-
}, this.state.minutes === 0 && this.state.seconds === 0 ? /*#__PURE__*/_react
|
|
149
|
-
style: buttonStyling,
|
|
150
|
-
onClick: this.handleClick
|
|
151
|
-
|
|
119
|
+
}, this.state.minutes === 0 && this.state.seconds === 0 ? /*#__PURE__*/_react["default"].createElement("button", {
|
|
120
|
+
style: _objectSpread(_objectSpread({}, buttonStyling), this.props.buttonStyle),
|
|
121
|
+
onClick: this.handleClick,
|
|
122
|
+
className: this.props.buttonClassName
|
|
123
|
+
}, this.props.ButtonText ? /*#__PURE__*/_react["default"].createElement("span", null, this.props.ButtonText, " ") : /*#__PURE__*/_react["default"].createElement("span", null, "Resend")) : /*#__PURE__*/_react["default"].createElement("span", {
|
|
124
|
+
className: this.props.timerSpanClass,
|
|
125
|
+
style: this.props.timerSpanStyle
|
|
126
|
+
}, this.props.text ? /*#__PURE__*/_react["default"].createElement("span", null, this.props.text, " ") : /*#__PURE__*/_react["default"].createElement("span", null, "Time left: "), this.state.minutes < 10 ? "0".concat(this.state.minutes) : this.state.minutes, ":", this.state.seconds < 10 ? "0".concat(this.state.seconds) : this.state.seconds));
|
|
127
|
+
}
|
|
128
|
+
}], [{
|
|
129
|
+
key: "propTypes",
|
|
130
|
+
get: function get() {
|
|
131
|
+
return {
|
|
132
|
+
options: _propTypes["default"].object
|
|
133
|
+
};
|
|
152
134
|
}
|
|
153
135
|
}]);
|
|
154
|
-
|
|
155
|
-
return Otp;
|
|
156
|
-
}(_react.Component);
|
|
157
|
-
|
|
158
|
-
exports.default = Otp;
|
|
136
|
+
}(_react.Component);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "otp-timer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "otp timer component",
|
|
5
5
|
"main": "lib/timer.js",
|
|
6
6
|
"author": "Simran Gupta & Tanmay Sharma",
|
|
@@ -18,24 +18,26 @@
|
|
|
18
18
|
"react-dom": "^16.13.1"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@babel/cli": "^7.
|
|
22
|
-
"@babel/core": "7.
|
|
23
|
-
"@babel/preset-env": "7.
|
|
24
|
-
"@babel/preset-react": "7.
|
|
25
|
-
"babel-jest": "^
|
|
26
|
-
"babel-loader": "
|
|
21
|
+
"@babel/cli": "^7.23.0",
|
|
22
|
+
"@babel/core": "^7.23.0",
|
|
23
|
+
"@babel/preset-env": "^7.23.0",
|
|
24
|
+
"@babel/preset-react": "^7.22.5",
|
|
25
|
+
"babel-jest": "^29.7.0",
|
|
26
|
+
"babel-loader": "^9.1.3",
|
|
27
|
+
"css-loader": "^7.1.2",
|
|
27
28
|
"enzyme": "3.9.0",
|
|
28
29
|
"enzyme-adapter-react-16": "^1.9.1",
|
|
29
|
-
"html-webpack-plugin": "
|
|
30
|
-
"jest": "^
|
|
30
|
+
"html-webpack-plugin": "^5.5.3",
|
|
31
|
+
"jest": "^29.7.0",
|
|
31
32
|
"jsdom": "13.2.0",
|
|
32
|
-
"
|
|
33
|
-
"webpack
|
|
34
|
-
"webpack-
|
|
33
|
+
"style-loader": "^4.0.0",
|
|
34
|
+
"webpack": "^5.89.0",
|
|
35
|
+
"webpack-cli": "^5.1.4",
|
|
36
|
+
"webpack-dev-server": "^4.15.0"
|
|
35
37
|
},
|
|
36
38
|
"scripts": {
|
|
37
39
|
"build": "babel src --out-dir lib",
|
|
38
|
-
"dev": "webpack
|
|
40
|
+
"dev": "webpack serve --mode development --port 3001 --hot --config example/webpack.config.js",
|
|
39
41
|
"test": "jest"
|
|
40
42
|
},
|
|
41
43
|
"keywords": [
|
package/src/timer.js
CHANGED
|
@@ -75,6 +75,7 @@ export default class Otp extends Component {
|
|
|
75
75
|
|
|
76
76
|
const buttonStyling = {
|
|
77
77
|
border: "none",
|
|
78
|
+
cursor: "pointer",
|
|
78
79
|
background: this.props.background ? this.props.background : "#0033cc",
|
|
79
80
|
color: this.props.buttonColor ? this.props.buttonColor : "#fff",
|
|
80
81
|
fontSize: "16px",
|
|
@@ -84,7 +85,7 @@ export default class Otp extends Component {
|
|
|
84
85
|
return (
|
|
85
86
|
<div style={textStyle}>
|
|
86
87
|
{this.state.minutes === 0 && this.state.seconds === 0 ? (
|
|
87
|
-
<button style={buttonStyling} onClick={this.handleClick}>
|
|
88
|
+
<button style={{...buttonStyling, ...this.props.buttonStyle}} onClick={this.handleClick} className={this.props.buttonClassName}>
|
|
88
89
|
{this.props.ButtonText ? (
|
|
89
90
|
<span>{this.props.ButtonText} </span>
|
|
90
91
|
) : (
|
|
@@ -92,7 +93,7 @@ export default class Otp extends Component {
|
|
|
92
93
|
)}
|
|
93
94
|
</button>
|
|
94
95
|
) : (
|
|
95
|
-
<span>
|
|
96
|
+
<span className={this.props.timerSpanClass} style={this.props.timerSpanStyle}>
|
|
96
97
|
{this.props.text ? (
|
|
97
98
|
<span>{this.props.text} </span>
|
|
98
99
|
) : (
|