@helpdice/ui 1.4.7 → 1.4.9
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/dist/button/button.compact.d.ts +15 -0
- package/dist/button/button.d.ts +1 -0
- package/dist/button/index.d.ts +1 -0
- package/dist/button/index.js +143 -63
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1652 -1301
- package/dist/modal/index.js +7 -5
- package/dist/table/index.js +12 -7
- package/dist/table/table-column.d.ts +1 -0
- package/dist/ui-provider/index.js +7 -5
- package/esm/button/button.compact.d.ts +15 -0
- package/esm/button/button.compact.js +77 -0
- package/esm/button/button.d.ts +1 -0
- package/esm/button/button.js +7 -5
- package/esm/button/index.d.ts +1 -0
- package/esm/button/index.js +1 -0
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -1
- package/esm/table/table-column.d.ts +1 -0
- package/esm/table/table-column.js +3 -1
- package/esm/table/table-head.js +2 -1
- package/esm/timer/hooks/index.js +2 -0
- package/esm/timer/hooks/useInterval.js +20 -0
- package/esm/timer/index.js +21 -0
- package/esm/timer/useStopwatch.js +55 -0
- package/esm/timer/useTime.js +17 -0
- package/esm/timer/useTimer.js +87 -0
- package/esm/timer/utils/Time.js +75 -0
- package/esm/timer/utils/Validate.js +27 -0
- package/esm/timer/utils/index.js +3 -0
- package/package.json +3 -2
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import { useState, useCallback } from 'react';
|
|
4
|
+
import { Time, Validate } from './utils';
|
|
5
|
+
import { useInterval } from './hooks';
|
|
6
|
+
var DEFAULT_DELAY = 1000;
|
|
7
|
+
function getDelayFromExpiryTimestamp(expiryTimestamp) {
|
|
8
|
+
if (!Validate.expiryTimestamp(expiryTimestamp)) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
var seconds = Time.getSecondsFromExpiry(expiryTimestamp);
|
|
12
|
+
var extraMilliSeconds = Math.floor((seconds - Math.floor(seconds)) * 1000);
|
|
13
|
+
return extraMilliSeconds > 0 ? extraMilliSeconds : DEFAULT_DELAY;
|
|
14
|
+
}
|
|
15
|
+
export default function useTimer() {
|
|
16
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
17
|
+
expiry = _ref.expiryTimestamp,
|
|
18
|
+
onExpire = _ref.onExpire,
|
|
19
|
+
_ref$autoStart = _ref.autoStart,
|
|
20
|
+
autoStart = _ref$autoStart === void 0 ? true : _ref$autoStart;
|
|
21
|
+
var _useState = useState(expiry),
|
|
22
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
23
|
+
expiryTimestamp = _useState2[0],
|
|
24
|
+
setExpiryTimestamp = _useState2[1];
|
|
25
|
+
var _useState3 = useState(Time.getSecondsFromExpiry(expiryTimestamp)),
|
|
26
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
27
|
+
seconds = _useState4[0],
|
|
28
|
+
setSeconds = _useState4[1];
|
|
29
|
+
var _useState5 = useState(autoStart),
|
|
30
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
31
|
+
isRunning = _useState6[0],
|
|
32
|
+
setIsRunning = _useState6[1];
|
|
33
|
+
var _useState7 = useState(autoStart),
|
|
34
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
35
|
+
didStart = _useState8[0],
|
|
36
|
+
setDidStart = _useState8[1];
|
|
37
|
+
var _useState9 = useState(getDelayFromExpiryTimestamp(expiryTimestamp)),
|
|
38
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
39
|
+
delay = _useState10[0],
|
|
40
|
+
setDelay = _useState10[1];
|
|
41
|
+
var handleExpire = useCallback(function () {
|
|
42
|
+
Validate.onExpire(onExpire) && onExpire();
|
|
43
|
+
setIsRunning(false);
|
|
44
|
+
setDelay(null);
|
|
45
|
+
}, [onExpire]);
|
|
46
|
+
var pause = useCallback(function () {
|
|
47
|
+
setIsRunning(false);
|
|
48
|
+
}, []);
|
|
49
|
+
var restart = useCallback(function (newExpiryTimestamp) {
|
|
50
|
+
var newAutoStart = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
51
|
+
setDelay(getDelayFromExpiryTimestamp(newExpiryTimestamp));
|
|
52
|
+
setDidStart(newAutoStart);
|
|
53
|
+
setIsRunning(newAutoStart);
|
|
54
|
+
setExpiryTimestamp(newExpiryTimestamp);
|
|
55
|
+
setSeconds(Time.getSecondsFromExpiry(newExpiryTimestamp));
|
|
56
|
+
}, []);
|
|
57
|
+
var resume = useCallback(function () {
|
|
58
|
+
var time = new Date();
|
|
59
|
+
time.setMilliseconds(time.getMilliseconds() + seconds * 1000);
|
|
60
|
+
restart(time);
|
|
61
|
+
}, [seconds, restart]);
|
|
62
|
+
var start = useCallback(function () {
|
|
63
|
+
if (didStart) {
|
|
64
|
+
setSeconds(Time.getSecondsFromExpiry(expiryTimestamp));
|
|
65
|
+
setIsRunning(true);
|
|
66
|
+
} else {
|
|
67
|
+
resume();
|
|
68
|
+
}
|
|
69
|
+
}, [expiryTimestamp, didStart, resume]);
|
|
70
|
+
useInterval(function () {
|
|
71
|
+
if (delay !== DEFAULT_DELAY) {
|
|
72
|
+
setDelay(DEFAULT_DELAY);
|
|
73
|
+
}
|
|
74
|
+
var secondsValue = Time.getSecondsFromExpiry(expiryTimestamp);
|
|
75
|
+
setSeconds(secondsValue);
|
|
76
|
+
if (secondsValue <= 0) {
|
|
77
|
+
handleExpire();
|
|
78
|
+
}
|
|
79
|
+
}, isRunning ? delay : null);
|
|
80
|
+
return _extends({}, Time.getTimeFromSeconds(seconds), {
|
|
81
|
+
start: start,
|
|
82
|
+
pause: pause,
|
|
83
|
+
resume: resume,
|
|
84
|
+
restart: restart,
|
|
85
|
+
isRunning: isRunning
|
|
86
|
+
});
|
|
87
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
var Time = /*#__PURE__*/function () {
|
|
4
|
+
function Time() {
|
|
5
|
+
_classCallCheck(this, Time);
|
|
6
|
+
}
|
|
7
|
+
return _createClass(Time, null, [{
|
|
8
|
+
key: "getTimeFromSeconds",
|
|
9
|
+
value: function getTimeFromSeconds(secs) {
|
|
10
|
+
var totalSeconds = Math.ceil(secs);
|
|
11
|
+
var days = Math.floor(totalSeconds / (60 * 60 * 24));
|
|
12
|
+
var hours = Math.floor(totalSeconds % (60 * 60 * 24) / (60 * 60));
|
|
13
|
+
var minutes = Math.floor(totalSeconds % (60 * 60) / 60);
|
|
14
|
+
var seconds = Math.floor(totalSeconds % 60);
|
|
15
|
+
return {
|
|
16
|
+
totalSeconds: totalSeconds,
|
|
17
|
+
seconds: seconds,
|
|
18
|
+
minutes: minutes,
|
|
19
|
+
hours: hours,
|
|
20
|
+
days: days
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}, {
|
|
24
|
+
key: "getSecondsFromExpiry",
|
|
25
|
+
value: function getSecondsFromExpiry(expiry, shouldRound) {
|
|
26
|
+
var now = new Date().getTime();
|
|
27
|
+
var milliSecondsDistance = expiry - now;
|
|
28
|
+
if (milliSecondsDistance > 0) {
|
|
29
|
+
var val = milliSecondsDistance / 1000;
|
|
30
|
+
return shouldRound ? Math.round(val) : val;
|
|
31
|
+
}
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
}, {
|
|
35
|
+
key: "getSecondsFromPrevTime",
|
|
36
|
+
value: function getSecondsFromPrevTime(prevTime, shouldRound) {
|
|
37
|
+
var now = new Date().getTime();
|
|
38
|
+
var milliSecondsDistance = now - prevTime;
|
|
39
|
+
if (milliSecondsDistance > 0) {
|
|
40
|
+
var val = milliSecondsDistance / 1000;
|
|
41
|
+
return shouldRound ? Math.round(val) : val;
|
|
42
|
+
}
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
}, {
|
|
46
|
+
key: "getSecondsFromTimeNow",
|
|
47
|
+
value: function getSecondsFromTimeNow() {
|
|
48
|
+
var now = new Date();
|
|
49
|
+
var currentTimestamp = now.getTime();
|
|
50
|
+
var offset = now.getTimezoneOffset() * 60;
|
|
51
|
+
return currentTimestamp / 1000 - offset;
|
|
52
|
+
}
|
|
53
|
+
}, {
|
|
54
|
+
key: "getFormattedTimeFromSeconds",
|
|
55
|
+
value: function getFormattedTimeFromSeconds(totalSeconds, format) {
|
|
56
|
+
var _Time$getTimeFromSeco = Time.getTimeFromSeconds(totalSeconds),
|
|
57
|
+
secondsValue = _Time$getTimeFromSeco.seconds,
|
|
58
|
+
minutes = _Time$getTimeFromSeco.minutes,
|
|
59
|
+
hours = _Time$getTimeFromSeco.hours;
|
|
60
|
+
var ampm = '';
|
|
61
|
+
var hoursValue = hours;
|
|
62
|
+
if (format === '12-hour') {
|
|
63
|
+
ampm = hours >= 12 ? 'pm' : 'am';
|
|
64
|
+
hoursValue = hours % 12;
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
seconds: secondsValue,
|
|
68
|
+
minutes: minutes,
|
|
69
|
+
hours: hoursValue,
|
|
70
|
+
ampm: ampm
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}]);
|
|
74
|
+
}();
|
|
75
|
+
export { Time as default };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
var Validate = /*#__PURE__*/function () {
|
|
4
|
+
function Validate() {
|
|
5
|
+
_classCallCheck(this, Validate);
|
|
6
|
+
}
|
|
7
|
+
return _createClass(Validate, null, [{
|
|
8
|
+
key: "expiryTimestamp",
|
|
9
|
+
value: function expiryTimestamp(_expiryTimestamp) {
|
|
10
|
+
var isValid = new Date(_expiryTimestamp).getTime() > 0;
|
|
11
|
+
if (!isValid) {
|
|
12
|
+
console.warn('react-timer-hook: { useTimer } Invalid expiryTimestamp settings', _expiryTimestamp); // eslint-disable-line
|
|
13
|
+
}
|
|
14
|
+
return isValid;
|
|
15
|
+
}
|
|
16
|
+
}, {
|
|
17
|
+
key: "onExpire",
|
|
18
|
+
value: function onExpire(_onExpire) {
|
|
19
|
+
var isValid = _onExpire && typeof _onExpire === 'function';
|
|
20
|
+
if (_onExpire && !isValid) {
|
|
21
|
+
console.warn('react-timer-hook: { useTimer } Invalid onExpire settings function', _onExpire); // eslint-disable-line
|
|
22
|
+
}
|
|
23
|
+
return isValid;
|
|
24
|
+
}
|
|
25
|
+
}]);
|
|
26
|
+
}();
|
|
27
|
+
export { Validate as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helpdice/ui",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.9",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "esm/index.d.ts",
|
|
6
6
|
"unpkg": "dist/index.min.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"build:after": "node scripts/move-built-in.js",
|
|
23
23
|
"build:types": "tsc -p ./scripts & tsc -p ./scripts --outDir ./esm",
|
|
24
24
|
"build": "yarn build:rollup && yarn build:babel && yarn build:types && yarn build:after",
|
|
25
|
-
"
|
|
25
|
+
"pusher": "yarn build && yarn publish --access public --non-interactive"
|
|
26
26
|
},
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"description": "Modern React UI library.",
|
|
@@ -105,6 +105,7 @@
|
|
|
105
105
|
"lodash-es": "^4.17.21",
|
|
106
106
|
"polished": "^4.3.1",
|
|
107
107
|
"push": "^0.1.1",
|
|
108
|
+
"pusher": "^5.2.0",
|
|
108
109
|
"react-fast-compare": "^3.2.2",
|
|
109
110
|
"react-is": "^19.0.0",
|
|
110
111
|
"react-syntax-highlighter": "^15.6.1",
|