Compare commits

...

6 Commits

Author SHA1 Message Date
689ff3cddb Fixed timeout and dists for build and publish
All checks were successful
continuous-integration/drone/push Build is passing
2021-04-30 19:11:28 +07:00
3b28919de1 Upgrade to verison 1.11.0
All checks were successful
continuous-integration/drone/push Build is passing
2021-04-30 17:42:37 +07:00
17a2d11f6a Updated git config 2021-04-30 17:42:03 +07:00
985ea41d64 Updated the version and add build
All checks were successful
continuous-integration/drone/push Build is passing
2021-03-10 18:02:12 +07:00
065bdef4e7 Upgrade to 1.10.8
All checks were successful
continuous-integration/drone/push Build is passing
2021-03-10 17:50:11 +07:00
76be5ed386 Add drone ci
All checks were successful
continuous-integration/drone/push Build is passing
2021-03-10 17:48:14 +07:00
9 changed files with 94 additions and 6 deletions

14
.drone.yml Normal file
View File

@@ -0,0 +1,14 @@
kind: pipeline
type: docker
name: ci
steps:
- name: npm
image: plugins/npm
settings:
username:
from_secret: NPM_USERNAME
password:
from_secret: NPM_PASSWORD
email:
from_secret: NPM_EMAIL

5
.gitignore vendored
View File

@@ -10,7 +10,4 @@
# Error File
yarn-error.log
/build
/dist
yarn-error.log

View File

@@ -1,5 +1,7 @@
# React Countdown Hook
[![Build Status](https://dci.osa.cubetiqs.com/api/badges/CUBETIQ/react-use-countdown/status.svg)](https://dci.osa.cubetiqs.com/CUBETIQ/react-use-countdown)
### Installation
```shell script
# NPM

1
dist/index.d.ts vendored Normal file
View File

@@ -0,0 +1 @@
export { default as useCountdown } from './useCountdown';

8
dist/index.js vendored Normal file
View File

@@ -0,0 +1,8 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useCountdown = void 0;
var useCountdown_1 = require("./useCountdown");
Object.defineProperty(exports, "useCountdown", { enumerable: true, get: function () { return __importDefault(useCountdown_1).default; } });

12
dist/useCountdown.d.ts vendored Normal file
View File

@@ -0,0 +1,12 @@
interface useCountdownOptions {
now?: () => Date;
onEnd?: () => void;
onCount?: (timeLeft: number) => void;
step?: number;
}
interface CountdownHookResult {
timeleft: number;
start: (timeLeft: number) => void;
}
declare function useCountdown(options?: useCountdownOptions): CountdownHookResult;
export default useCountdown;

54
dist/useCountdown.js vendored Normal file
View File

@@ -0,0 +1,54 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importDefault(require("react"));
var DEFAULT_OPTIONS = {
step: 1000,
};
function useCountdown(options) {
var _a = react_1.default.useState(), timeleft = _a[0], setTimeleft = _a[1];
var _b = react_1.default.useState(), targetDatetime = _b[0], setTargetDatetime = _b[1];
var _c = __assign(__assign({}, DEFAULT_OPTIONS), options), step = _c.step, onCount = _c.onCount, onEnd = _c.onEnd;
var start = function (countAsM) {
setTimeleft(countAsM);
};
var varTimeout = null;
react_1.default.useEffect(function () {
return function () { return clearTimeout(varTimeout); };
}, []);
react_1.default.useEffect(function () {
if (timeleft === undefined) {
return;
}
var newTimeleft = timeleft - step;
if (newTimeleft < 0) {
setTimeleft(0);
onEnd === null || onEnd === void 0 ? void 0 : onEnd();
}
else {
onCount === null || onCount === void 0 ? void 0 : onCount(timeleft);
varTimeout = setTimeout(function () {
setTimeleft(newTimeleft);
}, step);
}
}, [timeleft]);
var result = {
timeleft: timeleft || 0,
start: start,
};
return result;
}
exports.default = useCountdown;

View File

@@ -1,6 +1,6 @@
{
"name": "@cubetiq/react-use-countdown",
"version": "1.10.7",
"version": "1.11.1",
"description": "React Countdown with trigger",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",

View File

@@ -30,7 +30,7 @@ function useCountdown(options?: useCountdownOptions): CountdownHookResult {
const start = (countAsM: number) => {
setTimeleft(countAsM);
};
let varTimeout: number | null = null;
let varTimeout: Timeout | null = null;
React.useEffect(() => {
return () => clearTimeout(varTimeout!);