baseui 0.0.0-next-d88589e → 0.0.0-next-95cbfa8
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/badge/styled-components.js.flow +5 -0
- package/button-timed/button-timed.d.ts +4 -0
- package/button-timed/button-timed.js +124 -0
- package/button-timed/index.d.ts +5 -0
- package/button-timed/index.js +78 -0
- package/button-timed/index.js.flow +57 -0
- package/button-timed/package.json +4 -0
- package/button-timed/styled-components.d.ts +5 -0
- package/button-timed/styled-components.js +59 -0
- package/button-timed/types.d.ts +12 -0
- package/button-timed/types.js +5 -0
- package/button-timed/utils.d.ts +1 -0
- package/button-timed/utils.js +30 -0
- package/es/button-timed/button-timed.js +82 -0
- package/es/button-timed/index.js +11 -0
- package/es/button-timed/styled-components.js +49 -0
- package/es/button-timed/types.js +1 -0
- package/es/button-timed/utils.js +21 -0
- package/es/message-card/styled-components.js +6 -1
- package/esm/button-timed/button-timed.js +112 -0
- package/esm/button-timed/index.js +11 -0
- package/esm/button-timed/styled-components.js +53 -0
- package/esm/button-timed/types.js +1 -0
- package/esm/button-timed/utils.js +21 -0
- package/esm/message-card/styled-components.js +6 -1
- package/message-card/styled-components.js +6 -1
- package/package.json +1 -1
|
@@ -184,6 +184,7 @@ export const StyledRoot = styled<{}>('div', () => {
|
|
|
184
184
|
lineHeight: 'initial',
|
|
185
185
|
};
|
|
186
186
|
});
|
|
187
|
+
StyledRoot.displayName = 'StyledRoot';
|
|
187
188
|
|
|
188
189
|
const TOP_PLACEMENTS = [
|
|
189
190
|
PLACEMENT.topLeft,
|
|
@@ -254,6 +255,7 @@ export const StyledPositioner = styled<{
|
|
|
254
255
|
lineHeight: 'initial',
|
|
255
256
|
};
|
|
256
257
|
});
|
|
258
|
+
StyledPositioner.displayName = 'StyledPositioner';
|
|
257
259
|
|
|
258
260
|
export const StyledBadge = styled<{
|
|
259
261
|
$shape?: ShapeT,
|
|
@@ -286,6 +288,7 @@ export const StyledBadge = styled<{
|
|
|
286
288
|
};
|
|
287
289
|
}
|
|
288
290
|
);
|
|
291
|
+
StyledBadge.displayName = 'StyledBadge';
|
|
289
292
|
|
|
290
293
|
export const StyledNotificationCircle = styled<{
|
|
291
294
|
$color?: ColorT,
|
|
@@ -303,6 +306,7 @@ export const StyledNotificationCircle = styled<{
|
|
|
303
306
|
...$theme.typography.LabelXSmall,
|
|
304
307
|
};
|
|
305
308
|
});
|
|
309
|
+
StyledNotificationCircle.displayName = 'StyledNotificationCircle';
|
|
306
310
|
|
|
307
311
|
export const StyledHintDot = styled<{ $color: ColorT, $hidden?: boolean }>(
|
|
308
312
|
'div',
|
|
@@ -319,6 +323,7 @@ export const StyledHintDot = styled<{ $color: ColorT, $hidden?: boolean }>(
|
|
|
319
323
|
};
|
|
320
324
|
}
|
|
321
325
|
);
|
|
326
|
+
StyledHintDot.displayName = 'StyledHintDot';
|
|
322
327
|
|
|
323
328
|
declare var __DEV__: boolean;
|
|
324
329
|
declare var __NODE__: boolean;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var React = _interopRequireWildcard(require("react"));
|
|
11
|
+
|
|
12
|
+
var _button = require("../button");
|
|
13
|
+
|
|
14
|
+
var _styledComponents = require("./styled-components");
|
|
15
|
+
|
|
16
|
+
var _utils = require("./utils");
|
|
17
|
+
|
|
18
|
+
var _overrides = require("../helpers/overrides");
|
|
19
|
+
|
|
20
|
+
var _excluded = ["initialTime", "paused", "onClick", "disabled", "children", "overrides"],
|
|
21
|
+
_excluded2 = ["TimerContainer"];
|
|
22
|
+
|
|
23
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
24
|
+
|
|
25
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
|
|
26
|
+
|
|
27
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
28
|
+
|
|
29
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
30
|
+
|
|
31
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
32
|
+
|
|
33
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
34
|
+
|
|
35
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
36
|
+
|
|
37
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
38
|
+
|
|
39
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
40
|
+
|
|
41
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
42
|
+
|
|
43
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
44
|
+
|
|
45
|
+
var ButtonTimed = function ButtonTimed(props) {
|
|
46
|
+
var initialTime = props.initialTime,
|
|
47
|
+
_props$paused = props.paused,
|
|
48
|
+
paused = _props$paused === void 0 ? false : _props$paused,
|
|
49
|
+
onClickProp = props.onClick,
|
|
50
|
+
disabled = props.disabled,
|
|
51
|
+
children = props.children,
|
|
52
|
+
_props$overrides = props.overrides,
|
|
53
|
+
overrides = _props$overrides === void 0 ? {} : _props$overrides,
|
|
54
|
+
restProps = _objectWithoutProperties(props, _excluded);
|
|
55
|
+
|
|
56
|
+
var _React$useState = React.useState(initialTime * 1000),
|
|
57
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
58
|
+
timeRemaining = _React$useState2[0],
|
|
59
|
+
setTimeRemaining = _React$useState2[1];
|
|
60
|
+
|
|
61
|
+
React.useEffect(function () {
|
|
62
|
+
var timerId = setTimeout(function () {
|
|
63
|
+
if (timeRemaining > 0 && !paused) {
|
|
64
|
+
setTimeRemaining(function (seconds) {
|
|
65
|
+
return seconds - 100;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}, 100);
|
|
69
|
+
|
|
70
|
+
if (timeRemaining === 0) {
|
|
71
|
+
onClickProp();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return function () {
|
|
75
|
+
return clearTimeout(timerId);
|
|
76
|
+
};
|
|
77
|
+
}, [timeRemaining, paused]);
|
|
78
|
+
|
|
79
|
+
var onClick = function onClick() {
|
|
80
|
+
setTimeRemaining(0);
|
|
81
|
+
onClickProp();
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
var TimerContainerOverride = overrides.TimerContainer,
|
|
85
|
+
buttonOverrides = _objectWithoutProperties(overrides, _excluded2);
|
|
86
|
+
|
|
87
|
+
var _getOverrides = (0, _overrides.getOverrides)(TimerContainerOverride, _styledComponents.StyledTimerContainer),
|
|
88
|
+
_getOverrides2 = _slicedToArray(_getOverrides, 2),
|
|
89
|
+
TimerContainer = _getOverrides2[0],
|
|
90
|
+
timerContainerProps = _getOverrides2[1];
|
|
91
|
+
|
|
92
|
+
var buttonMergedOverrides = (0, _overrides.mergeOverrides)({
|
|
93
|
+
BaseButton: {
|
|
94
|
+
component: _styledComponents.StyledBaseButtonTimed,
|
|
95
|
+
props: {
|
|
96
|
+
$initialTime: initialTime,
|
|
97
|
+
$timeElapsed: (initialTime * 1000 - timeRemaining) / 1000
|
|
98
|
+
},
|
|
99
|
+
style: {
|
|
100
|
+
':after': {
|
|
101
|
+
animationPlayState: paused ? 'paused' : 'running'
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}, {
|
|
106
|
+
Root: buttonOverrides.Root || {},
|
|
107
|
+
BaseButton: buttonOverrides.BaseButton,
|
|
108
|
+
StartEnhancer: buttonOverrides.StartEnhancer || {},
|
|
109
|
+
EndEnhancer: buttonOverrides.EndEnhancer || {},
|
|
110
|
+
LoadingSpinnerContainer: buttonOverrides.LoadingSpinnerContainer || {},
|
|
111
|
+
LoadingSpinner: buttonOverrides.LoadingSpinner || {}
|
|
112
|
+
});
|
|
113
|
+
return /*#__PURE__*/React.createElement(_button.Button, _extends({}, restProps, {
|
|
114
|
+
overrides: buttonMergedOverrides,
|
|
115
|
+
onClick: onClick,
|
|
116
|
+
size: _button.SIZE.large,
|
|
117
|
+
kind: _button.KIND.primary,
|
|
118
|
+
shape: _button.SHAPE.default,
|
|
119
|
+
disabled: disabled || timeRemaining === 0
|
|
120
|
+
}), children, /*#__PURE__*/React.createElement(TimerContainer, timerContainerProps, "(".concat((0, _utils.formatTime)(timeRemaining), ")")));
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
var _default = ButtonTimed;
|
|
124
|
+
exports.default = _default;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { StyledStartEnhancer, StyledEndEnhancer, StyledLoadingSpinner, StyledLoadingSpinnerContainer } from '../button';
|
|
2
|
+
import { StyledBaseButtonTimed, StyledTimerContainer } from './styled-components';
|
|
3
|
+
export { StyledBaseButtonTimed, StyledTimerContainer, StyledStartEnhancer, StyledEndEnhancer, StyledLoadingSpinner, StyledLoadingSpinnerContainer, };
|
|
4
|
+
export * from './types';
|
|
5
|
+
export { default as ButtonTimed } from './button-timed';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
StyledStartEnhancer: true,
|
|
8
|
+
StyledEndEnhancer: true,
|
|
9
|
+
StyledLoadingSpinner: true,
|
|
10
|
+
StyledLoadingSpinnerContainer: true,
|
|
11
|
+
StyledBaseButtonTimed: true,
|
|
12
|
+
StyledTimerContainer: true,
|
|
13
|
+
ButtonTimed: true
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "ButtonTimed", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function get() {
|
|
18
|
+
return _buttonTimed.default;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(exports, "StyledBaseButtonTimed", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function get() {
|
|
24
|
+
return _styledComponents.StyledBaseButtonTimed;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(exports, "StyledEndEnhancer", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function get() {
|
|
30
|
+
return _button.StyledEndEnhancer;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(exports, "StyledLoadingSpinner", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function get() {
|
|
36
|
+
return _button.StyledLoadingSpinner;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(exports, "StyledLoadingSpinnerContainer", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function get() {
|
|
42
|
+
return _button.StyledLoadingSpinnerContainer;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports, "StyledStartEnhancer", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function get() {
|
|
48
|
+
return _button.StyledStartEnhancer;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(exports, "StyledTimerContainer", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function get() {
|
|
54
|
+
return _styledComponents.StyledTimerContainer;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
var _button = require("../button");
|
|
59
|
+
|
|
60
|
+
var _styledComponents = require("./styled-components");
|
|
61
|
+
|
|
62
|
+
var _types = require("./types");
|
|
63
|
+
|
|
64
|
+
Object.keys(_types).forEach(function (key) {
|
|
65
|
+
if (key === "default" || key === "__esModule") return;
|
|
66
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
67
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
68
|
+
Object.defineProperty(exports, key, {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
get: function get() {
|
|
71
|
+
return _types[key];
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
var _buttonTimed = _interopRequireDefault(require("./button-timed"));
|
|
77
|
+
|
|
78
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) Uber Technologies, Inc.
|
|
3
|
+
|
|
4
|
+
This source code is licensed under the MIT license found in the
|
|
5
|
+
LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
// @flow
|
|
8
|
+
import * as React from 'react';
|
|
9
|
+
import type { OverrideT } from '../helpers/overrides.js';
|
|
10
|
+
import { type StyletronComponent } from 'styletron-react';
|
|
11
|
+
import type { CustomColorsT } from '../button';
|
|
12
|
+
|
|
13
|
+
export type OverridesT = {
|
|
14
|
+
BaseButtonTimed?: OverrideT,
|
|
15
|
+
TimerContainer?: OverrideT,
|
|
16
|
+
Root?: OverrideT,
|
|
17
|
+
StartEnhancer?: OverrideT,
|
|
18
|
+
EndEnhancer?: OverrideT,
|
|
19
|
+
LoadingSpinnerContainer?: OverrideT,
|
|
20
|
+
LoadingSpinner?: OverrideT,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type ButtonTimedPropsT = {
|
|
24
|
+
initialTime: number,
|
|
25
|
+
onClick: (a?: SyntheticEvent<HTMLButtonElement>) => mixed,
|
|
26
|
+
overrides?: OverridesT,
|
|
27
|
+
paused?: boolean,
|
|
28
|
+
children?: React$Node,
|
|
29
|
+
colors?: CustomColorsT,
|
|
30
|
+
disabled?: boolean,
|
|
31
|
+
/** A helper rendered at the end of the button. */
|
|
32
|
+
// flowlint-next-line unclear-type:off
|
|
33
|
+
endEnhancer?: React.Node | React.AbstractComponent<any>,
|
|
34
|
+
/** Show loading button style and spinner. */
|
|
35
|
+
isLoading?: boolean,
|
|
36
|
+
/** Indicates that the button is selected */
|
|
37
|
+
isSelected?: boolean,
|
|
38
|
+
/** A helper rendered at the start of the button. */
|
|
39
|
+
// flowlint-next-line unclear-type:off
|
|
40
|
+
startEnhancer?: React.Node | React.AbstractComponent<any>,
|
|
41
|
+
type?: 'submit' | 'reset' | 'button',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
StyledStartEnhancer,
|
|
46
|
+
StyledEndEnhancer,
|
|
47
|
+
StyledLoadingSpinner,
|
|
48
|
+
StyledLoadingSpinnerContainer,
|
|
49
|
+
} from '../button';
|
|
50
|
+
declare export var StyledBaseButtonTimed: StyletronComponent<'div', {}>;
|
|
51
|
+
declare export var StyledTimerContainer: StyletronComponent<'div', {}>;
|
|
52
|
+
|
|
53
|
+
declare export var ButtonTimed: React.ComponentType<ButtonTimedPropsT>;
|
|
54
|
+
|
|
55
|
+
declare var __DEV__: boolean;
|
|
56
|
+
declare var __NODE__: boolean;
|
|
57
|
+
declare var __BROWSER__: boolean;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const StyledBaseButtonTimed: import("styletron-react").StyletronComponent<"button", {
|
|
2
|
+
$initialTime: number;
|
|
3
|
+
$timeElapsed: number;
|
|
4
|
+
} & import("../button").SharedStyleProps>;
|
|
5
|
+
export declare const StyledTimerContainer: import("styletron-react").StyletronComponent<"span", {}>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.StyledTimerContainer = exports.StyledBaseButtonTimed = void 0;
|
|
7
|
+
|
|
8
|
+
var _index = require("../styles/index");
|
|
9
|
+
|
|
10
|
+
var _button = require("../button");
|
|
11
|
+
|
|
12
|
+
var _util = require("../styles/util");
|
|
13
|
+
|
|
14
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
+
|
|
16
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
+
|
|
18
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
19
|
+
|
|
20
|
+
var StyledBaseButtonTimed = (0, _index.withStyle)(_button.StyledBaseButton, function (_ref) {
|
|
21
|
+
var $theme = _ref.$theme,
|
|
22
|
+
$initialTime = _ref.$initialTime,
|
|
23
|
+
$timeElapsed = _ref.$timeElapsed;
|
|
24
|
+
var completionPercentage = $timeElapsed / $initialTime * 100;
|
|
25
|
+
var timeLeft = $initialTime - $timeElapsed;
|
|
26
|
+
return _objectSpread({
|
|
27
|
+
position: 'relative'
|
|
28
|
+
}, $initialTime > 0 ? {
|
|
29
|
+
':after': {
|
|
30
|
+
animationDuration: "".concat(timeLeft, "s"),
|
|
31
|
+
animationName: {
|
|
32
|
+
from: {
|
|
33
|
+
transform: "translateX(".concat(completionPercentage, "%)")
|
|
34
|
+
},
|
|
35
|
+
to: {
|
|
36
|
+
transform: 'translateX(100%)'
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
animationTimingFunction: 'linear',
|
|
40
|
+
display: 'inline-block',
|
|
41
|
+
content: '""',
|
|
42
|
+
width: '100%',
|
|
43
|
+
height: '100%',
|
|
44
|
+
zIndex: '1',
|
|
45
|
+
position: 'absolute',
|
|
46
|
+
backgroundColor: (0, _util.hexToRgb)($theme.colors.backgroundPrimary, '0.2')
|
|
47
|
+
}
|
|
48
|
+
} : {});
|
|
49
|
+
});
|
|
50
|
+
exports.StyledBaseButtonTimed = StyledBaseButtonTimed;
|
|
51
|
+
StyledBaseButtonTimed.displayName = "StyledBaseButtonTimed";
|
|
52
|
+
StyledBaseButtonTimed.displayName = 'StyledBaseButtonTimed';
|
|
53
|
+
var StyledTimerContainer = (0, _index.styled)('span', {
|
|
54
|
+
// minWidth to ensure button width stays consistent as timeRemaining changes
|
|
55
|
+
minWidth: '53px'
|
|
56
|
+
});
|
|
57
|
+
exports.StyledTimerContainer = StyledTimerContainer;
|
|
58
|
+
StyledTimerContainer.displayName = "StyledTimerContainer";
|
|
59
|
+
StyledTimerContainer.displayName = 'StyledTimerContainer';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ButtonProps, ButtonOverrides } from '../button';
|
|
3
|
+
import type { Override } from '../helpers/overrides';
|
|
4
|
+
export declare type ButtonTimedOverrides = ButtonOverrides & {
|
|
5
|
+
TimerContainer?: Override;
|
|
6
|
+
};
|
|
7
|
+
export declare type ButtonTimedProps = Omit<ButtonProps, 'kind' | 'shape' | 'size' | 'onClick' | 'overrides'> & {
|
|
8
|
+
initialTime: number;
|
|
9
|
+
paused?: boolean;
|
|
10
|
+
onClick: (a?: React.SyntheticEvent<HTMLButtonElement>) => unknown;
|
|
11
|
+
overrides?: ButtonTimedOverrides;
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const formatTime: (totalMilliseconds: number) => string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.formatTime = void 0;
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
Copyright (c) Uber Technologies, Inc.
|
|
10
|
+
|
|
11
|
+
This source code is licensed under the MIT license found in the
|
|
12
|
+
LICENSE file in the root directory of this source tree.
|
|
13
|
+
*/
|
|
14
|
+
function roundUpToNearestInt(num) {
|
|
15
|
+
var cleanedNum = Math.trunc(num * 10) / 10;
|
|
16
|
+
return Math.ceil(cleanedNum);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function padTo2Digits(num) {
|
|
20
|
+
return num.toString().padStart(2, '0');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var formatTime = function formatTime(totalMilliseconds) {
|
|
24
|
+
var totalSeconds = totalMilliseconds / 1000;
|
|
25
|
+
var minutes = Math.floor(totalSeconds / 60);
|
|
26
|
+
var seconds = roundUpToNearestInt(totalSeconds % 60);
|
|
27
|
+
return "".concat(minutes, ":").concat(padTo2Digits(seconds));
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.formatTime = formatTime;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
Copyright (c) Uber Technologies, Inc.
|
|
5
|
+
|
|
6
|
+
This source code is licensed under the MIT license found in the
|
|
7
|
+
LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
import * as React from 'react';
|
|
10
|
+
import { Button, SIZE, KIND, SHAPE } from '../button';
|
|
11
|
+
import { StyledBaseButtonTimed, StyledTimerContainer } from './styled-components';
|
|
12
|
+
import { formatTime } from './utils';
|
|
13
|
+
import { getOverrides, mergeOverrides } from '../helpers/overrides';
|
|
14
|
+
|
|
15
|
+
const ButtonTimed = props => {
|
|
16
|
+
const {
|
|
17
|
+
initialTime,
|
|
18
|
+
// in seconds
|
|
19
|
+
paused = false,
|
|
20
|
+
onClick: onClickProp,
|
|
21
|
+
disabled,
|
|
22
|
+
children,
|
|
23
|
+
overrides = {},
|
|
24
|
+
...restProps
|
|
25
|
+
} = props;
|
|
26
|
+
const [timeRemaining, setTimeRemaining] = React.useState(initialTime * 1000);
|
|
27
|
+
React.useEffect(() => {
|
|
28
|
+
const timerId = setTimeout(() => {
|
|
29
|
+
if (timeRemaining > 0 && !paused) {
|
|
30
|
+
setTimeRemaining(seconds => seconds - 100);
|
|
31
|
+
}
|
|
32
|
+
}, 100);
|
|
33
|
+
|
|
34
|
+
if (timeRemaining === 0) {
|
|
35
|
+
onClickProp();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return () => clearTimeout(timerId);
|
|
39
|
+
}, [timeRemaining, paused]);
|
|
40
|
+
|
|
41
|
+
const onClick = () => {
|
|
42
|
+
setTimeRemaining(0);
|
|
43
|
+
onClickProp();
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const {
|
|
47
|
+
TimerContainer: TimerContainerOverride,
|
|
48
|
+
...buttonOverrides
|
|
49
|
+
} = overrides;
|
|
50
|
+
const [TimerContainer, timerContainerProps] = getOverrides(TimerContainerOverride, StyledTimerContainer);
|
|
51
|
+
const buttonMergedOverrides = mergeOverrides({
|
|
52
|
+
BaseButton: {
|
|
53
|
+
component: StyledBaseButtonTimed,
|
|
54
|
+
props: {
|
|
55
|
+
$initialTime: initialTime,
|
|
56
|
+
$timeElapsed: (initialTime * 1000 - timeRemaining) / 1000
|
|
57
|
+
},
|
|
58
|
+
style: {
|
|
59
|
+
':after': {
|
|
60
|
+
animationPlayState: paused ? 'paused' : 'running'
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}, {
|
|
65
|
+
Root: buttonOverrides.Root || {},
|
|
66
|
+
BaseButton: buttonOverrides.BaseButton,
|
|
67
|
+
StartEnhancer: buttonOverrides.StartEnhancer || {},
|
|
68
|
+
EndEnhancer: buttonOverrides.EndEnhancer || {},
|
|
69
|
+
LoadingSpinnerContainer: buttonOverrides.LoadingSpinnerContainer || {},
|
|
70
|
+
LoadingSpinner: buttonOverrides.LoadingSpinner || {}
|
|
71
|
+
});
|
|
72
|
+
return /*#__PURE__*/React.createElement(Button, _extends({}, restProps, {
|
|
73
|
+
overrides: buttonMergedOverrides,
|
|
74
|
+
onClick: onClick,
|
|
75
|
+
size: SIZE.large,
|
|
76
|
+
kind: KIND.primary,
|
|
77
|
+
shape: SHAPE.default,
|
|
78
|
+
disabled: disabled || timeRemaining === 0
|
|
79
|
+
}), children, /*#__PURE__*/React.createElement(TimerContainer, timerContainerProps, `(${formatTime(timeRemaining)})`));
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export default ButtonTimed;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) Uber Technologies, Inc.
|
|
3
|
+
|
|
4
|
+
This source code is licensed under the MIT license found in the
|
|
5
|
+
LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { StyledStartEnhancer, StyledEndEnhancer, StyledLoadingSpinner, StyledLoadingSpinnerContainer } from '../button';
|
|
8
|
+
import { StyledBaseButtonTimed, StyledTimerContainer } from './styled-components';
|
|
9
|
+
export { StyledBaseButtonTimed, StyledTimerContainer, StyledStartEnhancer, StyledEndEnhancer, StyledLoadingSpinner, StyledLoadingSpinnerContainer };
|
|
10
|
+
export * from './types';
|
|
11
|
+
export { default as ButtonTimed } from './button-timed';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) Uber Technologies, Inc.
|
|
3
|
+
|
|
4
|
+
This source code is licensed under the MIT license found in the
|
|
5
|
+
LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { styled, withStyle } from '../styles/index';
|
|
8
|
+
import { StyledBaseButton } from '../button';
|
|
9
|
+
import { hexToRgb as hexToRgba } from '../styles/util';
|
|
10
|
+
export const StyledBaseButtonTimed = withStyle(StyledBaseButton, ({
|
|
11
|
+
$theme,
|
|
12
|
+
$initialTime,
|
|
13
|
+
$timeElapsed
|
|
14
|
+
}) => {
|
|
15
|
+
const completionPercentage = $timeElapsed / $initialTime * 100;
|
|
16
|
+
const timeLeft = $initialTime - $timeElapsed;
|
|
17
|
+
return {
|
|
18
|
+
position: 'relative',
|
|
19
|
+
...($initialTime > 0 ? {
|
|
20
|
+
':after': {
|
|
21
|
+
animationDuration: `${timeLeft}s`,
|
|
22
|
+
animationName: {
|
|
23
|
+
from: {
|
|
24
|
+
transform: `translateX(${completionPercentage}%)`
|
|
25
|
+
},
|
|
26
|
+
to: {
|
|
27
|
+
transform: 'translateX(100%)'
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
animationTimingFunction: 'linear',
|
|
31
|
+
display: 'inline-block',
|
|
32
|
+
content: '""',
|
|
33
|
+
width: '100%',
|
|
34
|
+
height: '100%',
|
|
35
|
+
zIndex: '1',
|
|
36
|
+
position: 'absolute',
|
|
37
|
+
backgroundColor: hexToRgba($theme.colors.backgroundPrimary, '0.2')
|
|
38
|
+
}
|
|
39
|
+
} : {})
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
StyledBaseButtonTimed.displayName = "StyledBaseButtonTimed";
|
|
43
|
+
StyledBaseButtonTimed.displayName = 'StyledBaseButtonTimed';
|
|
44
|
+
export const StyledTimerContainer = styled('span', {
|
|
45
|
+
// minWidth to ensure button width stays consistent as timeRemaining changes
|
|
46
|
+
minWidth: '53px'
|
|
47
|
+
});
|
|
48
|
+
StyledTimerContainer.displayName = "StyledTimerContainer";
|
|
49
|
+
StyledTimerContainer.displayName = 'StyledTimerContainer';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) Uber Technologies, Inc.
|
|
3
|
+
|
|
4
|
+
This source code is licensed under the MIT license found in the
|
|
5
|
+
LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
function roundUpToNearestInt(num) {
|
|
8
|
+
const cleanedNum = Math.trunc(num * 10) / 10;
|
|
9
|
+
return Math.ceil(cleanedNum);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function padTo2Digits(num) {
|
|
13
|
+
return num.toString().padStart(2, '0');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const formatTime = totalMilliseconds => {
|
|
17
|
+
const totalSeconds = totalMilliseconds / 1000;
|
|
18
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
19
|
+
const seconds = roundUpToNearestInt(totalSeconds % 60);
|
|
20
|
+
return `${minutes}:${padTo2Digits(seconds)}`;
|
|
21
|
+
};
|
|
@@ -65,6 +65,7 @@ export const StyledRoot = styled('button', ({
|
|
|
65
65
|
};
|
|
66
66
|
});
|
|
67
67
|
StyledRoot.displayName = "StyledRoot";
|
|
68
|
+
StyledRoot.displayName = 'StyledRoot';
|
|
68
69
|
export const StyledImage = styled('div', ({
|
|
69
70
|
$imageLayout = IMAGE_LAYOUT.top,
|
|
70
71
|
$backgroundPosition = 'center',
|
|
@@ -84,6 +85,7 @@ export const StyledImage = styled('div', ({
|
|
|
84
85
|
};
|
|
85
86
|
});
|
|
86
87
|
StyledImage.displayName = "StyledImage";
|
|
88
|
+
StyledImage.displayName = 'StyledImage';
|
|
87
89
|
export const StyledContentContainer = styled('div', ({
|
|
88
90
|
$theme
|
|
89
91
|
}) => ({
|
|
@@ -95,14 +97,17 @@ export const StyledContentContainer = styled('div', ({
|
|
|
95
97
|
paddingLeft: $theme.sizing.scale600
|
|
96
98
|
}));
|
|
97
99
|
StyledContentContainer.displayName = "StyledContentContainer";
|
|
100
|
+
StyledContentContainer.displayName = 'StyledContentContainer';
|
|
98
101
|
export const StyledHeadingContainer = styled('div', ({
|
|
99
102
|
$theme
|
|
100
103
|
}) => ({ ...$theme.typography.HeadingXSmall
|
|
101
104
|
}));
|
|
102
105
|
StyledHeadingContainer.displayName = "StyledHeadingContainer";
|
|
106
|
+
StyledHeadingContainer.displayName = 'StyledHeadingContainer';
|
|
103
107
|
export const StyledParagraphContainer = styled('div', ({
|
|
104
108
|
$theme
|
|
105
109
|
}) => ({ ...$theme.typography.ParagraphSmall,
|
|
106
110
|
marginTop: $theme.sizing.scale100
|
|
107
111
|
}));
|
|
108
|
-
StyledParagraphContainer.displayName = "StyledParagraphContainer";
|
|
112
|
+
StyledParagraphContainer.displayName = "StyledParagraphContainer";
|
|
113
|
+
StyledParagraphContainer.displayName = 'StyledParagraphContainer';
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
var _excluded = ["initialTime", "paused", "onClick", "disabled", "children", "overrides"],
|
|
2
|
+
_excluded2 = ["TimerContainer"];
|
|
3
|
+
|
|
4
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
5
|
+
|
|
6
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
7
|
+
|
|
8
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
|
|
10
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
|
+
|
|
12
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
13
|
+
|
|
14
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
15
|
+
|
|
16
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
17
|
+
|
|
18
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
19
|
+
|
|
20
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
Copyright (c) Uber Technologies, Inc.
|
|
24
|
+
|
|
25
|
+
This source code is licensed under the MIT license found in the
|
|
26
|
+
LICENSE file in the root directory of this source tree.
|
|
27
|
+
*/
|
|
28
|
+
import * as React from 'react';
|
|
29
|
+
import { Button, SIZE, KIND, SHAPE } from '../button';
|
|
30
|
+
import { StyledBaseButtonTimed, StyledTimerContainer } from './styled-components';
|
|
31
|
+
import { formatTime } from './utils';
|
|
32
|
+
import { getOverrides, mergeOverrides } from '../helpers/overrides';
|
|
33
|
+
|
|
34
|
+
var ButtonTimed = function ButtonTimed(props) {
|
|
35
|
+
var initialTime = props.initialTime,
|
|
36
|
+
_props$paused = props.paused,
|
|
37
|
+
paused = _props$paused === void 0 ? false : _props$paused,
|
|
38
|
+
onClickProp = props.onClick,
|
|
39
|
+
disabled = props.disabled,
|
|
40
|
+
children = props.children,
|
|
41
|
+
_props$overrides = props.overrides,
|
|
42
|
+
overrides = _props$overrides === void 0 ? {} : _props$overrides,
|
|
43
|
+
restProps = _objectWithoutProperties(props, _excluded);
|
|
44
|
+
|
|
45
|
+
var _React$useState = React.useState(initialTime * 1000),
|
|
46
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
47
|
+
timeRemaining = _React$useState2[0],
|
|
48
|
+
setTimeRemaining = _React$useState2[1];
|
|
49
|
+
|
|
50
|
+
React.useEffect(function () {
|
|
51
|
+
var timerId = setTimeout(function () {
|
|
52
|
+
if (timeRemaining > 0 && !paused) {
|
|
53
|
+
setTimeRemaining(function (seconds) {
|
|
54
|
+
return seconds - 100;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}, 100);
|
|
58
|
+
|
|
59
|
+
if (timeRemaining === 0) {
|
|
60
|
+
onClickProp();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return function () {
|
|
64
|
+
return clearTimeout(timerId);
|
|
65
|
+
};
|
|
66
|
+
}, [timeRemaining, paused]);
|
|
67
|
+
|
|
68
|
+
var onClick = function onClick() {
|
|
69
|
+
setTimeRemaining(0);
|
|
70
|
+
onClickProp();
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
var TimerContainerOverride = overrides.TimerContainer,
|
|
74
|
+
buttonOverrides = _objectWithoutProperties(overrides, _excluded2);
|
|
75
|
+
|
|
76
|
+
var _getOverrides = getOverrides(TimerContainerOverride, StyledTimerContainer),
|
|
77
|
+
_getOverrides2 = _slicedToArray(_getOverrides, 2),
|
|
78
|
+
TimerContainer = _getOverrides2[0],
|
|
79
|
+
timerContainerProps = _getOverrides2[1];
|
|
80
|
+
|
|
81
|
+
var buttonMergedOverrides = mergeOverrides({
|
|
82
|
+
BaseButton: {
|
|
83
|
+
component: StyledBaseButtonTimed,
|
|
84
|
+
props: {
|
|
85
|
+
$initialTime: initialTime,
|
|
86
|
+
$timeElapsed: (initialTime * 1000 - timeRemaining) / 1000
|
|
87
|
+
},
|
|
88
|
+
style: {
|
|
89
|
+
':after': {
|
|
90
|
+
animationPlayState: paused ? 'paused' : 'running'
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}, {
|
|
95
|
+
Root: buttonOverrides.Root || {},
|
|
96
|
+
BaseButton: buttonOverrides.BaseButton,
|
|
97
|
+
StartEnhancer: buttonOverrides.StartEnhancer || {},
|
|
98
|
+
EndEnhancer: buttonOverrides.EndEnhancer || {},
|
|
99
|
+
LoadingSpinnerContainer: buttonOverrides.LoadingSpinnerContainer || {},
|
|
100
|
+
LoadingSpinner: buttonOverrides.LoadingSpinner || {}
|
|
101
|
+
});
|
|
102
|
+
return /*#__PURE__*/React.createElement(Button, _extends({}, restProps, {
|
|
103
|
+
overrides: buttonMergedOverrides,
|
|
104
|
+
onClick: onClick,
|
|
105
|
+
size: SIZE.large,
|
|
106
|
+
kind: KIND.primary,
|
|
107
|
+
shape: SHAPE.default,
|
|
108
|
+
disabled: disabled || timeRemaining === 0
|
|
109
|
+
}), children, /*#__PURE__*/React.createElement(TimerContainer, timerContainerProps, "(".concat(formatTime(timeRemaining), ")")));
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export default ButtonTimed;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) Uber Technologies, Inc.
|
|
3
|
+
|
|
4
|
+
This source code is licensed under the MIT license found in the
|
|
5
|
+
LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { StyledStartEnhancer, StyledEndEnhancer, StyledLoadingSpinner, StyledLoadingSpinnerContainer } from '../button';
|
|
8
|
+
import { StyledBaseButtonTimed, StyledTimerContainer } from './styled-components';
|
|
9
|
+
export { StyledBaseButtonTimed, StyledTimerContainer, StyledStartEnhancer, StyledEndEnhancer, StyledLoadingSpinner, StyledLoadingSpinnerContainer };
|
|
10
|
+
export * from './types';
|
|
11
|
+
export { default as ButtonTimed } from './button-timed';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
|
|
5
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
Copyright (c) Uber Technologies, Inc.
|
|
9
|
+
|
|
10
|
+
This source code is licensed under the MIT license found in the
|
|
11
|
+
LICENSE file in the root directory of this source tree.
|
|
12
|
+
*/
|
|
13
|
+
import { styled, withStyle } from '../styles/index';
|
|
14
|
+
import { StyledBaseButton } from '../button';
|
|
15
|
+
import { hexToRgb as hexToRgba } from '../styles/util';
|
|
16
|
+
export var StyledBaseButtonTimed = withStyle(StyledBaseButton, function (_ref) {
|
|
17
|
+
var $theme = _ref.$theme,
|
|
18
|
+
$initialTime = _ref.$initialTime,
|
|
19
|
+
$timeElapsed = _ref.$timeElapsed;
|
|
20
|
+
var completionPercentage = $timeElapsed / $initialTime * 100;
|
|
21
|
+
var timeLeft = $initialTime - $timeElapsed;
|
|
22
|
+
return _objectSpread({
|
|
23
|
+
position: 'relative'
|
|
24
|
+
}, $initialTime > 0 ? {
|
|
25
|
+
':after': {
|
|
26
|
+
animationDuration: "".concat(timeLeft, "s"),
|
|
27
|
+
animationName: {
|
|
28
|
+
from: {
|
|
29
|
+
transform: "translateX(".concat(completionPercentage, "%)")
|
|
30
|
+
},
|
|
31
|
+
to: {
|
|
32
|
+
transform: 'translateX(100%)'
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
animationTimingFunction: 'linear',
|
|
36
|
+
display: 'inline-block',
|
|
37
|
+
content: '""',
|
|
38
|
+
width: '100%',
|
|
39
|
+
height: '100%',
|
|
40
|
+
zIndex: '1',
|
|
41
|
+
position: 'absolute',
|
|
42
|
+
backgroundColor: hexToRgba($theme.colors.backgroundPrimary, '0.2')
|
|
43
|
+
}
|
|
44
|
+
} : {});
|
|
45
|
+
});
|
|
46
|
+
StyledBaseButtonTimed.displayName = "StyledBaseButtonTimed";
|
|
47
|
+
StyledBaseButtonTimed.displayName = 'StyledBaseButtonTimed';
|
|
48
|
+
export var StyledTimerContainer = styled('span', {
|
|
49
|
+
// minWidth to ensure button width stays consistent as timeRemaining changes
|
|
50
|
+
minWidth: '53px'
|
|
51
|
+
});
|
|
52
|
+
StyledTimerContainer.displayName = "StyledTimerContainer";
|
|
53
|
+
StyledTimerContainer.displayName = 'StyledTimerContainer';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) Uber Technologies, Inc.
|
|
3
|
+
|
|
4
|
+
This source code is licensed under the MIT license found in the
|
|
5
|
+
LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
function roundUpToNearestInt(num) {
|
|
8
|
+
var cleanedNum = Math.trunc(num * 10) / 10;
|
|
9
|
+
return Math.ceil(cleanedNum);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function padTo2Digits(num) {
|
|
13
|
+
return num.toString().padStart(2, '0');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export var formatTime = function formatTime(totalMilliseconds) {
|
|
17
|
+
var totalSeconds = totalMilliseconds / 1000;
|
|
18
|
+
var minutes = Math.floor(totalSeconds / 60);
|
|
19
|
+
var seconds = roundUpToNearestInt(totalSeconds % 60);
|
|
20
|
+
return "".concat(minutes, ":").concat(padTo2Digits(seconds));
|
|
21
|
+
};
|
|
@@ -71,6 +71,7 @@ export var StyledRoot = styled('button', function (_ref) {
|
|
|
71
71
|
});
|
|
72
72
|
});
|
|
73
73
|
StyledRoot.displayName = "StyledRoot";
|
|
74
|
+
StyledRoot.displayName = 'StyledRoot';
|
|
74
75
|
export var StyledImage = styled('div', function (_ref2) {
|
|
75
76
|
var _ref2$$imageLayout = _ref2.$imageLayout,
|
|
76
77
|
$imageLayout = _ref2$$imageLayout === void 0 ? IMAGE_LAYOUT.top : _ref2$$imageLayout,
|
|
@@ -90,6 +91,7 @@ export var StyledImage = styled('div', function (_ref2) {
|
|
|
90
91
|
});
|
|
91
92
|
});
|
|
92
93
|
StyledImage.displayName = "StyledImage";
|
|
94
|
+
StyledImage.displayName = 'StyledImage';
|
|
93
95
|
export var StyledContentContainer = styled('div', function (_ref3) {
|
|
94
96
|
var $theme = _ref3.$theme;
|
|
95
97
|
return {
|
|
@@ -102,15 +104,18 @@ export var StyledContentContainer = styled('div', function (_ref3) {
|
|
|
102
104
|
};
|
|
103
105
|
});
|
|
104
106
|
StyledContentContainer.displayName = "StyledContentContainer";
|
|
107
|
+
StyledContentContainer.displayName = 'StyledContentContainer';
|
|
105
108
|
export var StyledHeadingContainer = styled('div', function (_ref4) {
|
|
106
109
|
var $theme = _ref4.$theme;
|
|
107
110
|
return _objectSpread({}, $theme.typography.HeadingXSmall);
|
|
108
111
|
});
|
|
109
112
|
StyledHeadingContainer.displayName = "StyledHeadingContainer";
|
|
113
|
+
StyledHeadingContainer.displayName = 'StyledHeadingContainer';
|
|
110
114
|
export var StyledParagraphContainer = styled('div', function (_ref5) {
|
|
111
115
|
var $theme = _ref5.$theme;
|
|
112
116
|
return _objectSpread(_objectSpread({}, $theme.typography.ParagraphSmall), {}, {
|
|
113
117
|
marginTop: $theme.sizing.scale100
|
|
114
118
|
});
|
|
115
119
|
});
|
|
116
|
-
StyledParagraphContainer.displayName = "StyledParagraphContainer";
|
|
120
|
+
StyledParagraphContainer.displayName = "StyledParagraphContainer";
|
|
121
|
+
StyledParagraphContainer.displayName = 'StyledParagraphContainer';
|
|
@@ -75,6 +75,7 @@ var StyledRoot = (0, _styles.styled)('button', function (_ref) {
|
|
|
75
75
|
});
|
|
76
76
|
exports.StyledRoot = StyledRoot;
|
|
77
77
|
StyledRoot.displayName = "StyledRoot";
|
|
78
|
+
StyledRoot.displayName = 'StyledRoot';
|
|
78
79
|
var StyledImage = (0, _styles.styled)('div', function (_ref2) {
|
|
79
80
|
var _ref2$$imageLayout = _ref2.$imageLayout,
|
|
80
81
|
$imageLayout = _ref2$$imageLayout === void 0 ? _constants.IMAGE_LAYOUT.top : _ref2$$imageLayout,
|
|
@@ -95,6 +96,7 @@ var StyledImage = (0, _styles.styled)('div', function (_ref2) {
|
|
|
95
96
|
});
|
|
96
97
|
exports.StyledImage = StyledImage;
|
|
97
98
|
StyledImage.displayName = "StyledImage";
|
|
99
|
+
StyledImage.displayName = 'StyledImage';
|
|
98
100
|
var StyledContentContainer = (0, _styles.styled)('div', function (_ref3) {
|
|
99
101
|
var $theme = _ref3.$theme;
|
|
100
102
|
return {
|
|
@@ -108,12 +110,14 @@ var StyledContentContainer = (0, _styles.styled)('div', function (_ref3) {
|
|
|
108
110
|
});
|
|
109
111
|
exports.StyledContentContainer = StyledContentContainer;
|
|
110
112
|
StyledContentContainer.displayName = "StyledContentContainer";
|
|
113
|
+
StyledContentContainer.displayName = 'StyledContentContainer';
|
|
111
114
|
var StyledHeadingContainer = (0, _styles.styled)('div', function (_ref4) {
|
|
112
115
|
var $theme = _ref4.$theme;
|
|
113
116
|
return _objectSpread({}, $theme.typography.HeadingXSmall);
|
|
114
117
|
});
|
|
115
118
|
exports.StyledHeadingContainer = StyledHeadingContainer;
|
|
116
119
|
StyledHeadingContainer.displayName = "StyledHeadingContainer";
|
|
120
|
+
StyledHeadingContainer.displayName = 'StyledHeadingContainer';
|
|
117
121
|
var StyledParagraphContainer = (0, _styles.styled)('div', function (_ref5) {
|
|
118
122
|
var $theme = _ref5.$theme;
|
|
119
123
|
return _objectSpread(_objectSpread({}, $theme.typography.ParagraphSmall), {}, {
|
|
@@ -121,4 +125,5 @@ var StyledParagraphContainer = (0, _styles.styled)('div', function (_ref5) {
|
|
|
121
125
|
});
|
|
122
126
|
});
|
|
123
127
|
exports.StyledParagraphContainer = StyledParagraphContainer;
|
|
124
|
-
StyledParagraphContainer.displayName = "StyledParagraphContainer";
|
|
128
|
+
StyledParagraphContainer.displayName = "StyledParagraphContainer";
|
|
129
|
+
StyledParagraphContainer.displayName = 'StyledParagraphContainer';
|