@carbon/ibm-products 1.24.0 → 1.26.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. package/css/index-full-carbon.css +77 -19
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +1 -1
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon-released-only.css +26 -15
  6. package/css/index-without-carbon-released-only.css.map +1 -1
  7. package/css/index-without-carbon-released-only.min.css +1 -1
  8. package/css/index-without-carbon-released-only.min.css.map +1 -1
  9. package/css/index-without-carbon.css +77 -19
  10. package/css/index-without-carbon.css.map +1 -1
  11. package/css/index-without-carbon.min.css +1 -1
  12. package/css/index-without-carbon.min.css.map +1 -1
  13. package/css/index.css +77 -19
  14. package/css/index.css.map +1 -1
  15. package/css/index.min.css +1 -1
  16. package/css/index.min.css.map +1 -1
  17. package/es/components/Datagrid/Datagrid/DatagridToolbar.js +140 -12
  18. package/es/components/Datagrid/useActionsColumn.js +31 -6
  19. package/es/components/Datagrid/useSelectRows.js +2 -2
  20. package/es/components/Datagrid/useStickyColumn.js +3 -0
  21. package/es/components/EmptyStates/EmptyStateContent.js +2 -1
  22. package/es/components/ImportModal/ImportModal.js +10 -2
  23. package/es/components/WebTerminal/WebTerminal.js +25 -13
  24. package/es/components/WebTerminal/WebTerminalContentWrapper.js +8 -10
  25. package/es/components/WebTerminal/hooks/index.js +45 -0
  26. package/es/components/WebTerminal/index.js +2 -1
  27. package/es/components/WebTerminal/preview-components/Navigation.js +6 -10
  28. package/es/components/index.js +1 -1
  29. package/es/global/js/package-settings.js +1 -0
  30. package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +149 -10
  31. package/lib/components/Datagrid/useActionsColumn.js +31 -6
  32. package/lib/components/Datagrid/useSelectRows.js +1 -1
  33. package/lib/components/Datagrid/useStickyColumn.js +3 -0
  34. package/lib/components/EmptyStates/EmptyStateContent.js +2 -1
  35. package/lib/components/ImportModal/ImportModal.js +11 -2
  36. package/lib/components/WebTerminal/WebTerminal.js +26 -13
  37. package/lib/components/WebTerminal/WebTerminalContentWrapper.js +9 -9
  38. package/lib/components/WebTerminal/hooks/index.js +69 -0
  39. package/lib/components/WebTerminal/index.js +15 -1
  40. package/lib/components/WebTerminal/preview-components/Navigation.js +6 -10
  41. package/lib/components/index.js +12 -0
  42. package/lib/global/js/package-settings.js +1 -0
  43. package/package.json +10 -10
  44. package/scss/components/AddSelect/_add-select.scss +19 -2
  45. package/scss/components/Datagrid/_datagrid.scss +5 -0
  46. package/scss/components/Datagrid/styles/{datagrid.scss → _datagrid.scss} +42 -2
  47. package/scss/components/Datagrid/styles/{draggableElement.scss → _draggableElement.scss} +0 -0
  48. package/scss/components/Datagrid/styles/{index.scss → _index.scss} +0 -0
  49. package/scss/components/Datagrid/styles/{useActionsColumn.scss → _useActionsColumn.scss} +0 -0
  50. package/scss/components/Datagrid/styles/{useColumnCenterAlign.scss → _useColumnCenterAlign.scss} +0 -0
  51. package/scss/components/Datagrid/styles/{useColumnRightAlign.scss → _useColumnRightAlign.scss} +0 -0
  52. package/scss/components/Datagrid/styles/{useExpandedRow.scss → _useExpandedRow.scss} +0 -0
  53. package/scss/components/Datagrid/styles/{useNestedRows.scss → _useNestedRows.scss} +0 -0
  54. package/scss/components/Datagrid/styles/{useNestedTable.scss → _useNestedTable.scss} +0 -0
  55. package/scss/components/Datagrid/styles/{useSelectAllToggle.scss → _useSelectAllToggle.scss} +0 -0
  56. package/scss/components/Datagrid/styles/{useSortableColumns.scss → _useSortableColumns.scss} +0 -0
  57. package/scss/components/Datagrid/styles/{useStickyColumn.scss → _useStickyColumn.scss} +0 -0
  58. package/scss/components/Datagrid/styles/addons/{CustomizeColumnsModal.scss → _CustomizeColumnsModal.scss} +0 -0
  59. package/scss/components/Datagrid/styles/addons/{RowSizeDropdown.scss → _RowSizeDropdown.scss} +0 -0
  60. package/scss/components/EmptyStates/_empty-state.scss +16 -9
  61. package/scss/components/InlineEdit/_inline-edit.scss +1 -1
  62. package/css/components/Datagrid/styles/addons/CustomizeColumnsModal.css +0 -47
  63. package/css/components/Datagrid/styles/addons/CustomizeColumnsModal.css.map +0 -1
  64. package/css/components/Datagrid/styles/addons/RowSizeDropdown.css +0 -20
  65. package/css/components/Datagrid/styles/addons/RowSizeDropdown.css.map +0 -1
  66. package/css/components/Datagrid/styles/datagrid.css +0 -383
  67. package/css/components/Datagrid/styles/datagrid.css.map +0 -1
  68. package/css/components/Datagrid/styles/draggableElement.css +0 -57
  69. package/css/components/Datagrid/styles/draggableElement.css.map +0 -1
  70. package/css/components/Datagrid/styles/index.css +0 -732
  71. package/css/components/Datagrid/styles/index.css.map +0 -1
  72. package/css/components/Datagrid/styles/useActionsColumn.css +0 -23
  73. package/css/components/Datagrid/styles/useActionsColumn.css.map +0 -1
  74. package/css/components/Datagrid/styles/useColumnCenterAlign.css +0 -18
  75. package/css/components/Datagrid/styles/useColumnCenterAlign.css.map +0 -1
  76. package/css/components/Datagrid/styles/useColumnRightAlign.css +0 -28
  77. package/css/components/Datagrid/styles/useColumnRightAlign.css.map +0 -1
  78. package/css/components/Datagrid/styles/useExpandedRow.css +0 -9
  79. package/css/components/Datagrid/styles/useExpandedRow.css.map +0 -1
  80. package/css/components/Datagrid/styles/useNestedRows.css +0 -15
  81. package/css/components/Datagrid/styles/useNestedRows.css.map +0 -1
  82. package/css/components/Datagrid/styles/useNestedTable.css +0 -25
  83. package/css/components/Datagrid/styles/useNestedTable.css.map +0 -1
  84. package/css/components/Datagrid/styles/useSelectAllToggle.css +0 -28
  85. package/css/components/Datagrid/styles/useSelectAllToggle.css.map +0 -1
  86. package/css/components/Datagrid/styles/useSortableColumns.css +0 -50
  87. package/css/components/Datagrid/styles/useSortableColumns.css.map +0 -1
  88. package/css/components/Datagrid/styles/useStickyColumn.css +0 -35
  89. package/css/components/Datagrid/styles/useStickyColumn.css.map +0 -1
