@carbon/ibm-products 2.0.0-rc.5 → 2.0.0-rc.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. package/css/index-full-carbon.css +45 -6
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +2 -2
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon-released-only.css +6 -3
  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 +45 -6
  10. package/css/index-without-carbon.css.map +1 -1
  11. package/css/index-without-carbon.min.css +2 -2
  12. package/css/index-without-carbon.min.css.map +1 -1
  13. package/css/index.css +38 -3
  14. package/css/index.css.map +1 -1
  15. package/css/index.min.css +2 -2
  16. package/css/index.min.css.map +1 -1
  17. package/es/components/ActionSet/ActionSet.js +7 -3
  18. package/es/components/AddSelect/add-select-utils.js +2 -2
  19. package/es/components/Datagrid/Datagrid/DatagridContent.js +1 -1
  20. package/es/components/Datagrid/Datagrid/DatagridRow.js +3 -3
  21. package/es/components/Datagrid/Datagrid/DatagridToolbar.js +4 -2
  22. package/es/components/Datagrid/useNestedRowExpander.js +7 -2
  23. package/es/components/Datagrid/useRowExpander.js +11 -3
  24. package/es/components/OptionsTile/OptionsTile.js +28 -12
  25. package/es/global/js/hooks/index.js +2 -1
  26. package/es/global/js/hooks/useControllableState.js +83 -0
  27. package/lib/components/ActionSet/ActionSet.js +7 -3
  28. package/lib/components/AddSelect/add-select-utils.js +2 -2
  29. package/lib/components/Datagrid/Datagrid/DatagridContent.js +1 -1
  30. package/lib/components/Datagrid/Datagrid/DatagridRow.js +3 -3
  31. package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +4 -2
  32. package/lib/components/Datagrid/useNestedRowExpander.js +7 -1
  33. package/lib/components/Datagrid/useRowExpander.js +15 -3
  34. package/lib/components/OptionsTile/OptionsTile.js +28 -11
  35. package/lib/global/js/hooks/index.js +9 -1
  36. package/lib/global/js/hooks/useControllableState.js +94 -0
  37. package/package.json +2 -2
  38. package/scss/components/ActionSet/_action-set.scss +9 -4
  39. package/scss/components/Datagrid/styles/_useExpandedRow.scss +19 -1
  40. package/scss/components/Datagrid/styles/_useNestedRows.scss +17 -0
@@ -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 = ["children", "className", "enabled", "invalid", "invalidText", "locked", "lockedText", "onToggle", "open", "size", "summary", "title", "titleId", "warn", "warnText"];
5
+ var _excluded = ["children", "className", "enabled", "invalid", "invalidText", "locked", "lockedText", "onChange", "onToggle", "open", "size", "summary", "title", "titleId", "warn", "warnText"];
6
6
 
7
7
  /**
8
8
  * Copyright IBM Corp. 2021, 2022
@@ -17,7 +17,8 @@ import PropTypes from 'prop-types';
17
17
  import cx from 'classnames';
18
18
  import { getDevtoolsProps } from '../../global/js/utils/devtools';
19
19
  import uuidv4 from '../../global/js/utils/uuidv4';
20
- import { pkg } from '../../settings'; // Carbon and package components we use.
20
+ import { pkg } from '../../settings';
21
+ import { useControllableState } from '../../global/js/hooks'; // Carbon and package components we use.
21
22
 
22
23
  import { Toggle } from '@carbon/react';
23
24
  import { ChevronDown, Locked, WarningAltFilled, WarningFilled } from '@carbon/react/icons';
@@ -28,6 +29,7 @@ var componentName = 'OptionsTile'; // NOTE: the component SCSS is not imported h
28
29
  // Default values for props
29
30
 
30
31
  var defaults = {
32
+ onChange: function onChange() {},
31
33
  size: 'xl'
32
34
  };
33
35
  /**
@@ -42,6 +44,8 @@ export var OptionsTile = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
42
44
  invalidText = _ref.invalidText,
43
45
  locked = _ref.locked,
44
46
  lockedText = _ref.lockedText,
47
+ _ref$onChange = _ref.onChange,
48
+ _onChange = _ref$onChange === void 0 ? defaults.onChange : _ref$onChange,
45
49
  onToggle = _ref.onToggle,
46
50
  open = _ref.open,
47
51
  _ref$size = _ref.size,
@@ -55,18 +59,24 @@ export var OptionsTile = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
55
59
 
56
60
  var _useState = useState(open),
57
61
  _useState2 = _slicedToArray(_useState, 2),
58
- isOpen = _useState2[0],
59
- setIsOpen = _useState2[1];
62
+ prevIsOpen = _useState2[0],
63
+ setPrevIsOpen = _useState2[1];
60
64
 
61
- var _useState3 = useState(open),
65
+ var _useState3 = useState(false),
62
66
  _useState4 = _slicedToArray(_useState3, 2),
63
- prevIsOpen = _useState4[0],
64
- setPrevIsOpen = _useState4[1];
65
-
66
- var _useState5 = useState(false),
67
- _useState6 = _slicedToArray(_useState5, 2),
68
- closing = _useState6[0],
69
- setClosing = _useState6[1];
67
+ closing = _useState4[0],
68
+ setClosing = _useState4[1];
69
+
70
+ var _useControllableState = useControllableState({
71
+ value: open,
72
+ defaultValue: open || null,
73
+ onChange: function onChange(value) {
74
+ return _onChange(value);
75
+ }
76
+ }),
77
+ _useControllableState2 = _slicedToArray(_useControllableState, 2),
78
+ isOpen = _useControllableState2[0],
79
+ setIsOpen = _useControllableState2[1];
70
80
 
71
81
  var detailsRef = useRef(null);
72
82
  var contentRef = useRef(null);
@@ -297,6 +307,12 @@ OptionsTile.propTypes = {
297
307
  */
