baseui 0.0.0-next-4847bd9 → 0.0.0-next-dfc9b64
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.
|
@@ -53,28 +53,38 @@ var ButtonTimed = function ButtonTimed(props) {
|
|
|
53
53
|
overrides = _props$overrides === void 0 ? {} : _props$overrides,
|
|
54
54
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
55
55
|
|
|
56
|
-
var _React$useState = React.useState(
|
|
56
|
+
var _React$useState = React.useState(Date.now()),
|
|
57
57
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
startTime = _React$useState2[0],
|
|
59
|
+
setStartTime = _React$useState2[1];
|
|
60
60
|
|
|
61
|
+
var _React$useState3 = React.useState(initialTime * 1000),
|
|
62
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
63
|
+
timeRemaining = _React$useState4[0],
|
|
64
|
+
setTimeRemaining = _React$useState4[1];
|
|
65
|
+
|
|
66
|
+
React.useEffect(function () {
|
|
67
|
+
if (!paused) {
|
|
68
|
+
setStartTime(Date.now() - (initialTime * 1000 - timeRemaining));
|
|
69
|
+
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
70
|
+
|
|
71
|
+
}, [paused, initialTime]);
|
|
61
72
|
React.useEffect(function () {
|
|
62
|
-
var
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
var intervalId = setInterval(function () {
|
|
74
|
+
if (!paused) {
|
|
75
|
+
var elapsed = Date.now() - startTime;
|
|
76
|
+
var remaining = Math.max(initialTime * 1000 - elapsed, 0);
|
|
77
|
+
setTimeRemaining(remaining);
|
|
78
|
+
|
|
79
|
+
if (remaining === 0) {
|
|
80
|
+
onClickProp();
|
|
81
|
+
}
|
|
67
82
|
}
|
|
68
83
|
}, 100);
|
|
69
|
-
|
|
70
|
-
if (timeRemaining === 0) {
|
|
71
|
-
onClickProp();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
84
|
return function () {
|
|
75
|
-
return
|
|
85
|
+
return clearInterval(intervalId);
|
|
76
86
|
};
|
|
77
|
-
}, [
|
|
87
|
+
}, [startTime, paused, onClickProp, initialTime]);
|
|
78
88
|
|
|
79
89
|
var onClick = function onClick() {
|
|
80
90
|
setTimeRemaining(0);
|
package/button-timed/utils.js
CHANGED
|
@@ -11,19 +11,19 @@ Copyright (c) Uber Technologies, Inc.
|
|
|
11
11
|
This source code is licensed under the MIT license found in the
|
|
12
12
|
LICENSE file in the root directory of this source tree.
|
|
13
13
|
*/
|
|
14
|
-
function roundUpToNearestInt(num) {
|
|
15
|
-
var cleanedNum = Math.trunc(num * 10) / 10;
|
|
16
|
-
return Math.ceil(cleanedNum);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
14
|
function padTo2Digits(num) {
|
|
20
15
|
return num.toString().padStart(2, '0');
|
|
21
16
|
}
|
|
22
17
|
|
|
23
18
|
var formatTime = function formatTime(totalMilliseconds) {
|
|
24
|
-
var totalSeconds = totalMilliseconds / 1000;
|
|
19
|
+
var totalSeconds = Math.floor(totalMilliseconds / 1000); // If there are remaining milliseconds, consider it as an extra second.
|
|
20
|
+
|
|
21
|
+
if (totalMilliseconds % 1000 > 0) {
|
|
22
|
+
totalSeconds += 1;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
25
|
var minutes = Math.floor(totalSeconds / 60);
|
|
26
|
-
var seconds =
|
|
26
|
+
var seconds = Math.floor(totalSeconds % 60);
|
|
27
27
|
return "".concat(minutes, ":").concat(padTo2Digits(seconds));
|
|
28
28
|
};
|
|
29
29
|
|
|
@@ -23,20 +23,28 @@ const ButtonTimed = props => {
|
|
|
23
23
|
overrides = {},
|
|
24
24
|
...restProps
|
|
25
25
|
} = props;
|
|
26
|
+
const [startTime, setStartTime] = React.useState(Date.now());
|
|
26
27
|
const [timeRemaining, setTimeRemaining] = React.useState(initialTime * 1000);
|
|
27
28
|
React.useEffect(() => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
}, 100);
|
|
29
|
+
if (!paused) {
|
|
30
|
+
setStartTime(Date.now() - (initialTime * 1000 - timeRemaining));
|
|
31
|
+
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
}, [paused, initialTime]);
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
const intervalId = setInterval(() => {
|
|
36
|
+
if (!paused) {
|
|
37
|
+
const elapsed = Date.now() - startTime;
|
|
38
|
+
const remaining = Math.max(initialTime * 1000 - elapsed, 0);
|
|
39
|
+
setTimeRemaining(remaining);
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
if (remaining === 0) {
|
|
42
|
+
onClickProp();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}, 100);
|
|
46
|
+
return () => clearInterval(intervalId);
|
|
47
|
+
}, [startTime, paused, onClickProp, initialTime]);
|
|
40
48
|
|
|
41
49
|
const onClick = () => {
|
|
42
50
|
setTimeRemaining(0);
|
package/es/button-timed/utils.js
CHANGED
|
@@ -4,18 +4,18 @@ Copyright (c) Uber Technologies, Inc.
|
|
|
4
4
|
This source code is licensed under the MIT license found in the
|
|
5
5
|
LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
function roundUpToNearestInt(num) {
|
|
8
|
-
const cleanedNum = Math.trunc(num * 10) / 10;
|
|
9
|
-
return Math.ceil(cleanedNum);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
7
|
function padTo2Digits(num) {
|
|
13
8
|
return num.toString().padStart(2, '0');
|
|
14
9
|
}
|
|
15
10
|
|
|
16
11
|
export const formatTime = totalMilliseconds => {
|
|
17
|
-
|
|
12
|
+
let totalSeconds = Math.floor(totalMilliseconds / 1000); // If there are remaining milliseconds, consider it as an extra second.
|
|
13
|
+
|
|
14
|
+
if (totalMilliseconds % 1000 > 0) {
|
|
15
|
+
totalSeconds += 1;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
18
|
const minutes = Math.floor(totalSeconds / 60);
|
|
19
|
-
const seconds =
|
|
19
|
+
const seconds = Math.floor(totalSeconds % 60);
|
|
20
20
|
return `${minutes}:${padTo2Digits(seconds)}`;
|
|
21
21
|
};
|
|
@@ -42,28 +42,38 @@ var ButtonTimed = function ButtonTimed(props) {
|
|
|
42
42
|
overrides = _props$overrides === void 0 ? {} : _props$overrides,
|
|
43
43
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
44
44
|
|
|
45
|
-
var _React$useState = React.useState(
|
|
45
|
+
var _React$useState = React.useState(Date.now()),
|
|
46
46
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
startTime = _React$useState2[0],
|
|
48
|
+
setStartTime = _React$useState2[1];
|
|
49
49
|
|
|
50
|
+
var _React$useState3 = React.useState(initialTime * 1000),
|
|
51
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
52
|
+
timeRemaining = _React$useState4[0],
|
|
53
|
+
setTimeRemaining = _React$useState4[1];
|
|
54
|
+
|
|
55
|
+
React.useEffect(function () {
|
|
56
|
+
if (!paused) {
|
|
57
|
+
setStartTime(Date.now() - (initialTime * 1000 - timeRemaining));
|
|
58
|
+
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
59
|
+
|
|
60
|
+
}, [paused, initialTime]);
|
|
50
61
|
React.useEffect(function () {
|
|
51
|
-
var
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
var intervalId = setInterval(function () {
|
|
63
|
+
if (!paused) {
|
|
64
|
+
var elapsed = Date.now() - startTime;
|
|
65
|
+
var remaining = Math.max(initialTime * 1000 - elapsed, 0);
|
|
66
|
+
setTimeRemaining(remaining);
|
|
67
|
+
|
|
68
|
+
if (remaining === 0) {
|
|
69
|
+
onClickProp();
|
|
70
|
+
}
|
|
56
71
|
}
|
|
57
72
|
}, 100);
|
|
58
|
-
|
|
59
|
-
if (timeRemaining === 0) {
|
|
60
|
-
onClickProp();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
73
|
return function () {
|
|
64
|
-
return
|
|
74
|
+
return clearInterval(intervalId);
|
|
65
75
|
};
|
|
66
|
-
}, [
|
|
76
|
+
}, [startTime, paused, onClickProp, initialTime]);
|
|
67
77
|
|
|
68
78
|
var onClick = function onClick() {
|
|
69
79
|
setTimeRemaining(0);
|
|
@@ -4,18 +4,18 @@ Copyright (c) Uber Technologies, Inc.
|
|
|
4
4
|
This source code is licensed under the MIT license found in the
|
|
5
5
|
LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
function roundUpToNearestInt(num) {
|
|
8
|
-
var cleanedNum = Math.trunc(num * 10) / 10;
|
|
9
|
-
return Math.ceil(cleanedNum);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
7
|
function padTo2Digits(num) {
|
|
13
8
|
return num.toString().padStart(2, '0');
|
|
14
9
|
}
|
|
15
10
|
|
|
16
11
|
export var formatTime = function formatTime(totalMilliseconds) {
|
|
17
|
-
var totalSeconds = totalMilliseconds / 1000;
|
|
12
|
+
var totalSeconds = Math.floor(totalMilliseconds / 1000); // If there are remaining milliseconds, consider it as an extra second.
|
|
13
|
+
|
|
14
|
+
if (totalMilliseconds % 1000 > 0) {
|
|
15
|
+
totalSeconds += 1;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
18
|
var minutes = Math.floor(totalSeconds / 60);
|
|
19
|
-
var seconds =
|
|
19
|
+
var seconds = Math.floor(totalSeconds % 60);
|
|
20
20
|
return "".concat(minutes, ":").concat(padTo2Digits(seconds));
|
|
21
21
|
};
|