@carbon/react 1.80.0-rc.0 → 1.80.0

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.
Files changed (40) hide show
  1. package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +874 -874
  2. package/es/components/InlineLoading/InlineLoading.js +10 -2
  3. package/es/components/Menu/MenuItem.d.ts +3 -3
  4. package/es/components/Menu/MenuItem.js +1 -1
  5. package/es/components/OverflowMenu/OverflowMenu.js +2 -2
  6. package/es/components/Tag/DismissibleTag.d.ts +1 -55
  7. package/es/components/Tag/DismissibleTag.js +6 -4
  8. package/es/components/Tag/OperationalTag.d.ts +1 -1
  9. package/es/components/Tag/SelectableTag.d.ts +1 -43
  10. package/es/components/Tag/SelectableTag.js +7 -5
  11. package/es/components/TreeView/TreeNode.d.ts +1 -1
  12. package/es/components/TreeView/TreeNode.js +11 -4
  13. package/es/components/TreeView/TreeView.d.ts +1 -1
  14. package/es/components/TreeView/TreeView.js +6 -6
  15. package/es/internal/ClickListener.d.ts +13 -0
  16. package/es/internal/ClickListener.js +33 -60
  17. package/es/internal/useControllableState.d.ts +34 -0
  18. package/es/internal/useControllableState.js +15 -30
  19. package/es/internal/useOutsideClick.d.ts +8 -0
  20. package/es/internal/useOutsideClick.js +9 -6
  21. package/lib/components/InlineLoading/InlineLoading.js +10 -2
  22. package/lib/components/Menu/MenuItem.d.ts +3 -3
  23. package/lib/components/Menu/MenuItem.js +1 -1
  24. package/lib/components/OverflowMenu/OverflowMenu.js +2 -2
  25. package/lib/components/Tag/DismissibleTag.d.ts +1 -55
  26. package/lib/components/Tag/DismissibleTag.js +5 -3
  27. package/lib/components/Tag/OperationalTag.d.ts +1 -1
  28. package/lib/components/Tag/SelectableTag.d.ts +1 -43
  29. package/lib/components/Tag/SelectableTag.js +6 -4
  30. package/lib/components/TreeView/TreeNode.d.ts +1 -1
  31. package/lib/components/TreeView/TreeNode.js +11 -4
  32. package/lib/components/TreeView/TreeView.d.ts +1 -1
  33. package/lib/components/TreeView/TreeView.js +6 -6
  34. package/lib/internal/ClickListener.d.ts +13 -0
  35. package/lib/internal/ClickListener.js +32 -64
  36. package/lib/internal/useControllableState.d.ts +34 -0
  37. package/lib/internal/useControllableState.js +15 -30
  38. package/lib/internal/useOutsideClick.d.ts +8 -0
  39. package/lib/internal/useOutsideClick.js +9 -6
  40. package/package.json +8 -7
@@ -13,58 +13,43 @@ var React = require('react');
13
13
  var warning = require('./warning.js');
14
14
 
15
15
  /**
16
- * This custom hook simplifies the behavior of a component if it has state that
17
- * can be both controlled and uncontrolled. It functions identical to a
18
- * useState() hook and provides [state, setState] for you to use. You can use
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: this hook will warn if a component is switching from controlled to
23
- * uncontrolled, or vice-versa.
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
- function useControllableState(_ref) {
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 ?? defaultValue);
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
- function setState(stateOrUpdater) {
49
- const value = typeof stateOrUpdater === 'function' ? stateOrUpdater(state) : stateOrUpdater;
35
+ const setState = stateOrUpdater => {
36
+ const newValue = typeof stateOrUpdater === 'function' ? stateOrUpdater(state) : stateOrUpdater;
50
37
  if (controlled.current === false) {
51
- internalSetState(value);
38
+ internalSetState(newValue);
52
39
  }
53
40
  if (onChange) {
54
- onChange(value);
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
- function useOutsideClick(ref, callback) {
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.useEvent(window, 'click', event => {
28
- if (ref.current && !ref.current.contains(event.target)) {
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.0-rc.0",
4
+ "version": "1.80.0",
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.25.0",
55
- "@carbon/icons-react": "^11.58.0-rc.0",
56
- "@carbon/layout": "^11.32.0-rc.0",
57
- "@carbon/styles": "^1.79.0-rc.0",
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.0",
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-rc.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": "0d87b91846d3b2a877f9f385f4f4b16214388315"
150
+ "gitHead": "7c4674649e1a5bd1367d99797df86cdc338eff6e"
150
151
  }