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 CHANGED
@@ -45,10 +45,14 @@ Functionality:
45
45
 
46
46
  Styling:
47
47
 
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"} |
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
  ---
@@ -0,0 +1,3 @@
1
+ .btn {
2
+ color:red !important;
3
+ }
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.default = void 0;
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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
15
-
16
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
-
18
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
19
-
20
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
-
22
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
23
-
24
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
25
-
26
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
27
-
28
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
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(_assertThisInitialized(_this));
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
- seconds = _this2$state.seconds,
84
- minutes = _this2$state.minutes;
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
- } // wrapperFunction(e){
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.default.createElement("div", {
117
+ return /*#__PURE__*/_react["default"].createElement("div", {
147
118
  style: textStyle
148
- }, this.state.minutes === 0 && this.state.seconds === 0 ? /*#__PURE__*/_react.default.createElement("button", {
149
- style: buttonStyling,
150
- onClick: this.handleClick
151
- }, this.props.ButtonText ? /*#__PURE__*/_react.default.createElement("span", null, this.props.ButtonText, " ") : /*#__PURE__*/_react.default.createElement("span", null, "Resend")) : /*#__PURE__*/_react.default.createElement("span", null, 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));
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": "1.1.5",
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.2.3",
22
- "@babel/core": "7.3.3",
23
- "@babel/preset-env": "7.3.1",
24
- "@babel/preset-react": "7.0.0",
25
- "babel-jest": "^24.7.1",
26
- "babel-loader": "8.0.5",
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": "3.2.0",
30
- "jest": "^24.7.1",
30
+ "html-webpack-plugin": "^5.5.3",
31
+ "jest": "^29.7.0",
31
32
  "jsdom": "13.2.0",
32
- "webpack": "4.29.4",
33
- "webpack-cli": "3.2.3",
34
- "webpack-dev-server": "3.1.14"
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-dev-server --mode=development --port 3001 --inline --hot --config example/webpack.config",
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
  ) : (