298
308
  lockedText: PropTypes.string,
299
309
 
310
+ /**
311
+ * Provide a function which will be called each time the user
312
+ * toggles the open state of the OptionsTile.
313
+ */
314
+ onChange: PropTypes.func,
315
+
300
316
  /**
301
317
  * Provide a function which will be called each time the user
302
318
  * interacts with the toggle.
@@ -13,4 +13,5 @@ export { useCreateComponentStepChange } from './useCreateComponentStepChange';
13
13
  export { usePreviousValue } from './usePreviousValue';
14
14
  export { useResetCreateComponent } from './useResetCreateComponent';
15
15
  export { useRetrieveStepData } from './useRetrieveStepData';
16
- export { useValidCreateStepCount } from './useValidCreateStepCount';
16
+ export { useValidCreateStepCount } from './useValidCreateStepCount';
17
+ export { useControllableState } from './useControllableState';
@@ -0,0 +1,83 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+
3
+ /**
4
+ * Copyright IBM Corp. 2016, 2022
5
+ *
6
+ * This source code is licensed under the Apache-2.0 license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ import { useEffect, useRef, useState } from 'react';
10
+ import pconsole from '../utils/pconsole';
11
+ /**
12
+ * This custom hook simplifies the behavior of a component if it has state that
13
+ * can be both controlled and uncontrolled. It functions identical to a
14
+ * useState() hook and provides [state, setState] for you to use. You can use
15
+ * the `onChange` argument to allow updates to the `state` to be communicated to
16
+ * owners of controlled components.
17
+ *
18
+ * Note: this hook will warn if a component is switching from controlled to
19
+ * uncontrolled, or vice-versa.
20
+ *
21
+ * @param {object} config
22
+ * @param {string} config.name - the name of the custom component
23
+ * @param {any} config.defaultValue - the default value used for the state. This will be
24
+ * the fallback value used if `value` is not defined.
25
+ * @param {Function} config.onChange - an optional function that is called when
26
+ * the value of the state changes. This is useful for communicating to parents of
27
+ * controlled components that the value is requesting to be changed.
28
+ * @param {any} config.value - a controlled value. Omitting this means that the state is
29
+ * uncontrolled
30
+ * @returns {[any, Function]}
31
+ */
32
+
33
+ export function useControllableState(_ref) {
34
+ var defaultValue = _ref.defaultValue,
35
+ _ref$name = _ref.name,
36
+ name = _ref$name === void 0 ? 'custom' : _ref$name,
37
+ onChange = _ref.onChange,
38
+ value = _ref.value;
39
+
40
+ var _useState = useState(value !== null && value !== void 0 ? value : defaultValue),
41
+ _useState2 = _slicedToArray(_useState, 2),
42
+ state = _useState2[0],
43
+ internalSetState = _useState2[1];
44
+
45
+ var controlled = useRef(null);
46
+
47
+ if (controlled.current === null) {
48
+ controlled.current = value !== undefined;
49
+ }
50
+
51
+ function setState(stateOrUpdater) {
52
+ var value = typeof stateOrUpdater === 'function' ? stateOrUpdater(state) : stateOrUpdater;
53
+
54
+ if (controlled.current === false) {
55
+ internalSetState(value);
56
+ }
57
+
58
+ if (onChange) {
59
+ onChange(value);
60
+ }
61
+ }
62
+
63
+ useEffect(function () {
64
+ var controlledValue = value !== undefined; // Uncontrolled -> Controlled
65
+ // If the component prop is uncontrolled, the prop value should be undefined
66
+
67
+ if (controlled.current === false && controlledValue) {
68
+ pconsole.warn("A component is changing an uncontrolled %s component to be controlled.\n This is likely caused by the value changing to a defined value\n from undefined. Decide between using a controlled or uncontrolled\n value for the lifetime of the component.\n More info: https://reactjs.org/link/controlled-components");
69
+ } // Controlled -> Uncontrolled
70
+ // If the component prop is controlled, the prop value should be defined
71
+
72
+
73
+ if (controlled.current === true && !controlledValue) {
74
+ pconsole.warn("A component is changing a controlled %s component to be uncontrolled.\n 'This is likely caused by the value changing to an undefined value\n 'from a defined one. Decide between using a controlled or\n 'uncontrolled value for the lifetime of the component.\n 'More info: https://reactjs.org/link/controlled-components");
75
+ }
76
+ }, [name, value]);
77
+
78
+ if (controlled.current === true) {
79
+ return [value, setState];
80
+ }
81
+
82
+ return [state, setState];
83
+ }
@@ -25,7 +25,7 @@ var _propsHelper = require("../../global/js/utils/props-helper");
25
25
 
