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.
Files changed (64) hide show
  1. package/button-timed/button-timed.d.ts +4 -0
  2. package/button-timed/button-timed.js +124 -0
  3. package/button-timed/index.d.ts +5 -0
  4. package/button-timed/index.js +78 -0
  5. package/button-timed/index.js.flow +57 -0
  6. package/button-timed/package.json +4 -0
  7. package/button-timed/styled-components.d.ts +5 -0
  8. package/button-timed/styled-components.js +57 -0
  9. package/button-timed/types.d.ts +12 -0
  10. package/button-timed/types.js +5 -0
  11. package/button-timed/utils.d.ts +1 -0
  12. package/button-timed/utils.js +30 -0
  13. package/card/card.js.flow +1 -1
  14. package/card/types.d.ts +1 -1
  15. package/card/types.js.flow +1 -1
  16. package/data-table/data-table.js +10 -10
  17. package/data-table/data-table.js.flow +2 -2
  18. package/data-table/stateful-container.js +41 -35
  19. package/data-table/stateful-data-table.js +2 -0
  20. package/data-table/types.d.ts +3 -0
  21. package/data-table/types.js.flow +2 -0
  22. package/es/button-timed/button-timed.js +82 -0
  23. package/es/button-timed/index.js +11 -0
  24. package/es/button-timed/styled-components.js +47 -0
  25. package/es/button-timed/types.js +1 -0
  26. package/es/button-timed/utils.js +21 -0
  27. package/es/data-table/data-table.js +6 -6
  28. package/es/data-table/stateful-container.js +30 -18
  29. package/es/data-table/stateful-data-table.js +2 -0
  30. package/es/input/base-input.js +1 -3
  31. package/es/layer/tether.js +1 -1
  32. package/es/popover/popover.js +2 -2
  33. package/es/themes/dark-theme/color-component-tokens.js +1 -1
  34. package/esm/button-timed/button-timed.js +112 -0
  35. package/esm/button-timed/index.js +11 -0
  36. package/esm/button-timed/styled-components.js +51 -0
  37. package/esm/button-timed/types.js +1 -0
  38. package/esm/button-timed/utils.js +21 -0
  39. package/esm/data-table/data-table.js +10 -10
  40. package/esm/data-table/stateful-container.js +41 -35
  41. package/esm/data-table/stateful-data-table.js +2 -0
  42. package/esm/input/base-input.js +6 -9
  43. package/esm/layer/tether.js +1 -1
  44. package/esm/popover/popover.js +2 -2
  45. package/esm/themes/dark-theme/color-component-tokens.js +1 -1
  46. package/header-navigation/types.d.ts +3 -2
  47. package/header-navigation/types.js.flow +2 -0
  48. package/input/base-input.js +6 -9
  49. package/layer/tether.js +1 -1
  50. package/layer/tether.js.flow +1 -1
  51. package/layout-grid/types.d.ts +1 -1
  52. package/package.json +1 -1
  53. package/popover/popover.js +2 -2
  54. package/popover/popover.js.flow +3 -3
  55. package/popover/types.d.ts +4 -4
  56. package/popover/types.js.flow +4 -4
  57. package/skeleton/skeleton.js.flow +1 -1
  58. package/skeleton/types.d.ts +1 -1
  59. package/skeleton/types.js.flow +1 -1
  60. package/themes/dark-theme/color-component-tokens.js +1 -1
  61. package/themes/dark-theme/color-component-tokens.js.flow +1 -1
  62. package/themes/types.d.ts +5 -5
  63. package/tree-view/tree-label-interactable.d.ts +3 -3
  64. package/tree-view/tree-label-interactable.js.flow +2 -0
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import type { ButtonTimedProps } from './types';
3
+ declare const ButtonTimed: (props: ButtonTimedProps) => JSX.Element;
4
+ export default ButtonTimed;
@@ -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.TimerContainer),
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.BaseButtonTimed,
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 { BaseButtonTimed as StyledBaseButtonTimed, TimerContainer as 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.BaseButtonTimed;
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.TimerContainer;
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,4 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "../esm/button-timed/index.js"
4
+ }
@@ -0,0 +1,5 @@
1
+ export declare const BaseButtonTimed: import("styletron-react").StyletronComponent<"button", {
2
+ $initialTime: number;
3
+ $timeElapsed: number;
4
+ } & import("../button").SharedStyleProps>;
5
+ export declare const TimerContainer: import("styletron-react").StyletronComponent<"span", {}>;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TimerContainer = exports.BaseButtonTimed = 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 BaseButtonTimed = (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.BaseButtonTimed = BaseButtonTimed;
51
+ BaseButtonTimed.displayName = "BaseButtonTimed";
52
+ var TimerContainer = (0, _index.styled)('span', {
53
+ // minWidth to ensure button width stays consistent as timeRemaining changes
54
+ minWidth: '53px'
55
+ });
56
+ exports.TimerContainer = TimerContainer;
57
+ TimerContainer.displayName = "TimerContainer";
@@ -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,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -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;
package/card/card.js.flow CHANGED
@@ -44,7 +44,7 @@ function Card(props: CardsPropsT) {
44
44
  const {
45
45
  action,
46
46
  children,
47
- hasThumbnail,
47
+ hasThumbnail: hasThumbnailProp = hasThumbnail,
48
48
  headerImage,
49
49
  thumbnail: thumbnailSrc,
50
50
  title,
package/card/types.d.ts CHANGED
@@ -31,7 +31,7 @@ export declare type CardProps = {
31
31
  /** Content to be rendered within the Card body. */
32
32
  readonly children?: ReactNode;
33
33
  /** Function that takes Card props and returns a boolean that represents if a thumbnail will be rendered. */
34
- readonly hasThumbnail: (a: {
34
+ readonly hasThumbnail?: (a: {
35
35
  readonly thumbnail?: string;
36
36
  }) => boolean;
37
37
  /** Image to be positioned at the top of the Card. Can be a string representing the img src or an object with img attrs */
@@ -41,7 +41,7 @@ export type CardsPropsT = {
41
41
  /** Content to be rendered within the Card body. */
42
42
  +children?: Node,
43
43
  /** Function that takes Card props and returns a boolean that represents if a thumbnail will be rendered. */
44
- +hasThumbnail: ({ +thumbnail?: string }) => boolean,
44
+ +hasThumbnail?: ({ +thumbnail?: string }) => boolean,
45
45
  /** Image to be positioned at the top of the Card. Can be a string representing the img src or an object with img attrs */
46
46
  +headerImage?: string | ImagePropsT,
47
47
  +overrides: CardComponentsT,
@@ -476,9 +476,7 @@ var InnerTableElement = /*#__PURE__*/React.forwardRef(function (props, ref) {
476
476
  }
477
477
 
478
478
  var RowActionIcon = rowAction.renderIcon;
479
- return /*#__PURE__*/React.createElement(_button.Button // @ts-expect-error todo(flow->ts): alt on button?
480
- , {
481
- alt: rowAction.label,
479
+ return /*#__PURE__*/React.createElement(_button.Button, {
482
480
  key: rowAction.label,
483
481
  onClick: function onClick(event) {
484
482
  return rowAction.onClick({
@@ -489,6 +487,7 @@ var InnerTableElement = /*#__PURE__*/React.forwardRef(function (props, ref) {
489
487
  size: _button.SIZE.compact,
490
488
  kind: _button.KIND.tertiary,
491
489
  shape: _button.SHAPE.round,
490
+ title: rowAction.label,
492
491
  overrides: {
493
492
  BaseButton: {
494
493
  style: {
@@ -756,13 +755,6 @@ function DataTable(_ref2) {
756
755
 
757
756
  return result;
758
757
  }, [sortedIndices, filteredIndices, onIncludedRowsChange, allRows]);
759
- React.useImperativeHandle(controlRef, function () {
760
- return {
761
- getRows: function getRows() {
762
- return rows;
763
- }
764
- };
765
- }, [rows]);
766
758
 
767
759
  var _React$useState19 = React.useState(0),
768
760
  _React$useState20 = _slicedToArray(_React$useState19, 2),
@@ -857,6 +849,14 @@ function DataTable(_ref2) {
857
849
  onSort(columnIndex);
858
850
  }
859
851
  }, [onSort]);
852
+ React.useImperativeHandle(controlRef, function () {
853
+ return {
854
+ clearSelection: handleSelectNone,
855
+ getRows: function getRows() {
856
+ return rows;
857
+ }
858
+ };
859
+ }, [handleSelectNone, rows]);
860
860
 
861
861
  var _React$useState21 = React.useState(-1),
862
862
  _React$useState22 = _slicedToArray(_React$useState21, 2),
@@ -810,8 +810,6 @@ export function DataTable({
810
810
  return result;
811
811
  }, [sortedIndices, filteredIndices, onIncludedRowsChange, allRows]);
812
812
 
813
- React.useImperativeHandle(controlRef, () => ({ getRows: () => rows }), [rows]);
814
-
815
813
  const [browserScrollbarWidth, setBrowserScrollbarWidth] = React.useState(0);
816
814
  const normalizedWidths = React.useMemo(() => {
817
815
  const resizedWidths = measuredWidths.map((w, i) => Math.floor(w) + Math.floor(resizeDeltas[i]));
@@ -902,6 +900,8 @@ export function DataTable({
902
900
  [onSort]
903
901
  );
904
902
 
903
+ React.useImperativeHandle(controlRef, () => ({ getRows: () => rows, clearSelection: handleSelectNone }), [handleSelectNone, rows]);
904
+
905
905
  const [columnHighlightIndex, setColumnHighlightIndex] = React.useState(-1);
906
906
  const [rowHighlightIndex, setRowHighlightIndex] = React.useState(-1);
907
907
 
@@ -49,55 +49,66 @@ function useDuplicateColumnTitleWarning(columns) {
49
49
  }, [columns]);
50
50
  }
51
51
 
52
- function useSortParameters() {
53
- var initialSortIndex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1;
54
- var initialSortDirection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
52
+ var StatefulContainer = function StatefulContainer(props) {
53
+ useDuplicateColumnTitleWarning(props.columns);
55
54
 
56
- var _React$useState = React.useState(initialSortIndex),
55
+ var _React$useState = React.useState(typeof props.initialSortIndex === 'number' ? props.initialSortIndex : -1),
57
56
  _React$useState2 = _slicedToArray(_React$useState, 2),
58
57
  sortIndex = _React$useState2[0],
59
58
  setSortIndex = _React$useState2[1];
60
59
 
61
- var _React$useState3 = React.useState(initialSortDirection),
60
+ var _React$useState3 = React.useState(props.initialSortDirection),
62
61
  _React$useState4 = _slicedToArray(_React$useState3, 2),
63
62
  sortDirection = _React$useState4[0],
64
63
  setSortDirection = _React$useState4[1];
65
64
 
65
+ var _React$useState5 = React.useState(props.initialFilters || new Map()),
66
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
67
+ filters = _React$useState6[0],
68
+ setFilters = _React$useState6[1];
69
+
70
+ var _React$useState7 = React.useState(''),
71
+ _React$useState8 = _slicedToArray(_React$useState7, 2),
72
+ textQuery = _React$useState8[0],
73
+ setTextQuery = _React$useState8[1];
74
+
75
+ var _React$useState9 = React.useState(props.initialSelectedRowIds || new Set()),
76
+ _React$useState10 = _slicedToArray(_React$useState9, 2),
77
+ selectedRowIds = _React$useState10[0],
78
+ setSelectedRowIds = _React$useState10[1];
79
+
66
80
  function handleSort(columnIndex) {
81
+ var nextSortIndex;
82
+ var nextSortDirection;
83
+
67
84
  if (columnIndex === sortIndex) {
68
85
  if (sortDirection === _constants.SORT_DIRECTIONS.DESC) {
69
- setSortIndex(-1);
70
- setSortDirection(_constants.SORT_DIRECTIONS.ASC);
86
+ nextSortIndex = -1;
87
+ nextSortDirection = _constants.SORT_DIRECTIONS.ASC;
71
88
  } else {
72
- setSortDirection(_constants.SORT_DIRECTIONS.DESC);
89
+ nextSortIndex = columnIndex;
90
+ nextSortDirection = _constants.SORT_DIRECTIONS.DESC;
73
91
  }
74
92
  } else {
75
- setSortIndex(columnIndex);
76
- setSortDirection(_constants.SORT_DIRECTIONS.ASC);
93
+ nextSortIndex = columnIndex;
94
+ nextSortDirection = _constants.SORT_DIRECTIONS.ASC;
77
95
  }
78
- }
79
-
80
- return [sortIndex, sortDirection, handleSort];
81
- }
82
96
 
83
- var StatefulContainer = function StatefulContainer(props) {
84
- useDuplicateColumnTitleWarning(props.columns);
97
+ setSortIndex(nextSortIndex);
98
+ setSortDirection(nextSortDirection);
85
99
 
86
- var _useSortParameters = useSortParameters(props.initialSortIndex, props.initialSortDirection),
87
- _useSortParameters2 = _slicedToArray(_useSortParameters, 3),
88
- sortIndex = _useSortParameters2[0],
89
- sortDirection = _useSortParameters2[1],
90
- handleSort = _useSortParameters2[2];
100
+ if (props.onSort) {
101
+ props.onSort(nextSortIndex, nextSortDirection);
102
+ }
103
+ }
91
104
 
92
- var _React$useState5 = React.useState(props.initialFilters || new Map()),
93
- _React$useState6 = _slicedToArray(_React$useState5, 2),
94
- filters = _React$useState6[0],
95
- setFilters = _React$useState6[1];
105
+ function handleTextQueryChange(nextTextQuery) {
106
+ setTextQuery(nextTextQuery);
96
107
 
97
- var _React$useState7 = React.useState(''),
98
- _React$useState8 = _slicedToArray(_React$useState7, 2),
99
- textQuery = _React$useState8[0],
100
- setTextQuery = _React$useState8[1];
108
+ if (props.onTextQueryChange) {
109
+ props.onTextQueryChange(nextTextQuery);
110
+ }
111
+ }
101
112
 
102
113
  function handleFilterAdd(title, filterParams) {
103
114
  filters.set(title, filterParams);
@@ -119,11 +130,6 @@ var StatefulContainer = function StatefulContainer(props) {
119
130
  setFilters(new Map(filters));
120
131
  }
121
132
 
122
- var _React$useState9 = React.useState(props.initialSelectedRowIds || new Set()),
123
- _React$useState10 = _slicedToArray(_React$useState9, 2),
124
- selectedRowIds = _React$useState10[0],
125
- setSelectedRowIds = _React$useState10[1];
126
-
127
133
  function handleSelectChange(next) {
128
134
  setSelectedRowIds(next);
129
135
  var selectionCallback = props.onSelectionChange;
@@ -176,7 +182,7 @@ var StatefulContainer = function StatefulContainer(props) {
176
182
  onSelectNone: handleSelectNone,
177
183
  onSelectOne: handleSelectOne,
178
184
  onSort: handleSort,
179
- onTextQueryChange: setTextQuery,
185
+ onTextQueryChange: handleTextQueryChange,
180
186
  resizableColumnWidths: Boolean(props.resizableColumnWidths),
181
187
  rowHighlightIndex: props.rowHighlightIndex,
182
188
  selectedRowIds: selectedRowIds,
@@ -221,6 +221,8 @@ function StatefulDataTable(props) {
221
221
  onIncludedRowsChange: props.onIncludedRowsChange,
222
222
  onRowHighlightChange: props.onRowHighlightChange,
223
223
  onSelectionChange: props.onSelectionChange,
224
+ onSort: props.onSort,
225
+ onTextQueryChange: props.onTextQueryChange,
224
226
  resizableColumnWidths: props.resizableColumnWidths,
225
227
  rows: props.rows,
226
228
  rowActions: props.rowActions,
@@ -64,6 +64,7 @@ export declare type RowAction = {
64
64
  };
65
65
  export declare type ImperativeMethods = {
66
66
  getRows: () => Row[];
67
+ clearSelection: () => void;
67
68
  };
68
69
  export declare type ControlRef = {
69
70
  current: ImperativeMethods | null;
@@ -88,6 +89,8 @@ export declare type StatefulDataTableProps = {
88
89
  onIncludedRowsChange?: (rows: Row[]) => void;
89
90
  onRowHighlightChange?: (rowIndex: number, row: Row) => void;
90
91
  onSelectionChange?: (a: Row[]) => unknown;
92
+ onSort?: (columnIndex: number, sortDirection: SortDirections) => void;
93
+ onTextQueryChange?: (textQuery: string) => void;
91
94
  resizableColumnWidths?: boolean;
92
95
  rows: Row[];
93
96
  rowActions?: RowAction[] | ((a: Row) => RowAction[]);
@@ -89,6 +89,7 @@ export type RowActionT = {|
89
89
 
90
90
  type ImperativeMethodsT = {|
91
91
  getRows: () => RowT[],
92
+ clearSelection: () => mixed,
92
93
  |};
93
94
  export type ControlRefT = {
94
95
  current: ImperativeMethodsT | null,
@@ -110,6 +111,7 @@ export type StatefulDataTablePropsT = {|
110
111
  onIncludedRowsChange?: (rows: RowT[]) => void,
111
112
  onRowHighlightChange?: (rowIndex: number, row: RowT) => void,
112
113
  onSelectionChange?: (RowT[]) => mixed,
114
+ onSort?: (columnIndex: number, sortDirection: SortDirectionsT) => void,
113
115
  resizableColumnWidths?: boolean,
114
116
  rows: RowT[],
115
117
  rowActions?: RowActionT[] | ((RowT) => RowActionT[]),