@@ -32,19 +32,44 @@ var useActionsColumn = function useActionsColumn(hooks) {
32
32
 
33
33
  return [props, {
34
34
  children: /*#__PURE__*/React.createElement("div", {
35
- className: "".concat(blockClass, "__actions-column-content")
35
+ className: "".concat(blockClass, "__actions-column-contents")
36
36
  }, isFetching && /*#__PURE__*/React.createElement(IconSkeleton, {
37
37
  className: "".concat(blockClass, "__actions-column-loading")
38
- }), !isFetching && /*#__PURE__*/React.createElement(OverflowMenu, {
38
+ }), !isFetching && rowActions.length <= 2 && /*#__PURE__*/React.createElement("div", {
39
+ className: "".concat(blockClass, "_actions-column"),
40
+ style: {
41
+ display: 'flex'
42
+ }
43
+ }, rowActions.map(function (action) {
44
+ var id = action.id,
45
+ itemText = action.itemText,
46
+ _onClick = action.onClick,
47
+ icon = action.icon;
48
+ return /*#__PURE__*/React.createElement("div", {
49
+ className: "".concat(blockClass, "__actions-column-button"),
50
+ key: ""
51
+ }, /*#__PURE__*/React.createElement(OverflowMenu, {
52
+ renderIcon: icon,
53
+ hasIconOnly: true,
54
+ light: true,
55
+ iconDescription: itemText,
56
+ kind: "ghost",
57
+ onClick: function onClick(e) {
58
+ e.stopPropagation();
59
+
60
+ _onClick(id, row, e);
61
+ }
62
+ }));
63
+ })), !isFetching && rowActions.length > 2 && /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(OverflowMenu, {
39
64
  size: "sm",
40
65
  light: true,
41
66
  flipped: true,
42
67
  onClick: function onClick(e) {
43
- return e.stopPropagation();
68
+ e.stopPropagation();
44
69
  }
45
70
  }, rowActions.map(function (action) {
46
71
  var id = action.id,
47
- _onClick = action.onClick,
72
+ _onClick2 = action.onClick,
48
73
  shouldHideMenuItem = action.shouldHideMenuItem,
49
74
  shouldDisableMenuItem = action.shouldDisableMenuItem,
50
75
  disabled = action.disabled,
@@ -64,11 +89,11 @@ var useActionsColumn = function useActionsColumn(hooks) {
64
89
  onClick: function onClick(e) {
65
90
  e.stopPropagation();
66
91
 
67
- _onClick(id, row, e);
92
+ _onClick2(id, row, e);
68
93
  },
69
94
  key: id
70
95
  }));
71
- }))),
96
+ })))),
72
97
  className: cx((_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__actions-column-cell"), true), _defineProperty(_cx, "".concat(blockClass, "__cell"), true), _cx))
73
98
  }];
74
99
  }
@@ -21,7 +21,7 @@ import cx from 'classnames';
21
21
  import { TableSelectRow } from 'carbon-components-react';
