baseui 12.1.3 → 12.2.0
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/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 +57 -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/card/card.js.flow +1 -1
- package/card/types.d.ts +1 -1
- package/card/types.js.flow +1 -1
- package/data-table/data-table.js +10 -10
- package/data-table/data-table.js.flow +2 -2
- package/data-table/stateful-container.js +41 -35
- package/data-table/stateful-data-table.js +2 -0
- package/data-table/types.d.ts +3 -0
- package/data-table/types.js.flow +2 -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 +47 -0
- package/es/button-timed/types.js +1 -0
- package/es/button-timed/utils.js +21 -0
- package/es/data-table/data-table.js +6 -6
- package/es/data-table/stateful-container.js +30 -18
- package/es/data-table/stateful-data-table.js +2 -0
- package/es/input/base-input.js +1 -3
- package/es/layer/tether.js +1 -1
- package/es/popover/popover.js +2 -2
- package/es/themes/dark-theme/color-component-tokens.js +1 -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 +51 -0
- package/esm/button-timed/types.js +1 -0
- package/esm/button-timed/utils.js +21 -0
- package/esm/data-table/data-table.js +10 -10
- package/esm/data-table/stateful-container.js +41 -35
- package/esm/data-table/stateful-data-table.js +2 -0
- package/esm/input/base-input.js +6 -9
- package/esm/layer/tether.js +1 -1
- package/esm/popover/popover.js +2 -2
- package/esm/themes/dark-theme/color-component-tokens.js +1 -1
- package/header-navigation/types.d.ts +3 -2
- package/header-navigation/types.js.flow +2 -0
- package/input/base-input.js +6 -9
- package/layer/tether.js +1 -1
- package/layer/tether.js.flow +1 -1
- package/layout-grid/types.d.ts +1 -1
- package/package.json +1 -1
- package/popover/popover.js +2 -2
- package/popover/popover.js.flow +3 -3
- package/popover/types.d.ts +4 -4
- package/popover/types.js.flow +4 -4
- package/skeleton/skeleton.js.flow +1 -1
- package/skeleton/types.d.ts +1 -1
- package/skeleton/types.js.flow +1 -1
- package/themes/dark-theme/color-component-tokens.js +1 -1
- package/themes/dark-theme/color-component-tokens.js.flow +1 -1
- package/themes/types.d.ts +5 -5
- package/tree-view/tree-label-interactable.d.ts +3 -3
- package/tree-view/tree-label-interactable.js.flow +2 -0
|
@@ -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 { BaseButtonTimed as StyledBaseButtonTimed, TimerContainer as 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 { BaseButtonTimed as StyledBaseButtonTimed, TimerContainer as 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,47 @@
|
|
|
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 BaseButtonTimed = 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
|
+
BaseButtonTimed.displayName = "BaseButtonTimed";
|
|
43
|
+
export const TimerContainer = styled('span', {
|
|
44
|
+
// minWidth to ensure button width stays consistent as timeRemaining changes
|
|
45
|
+
minWidth: '53px'
|
|
46
|
+
});
|
|
47
|
+
TimerContainer.displayName = "TimerContainer";
|
|
@@ -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
|
+
};
|
|
@@ -389,9 +389,7 @@ const InnerTableElement = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
389
389
|
}
|
|
390
390
|
|
|
391
391
|
const RowActionIcon = rowAction.renderIcon;
|
|
392
|
-
return /*#__PURE__*/React.createElement(Button
|
|
393
|
-
, {
|
|
394
|
-
alt: rowAction.label,
|
|
392
|
+
return /*#__PURE__*/React.createElement(Button, {
|
|
395
393
|
key: rowAction.label,
|
|
396
394
|
onClick: event => rowAction.onClick({
|
|
397
395
|
event,
|
|
@@ -400,6 +398,7 @@ const InnerTableElement = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
400
398
|
size: BUTTON_SIZES.compact,
|
|
401
399
|
kind: BUTTON_KINDS.tertiary,
|
|
402
400
|
shape: BUTTON_SHAPES.round,
|
|
401
|
+
title: rowAction.label,
|
|
403
402
|
overrides: {
|
|
404
403
|
BaseButton: {
|
|
405
404
|
style: {
|
|
@@ -598,9 +597,6 @@ export function DataTable({
|
|
|
598
597
|
|
|
599
598
|
return result;
|
|
600
599
|
}, [sortedIndices, filteredIndices, onIncludedRowsChange, allRows]);
|
|
601
|
-
React.useImperativeHandle(controlRef, () => ({
|
|
602
|
-
getRows: () => rows
|
|
603
|
-
}), [rows]);
|
|
604
600
|
const [browserScrollbarWidth, setBrowserScrollbarWidth] = React.useState(0);
|
|
605
601
|
const normalizedWidths = React.useMemo(() => {
|
|
606
602
|
const resizedWidths = measuredWidths.map((w, i) => Math.floor(w) + Math.floor(resizeDeltas[i]));
|
|
@@ -686,6 +682,10 @@ export function DataTable({
|
|
|
686
682
|
onSort(columnIndex);
|
|
687
683
|
}
|
|
688
684
|
}, [onSort]);
|
|
685
|
+
React.useImperativeHandle(controlRef, () => ({
|
|
686
|
+
clearSelection: handleSelectNone,
|
|
687
|
+
getRows: () => rows
|
|
688
|
+
}), [handleSelectNone, rows]);
|
|
689
689
|
const [columnHighlightIndex, setColumnHighlightIndex] = React.useState(-1);
|
|
690
690
|
const [rowHighlightIndex, setRowHighlightIndex] = React.useState(-1);
|
|
691
691
|
|
|
@@ -19,32 +19,46 @@ function useDuplicateColumnTitleWarning(columns) {
|
|
|
19
19
|
}, [columns]);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const [
|
|
22
|
+
export const StatefulContainer = props => {
|
|
23
|
+
useDuplicateColumnTitleWarning(props.columns);
|
|
24
|
+
const [sortIndex, setSortIndex] = React.useState(typeof props.initialSortIndex === 'number' ? props.initialSortIndex : -1);
|
|
25
|
+
const [sortDirection, setSortDirection] = React.useState(props.initialSortDirection);
|
|
26
|
+
const [filters, setFilters] = React.useState(props.initialFilters || new Map());
|
|
27
|
+
const [textQuery, setTextQuery] = React.useState('');
|
|
28
|
+
const [selectedRowIds, setSelectedRowIds] = React.useState(props.initialSelectedRowIds || new Set());
|
|
25
29
|
|
|
26
30
|
function handleSort(columnIndex) {
|
|
31
|
+
let nextSortIndex;
|
|
32
|
+
let nextSortDirection;
|
|
33
|
+
|
|
27
34
|
if (columnIndex === sortIndex) {
|
|
28
35
|
if (sortDirection === SORT_DIRECTIONS.DESC) {
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
nextSortIndex = -1;
|
|
37
|
+
nextSortDirection = SORT_DIRECTIONS.ASC;
|
|
31
38
|
} else {
|
|
32
|
-
|
|
39
|
+
nextSortIndex = columnIndex;
|
|
40
|
+
nextSortDirection = SORT_DIRECTIONS.DESC;
|
|
33
41
|
}
|
|
34
42
|
} else {
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
nextSortIndex = columnIndex;
|
|
44
|
+
nextSortDirection = SORT_DIRECTIONS.ASC;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
setSortIndex(nextSortIndex);
|
|
48
|
+
setSortDirection(nextSortDirection);
|
|
49
|
+
|
|
50
|
+
if (props.onSort) {
|
|
51
|
+
props.onSort(nextSortIndex, nextSortDirection);
|
|
37
52
|
}
|
|
38
53
|
}
|
|
39
54
|
|
|
40
|
-
|
|
41
|
-
|
|
55
|
+
function handleTextQueryChange(nextTextQuery) {
|
|
56
|
+
setTextQuery(nextTextQuery);
|
|
42
57
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const [textQuery, setTextQuery] = React.useState('');
|
|
58
|
+
if (props.onTextQueryChange) {
|
|
59
|
+
props.onTextQueryChange(nextTextQuery);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
48
62
|
|
|
49
63
|
function handleFilterAdd(title, filterParams) {
|
|
50
64
|
filters.set(title, filterParams);
|
|
@@ -66,8 +80,6 @@ export const StatefulContainer = props => {
|
|
|
66
80
|
setFilters(new Map(filters));
|
|
67
81
|
}
|
|
68
82
|
|
|
69
|
-
const [selectedRowIds, setSelectedRowIds] = React.useState(props.initialSelectedRowIds || new Set());
|
|
70
|
-
|
|
71
83
|
function handleSelectChange(next) {
|
|
72
84
|
setSelectedRowIds(next);
|
|
73
85
|
const selectionCallback = props.onSelectionChange;
|
|
@@ -116,7 +128,7 @@ export const StatefulContainer = props => {
|
|
|
116
128
|
onSelectNone: handleSelectNone,
|
|
117
129
|
onSelectOne: handleSelectOne,
|
|
118
130
|
onSort: handleSort,
|
|
119
|
-
onTextQueryChange:
|
|
131
|
+
onTextQueryChange: handleTextQueryChange,
|
|
120
132
|
resizableColumnWidths: Boolean(props.resizableColumnWidths),
|
|
121
133
|
rowHighlightIndex: props.rowHighlightIndex,
|
|
122
134
|
selectedRowIds,
|
|
@@ -140,6 +140,8 @@ export function StatefulDataTable(props) {
|
|
|
140
140
|
onIncludedRowsChange: props.onIncludedRowsChange,
|
|
141
141
|
onRowHighlightChange: props.onRowHighlightChange,
|
|
142
142
|
onSelectionChange: props.onSelectionChange,
|
|
143
|
+
onSort: props.onSort,
|
|
144
|
+
onTextQueryChange: props.onTextQueryChange,
|
|
143
145
|
resizableColumnWidths: props.resizableColumnWidths,
|
|
144
146
|
rows: props.rows,
|
|
145
147
|
rowActions: props.rowActions,
|
package/es/input/base-input.js
CHANGED
|
@@ -236,8 +236,6 @@ class BaseInput extends React.Component {
|
|
|
236
236
|
|
|
237
237
|
render() {
|
|
238
238
|
const {
|
|
239
|
-
value,
|
|
240
|
-
type,
|
|
241
239
|
overrides: {
|
|
242
240
|
InputContainer: InputContainerOverride,
|
|
243
241
|
Input: InputOverride,
|
|
@@ -289,7 +287,7 @@ class BaseInput extends React.Component {
|
|
|
289
287
|
max: this.props.max,
|
|
290
288
|
step: this.props.step,
|
|
291
289
|
rows: this.props.type === CUSTOM_INPUT_TYPE.textarea ? this.props.rows : null
|
|
292
|
-
}, sharedProps, inputProps)
|
|
290
|
+
}, sharedProps, inputProps)), this.renderClear(), this.renderMaskToggle(), /*#__PURE__*/React.createElement(After, _extends({}, sharedProps, afterProps)));
|
|
293
291
|
}
|
|
294
292
|
|
|
295
293
|
}
|
package/es/layer/tether.js
CHANGED
|
@@ -83,7 +83,7 @@ class Tether extends React.Component {
|
|
|
83
83
|
// eslint-disable-next-line no-console
|
|
84
84
|
console.warn(`[baseui][TetherBehavior] ref has not been passed to the Popper's anchor element.
|
|
85
85
|
See how to pass the ref to an anchor element in the Popover example
|
|
86
|
-
|
|
86
|
+
https://baseweb.design/components/popover/#anchor-ref-handling-example`);
|
|
87
87
|
}
|
|
88
88
|
} else {
|
|
89
89
|
this.initializePopper();
|
package/es/popover/popover.js
CHANGED
|
@@ -132,7 +132,7 @@ class PopoverInner extends React.Component {
|
|
|
132
132
|
return;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
if (!anchor || anchor === target || target instanceof Node &&
|
|
135
|
+
if (!anchor || anchor === target || target instanceof Node && anchor.contains(target)) {
|
|
136
136
|
return;
|
|
137
137
|
}
|
|
138
138
|
|
|
@@ -162,7 +162,7 @@ class PopoverInner extends React.Component {
|
|
|
162
162
|
// eslint-disable-next-line no-console
|
|
163
163
|
console.warn(`[baseui][Popover] ref has not been passed to the Popper's anchor element.
|
|
164
164
|
See how to pass the ref to an anchor element in the Popover example
|
|
165
|
-
|
|
165
|
+
https://baseweb.design/components/popover/#anchor-ref-handling-example`);
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
}
|
|
@@ -22,7 +22,7 @@ export default ((themePrimitives = colorTokens) => ({
|
|
|
22
22
|
bannerActionHighPositive: themePrimitives.positive600,
|
|
23
23
|
bannerActionHighWarning: themePrimitives.warning600,
|
|
24
24
|
// Buttons
|
|
25
|
-
buttonPrimaryFill: themePrimitives.
|
|
25
|
+
buttonPrimaryFill: themePrimitives.primaryA,
|
|
26
26
|
buttonPrimaryText: themePrimitives.black,
|
|
27
27
|
buttonPrimaryHover: themePrimitives.primary100,
|
|
28
28
|
buttonPrimaryActive: themePrimitives.primary200,
|
|
@@ -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 { BaseButtonTimed as StyledBaseButtonTimed, TimerContainer as 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 { BaseButtonTimed as StyledBaseButtonTimed, TimerContainer as 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,51 @@
|
|
|
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 BaseButtonTimed = 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
|
+
BaseButtonTimed.displayName = "BaseButtonTimed";
|
|
47
|
+
export var TimerContainer = styled('span', {
|
|
48
|
+
// minWidth to ensure button width stays consistent as timeRemaining changes
|
|
49
|
+
minWidth: '53px'
|
|
50
|
+
});
|
|
51
|
+
TimerContainer.displayName = "TimerContainer";
|
|
@@ -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
|
+
};
|
|
@@ -457,9 +457,7 @@ var InnerTableElement = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
457
457
|
}
|
|
458
458
|
|
|
459
459
|
var RowActionIcon = rowAction.renderIcon;
|
|
460
|
-
return /*#__PURE__*/React.createElement(Button
|
|
461
|
-
, {
|
|
462
|
-
alt: rowAction.label,
|
|
460
|
+
return /*#__PURE__*/React.createElement(Button, {
|
|
463
461
|
key: rowAction.label,
|
|
464
462
|
onClick: function onClick(event) {
|
|
465
463
|
return rowAction.onClick({
|
|
@@ -470,6 +468,7 @@ var InnerTableElement = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
470
468
|
size: BUTTON_SIZES.compact,
|
|
471
469
|
kind: BUTTON_KINDS.tertiary,
|
|
472
470
|
shape: BUTTON_SHAPES.round,
|
|
471
|
+
title: rowAction.label,
|
|
473
472
|
overrides: {
|
|
474
473
|
BaseButton: {
|
|
475
474
|
style: {
|
|
@@ -737,13 +736,6 @@ export function DataTable(_ref2) {
|
|
|
737
736
|
|
|
738
737
|
return result;
|
|
739
738
|
}, [sortedIndices, filteredIndices, onIncludedRowsChange, allRows]);
|
|
740
|
-
React.useImperativeHandle(controlRef, function () {
|
|
741
|
-
return {
|
|
742
|
-
getRows: function getRows() {
|
|
743
|
-
return rows;
|
|
744
|
-
}
|
|
745
|
-
};
|
|
746
|
-
}, [rows]);
|
|
747
739
|
|
|
748
740
|
var _React$useState19 = React.useState(0),
|
|
749
741
|
_React$useState20 = _slicedToArray(_React$useState19, 2),
|
|
@@ -838,6 +830,14 @@ export function DataTable(_ref2) {
|
|
|
838
830
|
onSort(columnIndex);
|
|
839
831
|
}
|
|
840
832
|
}, [onSort]);
|
|
833
|
+
React.useImperativeHandle(controlRef, function () {
|
|
834
|
+
return {
|
|
835
|
+
clearSelection: handleSelectNone,
|
|
836
|
+
getRows: function getRows() {
|
|
837
|
+
return rows;
|
|
838
|
+
}
|
|
839
|
+
};
|
|
840
|
+
}, [handleSelectNone, rows]);
|
|
841
841
|
|
|
842
842
|
var _React$useState21 = React.useState(-1),
|
|
843
843
|
_React$useState22 = _slicedToArray(_React$useState21, 2),
|