26
26
  var _react2 = require("@carbon/react");
27
27
 
28
- var _excluded = ["className", "disabled", "kind", "label", "loading"],
28
+ var _excluded = ["className", "disabled", "kind", "label", "loading", "isExpressive"],
29
29
  _excluded2 = ["actions", "buttonSize", "className", "size"];
30
30
 
31
31
  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; }
@@ -36,15 +36,19 @@ var blockClass = "".concat(_settings.pkg.prefix, "--action-set");
36
36
  var componentName = 'ActionSet'; // NOTE: the component SCSS is not imported here: it is rolled up separately.
37
37
 
38
38
  var ActionSetButton = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
39
+ var _ref2;
40
+
39
41
  var className = _ref.className,
40
42
  disabled = _ref.disabled,
41
43
  kind = _ref.kind,
42
44
  label = _ref.label,
43
45
  loading = _ref.loading,
46
+ _ref$isExpressive = _ref.isExpressive,
47
+ isExpressive = _ref$isExpressive === void 0 ? true : _ref$isExpressive,
44
48
  rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
45
49
  return /*#__PURE__*/_react.default.createElement(_react2.Button, (0, _extends2.default)({}, rest, {
46
- isExpressive: true,
47
- className: (0, _classnames.default)(className, ["".concat(blockClass, "__action-button"), (0, _defineProperty2.default)({}, "".concat(blockClass, "__action-button--ghost"), kind === 'ghost' || kind === 'danger--ghost')]),
50
+ isExpressive: isExpressive,
51
+ className: (0, _classnames.default)(className, ["".concat(blockClass, "__action-button"), (_ref2 = {}, (0, _defineProperty2.default)(_ref2, "".concat(blockClass, "__action-button--ghost"), kind === 'ghost' || kind === 'danger--ghost'), (0, _defineProperty2.default)(_ref2, "".concat(blockClass, "__action-button--expressive"), isExpressive), _ref2)]),
48
52
  disabled: disabled || loading || false,
49
53
  kind: kind,
50
54
  ref: ref
@@ -104,7 +104,7 @@ var getFilteredItems = function getFilteredItems(useNormalizedItems, normalizedI
104
104
 
105
105
  if (searchTerm || globalFiltersApplied) {
106
106
  var results = itemIds.reduce(function (prev, cur) {
107
- if (normalizedItems[cur].title.toLowerCase().includes(searchTerm)) {
107
+ if (normalizedItems[cur].title.toLowerCase().includes(searchTerm.toLowerCase())) {
108
108
  prev.push(normalizedItems[cur]);
109
109
  }
110
110
 
@@ -151,7 +151,7 @@ var getFilteredItems = function getFilteredItems(useNormalizedItems, normalizedI
151
151
  } else {
152
152
  if (searchTerm) {
153
153
  return items.entries.filter(function (item) {
154
- return item.title.toLowerCase().includes(searchTerm);
154
+ return item.title.toLowerCase().includes(searchTerm.toLowerCase());
155
155
  });
156
156
  }
157
157
 
@@ -140,7 +140,7 @@ var DatagridContent = function DatagridContent(_ref) {
140
140
  }
141
141
 
142
142
  var gridElement = document.querySelector("#".concat(tableId));
143
- var tableHeader = document.querySelector(".".concat(_settings.carbon.prefix, "--data-table-header"));
143
+ var tableHeader = gridElement === null || gridElement === void 0 ? void 0 : gridElement.querySelector(".".concat(_settings.carbon.prefix, "--data-table-header"));
144
144
  gridElement.style.setProperty("--".concat(blockClass, "--grid-width"), (0, _layout.px)(totalColumnsWidth + 32));
145
145
 
146
146
  if (gridActive) {
@@ -50,7 +50,7 @@ var DatagridRow = function DatagridRow(datagridState) {
50
50
  var activeCellId = state.activeCellId;
51
51
  var activeCellObject = activeCellId && (0, _getCellIdAsObject.getCellIdAsObject)(activeCellId);
52
52
  return /*#__PURE__*/_react.default.createElement(TableRow, (0, _extends2.default)({
53
- className: (0, _classnames.default)("".concat(blockClass, "__carbon-row"), (_cx = {}, (0, _defineProperty2.default)(_cx, "".concat(blockClass, "__carbon-row-expanded"), row.isExpanded), (0, _defineProperty2.default)(_cx, "".concat(_settings.carbon.prefix, "--data-table--selected"), row.isSelected), (0, _defineProperty2.default)(_cx, "".concat(blockClass, "__carbon-row-hover-active"), activeCellObject && row.index === activeCellObject.row), _cx))
53
+ className: (0, _classnames.default)("".concat(blockClass, "__carbon-row"), (_cx = {}, (0, _defineProperty2.default)(_cx, "".concat(blockClass, "__carbon-row-expanded"), row.isExpanded), (0, _defineProperty2.default)(_cx, "".concat(blockClass, "__carbon-row-expandable"), row.canExpand), (0, _defineProperty2.default)(_cx, "".concat(_settings.carbon.prefix, "--data-table--selected"), row.isSelected), (0, _defineProperty2.default)(_cx, "".concat(blockClass, "__carbon-row-hover-active"), activeCellObject && row.index === activeCellObject.row), _cx))
54
54
  }, row.getRowProps(), {
55
55
  key: row.id,
56
56
  onMouseEnter: function onMouseEnter(event) {
@@ -61,7 +61,7 @@ var DatagridRow = function DatagridRow(datagridState) {
61
61
  var hoverRow = event.target.closest(".".concat(blockClass, "__carbon-row-expanded"));
62
62
  hoverRow === null || hoverRow === void 0 ? void 0 : hoverRow.classList.remove("".concat(blockClass, "__carbon-row-expanded-hover-active"));
63
63
  }
64
- }), row.cells.map(function (cell) {
64
+ }), row.cells.map(function (cell, index) {
65
65
  var cellProps = cell.getCellProps();
66
66
  var children = cellProps.children,
67
67
  restProps = (0, _objectWithoutProperties2.default)(cellProps, _excluded);
@@ -76,7 +76,7 @@ var DatagridRow = function DatagridRow(datagridState) {
76
76
  }
77
77
 
78
78
  return /*#__PURE__*/_react.default.createElement(TableCell, (0, _extends2.default)({
79
- className: "".concat(blockClass, "__cell")
79
+ className: (0, _classnames.default)("".concat(blockClass, "__cell"), (0, _defineProperty2.default)({}, "".concat(blockClass, "__expandable-row-cell"), row.canExpand && index === 0))
80
80
  }, restProps, {
81
81
  key: cell.column.id
82
82
  }), content);
@@ -58,7 +58,8 @@ var DatagridBatchActionsToolbar = function DatagridBatchActionsToolbar(datagridS
58
58
 
59
59
  var selectedFlatRows = datagridState.selectedFlatRows,
60
60
  toggleAllRowsSelected = datagridState.toggleAllRowsSelected,
61
- toolbarBatchActions = datagridState.toolbarBatchActions;
61
+ toolbarBatchActions = datagridState.toolbarBatchActions,
62
+ setGlobalFilter = datagridState.setGlobalFilter;
62
63
  var totalSelected = selectedFlatRows && selectedFlatRows.length; // Get initial width of batch actions container,
63
64
  // used to measure when all items are put inside
64
65
  // the ButtonMenu
@@ -135,7 +136,8 @@ var DatagridBatchActionsToolbar = function DatagridBatchActionsToolbar(datagridS
135
136
  shouldShowBatchActions: totalSelected > 0,
136
137
  totalSelected: totalSelected,
137
138
  onCancel: function onCancel() {
138
- return toggleAllRowsSelected(false);
139
+ toggleAllRowsSelected(false);
140
+ setGlobalFilter(null);
139
141
  }
140
142
  }, !displayAllInMenu && toolbarBatchActions && (toolbarBatchActions === null || toolbarBatchActions === void 0 ? void 0 : toolbarBatchActions.map(function (batchAction, index) {
141
143
  if (index < 2 && toolbarBatchActions.length > 3 || index < 3 && toolbarBatchActions.length === 3) {
@@ -9,6 +9,8 @@ exports.default = void 0;
9
9
 
10
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
11
 
12
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
+
12
14
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
15
 
14
16
  var _react = _interopRequireDefault(require("react"));
@@ -38,7 +40,11 @@ var useNestedRowExpander = function useNestedRowExpander(hooks) {
38
40
  var _cx;
39
41
 
40
42
  var row = _ref.row;
41
- return row.canExpand && /*#__PURE__*/_react.default.createElement("span", row.getToggleRowExpandedProps(), /*#__PURE__*/_react.default.createElement(_icons.ChevronRight, {
43
+ return row.canExpand && /*#__PURE__*/_react.default.createElement("button", (0, _extends2.default)({
44
+ type: "button",
45
+ "aria-label": "Expand current row",
46
+ className: (0, _classnames.default)("".concat(blockClass, "__row-expander"), "".concat(_settings.carbon.prefix, "--btn"), "".concat(_settings.carbon.prefix, "--btn--ghost"))
47
+ }, row.getToggleRowExpandedProps()), /*#__PURE__*/_react.default.createElement(_icons.ChevronRight, {
42
48
  className: (0, _classnames.default)("".concat(blockClass, "__expander-icon"), (_cx = {}, (0, _defineProperty2.default)(_cx, "".concat(blockClass, "__expander-icon--not-open"), !row.isExpanded), (0, _defineProperty2.default)(_cx, "".concat(blockClass, "__expander-icon--open"), row.isExpanded), _cx))
43
49
  }));
44
50
  },
@@ -9,10 +9,16 @@ exports.default = void 0;
9
9
 
10
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
11
 
12
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
+
12
14
  var _react = _interopRequireDefault(require("react"));
13
15
 
14
16
  var _icons = require("@carbon/react/icons");
15
17
 
18
+ var _settings = require("../../settings");
19
+
20
+ var _classnames = _interopRequireDefault(require("classnames"));
21
+
16
22
  /* eslint-disable react/prop-types */
17
23
 
18
24
  /*
@@ -22,16 +28,22 @@ var _icons = require("@carbon/react/icons");
22
28
  * US Government Users Restricted Rights - Use, duplication or disclosure
23
29
  * restricted by GSA ADP Schedule Contract with IBM Corp.
24
30
  */
31
+ var blockClass = "".concat(_settings.pkg.prefix, "--datagrid");
32
+
25
33
  var useRowExpander = function useRowExpander(hooks) {
26
34
  var visibleColumns = function visibleColumns(columns) {
27
35
  var expanderColumn = {
28
36
  id: 'expander',
29
37
  Cell: function Cell(_ref) {
30
38
  var row = _ref.row;
31
- return row.canExpand && /*#__PURE__*/_react.default.createElement("span", row.getToggleRowExpandedProps(), row.isExpanded ? /*#__PURE__*/_react.default.createElement(_icons.ChevronUp, {
32
- size: 16
39
+ return row.canExpand && /*#__PURE__*/_react.default.createElement("button", (0, _extends2.default)({
40
+ type: "button",
41
+ "aria-label": "Expand current row",
42
+ className: (0, _classnames.default)("".concat(blockClass, "__row-expander"), "".concat(_settings.carbon.prefix, "--btn"), "".concat(_settings.carbon.prefix, "--btn--ghost"))
43
+ }, row.getToggleRowExpandedProps()), row.isExpanded ? /*#__PURE__*/_react.default.createElement(_icons.ChevronUp, {
44
+ className: "".concat(blockClass, "__row-expander--icon")
33
45
  }) : /*#__PURE__*/_react.default.createElement(_icons.ChevronDown, {
34
- size: 16
46
+ className: "".concat(blockClass, "__row-expander--icon")
35
47
  }));
36
48
  },
37
49
  width: 48,
@@ -29,13 +29,15 @@ var _uuidv = _interopRequireDefault(require("../../global/js/utils/uuidv4"));
29
29
 
30
30
  var _settings = require("../../settings");
31
31
 
32
+ var _hooks = require("../../global/js/hooks");
33
+
32
34
  var _react2 = require("@carbon/react");
33
35
 
34
36
  var _icons = require("@carbon/react/icons");
35
37
 
36
38
  var carbonMotion = _interopRequireWildcard(require("@carbon/motion"));
37
39
 
38
- var _excluded = ["children", "className", "enabled", "invalid", "invalidText", "locked", "lockedText", "onToggle", "open", "size", "summary", "title", "titleId", "warn", "warnText"];
40
+ var _excluded = ["children", "className", "enabled", "invalid", "invalidText", "locked", "lockedText", "onChange", "onToggle", "open", "size", "summary", "title", "titleId", "warn", "warnText"];
39
41
 
40
42
  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); }
41
43
 
@@ -47,6 +49,7 @@ var componentName = 'OptionsTile'; // NOTE: the component SCSS is not imported h
47
49
  // Default values for props
48
50
 
49
51
  var defaults = {
52
+ onChange: function onChange() {},
50
53
  size: 'xl'
51
54
  };
52
55
  /**
@@ -61,6 +64,8 @@ var OptionsTile = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
61
64
  invalidText = _ref.invalidText,
62
65
  locked = _ref.locked,
63
66
  lockedText = _ref.lockedText,
67
+ _ref$onChange = _ref.onChange,
68
+ _onChange = _ref$onChange === void 0 ? defaults.onChange : _ref$onChange,
64
69
  onToggle = _ref.onToggle,
65
70
  open = _ref.open,
66
71
  _ref$size = _ref.size,
@@ -74,18 +79,24 @@ var OptionsTile = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
74
79
 
75
80
  var _useState = (0, _react.useState)(open),
76
81
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
77
- isOpen = _useState2[0],
78
- setIsOpen = _useState2[1];
82
+ prevIsOpen = _useState2[0],
83
+ setPrevIsOpen = _useState2[1];
79
84
 
80
- var _useState3 = (0, _react.useState)(open),
85
+ var _useState3 = (0, _react.useState)(false),
81
86
  _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
82
- prevIsOpen = _useState4[0],
83
- setPrevIsOpen = _useState4[1];
84
-
85
- var _useState5 = (0, _react.useState)(false),
86
- _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
87
- closing = _useState6[0],
88
- setClosing = _useState6[1];
87
+ closing = _useState4[0],
88
+ setClosing = _useState4[1];
89
+
90
+ var _useControllableState = (0, _hooks.useControllableState)({
91
+ value: open,
92
+ defaultValue: open || null,
93
+ onChange: function onChange(value) {
94
+ return _onChange(value);
95
+ }
96
+ }),
97
+ _useControllableState2 = (0, _slicedToArray2.default)(_useControllableState, 2),
98
+ isOpen = _useControllableState2[0],
99
+ setIsOpen = _useControllableState2[1];
89
100
 
90
101
  var detailsRef = (0, _react.useRef)(null);
91
102
  var contentRef = (0, _react.useRef)(null);
@@ -318,6 +329,12 @@ OptionsTile.propTypes = {
318
329
  */
319
330
  lockedText: _propTypes.default.string,
320
331
 
332
+ /**
333
+ * Provide a function which will be called each time the user
334
+ * toggles the open state of the OptionsTile.
335
+ */
336
+ onChange: _propTypes.default.func,
337
+
321
338
  /**
322
339
  * Provide a function which will be called each time the user
323
340
  * interacts with the toggle.
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "useClickOutside", {
15
15
  return _useClickOutside.useClickOutside;
16
16
  }
17
17
  });
18
+ Object.defineProperty(exports, "useControllableState", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _useControllableState.useControllableState;
22
+ }
23
+ });
18
24
  Object.defineProperty(exports, "useCreateComponentFocus", {
19
25
  enumerable: true,
20
26
  get: function get() {
@@ -88,4 +94,6 @@ var _useResetCreateComponent = require("./useResetCreateComponent");
88
94
 
89
95
  var _useRetrieveStepData = require("./useRetrieveStepData");
90
96
 
91
- var _useValidCreateStepCount = require("./useValidCreateStepCount");
97
+ var _useValidCreateStepCount = require("./useValidCreateStepCount");
98
+
99
+ var _useControllableState = require("./useControllableState");
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.useControllableState = useControllableState;
9
+
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+
12
+ var _react = require("react");
13
+
14
+ var _pconsole = _interopRequireDefault(require("../utils/pconsole"));
15
+
16
+ /**
17
+ * Copyright IBM Corp. 2016, 2022
18
+ *
19
+ * This source code is licensed under the Apache-2.0 license found in the
20
+ * LICENSE file in the root directory of this source tree.
21
+ */
22
+
23
+ /**
24
+ * This custom hook simplifies the behavior of a component if it has state that
25
+ * can be both controlled and uncontrolled. It functions identical to a
26
+ * useState() hook and provides [state, setState] for you to use. You can use
27
+ * the `onChange` argument to allow updates to the `state` to be communicated to
28
+ * owners of controlled components.
29
+ *
30
+ * Note: this hook will warn if a component is switching from controlled to
31
+ * uncontrolled, or vice-versa.
32
+ *
33
+ * @param {object} config
34
+ * @param {string} config.name - the name of the custom component
35
+ * @param {any} config.defaultValue - the default value used for the state. This will be
36
+ * the fallback value used if `value` is not defined.
37
+ * @param {Function} config.onChange - an optional function that is called when
38
+ * the value of the state changes. This is useful for communicating to parents of
39
+ * controlled components that the value is requesting to be changed.
40
+ * @param {any} config.value - a controlled value. Omitting this means that the state is
41
+ * uncontrolled
42
+ * @returns {[any, Function]}
43
+ */
44
+ function useControllableState(_ref) {
45
+ var defaultValue = _ref.defaultValue,
46
+ _ref$name = _ref.name,
47
+ name = _ref$name === void 0 ? 'custom' : _ref$name,
48
+ onChange = _ref.onChange,
49
+ value = _ref.value;
50
+
51
+ var _useState = (0, _react.useState)(value !== null && value !== void 0 ? value : defaultValue),
52
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
53
+ state = _useState2[0],
54
+ internalSetState = _useState2[1];
55
+
56
+ var controlled = (0, _react.useRef)(null);
57
+
58
+ if (controlled.current === null) {
59
+ controlled.current = value !== undefined;
60
+ }
61
+
62
+ function setState(stateOrUpdater) {
63
+ var value = typeof stateOrUpdater === 'function' ? stateOrUpdater(state) : stateOrUpdater;
64
+
65
+ if (controlled.current === false) {
66
+ internalSetState(value);
67
+ }
68
+
69
+ if (onChange) {
70
+ onChange(value);
71
+ }
72
+ }
73
+
74
+ (0, _react.useEffect)(function () {
75
+ var controlledValue = value !== undefined; // Uncontrolled -> Controlled
76
+ // If the component prop is uncontrolled, the prop value should be undefined
77
+
78
+ if (controlled.current === false && controlledValue) {
79
+ _pconsole.default.warn("A component is changing an uncontrolled %s component to be controlled.\n This is likely caused by the value changing to a defined value\n from undefined. Decide between using a controlled or uncontrolled\n value for the lifetime of the component.\n More info: https://reactjs.org/link/controlled-components");
80
+ } // Controlled -> Uncontrolled
81
+ // If the component prop is controlled, the prop value should be defined
82
+
83
+
84
+ if (controlled.current === true && !controlledValue) {
85
+ _pconsole.default.warn("A component is changing a controlled %s component to be uncontrolled.\n 'This is likely caused by the value changing to an undefined value\n 'from a defined one. Decide between using a controlled or\n 'uncontrolled value for the lifetime of the component.\n 'More info: https://reactjs.org/link/controlled-components");
86
+ }
87
+ }, [name, value]);
88
+
89
+ if (controlled.current === true) {
90
+ return [value, setState];
91
+ }
92
+
93
+ return [state, setState];
94
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/ibm-products",
3
3
  "description": "Carbon for IBM Products",
4
- "version": "2.0.0-rc.5",
4
+ "version": "2.0.0-rc.7",
5
5
  "license": "Apache-2.0",
6
6
  "main": "lib/index.js",
7
7
  "module": "es/index.js",
@@ -94,5 +94,5 @@
94
94
  "react": "^16.8.6 || ^17.0.1",
95
95
  "react-dom": "^16.8.6 || ^17.0.1"
96
96
  },
97
- "gitHead": "53c78f2c4c8144b4fbedd9ba12c119c8bc2b8bda"
97
+ "gitHead": "85f73a55da546c111f110732a27921769d970c03"
98
98
  }
@@ -22,15 +22,20 @@ $action-set-block-class: #{c4p-settings.$pkg-prefix}--action-set;
22
22
  .#{$action-set-block-class} .#{$action-set-block-class}__action-button {
23
23
  @include type.type-style('body-short-01');
24
24
 
25
- height: $spacing-10;
26
25
  align-items: center;
27
- padding-top: $spacing-05;
28
- padding-bottom: $spacing-07;
29
26
  margin: 0;
27
+
28
+ &.#{$action-set-block-class}__action-button--expressive {
29
+ height: $spacing-10;
30
+ padding-top: $spacing-05;
31
+ padding-bottom: $spacing-07;
32
+ }
30
33
  }
31
34
 
32
35
  .#{$action-set-block-class}.#{c4p-settings.$carbon-prefix}--btn-set
33
- .#{$action-set-block-class}__action-button.#{c4p-settings.$carbon-prefix}--btn.#{c4p-settings.$carbon-prefix}--btn--expressive {
36
+ .#{$action-set-block-class}__action-button.#{c4p-settings.$carbon-prefix}--btn.#{c4p-settings.$carbon-prefix}--btn--expressive,
37
+ .#{$action-set-block-class}.#{c4p-settings.$carbon-prefix}--btn-set
38
+ .#{$action-set-block-class}__action-button.#{c4p-settings.$carbon-prefix}--btn {
34
39
  max-width: none;
35
40
  }
36
41
 
@@ -6,7 +6,7 @@
6
6
  * restricted by GSA ADP Schedule Contract with IBM Corp.
7
7
  */
8
8
 
9
- @use '../../../global/styles/project-settings';
9
+ @use '../../../global/styles/project-settings' as c4p-settings;
10
10
  @use '@carbon/styles/scss/theme' as *;
11
11
  @use '@carbon/styles/scss/spacing' as *;
12
12
  @use './variables';
@@ -40,3 +40,21 @@
40
40
  width: 100%;
41
41
  @include shared-pseudo-styles();
42
42
  }
43
+
44
+ .#{variables.$block-class}__carbon-row.#{variables.$block-class}__carbon-row-expandable
45
+ .#{variables.$block-class}__cell.#{variables.$block-class}__expandable-row-cell {
46
+ padding: $spacing-03;
47
+ padding-right: 0;
48
+ }
49
+
50
+ .#{variables.$block-class}__row-expander.#{c4p-settings.$carbon-prefix}--btn {
51
+ display: flex;
52
+ width: $spacing-07;
53
+ height: $spacing-07;
54
+ min-height: $spacing-07;
55
+ justify-content: center;
56
+ padding: 0;
57
+ .#{variables.$block-class}__row-expander--icon {
58
+ fill: $layer-selected-inverse;
59
+ }
60
+ }
@@ -33,3 +33,20 @@
33
33
  td:first-child {
34
34
  border-bottom: none;
35
35
  }
36
+
37
+ .#{$block-class} .#{$block-class}__carbon-row-expandable {
38
+ position: relative;
39
+ }
40
+
41
+ .#{$block-class}
42
+ tr.#{$block-class}__carbon-nested-row
43
+ + :not(tr.#{$block-class}__carbon-nested-row)::before {
44
+ position: absolute;
45
+ /* stylelint-disable-next-line carbon/layout-token-use */
46
+ top: -1px;
47
+ left: 0;
48
+ width: 100%;
49
+ height: 1px;
50
+ background-color: $border-subtle;
51
+ content: '';
52
+ }