baseui 0.0.0-next-4847bd9 → 0.0.0-next-96b59fd

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.
@@ -90,7 +90,7 @@ var EndEnhancer = (0, _styles.styled)('div', function (_ref2) {
90
90
  var marginDirection = $theme.direction === 'rtl' ? 'marginRight' : 'marginLeft';
91
91
  return _defineProperty({
92
92
  display: 'flex'
93
- }, marginDirection, $theme.sizing.scale500);
93
+ }, marginDirection, $theme.sizing.scale300);
94
94
  });
95
95
  exports.EndEnhancer = EndEnhancer;
96
96
  EndEnhancer.displayName = "EndEnhancer";
@@ -100,7 +100,7 @@ var StartEnhancer = (0, _styles.styled)('div', function (_ref4) {
100
100
  var marginDirection = $theme.direction === 'rtl' ? 'marginLeft' : 'marginRight';
101
101
  return _defineProperty({
102
102
  display: 'flex'
103
- }, marginDirection, $theme.sizing.scale500);
103
+ }, marginDirection, $theme.sizing.scale300);
104
104
  });
105
105
  exports.StartEnhancer = StartEnhancer;
106
106
  StartEnhancer.displayName = "StartEnhancer";
@@ -72,7 +72,7 @@ export const EndEnhancer = styled<SharedStylePropsT>('div', ({ $theme }) => {
72
72
  const marginDirection: string = $theme.direction === 'rtl' ? 'marginRight' : 'marginLeft';
73
73
  return {
74
74
  display: 'flex',
75
- [marginDirection]: $theme.sizing.scale500,
75
+ [marginDirection]: $theme.sizing.scale300,
76
76
  };
77
77
  });
78
78
 
@@ -80,7 +80,7 @@ export const StartEnhancer = styled<SharedStylePropsT>('div', ({ $theme }) => {
80
80
  const marginDirection: string = $theme.direction === 'rtl' ? 'marginLeft' : 'marginRight';
81
81
  return {
82
82
  display: 'flex',
83
- [marginDirection]: $theme.sizing.scale500,
83
+ [marginDirection]: $theme.sizing.scale300,
84
84
  };
85
85
  });
86
86
 
@@ -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(initialTime * 1000),
56
+ var _React$useState = React.useState(Date.now()),
57
57
  _React$useState2 = _slicedToArray(_React$useState, 2),
58
- timeRemaining = _React$useState2[0],
59
- setTimeRemaining = _React$useState2[1];
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 timerId = setTimeout(function () {
63
- if (timeRemaining > 0 && !paused) {
64
- setTimeRemaining(function (seconds) {
65
- return seconds - 100;
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 clearTimeout(timerId);
85
+ return clearInterval(intervalId);
76
86
  };
77
- }, [timeRemaining, paused]);
87
+ }, [startTime, paused, onClickProp, initialTime]);
78
88
 
79
89
  var onClick = function onClick() {
80
90
  setTimeRemaining(0);
@@ -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 = roundUpToNearestInt(totalSeconds % 60);
26
+ var seconds = Math.floor(totalSeconds % 60);
27
27
  return "".concat(minutes, ":").concat(padTo2Digits(seconds));
28
28
  };
29
29
 
@@ -86,7 +86,7 @@ export const EndEnhancer = styled('div', ({
86
86
  const marginDirection = $theme.direction === 'rtl' ? 'marginRight' : 'marginLeft';
87
87
  return {
88
88
  display: 'flex',
89
- [marginDirection]: $theme.sizing.scale500
89
+ [marginDirection]: $theme.sizing.scale300
90
90
  };
91
91
  });
92
92
  EndEnhancer.displayName = "EndEnhancer";
@@ -97,7 +97,7 @@ export const StartEnhancer = styled('div', ({
97
97
  const marginDirection = $theme.direction === 'rtl' ? 'marginLeft' : 'marginRight';
98
98
  return {
99
99
  display: 'flex',
100
- [marginDirection]: $theme.sizing.scale500
100
+ [marginDirection]: $theme.sizing.scale300
101
101
  };
102
102
  });
103
103
  StartEnhancer.displayName = "StartEnhancer";
@@ -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
- const timerId = setTimeout(() => {
29
- if (timeRemaining > 0 && !paused) {
30
- setTimeRemaining(seconds => seconds - 100);
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
- if (timeRemaining === 0) {
35
- onClickProp();
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
- return () => clearTimeout(timerId);
39
- }, [timeRemaining, paused]);
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);
@@ -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
- const totalSeconds = totalMilliseconds / 1000;
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 = roundUpToNearestInt(totalSeconds % 60);
19
+ const seconds = Math.floor(totalSeconds % 60);
20
20
  return `${minutes}:${padTo2Digits(seconds)}`;
21
21
  };
@@ -86,7 +86,7 @@ export var EndEnhancer = styled('div', function (_ref2) {
86
86
  var marginDirection = $theme.direction === 'rtl' ? 'marginRight' : 'marginLeft';
87
87
  return _defineProperty({
88
88
  display: 'flex'
89
- }, marginDirection, $theme.sizing.scale500);
89
+ }, marginDirection, $theme.sizing.scale300);
90
90
  });
91
91
  EndEnhancer.displayName = "EndEnhancer";
92
92
  EndEnhancer.displayName = 'EndEnhancer';
@@ -95,7 +95,7 @@ export var StartEnhancer = styled('div', function (_ref4) {
95
95
  var marginDirection = $theme.direction === 'rtl' ? 'marginLeft' : 'marginRight';
96
96
  return _defineProperty({
97
97
  display: 'flex'
98
- }, marginDirection, $theme.sizing.scale500);
98
+ }, marginDirection, $theme.sizing.scale300);
99
99
  });
100
100
  StartEnhancer.displayName = "StartEnhancer";
101
101
  StartEnhancer.displayName = 'StartEnhancer';
@@ -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(initialTime * 1000),
45
+ var _React$useState = React.useState(Date.now()),
46
46
  _React$useState2 = _slicedToArray(_React$useState, 2),
47
- timeRemaining = _React$useState2[0],
48
- setTimeRemaining = _React$useState2[1];
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 timerId = setTimeout(function () {
52
- if (timeRemaining > 0 && !paused) {
53
- setTimeRemaining(function (seconds) {
54
- return seconds - 100;
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 clearTimeout(timerId);
74
+ return clearInterval(intervalId);
65
75
  };
66
- }, [timeRemaining, paused]);
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 = roundUpToNearestInt(totalSeconds % 60);
19
+ var seconds = Math.floor(totalSeconds % 60);
20
20
  return "".concat(minutes, ":").concat(padTo2Digits(seconds));
21
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baseui",
3
- "version": "0.0.0-next-4847bd9",
3
+ "version": "0.0.0-next-96b59fd",
4
4
  "description": "A React Component library implementing the Base design language",
5
5
  "keywords": [
6
6
  "react",