22
22
  import { SelectAll } from './Datagrid/DatagridSelectAll';
23
23
  import { selectionColumnId } from './common-column-ids';
24
- import { pkg } from '../../settings';
24
+ import { pkg, carbon } from '../../settings';
25
25
  var blockClass = "".concat(pkg.prefix, "--datagrid");
26
26
 
27
27
  var useSelectRows = function useSelectRows(hooks) {
@@ -57,7 +57,7 @@ var useHighlightSelection = function useHighlightSelection(hooks) {
57
57
  var getRowProps = function getRowProps(props, _ref) {
58
58
  var row = _ref.row;
59
59
  return [props, {
60
- className: cx("".concat(blockClass, "__carbon-row"), row.getToggleRowSelectedProps().checked ? 'bx--data-table--selected' : '')
60
+ className: cx("".concat(blockClass, "__carbon-row"), row.getToggleRowSelectedProps().checked ? "".concat(carbon.prefix, "--data-table--selected ").concat(blockClass, "__active-row") : '')
61
61
  }];
62
62
  };
63
63
 
@@ -117,6 +117,9 @@ var useStickyColumn = function useStickyColumn(hooks) {
117
117
  if (spacerIdx >= 0 && stickyIdx >= 0 && stickyIdx < spacerIdx) {
118
118
  var _temp = newHeaders[spacerIdx];
119
119
  newHeaders[spacerIdx] = newHeaders[stickyIdx];
120
+ newHeaders[spacerIdx].canResize = false;
121
+ newHeaders[spacerIdx].disableResizing = true;
122
+ delete newHeaders[spacerIdx].getResizerProps;
120
123
  newHeaders[stickyIdx] = _temp;
121
124
  }
122
125
  });
@@ -36,7 +36,8 @@ export var EmptyStateContent = function EmptyStateContent(_ref) {
36
36
  className: "".concat(blockClass, "__action-button"),
37
37
  kind: action.kind || 'tertiary',
38
38
  onClick: action.onClick,
39
- renderIcon: action.renderIcon || null
39
+ renderIcon: action.renderIcon || null,
40
+ size: 'sm'
40
41
  }), action.text), (link === null || link === void 0 ? void 0 : link.text) && (link === null || link === void 0 ? void 0 : link.href) && /*#__PURE__*/React.createElement(Link, _extends({}, link, {
41
42
  className: "".concat(blockClass, "__link"),
42
43
  href: link.href
@@ -4,7 +4,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
4
4
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
5
5
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
6
6
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
7
- var _excluded = ["accept", "className", "defaultErrorBody", "defaultErrorHeader", "description", "fetchErrorBody", "fetchErrorHeader", "fileDropHeader", "fileDropLabel", "fileUploadLabel", "inputButtonText", "inputId", "inputLabel", "inputPlaceholder", "invalidFileTypeErrorBody", "invalidFileTypeErrorHeader", "invalidIconDescription", "maxFileSize", "maxFileSizeErrorBody", "maxFileSizeErrorHeader", "onClose", "onRequestSubmit", "open", "primaryButtonText", "secondaryButtonText", "title"];
7
+ var _excluded = ["accept", "className", "defaultErrorBody", "defaultErrorHeader", "description", "fetchErrorBody", "fetchErrorHeader", "fileDropHeader", "fileDropLabel", "fileUploadLabel", "inputButtonIcon", "inputButtonText", "inputId", "inputLabel", "inputPlaceholder", "invalidFileTypeErrorBody", "invalidFileTypeErrorHeader", "invalidIconDescription", "maxFileSize", "maxFileSizeErrorBody", "maxFileSizeErrorHeader", "onClose", "onRequestSubmit", "open", "primaryButtonText", "secondaryButtonText", "title"];
8
8
  import _regeneratorRuntime from "@babel/runtime/regenerator";
9
9
 
10
10
  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; }
@@ -18,6 +18,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
18
18
  // LICENSE file in the root directory of this source tree.
19
19
  //
20
20
  import React, { useState, forwardRef } from 'react';
21
+ import { Add20 } from '@carbon/icons-react';
21
22
  import { ComposedModal, ModalHeader, ModalFooter, ModalBody, FileUploaderDropContainer, FileUploaderItem, TextInput, Button } from 'carbon-components-react';
22
23
  import cx from 'classnames';
23
24
  import PropTypes from 'prop-types';
@@ -41,6 +42,7 @@ export var ImportModal = /*#__PURE__*/forwardRef(function (_ref, ref) {
41
42
  fileDropHeader = _ref.fileDropHeader,
42
43
  fileDropLabel = _ref.fileDropLabel,
43
44
  fileUploadLabel = _ref.fileUploadLabel,
45
+ inputButtonIcon = _ref.inputButtonIcon,
44
46
  inputButtonText = _ref.inputButtonText,
45
47
  inputId = _ref.inputId,
46
48
  inputLabel = _ref.inputLabel,
@@ -252,7 +254,8 @@ export var ImportModal = /*#__PURE__*/forwardRef(function (_ref, ref) {
252
254
  onClick: fetchFile,
253
255
  className: "".concat(blockClass, "__import-button"),
254
256
  size: "sm",
255
- disabled: importButtonDisabled
257
+ disabled: importButtonDisabled,
258
+ renderIcon: inputButtonIcon ? Add20 : null
256
259
  }, inputButtonText)), /*#__PURE__*/React.createElement("div", {
257
260
  className: "".concat(carbon.prefix, "--file-container ").concat(blockClass, "__file-container")
258
261
  }, hasFiles && /*#__PURE__*/React.createElement("p", {
@@ -341,6 +344,11 @@ ImportModal.propTypes = {
341
344
  */
342
345
  fileUploadLabel: PropTypes.string,
343
346
 
347
+ /**
348
+ * Button icon for import by url button
349
+ */
350
+ inputButtonIcon: PropTypes.bool,
351
+
344
352
  /**
345
353
  * Button text for import by url button
346
354
  */
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
5
- var _excluded = ["actions", "children", "className", "closeIconDescription", "closeTerminal", "documentationLinks", "documentationLinksIconDescription", "open"];
5
+ var _excluded = ["actions", "children", "className", "closeIconDescription", "documentationLinks", "documentationLinksIconDescription", "isInitiallyOpen"];
6
6
 
7
7
  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; }
8
8
 
@@ -24,6 +24,7 @@ import { pkg } from '../../settings'; // Carbon and package components we use.
24
24
  import { Close16 as Close, Help16 as Help } from '@carbon/icons-react';
25
25
  import { Button, OverflowMenu, OverflowMenuItem } from 'carbon-components-react';
26
26
  import { moderate02 } from '@carbon/motion';
27
+ import { useWebTerminal } from './hooks';
27
28
  import { getDevtoolsProps } from '../../global/js/utils/devtools'; // The block part of our conventional BEM class names (blockClass__E--M).
28
29
 
29
30
  var componentName = 'WebTerminal';
@@ -32,7 +33,8 @@ var blockClass = "".concat(pkg.prefix, "--web-terminal"); // Default values for
32
33
  var defaults = {
33
34
  actions: Object.freeze([]),
34
35
  documentationLinks: Object.freeze([]),
35
- documentationLinksIconDescription: 'Show documentation links'
36
+ documentationLinksIconDescription: 'Show documentation links',
37
+ isInitiallyOpen: false
36
38
  };
37
39
  export var WebTerminal = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
38
40
  var _ref3;
@@ -42,14 +44,19 @@ export var WebTerminal = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
42
44
  children = _ref.children,
43
45
  className = _ref.className,
44
46
  closeIconDescription = _ref.closeIconDescription,
45
- closeTerminal = _ref.closeTerminal,
46
47
  _ref$documentationLin = _ref.documentationLinks,
47
48
  documentationLinks = _ref$documentationLin === void 0 ? defaults.documentationLinks : _ref$documentationLin,
48
49
  _ref$documentationLin2 = _ref.documentationLinksIconDescription,
49
50
  documentationLinksIconDescription = _ref$documentationLin2 === void 0 ? defaults.documentationLinksIconDescription : _ref$documentationLin2,
50
- open = _ref.open,
51
+ _ref$isInitiallyOpen = _ref.isInitiallyOpen,
52
+ isInitiallyOpen = _ref$isInitiallyOpen === void 0 ? defaults.isInitiallyOpen : _ref$isInitiallyOpen,
51
53
  rest = _objectWithoutProperties(_ref, _excluded);
52
54
 
55
+ var _useWebTerminal = useWebTerminal(),
56
+ open = _useWebTerminal.open,
57
+ closeWebTerminal = _useWebTerminal.closeWebTerminal,
58
+ openWebTerminal = _useWebTerminal.openWebTerminal;
59
+
53
60
  var _useState = useState(open),
54
61
  _useState2 = _slicedToArray(_useState, 2),
55
62
  shouldRender = _useState2[0],
@@ -69,6 +76,16 @@ export var WebTerminal = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
69
76
  setRender(true);
70
77
  }
71
78
  }, [open]);
79
+ /**
80
+ On render, check if user want's the web terminal to be open by default
81
+ */
82
+
83
+ useEffect(function () {
84
+ if (isInitiallyOpen) {
85
+ openWebTerminal();
86
+ }
87
+ }, []); // eslint-disable-line
88
+
72
89
  /**
73
90
  When the web terminal slide in animation is complete, sets render to false.
74
91
  */
@@ -88,7 +105,7 @@ export var WebTerminal = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
88
105
  setRender(false);
89
106
  }
90
107
 
91
- closeTerminal();
108
+ closeWebTerminal();
92
109
  };
93
110
 
94
111
  return shouldRender ? /*#__PURE__*/React.createElement("div", _extends({}, _objectSpread(_objectSpread({}, rest), getDevtoolsProps(componentName)), {
@@ -172,23 +189,18 @@ WebTerminal.propTypes = {
172
189
  */
173
190
  closeIconDescription: PropTypes.string.isRequired,
174
191
 
175
- /**
176
- * Function that should set the open prop to false
177
- */
178
- closeTerminal: PropTypes.func.isRequired,
179
-
180
192
  /**
181
193
  * Array of objects for each documentation link. Each documentation link uses the prop types of OverflowMenuItems. See more: https://react.carbondesignsystem.com/?path=/docs/components-overflowmenu--default
182
194
  */
183
195
  documentationLinks: PropTypes.arrayOf(PropTypes.shape(_objectSpread({}, OverflowMenuItem.propTypes))),
184
196
 
185
197
  /**
186
- * Icon description for the documentation link overflow menu
198
+ * Description for the documentation link overflow menu tooltip
187
199
  */
188
200
  documentationLinksIconDescription: PropTypes.string,
189
201
 
190
202
  /**
191
- * Boolean that determines if the web terminal is opened or closed
203
+ * Optionally pass if the web terminal should be open by default
192
204
  */
193
- open: PropTypes.bool.isRequired
205
+ isInitiallyOpen: PropTypes.bool
194
206
  };
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
- var _excluded = ["children", "isTerminalOpen"];
4
+ var _excluded = ["children"];
5
5
 
6
6
  /**
7
7
  * Copyright IBM Corp. 2020, 2021
@@ -14,18 +14,21 @@ import React from 'react'; // Other standard imports.
14
14
 
15
15
  import PropTypes from 'prop-types';
16
16
  import cx from 'classnames';
17
- import { pkg } from '../../settings'; // The block part of our conventional BEM class names (blockClass__E--M).
17
+ import { pkg } from '../../settings';
18
+ import { useWebTerminal } from './hooks'; // The block part of our conventional BEM class names (blockClass__E--M).
18
19
 
19
20
  var componentName = 'WebTerminalContentWrapper';
20
21
  var blockClass = "".concat(pkg.prefix, "--web-terminal-content-wrapper");
21
22
  export var WebTerminalContentWrapper = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
22
23
  var children = _ref.children,
23
- isTerminalOpen = _ref.isTerminalOpen,
24
24
  rest = _objectWithoutProperties(_ref, _excluded);
25
25
 
26
+ var _useWebTerminal = useWebTerminal(),
27
+ open = _useWebTerminal.open;
28
+
26
29
  return /*#__PURE__*/React.createElement("div", _extends({
27
30
  ref: ref,
28
- className: cx([blockClass, _defineProperty({}, "".concat(blockClass, "--open"), isTerminalOpen)])
31
+ className: cx([blockClass, _defineProperty({}, "".concat(blockClass, "--open"), open)])
29
32
  }, rest), children);
30
33
  }); // Return a placeholder if not released and not enabled by feature flag
31
34
 
@@ -40,10 +43,5 @@ WebTerminalContentWrapper.propTypes = {
40
43
  /**
41
44
  * Pass in content as children.
42
45
  */
43
- children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
44
-
45
- /**
46
- * A boolean to determine if the terminal is open.
47
- */
48
- isTerminalOpen: PropTypes.bool.isRequired
46
+ children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired
49
47
  };
@@ -0,0 +1,45 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import React, { useState, useCallback, createContext } from 'react';
3
+ import { useContext } from 'react';
4
+ import PropTypes from 'prop-types';
5
+ import { pkg } from '../../../settings';
6
+ export var WebTerminalContext = /*#__PURE__*/createContext();
7
+ var componentName = 'WebTerminalProvider';
8
+ export var WebTerminalProvider = function WebTerminalProvider(_ref) {
9
+ var children = _ref.children;
10
+
11
+ var _useState = useState(false),
12
+ _useState2 = _slicedToArray(_useState, 2),
13
+ open = _useState2[0],
14
+ setOpen = _useState2[1];
15
+
16
+ var openWebTerminal = useCallback(function () {
17
+ return setOpen(true);
18
+ }, []);
19
+ var closeWebTerminal = useCallback(function () {
20
+ return setOpen(false);
21
+ }, []);
22
+ var toggleWebTerminal = useCallback(function () {
23
+ return setOpen(!open);
24
+ }, [open]);
25
+ return /*#__PURE__*/React.createElement(WebTerminalContext.Provider, {
26
+ value: {
27
+ open: open,
28
+ openWebTerminal: openWebTerminal,
29
+ closeWebTerminal: closeWebTerminal,
30
+ toggleWebTerminal: toggleWebTerminal
31
+ }
32
+ }, children);
33
+ }; // Return a placeholder if not released and not enabled by feature flag
34
+
35
+ WebTerminalProvider = pkg.checkComponentEnabled(WebTerminalProvider, componentName);
36
+ WebTerminalProvider.propTypes = {
37
+ /**
38
+ * Provide your own terminal component as children to show up in the web terminal
39
+ */
40
+ children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired
41
+ }; // Custom hook that exposes the provided value from context
42
+
43
+ export var useWebTerminal = function useWebTerminal() {
44
+ return useContext(WebTerminalContext);
45
+ };
@@ -1,2 +1,3 @@
1
1
  export { WebTerminal } from './WebTerminal';
2
- export { WebTerminalContentWrapper } from './WebTerminalContentWrapper';
2
+ export { WebTerminalContentWrapper } from './WebTerminalContentWrapper';
3
+ export { useWebTerminal, WebTerminalProvider } from './hooks';
@@ -1,10 +1,12 @@
1
1
  import React from 'react';
2
2
  import { Header, HeaderName, HeaderGlobalAction, HeaderGlobalBar } from 'carbon-components-react';
3
3
  import { Terminal20 as Terminal, Search20 as Search, User20 as User } from '@carbon/icons-react';
4
- import PropTypes from 'prop-types';
4
+ import { useWebTerminal } from '../hooks';
5
+
6
+ var Navigation = function Navigation() {
7
+ var _useWebTerminal = useWebTerminal(),
8
+ openWebTerminal = _useWebTerminal.openWebTerminal;
5
9
 
6
- var Navigation = function Navigation(_ref) {
7
- var openTerminal = _ref.openTerminal;
8
10
  return /*#__PURE__*/React.createElement(Header, {
9
11
  "aria-label": "IBM Platform Name"
10
12
  }, /*#__PURE__*/React.createElement(HeaderName, {
@@ -12,7 +14,7 @@ var Navigation = function Navigation(_ref) {
12
14
  prefix: "IBM"
13
15
  }, "[Platform]"), /*#__PURE__*/React.createElement(HeaderGlobalBar, null, /*#__PURE__*/React.createElement(HeaderGlobalAction, {
14
16
  "aria-label": "Web terminal",
15
- onClick: openTerminal
17
+ onClick: openWebTerminal
16
18
  }, /*#__PURE__*/React.createElement(Terminal, null)), /*#__PURE__*/React.createElement(HeaderGlobalAction, {
17
19
  "aria-label": "Search",
18
20
  onClick: function onClick() {}
@@ -22,10 +24,4 @@ var Navigation = function Navigation(_ref) {
22
24
  }, /*#__PURE__*/React.createElement(User, null))));
23
25
  };
24
26
 
25
- Navigation.propTypes = {
26
- /**
27
- * Opens the terminal
28
- */
29
- openTerminal: PropTypes.func.isRequired
30
- };
31
27
  export default Navigation;
@@ -32,7 +32,7 @@ export { TagSet } from './TagSet';
32
32
  export { Tearsheet, TearsheetNarrow } from './Tearsheet';
33
33
  export { Toolbar, ToolbarButton, ToolbarGroup } from './Toolbar';
34
34
  export { UserProfileImage } from './UserProfileImage';
35
- export { WebTerminal, WebTerminalContentWrapper } from './WebTerminal';
35
+ export { WebTerminal, WebTerminalContentWrapper, useWebTerminal, WebTerminalProvider } from './WebTerminal';
36
36
  export { EditSidePanel } from './EditSidePanel';
37
37
  export { OptionsTile } from './OptionsTile';
38
38
  export { InlineEdit } from './InlineEdit';
@@ -62,6 +62,7 @@ var defaults = {
62
62
  ToolbarGroup: false,
63
63
  WebTerminal: false,
64
64
  WebTerminalContentWrapper: false,
65
+ WebTerminalProvider: false,
65
66
  EditSidePanel: false,
66
67
  CancelableTextEdit: false,
67
68
  DataSpreadsheet: false,
@@ -2,33 +2,172 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
5
7
  Object.defineProperty(exports, "__esModule", {
6
8
  value: true
7
9
  });
8
10
  exports.default = void 0;
9
11
 
10
- var _react = _interopRequireDefault(require("react"));
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
14
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
+
16
+ var _react = _interopRequireWildcard(require("react"));
17
+
18
+ var _iconsReact = require("@carbon/icons-react");
11
19
 
12
20
  var _carbonComponentsReact = require("carbon-components-react");
13
21
 
22
+ var _reactResizeDetector = require("react-resize-detector");
23
+
24
+ var _ButtonMenu = require("../../ButtonMenu");
25
+
14
26
  var _settings = require("../../../settings");
15
27
 
16
- /*
17
- * Licensed Materials - Property of IBM
18
- * 5724-Q36
19
- * (c) Copyright IBM Corp. 2020
20
- * US Government Users Restricted Rights - Use, duplication or disclosure
21
- * restricted by GSA ADP Schedule Contract with IBM Corp.
28
+ var _classnames = _interopRequireDefault(require("classnames"));
29
+
30
+ 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); }
31
+
32
+ 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; }
33
+
34
+ /**
35
+ * Copyright IBM Corp. 2022, 2022
36
+ *
37
+ * This source code is licensed under the Apache-2.0 license found in the
38
+ * LICENSE file in the root directory of this source tree.
22
39
  */
23
40
  var blockClass = "".concat(_settings.pkg.prefix, "--datagrid");
24
41
  var TableToolbar = _carbonComponentsReact.DataTable.TableToolbar;
25
42
 
43
+ var DatagridBatchActionsToolbar = function DatagridBatchActionsToolbar(datagridState, width, ref) {
44
+ var _useState = (0, _react.useState)(false),
45
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
46
+ displayAllInMenu = _useState2[0],
47
+ setDisplayAllInMenu = _useState2[1];
48
+
49
+ var _useState3 = (0, _react.useState)(null),
50
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
51
+ initialListWidth = _useState4[0],
52
+ setInitialListWidth = _useState4[1];
53
+
54
+ var _useState5 = (0, _react.useState)(false),
55
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
56
+ receivedInitialWidth = _useState6[0],
57
+ setReceivedInitialWidth = _useState6[1];
58
+
59
+ var selectedFlatRows = datagridState.selectedFlatRows,
60
+ toggleAllRowsSelected = datagridState.toggleAllRowsSelected,
61
+ toolbarBatchActions = datagridState.toolbarBatchActions;
62
+ var totalSelected = selectedFlatRows && selectedFlatRows.length; // Get initial width of batch actions container,
63
+ // used to measure when all items are put inside
64
+ // the ButtonMenu
65
+
66
+ (0, _react.useEffect)(function () {
67
+ if (totalSelected === 1 && !receivedInitialWidth) {
68
+ var batchActionListWidth = ref.current.querySelector(".".concat(_settings.carbon.prefix, "--action-list")).offsetWidth;
69
+ setInitialListWidth(batchActionListWidth);
70
+ setReceivedInitialWidth(true);
71
+ }
72
+ }, [totalSelected, receivedInitialWidth, ref]);
73
+ (0, _react.useEffect)(function () {
74
+ var summaryWidth = ref.current.querySelector(".".concat(_settings.carbon.prefix, "--batch-summary")).offsetWidth;
75
+
76
+ if (width < summaryWidth + initialListWidth + 32) {
77
+ setDisplayAllInMenu(true);
78
+ } else {
79
+ setDisplayAllInMenu(false);
80
+ }
81
+ }, [width, ref, initialListWidth]); // Render batch actions in ButtonMenu
82
+
83
+ var renderBatchActionOverflow = function renderBatchActionOverflow() {
84
+ var minWidthBeforeOverflowIcon = 380; // Do not render ButtonMenu when there are 3 or less items
85
+ // and if there is enough available space to render all the items
86
+
87
+ if ((toolbarBatchActions === null || toolbarBatchActions === void 0 ? void 0 : toolbarBatchActions.length) <= 3 && !displayAllInMenu) {
88
+ return null;
89
+ }
90
+
91
+ return /*#__PURE__*/_react.default.createElement(_ButtonMenu.ButtonMenu, {
92
+ label: width > minWidthBeforeOverflowIcon ? 'More' : null,
93
+ renderIcon: width > minWidthBeforeOverflowIcon ? _iconsReact.Add16 : _iconsReact.OverflowMenuVertical16,
94
+ className: (0, _classnames.default)("".concat(blockClass, "__button-menu"), (0, _defineProperty2.default)({}, "".concat(blockClass, "__button-menu--icon-only"), width <= minWidthBeforeOverflowIcon)),
95
+ menuOptionsClass: "".concat(blockClass, "__button-menu-options"),
96
+ flipped: true
97
+ }, toolbarBatchActions && toolbarBatchActions.map(function (batchAction, index) {
98
+ if (index < 2) {
99
+ if (displayAllInMenu) {
100
+ return /*#__PURE__*/_react.default.createElement(_ButtonMenu.ButtonMenuItem, {
101
+ key: "".concat(batchAction.label, "-").concat(index),
102
+ itemText: batchAction.label,
103
+ onClick: function onClick() {
104
+ batchAction.onClick();
105
+
106
+ if (batchAction.type === 'select_all') {
107
+ toggleAllRowsSelected(true);
108
+ }
109
+ }
110
+ });
111
+ }
112
+
113
+ return null;
114
+ }
115
+
116
+ return /*#__PURE__*/_react.default.createElement(_ButtonMenu.ButtonMenuItem, {
117
+ key: "".concat(batchAction.label, "-").concat(index),
118
+ itemText: batchAction.label,
119
+ onClick: function onClick() {
120
+ batchAction.onClick();
121
+
122
+ if (batchAction.type === 'select_all') {
123
+ toggleAllRowsSelected(true);
124
+ }
125
+ }
126
+ });
127
+ }));
128
+ }; // Only display the first two batch actions, the rest are
129
+ // displayed inside of the ButtonMenu if there are more than
130
+ // 3 batch actions
131
+
132
+
133
+ return /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.TableBatchActions, {
134
+ shouldShowBatchActions: totalSelected > 0,
135
+ totalSelected: totalSelected,
136
+ onCancel: function onCancel() {
137
+ return toggleAllRowsSelected(false);
138
+ }
139
+ }, !displayAllInMenu && toolbarBatchActions && (toolbarBatchActions === null || toolbarBatchActions === void 0 ? void 0 : toolbarBatchActions.map(function (batchAction, index) {
140
+ if (index < 2 && toolbarBatchActions.length > 3 || index < 3 && toolbarBatchActions.length === 3) {
141
+ return /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.TableBatchAction, {
142
+ key: "".concat(batchAction.label, "-").concat(index),
143
+ renderIcon: batchAction.renderIcon,
144
+ onClick: function onClick() {
145
+ batchAction.onClick();
146
+
147
+ if (batchAction.type === 'select_all') {
148
+ toggleAllRowsSelected(true);
149
+ }
150
+ },
151
+ iconDescription: batchAction.label
152
+ }, batchAction.label);
153
+ }
154
+ })), renderBatchActionOverflow());
155
+ };
156
+
26
157
  var DatagridToolbar = function DatagridToolbar(datagridState) {
158
+ var _useResizeDetector = (0, _reactResizeDetector.useResizeDetector)(),
159
+ width = _useResizeDetector.width,
160
+ ref = _useResizeDetector.ref;
161
+
27
162
  var DatagridActions = datagridState.DatagridActions,
28
- DatagridBatchActions = datagridState.DatagridBatchActions;
29
- return DatagridActions || DatagridBatchActions ? /*#__PURE__*/_react.default.createElement("div", {
163
+ DatagridBatchActions = datagridState.DatagridBatchActions,
164
+ batchActions = datagridState.batchActions;
165
+ return batchActions && DatagridActions ? /*#__PURE__*/_react.default.createElement("div", {
166
+ ref: ref,
167
+ className: "".concat(blockClass, "__table-toolbar")
168
+ }, /*#__PURE__*/_react.default.createElement(TableToolbar, null, DatagridActions && DatagridActions(datagridState), DatagridBatchActionsToolbar && DatagridBatchActionsToolbar(datagridState, width, ref))) : /*#__PURE__*/_react.default.createElement("div", {
30
169
  className: "".concat(blockClass, "__table-toolbar")
31
- }, /*#__PURE__*/_react.default.createElement(TableToolbar, null, DatagridActions && DatagridActions(datagridState), DatagridBatchActions && DatagridBatchActions(datagridState))) : null;
170
+ }, /*#__PURE__*/_react.default.createElement(TableToolbar, null, DatagridActions && DatagridActions(datagridState), DatagridBatchActions && DatagridBatchActions(datagridState)));
32
171
  };
33
172
 
34
173
  var _default = DatagridToolbar;
@@ -40,19 +40,44 @@ var useActionsColumn = function useActionsColumn(hooks) {
40
40
 
41
41
  return [props, {
42
42
  children: /*#__PURE__*/_react.default.createElement("div", {
43
- className: "".concat(blockClass, "__actions-column-content")
43
+ className: "".concat(blockClass, "__actions-column-contents")
44
44
  }, isFetching && /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.IconSkeleton, {
45
45
  className: "".concat(blockClass, "__actions-column-loading")
46
- }), !isFetching && /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.OverflowMenu, {
46
+ }), !isFetching && rowActions.length <= 2 && /*#__PURE__*/_react.default.createElement("div", {
47
+ className: "".concat(blockClass, "_actions-column"),
48
+ style: {
49
+ display: 'flex'
50
+ }
51
+ }, rowActions.map(function (action) {
52
+ var id = action.id,
53
+ itemText = action.itemText,
54
+ _onClick = action.onClick,
55
+ icon = action.icon;
56
+ return /*#__PURE__*/_react.default.createElement("div", {
57
+ className: "".concat(blockClass, "__actions-column-button"),
58
+ key: ""
59
+ }, /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.OverflowMenu, {
60
+ renderIcon: icon,
61
+ hasIconOnly: true,
62
+ light: true,
63
+ iconDescription: itemText,
64
+ kind: "ghost",
65
+ onClick: function onClick(e) {
66
+ e.stopPropagation();
67
+
68
+ _onClick(id, row, e);
69
+ }
70
+ }));
71
+ })), !isFetching && rowActions.length > 2 && /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.OverflowMenu, {
47
72
  size: "sm",
48
73
  light: true,
49
74
  flipped: true,
50
75
  onClick: function onClick(e) {
51
- return e.stopPropagation();
76
+ e.stopPropagation();
52
77
  }
53
78
  }, rowActions.map(function (action) {
54
79
  var id = action.id,
55
- _onClick = action.onClick,
80
+ _onClick2 = action.onClick,
56
81
  shouldHideMenuItem = action.shouldHideMenuItem,
57
82
  shouldDisableMenuItem = action.shouldDisableMenuItem,
58
83
  disabled = action.disabled,
@@ -71,11 +96,11 @@ var useActionsColumn = function useActionsColumn(hooks) {
71
96
  onClick: function onClick(e) {
72
97
  e.stopPropagation();
73
98
 
74
- _onClick(id, row, e);
99
+ _onClick2(id, row, e);
75
100
  },
76
101
  key: id
77
102
  }));
78
- }))),
103
+ })))),
79
104
  className: (0, _classnames.default)((_cx = {}, (0, _defineProperty2.default)(_cx, "".concat(blockClass, "__actions-column-cell"), true), (0, _defineProperty2.default)(_cx, "".concat(blockClass, "__cell"), true), _cx))
80
105
  }];
81
106
  }