@carbon/react 1.80.0-rc.0 → 1.80.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +822 -822
- package/es/components/ComposedModal/ComposedModal.js +16 -8
- package/es/components/InlineLoading/InlineLoading.js +10 -2
- package/es/components/Menu/MenuItem.d.ts +3 -3
- package/es/components/Menu/MenuItem.js +1 -1
- package/es/components/Modal/Modal.js +17 -5
- package/es/components/OverflowMenu/OverflowMenu.js +2 -2
- package/es/components/Tag/DismissibleTag.d.ts +1 -55
- package/es/components/Tag/DismissibleTag.js +6 -4
- package/es/components/Tag/OperationalTag.d.ts +1 -1
- package/es/components/Tag/SelectableTag.d.ts +1 -43
- package/es/components/Tag/SelectableTag.js +7 -5
- package/es/components/TreeView/TreeNode.d.ts +1 -1
- package/es/components/TreeView/TreeNode.js +11 -4
- package/es/components/TreeView/TreeView.d.ts +1 -1
- package/es/components/TreeView/TreeView.js +6 -6
- package/es/internal/ClickListener.d.ts +13 -0
- package/es/internal/ClickListener.js +33 -60
- package/es/internal/useControllableState.d.ts +34 -0
- package/es/internal/useControllableState.js +15 -30
- package/es/internal/useOutsideClick.d.ts +8 -0
- package/es/internal/useOutsideClick.js +9 -6
- package/lib/components/ComposedModal/ComposedModal.js +14 -6
- package/lib/components/InlineLoading/InlineLoading.js +10 -2
- package/lib/components/Menu/MenuItem.d.ts +3 -3
- package/lib/components/Menu/MenuItem.js +1 -1
- package/lib/components/Modal/Modal.js +15 -3
- package/lib/components/OverflowMenu/OverflowMenu.js +2 -2
- package/lib/components/Tag/DismissibleTag.d.ts +1 -55
- package/lib/components/Tag/DismissibleTag.js +5 -3
- package/lib/components/Tag/OperationalTag.d.ts +1 -1
- package/lib/components/Tag/SelectableTag.d.ts +1 -43
- package/lib/components/Tag/SelectableTag.js +6 -4
- package/lib/components/TreeView/TreeNode.d.ts +1 -1
- package/lib/components/TreeView/TreeNode.js +11 -4
- package/lib/components/TreeView/TreeView.d.ts +1 -1
- package/lib/components/TreeView/TreeView.js +6 -6
- package/lib/internal/ClickListener.d.ts +13 -0
- package/lib/internal/ClickListener.js +32 -64
- package/lib/internal/useControllableState.d.ts +34 -0
- package/lib/internal/useControllableState.js +15 -30
- package/lib/internal/useOutsideClick.d.ts +8 -0
- package/lib/internal/useOutsideClick.js +9 -6
- package/package.json +8 -7
|
@@ -54,7 +54,11 @@ const TreeView = _ref => {
|
|
|
54
54
|
const treeWalker = React.useRef(treeRootRef?.current);
|
|
55
55
|
const controllableSelectionState = useControllableState.useControllableState({
|
|
56
56
|
value: preselected,
|
|
57
|
-
onChange:
|
|
57
|
+
onChange: newSelected => {
|
|
58
|
+
onSelect?.(undefined, {
|
|
59
|
+
activeNodeId: newSelected[0]
|
|
60
|
+
});
|
|
61
|
+
},
|
|
58
62
|
defaultValue: []
|
|
59
63
|
});
|
|
60
64
|
const uncontrollableSelectionState = React.useState(preselected ?? []);
|
|
@@ -137,11 +141,7 @@ const TreeView = _ref => {
|
|
|
137
141
|
});
|
|
138
142
|
function handleKeyDown(event) {
|
|
139
143
|
event.stopPropagation();
|
|
140
|
-
if (match.matches(event, [keys.ArrowUp, keys.ArrowDown, keys.Home, keys.End
|
|
141
|
-
// @ts-ignore - `matches` doesn't like the object syntax without missing properties
|
|
142
|
-
{
|
|
143
|
-
code: 'KeyA'
|
|
144
|
-
}])) {
|
|
144
|
+
if (match.matches(event, [keys.ArrowUp, keys.ArrowDown, keys.Home, keys.End])) {
|
|
145
145
|
event.preventDefault();
|
|
146
146
|
}
|
|
147
147
|
if (!treeWalker.current) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React, { type ReactElement } from 'react';
|
|
8
|
+
interface ClickListenerProps {
|
|
9
|
+
children: ReactElement;
|
|
10
|
+
onClickOutside: (event: MouseEvent) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare const ClickListener: ({ children, onClickOutside, }: ClickListenerProps) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
13
|
+
export {};
|
|
@@ -9,75 +9,43 @@
|
|
|
9
9
|
|
|
10
10
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
11
|
|
|
12
|
-
var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js');
|
|
13
|
-
var PropTypes = require('prop-types');
|
|
14
12
|
var React = require('react');
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class ClickListener extends React__default["default"].Component {
|
|
26
|
-
static getEventTarget(evt) {
|
|
27
|
-
// support Shadow DOM
|
|
28
|
-
if (evt.composed && typeof evt.composedPath === 'function') {
|
|
29
|
-
return evt.composedPath()[0];
|
|
14
|
+
const ClickListener = _ref => {
|
|
15
|
+
let {
|
|
16
|
+
children,
|
|
17
|
+
onClickOutside
|
|
18
|
+
} = _ref;
|
|
19
|
+
const elementRef = React.useRef(null);
|
|
20
|
+
const getEventTarget = event => {
|
|
21
|
+
if (event.composed && typeof event.composedPath === 'function') {
|
|
22
|
+
return event.composedPath()[0];
|
|
30
23
|
}
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.handleDocumentClick = this.handleDocumentClick.bind(this);
|
|
39
|
-
}
|
|
40
|
-
componentDidMount() {
|
|
41
|
-
document.addEventListener('click', this.handleDocumentClick);
|
|
42
|
-
}
|
|
43
|
-
componentWillUnmount() {
|
|
44
|
-
document.removeEventListener('click', this.handleDocumentClick);
|
|
45
|
-
}
|
|
46
|
-
handleDocumentClick(evt) {
|
|
47
|
-
if (this.element) {
|
|
48
|
-
if (this.element.contains && !this.element.contains(ClickListener.getEventTarget(evt))) {
|
|
49
|
-
this.props.onClickOutside(evt);
|
|
24
|
+
return event.target;
|
|
25
|
+
};
|
|
26
|
+
const handleDocumentClick = event => {
|
|
27
|
+
if (elementRef.current?.contains) {
|
|
28
|
+
const eventTarget = getEventTarget(event);
|
|
29
|
+
if (eventTarget instanceof Node && !elementRef.current.contains(eventTarget)) {
|
|
30
|
+
onClickOutside(event);
|
|
50
31
|
}
|
|
51
32
|
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
* This means that here we target the following `ref` location:
|
|
63
|
-
*
|
|
64
|
-
* <ClickListener onClickOutside={() => {}}>
|
|
65
|
-
* <Child ref={targetedRefHere} />
|
|
66
|
-
* </ClickListener>
|
|
67
|
-
*/
|
|
68
|
-
if (children.ref && typeof children.ref === 'function') {
|
|
33
|
+
};
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
document.addEventListener('click', handleDocumentClick);
|
|
36
|
+
return () => {
|
|
37
|
+
document.removeEventListener('click', handleDocumentClick);
|
|
38
|
+
};
|
|
39
|
+
}, [onClickOutside]);
|
|
40
|
+
const handleRef = el => {
|
|
41
|
+
elementRef.current = el;
|
|
42
|
+
if ('ref' in children && typeof children.ref === 'function') {
|
|
69
43
|
children.ref(el);
|
|
70
44
|
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
_rollupPluginBabelHelpers.defineProperty(ClickListener, "propTypes", {
|
|
79
|
-
children: PropTypes__default["default"].element.isRequired,
|
|
80
|
-
onClickOutside: PropTypes__default["default"].func.isRequired
|
|
81
|
-
});
|
|
45
|
+
};
|
|
46
|
+
return /*#__PURE__*/React.cloneElement(children, {
|
|
47
|
+
ref: handleRef
|
|
48
|
+
});
|
|
49
|
+
};
|
|
82
50
|
|
|
83
|
-
exports
|
|
51
|
+
exports.ClickListener = ClickListener;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
interface UseControllableStateConfig<T> {
|
|
8
|
+
/** The name of the component. */
|
|
9
|
+
name?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The default value for the component. This value is used when the component
|
|
12
|
+
* is uncontrolled (i.e., when `value` is not provided).
|
|
13
|
+
*/
|
|
14
|
+
defaultValue: T;
|
|
15
|
+
/**
|
|
16
|
+
* This callback is called whenever the state changes. It's useful for
|
|
17
|
+
* communicating state updates to parent components of controlled components.
|
|
18
|
+
*/
|
|
19
|
+
onChange?: (value: T) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Controlled value. If this prop is omitted, the state will be uncontrolled.
|
|
22
|
+
*/
|
|
23
|
+
value?: T;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* This hook simplifies the behavior of a component that has state which can be
|
|
27
|
+
* both controlled and uncontrolled. It works like `useState`. You can use the
|
|
28
|
+
* `onChange` callback to communicate state updates to parent components.
|
|
29
|
+
*
|
|
30
|
+
* Note: This hook will warn if the component switches between controlled and
|
|
31
|
+
* uncontrolled states.
|
|
32
|
+
*/
|
|
33
|
+
export declare const useControllableState: <T>({ defaultValue, name, onChange, value, }: UseControllableStateConfig<T>) => [T, (stateOrUpdater: T | ((prev: T) => T)) => void];
|
|
34
|
+
export {};
|
|
@@ -13,58 +13,43 @@ var React = require('react');
|
|
|
13
13
|
var warning = require('./warning.js');
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* This
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* the `onChange` argument to allow updates to the `state` to be communicated to
|
|
20
|
-
* owners of controlled components.
|
|
16
|
+
* This hook simplifies the behavior of a component that has state which can be
|
|
17
|
+
* both controlled and uncontrolled. It works like `useState`. You can use the
|
|
18
|
+
* `onChange` callback to communicate state updates to parent components.
|
|
21
19
|
*
|
|
22
|
-
* Note:
|
|
23
|
-
* uncontrolled
|
|
24
|
-
*
|
|
25
|
-
* @param {object} config
|
|
26
|
-
* @param {string} [config.name] - the name of the custom component
|
|
27
|
-
* @param {any} config.defaultValue - the default value used for the state. This will be
|
|
28
|
-
* the fallback value used if `value` is not defined.
|
|
29
|
-
* @param {Function|undefined} config.onChange - an optional function that is called when
|
|
30
|
-
* the value of the state changes. This is useful for communicating to parents of
|
|
31
|
-
* controlled components that the value is requesting to be changed.
|
|
32
|
-
* @param {any} config.value - a controlled value. Omitting this means that the state is
|
|
33
|
-
* uncontrolled
|
|
34
|
-
* @returns {[any, (v: any) => void]}
|
|
20
|
+
* Note: This hook will warn if the component switches between controlled and
|
|
21
|
+
* uncontrolled states.
|
|
35
22
|
*/
|
|
36
|
-
|
|
23
|
+
const useControllableState = _ref => {
|
|
37
24
|
let {
|
|
38
25
|
defaultValue,
|
|
39
26
|
name = 'custom',
|
|
40
27
|
onChange,
|
|
41
28
|
value
|
|
42
29
|
} = _ref;
|
|
43
|
-
const [state, internalSetState] = React.useState(value
|
|
30
|
+
const [state, internalSetState] = React.useState(typeof value !== 'undefined' ? value : defaultValue);
|
|
44
31
|
const controlled = React.useRef(null);
|
|
45
32
|
if (controlled.current === null) {
|
|
46
|
-
controlled.current = value !== undefined;
|
|
33
|
+
controlled.current = typeof value !== 'undefined';
|
|
47
34
|
}
|
|
48
|
-
|
|
49
|
-
const
|
|
35
|
+
const setState = stateOrUpdater => {
|
|
36
|
+
const newValue = typeof stateOrUpdater === 'function' ? stateOrUpdater(state) : stateOrUpdater;
|
|
50
37
|
if (controlled.current === false) {
|
|
51
|
-
internalSetState(
|
|
38
|
+
internalSetState(newValue);
|
|
52
39
|
}
|
|
53
40
|
if (onChange) {
|
|
54
|
-
onChange(
|
|
41
|
+
onChange(newValue);
|
|
55
42
|
}
|
|
56
|
-
}
|
|
43
|
+
};
|
|
57
44
|
React.useEffect(() => {
|
|
58
|
-
const controlledValue = value !== undefined;
|
|
45
|
+
const controlledValue = typeof value !== 'undefined';
|
|
59
46
|
|
|
60
47
|
// Uncontrolled -> Controlled
|
|
61
|
-
// If the component prop is uncontrolled, the prop value should be undefined
|
|
62
48
|
if (controlled.current === false && controlledValue) {
|
|
63
49
|
process.env.NODE_ENV !== "production" ? warning.warning(false, `A component is changing an uncontrolled ${name} component to be controlled. ` + 'This is likely caused by the value changing to a defined value ' + 'from undefined. Decide between using a controlled or uncontrolled ' + 'value for the lifetime of the component. ' + 'More info: https://reactjs.org/link/controlled-components') : void 0;
|
|
64
50
|
}
|
|
65
51
|
|
|
66
52
|
// Controlled -> Uncontrolled
|
|
67
|
-
// If the component prop is controlled, the prop value should be defined
|
|
68
53
|
if (controlled.current === true && !controlledValue) {
|
|
69
54
|
process.env.NODE_ENV !== "production" ? warning.warning(false, `A component is changing a controlled ${name} component to be uncontrolled. ` + 'This is likely caused by the value changing to an undefined value ' + 'from a defined one. Decide between using a controlled or ' + 'uncontrolled value for the lifetime of the component. ' + 'More info: https://reactjs.org/link/controlled-components') : void 0;
|
|
70
55
|
}
|
|
@@ -73,6 +58,6 @@ function useControllableState(_ref) {
|
|
|
73
58
|
return [value, setState];
|
|
74
59
|
}
|
|
75
60
|
return [state, setState];
|
|
76
|
-
}
|
|
61
|
+
};
|
|
77
62
|
|
|
78
63
|
exports.useControllableState = useControllableState;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { type RefObject } from 'react';
|
|
8
|
+
export declare const useOutsideClick: <T extends HTMLElement>(ref: RefObject<T>, callback: (event: MouseEvent) => void) => void;
|
|
@@ -10,26 +10,29 @@
|
|
|
10
10
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
11
|
|
|
12
12
|
var React = require('react');
|
|
13
|
-
var useEvent = require('./useEvent.js');
|
|
14
13
|
var environment = require('./environment.js');
|
|
14
|
+
var useEvent = require('./useEvent.js');
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
const useOutsideClick = (ref, callback) => {
|
|
17
17
|
const savedCallback = React.useRef(callback);
|
|
18
18
|
React.useEffect(() => {
|
|
19
19
|
savedCallback.current = callback;
|
|
20
|
-
});
|
|
20
|
+
}, [callback]);
|
|
21
21
|
|
|
22
22
|
// We conditionally guard the `useEvent` hook for SSR. `canUseDOM` can be
|
|
23
23
|
// treated as a constant as it will be false when executed in a Node.js
|
|
24
24
|
// environment and true when executed in the browser
|
|
25
25
|
if (environment.canUseDOM) {
|
|
26
26
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
27
|
-
useEvent.
|
|
28
|
-
|
|
27
|
+
useEvent.useWindowEvent('click', event => {
|
|
28
|
+
const {
|
|
29
|
+
target
|
|
30
|
+
} = event;
|
|
31
|
+
if (target instanceof Node && ref.current && !ref.current.contains(target)) {
|
|
29
32
|
savedCallback.current(event);
|
|
30
33
|
}
|
|
31
34
|
});
|
|
32
35
|
}
|
|
33
|
-
}
|
|
36
|
+
};
|
|
34
37
|
|
|
35
38
|
exports.useOutsideClick = useOutsideClick;
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carbon/react",
|
|
3
3
|
"description": "React components for the Carbon Design System",
|
|
4
|
-
"version": "1.80.
|
|
4
|
+
"version": "1.80.1",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
8
8
|
"module": "es/index.js",
|
|
9
|
+
"sass": "index.scss",
|
|
9
10
|
"repository": {
|
|
10
11
|
"type": "git",
|
|
11
12
|
"url": "https://github.com/carbon-design-system/carbon.git",
|
|
@@ -51,10 +52,10 @@
|
|
|
51
52
|
},
|
|
52
53
|
"dependencies": {
|
|
53
54
|
"@babel/runtime": "^7.24.7",
|
|
54
|
-
"@carbon/feature-flags": "^0.
|
|
55
|
-
"@carbon/icons-react": "^11.58.0
|
|
56
|
-
"@carbon/layout": "^11.32.0
|
|
57
|
-
"@carbon/styles": "^1.79.
|
|
55
|
+
"@carbon/feature-flags": "^0.26.0",
|
|
56
|
+
"@carbon/icons-react": "^11.58.0",
|
|
57
|
+
"@carbon/layout": "^11.32.0",
|
|
58
|
+
"@carbon/styles": "^1.79.1",
|
|
58
59
|
"@floating-ui/react": "^0.27.4",
|
|
59
60
|
"@ibm/telemetry-js": "^1.5.0",
|
|
60
61
|
"classnames": "2.5.1",
|
|
@@ -79,7 +80,7 @@
|
|
|
79
80
|
"@babel/preset-react": "^7.24.7",
|
|
80
81
|
"@babel/preset-typescript": "^7.24.7",
|
|
81
82
|
"@carbon/test-utils": "^10.35.0",
|
|
82
|
-
"@carbon/themes": "^11.50.0
|
|
83
|
+
"@carbon/themes": "^11.50.0",
|
|
83
84
|
"@figma/code-connect": "^1.2.4",
|
|
84
85
|
"@rollup/plugin-babel": "^6.0.0",
|
|
85
86
|
"@rollup/plugin-commonjs": "^28.0.0",
|
|
@@ -146,5 +147,5 @@
|
|
|
146
147
|
"**/*.scss",
|
|
147
148
|
"**/*.css"
|
|
148
149
|
],
|
|
149
|
-
"gitHead": "
|
|
150
|
+
"gitHead": "1fcbf602a0c0a9e33987b3b63e7a7a8b39af47d0"
|
|
150
151
|
}
|