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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. package/css/index-full-carbon.css +28 -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 +28 -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 +21 -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/useNestedRowExpander.js +7 -2
  20. package/es/components/OptionsTile/OptionsTile.js +28 -12
  21. package/es/global/js/hooks/index.js +2 -1
  22. package/es/global/js/hooks/useControllableState.js +83 -0
  23. package/lib/components/ActionSet/ActionSet.js +7 -3
  24. package/lib/components/AddSelect/add-select-utils.js +2 -2
  25. package/lib/components/Datagrid/useNestedRowExpander.js +7 -1
  26. package/lib/components/OptionsTile/OptionsTile.js +28 -11
  27. package/lib/global/js/hooks/index.js +9 -1
  28. package/lib/global/js/hooks/useControllableState.js +94 -0
  29. package/package.json +2 -2
  30. package/scss/components/ActionSet/_action-set.scss +9 -4
  31. package/scss/components/Datagrid/styles/_useNestedRows.scss +17 -0
@@ -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
 
@@ -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
  },
@@ -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.6",
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": "86f2f494ebd950387c6dbbe4b84a5bce0f9fc6ba"
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
 
@@ -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
+ }