@carbon/ibm-products 1.35.2 → 1.36.0
Sign up to get free protection for your applications and to get access to all the features.
- package/css/index-full-carbon.css +21 -3
- package/css/index-full-carbon.css.map +1 -1
- package/css/index-full-carbon.min.css +2 -2
- package/css/index-full-carbon.min.css.map +1 -1
- package/css/index-without-carbon-released-only.css +6 -3
- package/css/index-without-carbon-released-only.css.map +1 -1
- package/css/index-without-carbon-released-only.min.css +1 -1
- package/css/index-without-carbon-released-only.min.css.map +1 -1
- package/css/index-without-carbon.css +21 -3
- package/css/index-without-carbon.css.map +1 -1
- package/css/index-without-carbon.min.css +2 -2
- package/css/index-without-carbon.min.css.map +1 -1
- package/css/index.css +21 -3
- package/css/index.css.map +1 -1
- package/css/index.min.css +2 -2
- package/css/index.min.css.map +1 -1
- package/es/components/ActionSet/ActionSet.js +6 -3
- package/es/components/AddSelect/add-select-utils.js +2 -2
- package/es/components/Datagrid/useNestedRowExpander.js +8 -3
- package/es/components/OptionsTile/OptionsTile.js +25 -10
- package/es/global/js/hooks/index.js +2 -1
- package/es/global/js/hooks/useControllableState.js +74 -0
- package/lib/components/ActionSet/ActionSet.js +6 -3
- package/lib/components/AddSelect/add-select-utils.js +2 -2
- package/lib/components/Datagrid/useNestedRowExpander.js +7 -2
- package/lib/components/OptionsTile/OptionsTile.js +25 -10
- package/lib/global/js/hooks/index.js +8 -1
- package/lib/global/js/hooks/useControllableState.js +80 -0
- package/package.json +2 -2
- package/scss/components/ActionSet/_action-set.scss +9 -4
- 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
|
* Copyright IBM Corp. 2021, 2022
|
8
8
|
*
|
@@ -19,6 +19,7 @@ import cx from 'classnames';
|
|
19
19
|
import { getDevtoolsProps } from '../../global/js/utils/devtools';
|
20
20
|
import uuidv4 from '../../global/js/utils/uuidv4';
|
21
21
|
import { pkg } from '../../settings';
|
22
|
+
import { useControllableState } from '../../global/js/hooks';
|
22
23
|
|
23
24
|
// Carbon and package components we use.
|
24
25
|
import { Toggle } from 'carbon-components-react';
|
@@ -33,6 +34,7 @@ var componentName = 'OptionsTile';
|
|
33
34
|
|
34
35
|
// Default values for props
|
35
36
|
var defaults = {
|
37
|
+
onChange: function onChange() {},
|
36
38
|
size: 'xl'
|
37
39
|
};
|
38
40
|
|
@@ -47,6 +49,8 @@ export var OptionsTile = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
47
49
|
invalidText = _ref.invalidText,
|
48
50
|
locked = _ref.locked,
|
49
51
|
lockedText = _ref.lockedText,
|
52
|
+
_ref$onChange = _ref.onChange,
|
53
|
+
_onChange = _ref$onChange === void 0 ? defaults.onChange : _ref$onChange,
|
50
54
|
onToggle = _ref.onToggle,
|
51
55
|
open = _ref.open,
|
52
56
|
_ref$size = _ref.size,
|
@@ -59,16 +63,22 @@ export var OptionsTile = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
59
63
|
rest = _objectWithoutProperties(_ref, _excluded);
|
60
64
|
var _useState = useState(open),
|
61
65
|
_useState2 = _slicedToArray(_useState, 2),
|
62
|
-
|
63
|
-
|
64
|
-
var _useState3 = useState(
|
66
|
+
prevIsOpen = _useState2[0],
|
67
|
+
setPrevIsOpen = _useState2[1];
|
68
|
+
var _useState3 = useState(false),
|
65
69
|
_useState4 = _slicedToArray(_useState3, 2),
|
66
|
-
|
67
|
-
|
68
|
-
var
|
69
|
-
|
70
|
-
|
71
|
-
|
70
|
+
closing = _useState4[0],
|
71
|
+
setClosing = _useState4[1];
|
72
|
+
var _useControllableState = useControllableState({
|
73
|
+
value: open,
|
74
|
+
defaultValue: open || null,
|
75
|
+
onChange: function onChange(value) {
|
76
|
+
return _onChange(value);
|
77
|
+
}
|
78
|
+
}),
|
79
|
+
_useControllableState2 = _slicedToArray(_useControllableState, 2),
|
80
|
+
isOpen = _useControllableState2[0],
|
81
|
+
setIsOpen = _useControllableState2[1];
|
72
82
|
var detailsRef = useRef(null);
|
73
83
|
var contentRef = useRef(null);
|
74
84
|
var id = uuidv4();
|
@@ -272,6 +282,11 @@ OptionsTile.propTypes = {
|
|
272
282
|
* Provide a text explaining why the OptionsTile is in locked state.
|
273
283
|
*/
|
274
284
|
lockedText: PropTypes.string,
|
285
|
+
/**
|
286
|
+
* Provide a function which will be called each time the user
|
287
|
+
* toggles the open state of the OptionsTile.
|
288
|
+
*/
|
289
|
+
onChange: PropTypes.func,
|
275
290
|
/**
|
276
291
|
* Provide a function which will be called each time the user
|
277
292
|
* interacts with the toggle.
|
@@ -14,4 +14,5 @@ export { useCreateComponentStepChange } from './useCreateComponentStepChange';
|
|
14
14
|
export { usePreviousValue } from './usePreviousValue';
|
15
15
|
export { useResetCreateComponent } from './useResetCreateComponent';
|
16
16
|
export { useRetrieveStepData } from './useRetrieveStepData';
|
17
|
-
export { useValidCreateStepCount } from './useValidCreateStepCount';
|
17
|
+
export { useValidCreateStepCount } from './useValidCreateStepCount';
|
18
|
+
export { useControllableState } from './useControllableState';
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
2
|
+
/**
|
3
|
+
* Copyright IBM Corp. 2016, 2022
|
4
|
+
*
|
5
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
7
|
+
*/
|
8
|
+
|
9
|
+
import { useEffect, useRef, useState } from 'react';
|
10
|
+
import pconsole from '../utils/pconsole';
|
11
|
+
|
12
|
+
/**
|
13
|
+
* This custom hook simplifies the behavior of a component if it has state that
|
14
|
+
* can be both controlled and uncontrolled. It functions identical to a
|
15
|
+
* useState() hook and provides [state, setState] for you to use. You can use
|
16
|
+
* the `onChange` argument to allow updates to the `state` to be communicated to
|
17
|
+
* owners of controlled components.
|
18
|
+
*
|
19
|
+
* Note: this hook will warn if a component is switching from controlled to
|
20
|
+
* uncontrolled, or vice-versa.
|
21
|
+
*
|
22
|
+
* @param {object} config
|
23
|
+
* @param {string} config.name - the name of the custom component
|
24
|
+
* @param {any} config.defaultValue - the default value used for the state. This will be
|
25
|
+
* the fallback value used if `value` is not defined.
|
26
|
+
* @param {Function} config.onChange - an optional function that is called when
|
27
|
+
* the value of the state changes. This is useful for communicating to parents of
|
28
|
+
* controlled components that the value is requesting to be changed.
|
29
|
+
* @param {any} config.value - a controlled value. Omitting this means that the state is
|
30
|
+
* uncontrolled
|
31
|
+
* @returns {[any, Function]}
|
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
|
+
var _useState = useState(value !== null && value !== void 0 ? value : defaultValue),
|
40
|
+
_useState2 = _slicedToArray(_useState, 2),
|
41
|
+
state = _useState2[0],
|
42
|
+
internalSetState = _useState2[1];
|
43
|
+
var controlled = useRef(null);
|
44
|
+
if (controlled.current === null) {
|
45
|
+
controlled.current = value !== undefined;
|
46
|
+
}
|
47
|
+
function setState(stateOrUpdater) {
|
48
|
+
var value = typeof stateOrUpdater === 'function' ? stateOrUpdater(state) : stateOrUpdater;
|
49
|
+
if (controlled.current === false) {
|
50
|
+
internalSetState(value);
|
51
|
+
}
|
52
|
+
if (onChange) {
|
53
|
+
onChange(value);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
useEffect(function () {
|
57
|
+
var controlledValue = value !== undefined;
|
58
|
+
// Uncontrolled -> Controlled
|
59
|
+
// If the component prop is uncontrolled, the prop value should be undefined
|
60
|
+
if (controlled.current === false && controlledValue) {
|
61
|
+
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");
|
62
|
+
}
|
63
|
+
|
64
|
+
// Controlled -> Uncontrolled
|
65
|
+
// If the component prop is controlled, the prop value should be defined
|
66
|
+
if (controlled.current === true && !controlledValue) {
|
67
|
+
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");
|
68
|
+
}
|
69
|
+
}, [name, value]);
|
70
|
+
if (controlled.current === true) {
|
71
|
+
return [value, setState];
|
72
|
+
}
|
73
|
+
return [state, setState];
|
74
|
+
}
|
@@ -14,7 +14,7 @@ var _classnames = _interopRequireDefault(require("classnames"));
|
|
14
14
|
var _settings = require("../../settings");
|
15
15
|
var _propsHelper = require("../../global/js/utils/props-helper");
|
16
16
|
var _carbonComponentsReact = require("carbon-components-react");
|
17
|
-
var _excluded = ["className", "disabled", "kind", "label", "loading"],
|
17
|
+
var _excluded = ["className", "disabled", "kind", "label", "loading", "isExpressive"],
|
18
18
|
_excluded2 = ["actions", "buttonSize", "className", "size"];
|
19
19
|
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; }
|
20
20
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
@@ -24,15 +24,18 @@ var componentName = 'ActionSet';
|
|
24
24
|
// NOTE: the component SCSS is not imported here: it is rolled up separately.
|
25
25
|
|
26
26
|
var ActionSetButton = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
27
|
+
var _ref2;
|
27
28
|
var className = _ref.className,
|
28
29
|
disabled = _ref.disabled,
|
29
30
|
kind = _ref.kind,
|
30
31
|
label = _ref.label,
|
31
32
|
loading = _ref.loading,
|
33
|
+
_ref$isExpressive = _ref.isExpressive,
|
34
|
+
isExpressive = _ref$isExpressive === void 0 ? true : _ref$isExpressive,
|
32
35
|
rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
33
36
|
return /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.Button, (0, _extends2.default)({}, rest, {
|
34
|
-
isExpressive:
|
35
|
-
className: (0, _classnames.default)(className, ["".concat(blockClass, "__action-button"), (0, _defineProperty2.default)(
|
37
|
+
isExpressive: isExpressive,
|
38
|
+
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)]),
|
36
39
|
disabled: disabled || loading || false,
|
37
40
|
kind: kind,
|
38
41
|
ref: ref
|
@@ -83,7 +83,7 @@ var getFilteredItems = function getFilteredItems(useNormalizedItems, normalizedI
|
|
83
83
|
var itemIds = Object.keys(normalizedItems);
|
84
84
|
if (searchTerm || globalFiltersApplied) {
|
85
85
|
var results = itemIds.reduce(function (prev, cur) {
|
86
|
-
if (normalizedItems[cur].title.toLowerCase().includes(searchTerm)) {
|
86
|
+
if (normalizedItems[cur].title.toLowerCase().includes(searchTerm.toLowerCase())) {
|
87
87
|
prev.push(normalizedItems[cur]);
|
88
88
|
}
|
89
89
|
return prev;
|
@@ -122,7 +122,7 @@ var getFilteredItems = function getFilteredItems(useNormalizedItems, normalizedI
|
|
122
122
|
} else {
|
123
123
|
if (searchTerm) {
|
124
124
|
return items.entries.filter(function (item) {
|
125
|
-
return item.title.toLowerCase().includes(searchTerm);
|
125
|
+
return item.title.toLowerCase().includes(searchTerm.toLowerCase());
|
126
126
|
});
|
127
127
|
}
|
128
128
|
return items.entries;
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
});
|
7
7
|
exports.default = void 0;
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
9
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
9
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
10
11
|
var _react = _interopRequireDefault(require("react"));
|
11
12
|
var _iconsReact = require("@carbon/icons-react");
|
@@ -28,8 +29,12 @@ var useNestedRowExpander = function useNestedRowExpander(hooks) {
|
|
28
29
|
Cell: function Cell(_ref) {
|
29
30
|
var _cx;
|
30
31
|
var row = _ref.row;
|
31
|
-
return row.canExpand && /*#__PURE__*/_react.default.createElement("
|
32
|
-
|
32
|
+
return row.canExpand && /*#__PURE__*/_react.default.createElement("button", (0, _extends2.default)({
|
33
|
+
type: "button",
|
34
|
+
"aria-label": "Expand current row",
|
35
|
+
className: (0, _classnames.default)("".concat(blockClass, "__row-expander"), "".concat(_settings.carbon.prefix, "--btn"), "".concat(_settings.carbon.prefix, "--btn--ghost"))
|
36
|
+
}, row.getToggleRowExpandedProps()), /*#__PURE__*/_react.default.createElement(_iconsReact.ChevronRight16, {
|
37
|
+
className: (0, _classnames.default)("".concat(blockClass, "__expander-icon"), "".concat(blockClass, "__row-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))
|
33
38
|
}));
|
34
39
|
},
|
35
40
|
width: 48,
|
@@ -16,10 +16,11 @@ var _classnames = _interopRequireDefault(require("classnames"));
|
|
16
16
|
var _devtools = require("../../global/js/utils/devtools");
|
17
17
|
var _uuidv = _interopRequireDefault(require("../../global/js/utils/uuidv4"));
|
18
18
|
var _settings = require("../../settings");
|
19
|
+
var _hooks = require("../../global/js/hooks");
|
19
20
|
var _carbonComponentsReact = require("carbon-components-react");
|
20
21
|
var _iconsReact = require("@carbon/icons-react");
|
21
22
|
var carbonMotion = _interopRequireWildcard(require("@carbon/motion"));
|
22
|
-
var _excluded = ["children", "className", "enabled", "invalid", "invalidText", "locked", "lockedText", "onToggle", "open", "size", "summary", "title", "titleId", "warn", "warnText"];
|
23
|
+
var _excluded = ["children", "className", "enabled", "invalid", "invalidText", "locked", "lockedText", "onChange", "onToggle", "open", "size", "summary", "title", "titleId", "warn", "warnText"];
|
23
24
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
24
25
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
25
26
|
// The block part of our conventional BEM class names (blockClass__E--M).
|
@@ -30,6 +31,7 @@ var componentName = 'OptionsTile';
|
|
30
31
|
|
31
32
|
// Default values for props
|
32
33
|
var defaults = {
|
34
|
+
onChange: function onChange() {},
|
33
35
|
size: 'xl'
|
34
36
|
};
|
35
37
|
|
@@ -44,6 +46,8 @@ var OptionsTile = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
44
46
|
invalidText = _ref.invalidText,
|
45
47
|
locked = _ref.locked,
|
46
48
|
lockedText = _ref.lockedText,
|
49
|
+
_ref$onChange = _ref.onChange,
|
50
|
+
_onChange = _ref$onChange === void 0 ? defaults.onChange : _ref$onChange,
|
47
51
|
onToggle = _ref.onToggle,
|
48
52
|
open = _ref.open,
|
49
53
|
_ref$size = _ref.size,
|
@@ -56,16 +60,22 @@ var OptionsTile = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
56
60
|
rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
57
61
|
var _useState = (0, _react.useState)(open),
|
58
62
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
59
|
-
|
60
|
-
|
61
|
-
var _useState3 = (0, _react.useState)(
|
63
|
+
prevIsOpen = _useState2[0],
|
64
|
+
setPrevIsOpen = _useState2[1];
|
65
|
+
var _useState3 = (0, _react.useState)(false),
|
62
66
|
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
63
|
-
|
64
|
-
|
65
|
-
var
|
66
|
-
|
67
|
-
|
68
|
-
|
67
|
+
closing = _useState4[0],
|
68
|
+
setClosing = _useState4[1];
|
69
|
+
var _useControllableState = (0, _hooks.useControllableState)({
|
70
|
+
value: open,
|
71
|
+
defaultValue: open || null,
|
72
|
+
onChange: function onChange(value) {
|
73
|
+
return _onChange(value);
|
74
|
+
}
|
75
|
+
}),
|
76
|
+
_useControllableState2 = (0, _slicedToArray2.default)(_useControllableState, 2),
|
77
|
+
isOpen = _useControllableState2[0],
|
78
|
+
setIsOpen = _useControllableState2[1];
|
69
79
|
var detailsRef = (0, _react.useRef)(null);
|
70
80
|
var contentRef = (0, _react.useRef)(null);
|
71
81
|
var id = (0, _uuidv.default)();
|
@@ -270,6 +280,11 @@ OptionsTile.propTypes = {
|
|
270
280
|
* Provide a text explaining why the OptionsTile is in locked state.
|
271
281
|
*/
|
272
282
|
lockedText: _propTypes.default.string,
|
283
|
+
/**
|
284
|
+
* Provide a function which will be called each time the user
|
285
|
+
* toggles the open state of the OptionsTile.
|
286
|
+
*/
|
287
|
+
onChange: _propTypes.default.func,
|
273
288
|
/**
|
274
289
|
* Provide a function which will be called each time the user
|
275
290
|
* 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() {
|
@@ -78,4 +84,5 @@ var _useCreateComponentStepChange = require("./useCreateComponentStepChange");
|
|
78
84
|
var _usePreviousValue = require("./usePreviousValue");
|
79
85
|
var _useResetCreateComponent = require("./useResetCreateComponent");
|
80
86
|
var _useRetrieveStepData = require("./useRetrieveStepData");
|
81
|
-
var _useValidCreateStepCount = require("./useValidCreateStepCount");
|
87
|
+
var _useValidCreateStepCount = require("./useValidCreateStepCount");
|
88
|
+
var _useControllableState = require("./useControllableState");
|
@@ -0,0 +1,80 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.useControllableState = useControllableState;
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
9
|
+
var _react = require("react");
|
10
|
+
var _pconsole = _interopRequireDefault(require("../utils/pconsole"));
|
11
|
+
/**
|
12
|
+
* Copyright IBM Corp. 2016, 2022
|
13
|
+
*
|
14
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
15
|
+
* LICENSE file in the root directory of this source tree.
|
16
|
+
*/
|
17
|
+
|
18
|
+
/**
|
19
|
+
* This custom hook simplifies the behavior of a component if it has state that
|
20
|
+
* can be both controlled and uncontrolled. It functions identical to a
|
21
|
+
* useState() hook and provides [state, setState] for you to use. You can use
|
22
|
+
* the `onChange` argument to allow updates to the `state` to be communicated to
|
23
|
+
* owners of controlled components.
|
24
|
+
*
|
25
|
+
* Note: this hook will warn if a component is switching from controlled to
|
26
|
+
* uncontrolled, or vice-versa.
|
27
|
+
*
|
28
|
+
* @param {object} config
|
29
|
+
* @param {string} config.name - the name of the custom component
|
30
|
+
* @param {any} config.defaultValue - the default value used for the state. This will be
|
31
|
+
* the fallback value used if `value` is not defined.
|
32
|
+
* @param {Function} config.onChange - an optional function that is called when
|
33
|
+
* the value of the state changes. This is useful for communicating to parents of
|
34
|
+
* controlled components that the value is requesting to be changed.
|
35
|
+
* @param {any} config.value - a controlled value. Omitting this means that the state is
|
36
|
+
* uncontrolled
|
37
|
+
* @returns {[any, Function]}
|
38
|
+
*/
|
39
|
+
function useControllableState(_ref) {
|
40
|
+
var defaultValue = _ref.defaultValue,
|
41
|
+
_ref$name = _ref.name,
|
42
|
+
name = _ref$name === void 0 ? 'custom' : _ref$name,
|
43
|
+
onChange = _ref.onChange,
|
44
|
+
value = _ref.value;
|
45
|
+
var _useState = (0, _react.useState)(value !== null && value !== void 0 ? value : defaultValue),
|
46
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
47
|
+
state = _useState2[0],
|
48
|
+
internalSetState = _useState2[1];
|
49
|
+
var controlled = (0, _react.useRef)(null);
|
50
|
+
if (controlled.current === null) {
|
51
|
+
controlled.current = value !== undefined;
|
52
|
+
}
|
53
|
+
function setState(stateOrUpdater) {
|
54
|
+
var value = typeof stateOrUpdater === 'function' ? stateOrUpdater(state) : stateOrUpdater;
|
55
|
+
if (controlled.current === false) {
|
56
|
+
internalSetState(value);
|
57
|
+
}
|
58
|
+
if (onChange) {
|
59
|
+
onChange(value);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
(0, _react.useEffect)(function () {
|
63
|
+
var controlledValue = value !== undefined;
|
64
|
+
// Uncontrolled -> Controlled
|
65
|
+
// If the component prop is uncontrolled, the prop value should be undefined
|
66
|
+
if (controlled.current === false && controlledValue) {
|
67
|
+
_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");
|
68
|
+
}
|
69
|
+
|
70
|
+
// Controlled -> Uncontrolled
|
71
|
+
// If the component prop is controlled, the prop value should be defined
|
72
|
+
if (controlled.current === true && !controlledValue) {
|
73
|
+
_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");
|
74
|
+
}
|
75
|
+
}, [name, value]);
|
76
|
+
if (controlled.current === true) {
|
77
|
+
return [value, setState];
|
78
|
+
}
|
79
|
+
return [state, setState];
|
80
|
+
}
|
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": "1.
|
4
|
+
"version": "1.36.0",
|
5
5
|
"license": "Apache-2.0",
|
6
6
|
"main": "lib/index.js",
|
7
7
|
"module": "es/index.js",
|
@@ -95,5 +95,5 @@
|
|
95
95
|
"react": "^16.8.6 || ^17.0.1",
|
96
96
|
"react-dom": "^16.8.6 || ^17.0.1"
|
97
97
|
},
|
98
|
-
"gitHead": "
|
98
|
+
"gitHead": "5d3cd5d3456d537a654f4d5ad010137bf567ca3a"
|
99
99
|
}
|
@@ -25,15 +25,20 @@
|
|
25
25
|
.#{$block-class} .#{$block-class}__action-button {
|
26
26
|
@include carbon--type-style('body-short-01');
|
27
27
|
|
28
|
-
height: $spacing-10;
|
29
28
|
align-items: center;
|
30
|
-
padding-top: $spacing-05;
|
31
|
-
padding-bottom: $spacing-07;
|
32
29
|
margin: 0;
|
30
|
+
|
31
|
+
&.#{$block-class}__action-button--expressive {
|
32
|
+
height: $spacing-10;
|
33
|
+
padding-top: $spacing-05;
|
34
|
+
padding-bottom: $spacing-07;
|
35
|
+
}
|
33
36
|
}
|
34
37
|
|
35
38
|
.#{$block-class}.#{$carbon-prefix}--btn-set
|
36
|
-
.#{$block-class}__action-button.#{$carbon-prefix}--btn.#{$carbon-prefix}--btn--expressive
|
39
|
+
.#{$block-class}__action-button.#{$carbon-prefix}--btn.#{$carbon-prefix}--btn--expressive,
|
40
|
+
.#{$block-class}.#{$carbon-prefix}--btn-set
|
41
|
+
.#{$block-class}__action-button.#{$carbon-prefix}--btn {
|
37
42
|
max-width: none;
|
38
43
|
}
|
39
44
|
|
@@ -29,3 +29,20 @@
|
|
29
29
|
td:first-child {
|
30
30
|
border-bottom: none;
|
31
31
|
}
|
32
|
+
|
33
|
+
.#{$block-class} .#{$block-class}__carbon-row-expandable {
|
34
|
+
position: relative;
|
35
|
+
}
|
36
|
+
|
37
|
+
.#{$block-class}
|
38
|
+
tr.#{$block-class}__carbon-nested-row
|
39
|
+
+ :not(tr.#{$block-class}__carbon-nested-row)::before {
|
40
|
+
position: absolute;
|
41
|
+
/* stylelint-disable-next-line carbon/layout-token-use */
|
42
|
+
top: -1px;
|
43
|
+
left: 0;
|
44
|
+
width: 100%;
|
45
|
+
height: 1px;
|
46
|
+
background-color: $border-subtle;
|
47
|
+
content: '';
|
48
|
+
}
|