carbon-react 123.2.0 → 123.2.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.
@@ -122,7 +122,8 @@ export const Drawer = ({
122
122
  animationDuration: animationDuration,
123
123
  className: getClassNames(),
124
124
  ref: drawerSidebarContentRef,
125
- backgroundColor: backgroundColor
125
+ backgroundColor: backgroundColor,
126
+ "data-element": "drawer-content"
126
127
  }, stickyHeader && /*#__PURE__*/React.createElement(StyledSidebarHeader, {
127
128
  isExpanded: isExpanded
128
129
  }, title && /*#__PURE__*/React.createElement(StyledSidebarTitle, null, title), getControls()), !stickyHeader && /*#__PURE__*/React.createElement(React.Fragment, null, title && /*#__PURE__*/React.createElement(StyledSidebarTitle, null, title), getControls()), /*#__PURE__*/React.createElement(StyledDrawerSidebar, {
@@ -5,7 +5,7 @@ declare type FixedNavigationBarContextProps = {
5
5
  };
6
6
  declare const FixedNavigationBarContext: React.Context<FixedNavigationBarContextProps>;
7
7
  export interface FixedNavigationBarContextProviderProps extends Pick<NavigationBarProps, "position" | "orientation" | "offset" | "children"> {
8
- navbarElement: HTMLElement | null;
8
+ navbarRef: React.RefObject<HTMLElement>;
9
9
  }
10
- export declare const FixedNavigationBarContextProvider: ({ position, orientation, offset, children, navbarElement, }: FixedNavigationBarContextProviderProps) => React.JSX.Element;
10
+ export declare const FixedNavigationBarContextProvider: ({ position, orientation, offset, children, navbarRef, }: FixedNavigationBarContextProviderProps) => React.JSX.Element;
11
11
  export default FixedNavigationBarContext;
@@ -1,4 +1,4 @@
1
- import React, { createContext, useState, useCallback } from "react";
1
+ import React, { createContext, useState, useCallback, useEffect } from "react";
2
2
  import useResizeObserver from "../../hooks/__internal__/useResizeObserver/useResizeObserver";
3
3
  const FixedNavigationBarContext = /*#__PURE__*/createContext({});
4
4
  export const FixedNavigationBarContextProvider = ({
@@ -6,13 +6,14 @@ export const FixedNavigationBarContextProvider = ({
6
6
  orientation,
7
7
  offset,
8
8
  children,
9
- navbarElement
9
+ navbarRef
10
10
  }) => {
11
- const [navbarHeight, setNavbarHeight] = useState(navbarElement?.offsetHeight);
12
- const updateHeight = useCallback(() => setNavbarHeight(navbarElement?.offsetHeight), [navbarElement]);
13
- useResizeObserver({
14
- current: navbarElement
15
- }, updateHeight);
11
+ const [navbarHeight, setNavbarHeight] = useState(navbarRef.current?.offsetHeight);
12
+ const updateHeight = useCallback(() => setNavbarHeight(navbarRef.current?.offsetHeight), [navbarRef]);
13
+ useEffect(() => {
14
+ updateHeight();
15
+ }, [updateHeight]);
16
+ useResizeObserver(navbarRef, updateHeight);
16
17
  let submenuMaxHeight;
17
18
  if (position === "fixed") {
18
19
  if (orientation === "top" && navbarHeight !== undefined) {
@@ -1,5 +1,5 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
- import React, { useState } from "react";
2
+ import React, { useRef } from "react";
3
3
  import PropTypes from "prop-types";
4
4
  import StyledNavigationBar from "./navigation-bar.style";
5
5
  import { FixedNavigationBarContextProvider } from "./fixed-navigation-bar.context";
@@ -9,13 +9,18 @@ const NavigationBar = ({
9
9
  children,
10
10
  ariaLabel,
11
11
  position,
12
- offset = "0",
12
+ offset = "0px",
13
13
  orientation,
14
14
  isGlobal,
15
15
  ...props
16
16
  }) => {
17
- const [navbarElement, setNavbarElement] = useState(null);
18
- return /*#__PURE__*/React.createElement(StyledNavigationBar, _extends({
17
+ const navbarRef = useRef(null);
18
+ return /*#__PURE__*/React.createElement(FixedNavigationBarContextProvider, {
19
+ orientation: isGlobal ? "top" : orientation,
20
+ offset: isGlobal ? "0px" : offset,
21
+ position: isGlobal ? "fixed" : position,
22
+ navbarRef: navbarRef
23
+ }, /*#__PURE__*/React.createElement(StyledNavigationBar, _extends({
19
24
  role: "navigation",
20
25
  "data-component": isGlobal ? "global-header" : "navigation-bar",
21
26
  "aria-label": isGlobal ? "Global Header" : ariaLabel,
@@ -25,13 +30,8 @@ const NavigationBar = ({
25
30
  position: isGlobal ? "fixed" : position
26
31
  }, props, {
27
32
  isGlobal: isGlobal,
28
- ref: setNavbarElement
29
- }), /*#__PURE__*/React.createElement(FixedNavigationBarContextProvider, {
30
- orientation: isGlobal ? "top" : orientation,
31
- offset: isGlobal ? "0px" : offset,
32
- position: isGlobal ? "fixed" : position,
33
- navbarElement: navbarElement
34
- }, !isLoading && children));
33
+ ref: navbarRef
34
+ }), !isLoading && children));
35
35
  };
36
36
  NavigationBar.propTypes = {
37
37
  "alignContent": PropTypes.oneOfType([PropTypes.oneOf(["-moz-initial", "baseline", "center", "end", "flex-end", "flex-start", "inherit", "initial", "normal", "revert", "space-around", "space-between", "space-evenly", "start", "stretch", "unset"]), PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf(["-moz-initial", "baseline", "center", "end", "flex-end", "flex-start", "inherit", "initial", "normal", "revert", "space-around", "space-between", "space-evenly", "start", "stretch", "unset", null]), PropTypes.shape({
@@ -132,7 +132,8 @@ const Drawer = ({
132
132
  animationDuration: animationDuration,
133
133
  className: getClassNames(),
134
134
  ref: drawerSidebarContentRef,
135
- backgroundColor: backgroundColor
135
+ backgroundColor: backgroundColor,
136
+ "data-element": "drawer-content"
136
137
  }, stickyHeader && /*#__PURE__*/_react.default.createElement(_drawer.StyledSidebarHeader, {
137
138
  isExpanded: isExpanded
138
139
  }, title && /*#__PURE__*/_react.default.createElement(_drawer.StyledSidebarTitle, null, title), getControls()), !stickyHeader && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, title && /*#__PURE__*/_react.default.createElement(_drawer.StyledSidebarTitle, null, title), getControls()), /*#__PURE__*/_react.default.createElement(_drawer.StyledDrawerSidebar, {
@@ -5,7 +5,7 @@ declare type FixedNavigationBarContextProps = {
5
5
  };
6
6
  declare const FixedNavigationBarContext: React.Context<FixedNavigationBarContextProps>;
7
7
  export interface FixedNavigationBarContextProviderProps extends Pick<NavigationBarProps, "position" | "orientation" | "offset" | "children"> {
8
- navbarElement: HTMLElement | null;
8
+ navbarRef: React.RefObject<HTMLElement>;
9
9
  }
10
- export declare const FixedNavigationBarContextProvider: ({ position, orientation, offset, children, navbarElement, }: FixedNavigationBarContextProviderProps) => React.JSX.Element;
10
+ export declare const FixedNavigationBarContextProvider: ({ position, orientation, offset, children, navbarRef, }: FixedNavigationBarContextProviderProps) => React.JSX.Element;
11
11
  export default FixedNavigationBarContext;
@@ -15,13 +15,14 @@ const FixedNavigationBarContextProvider = ({
15
15
  orientation,
16
16
  offset,
17
17
  children,
18
- navbarElement
18
+ navbarRef
19
19
  }) => {
20
- const [navbarHeight, setNavbarHeight] = (0, _react.useState)(navbarElement?.offsetHeight);
21
- const updateHeight = (0, _react.useCallback)(() => setNavbarHeight(navbarElement?.offsetHeight), [navbarElement]);
22
- (0, _useResizeObserver.default)({
23
- current: navbarElement
24
- }, updateHeight);
20
+ const [navbarHeight, setNavbarHeight] = (0, _react.useState)(navbarRef.current?.offsetHeight);
21
+ const updateHeight = (0, _react.useCallback)(() => setNavbarHeight(navbarRef.current?.offsetHeight), [navbarRef]);
22
+ (0, _react.useEffect)(() => {
23
+ updateHeight();
24
+ }, [updateHeight]);
25
+ (0, _useResizeObserver.default)(navbarRef, updateHeight);
25
26
  let submenuMaxHeight;
26
27
  if (position === "fixed") {
27
28
  if (orientation === "top" && navbarHeight !== undefined) {
@@ -18,13 +18,18 @@ const NavigationBar = ({
18
18
  children,
19
19
  ariaLabel,
20
20
  position,
21
- offset = "0",
21
+ offset = "0px",
22
22
  orientation,
23
23
  isGlobal,
24
24
  ...props
25
25
  }) => {
26
- const [navbarElement, setNavbarElement] = (0, _react.useState)(null);
27
- return /*#__PURE__*/_react.default.createElement(_navigationBar.default, _extends({
26
+ const navbarRef = (0, _react.useRef)(null);
27
+ return /*#__PURE__*/_react.default.createElement(_fixedNavigationBar.FixedNavigationBarContextProvider, {
28
+ orientation: isGlobal ? "top" : orientation,
29
+ offset: isGlobal ? "0px" : offset,
30
+ position: isGlobal ? "fixed" : position,
31
+ navbarRef: navbarRef
32
+ }, /*#__PURE__*/_react.default.createElement(_navigationBar.default, _extends({
28
33
  role: "navigation",
29
34
  "data-component": isGlobal ? "global-header" : "navigation-bar",
30
35
  "aria-label": isGlobal ? "Global Header" : ariaLabel,
@@ -34,13 +39,8 @@ const NavigationBar = ({
34
39
  position: isGlobal ? "fixed" : position
35
40
  }, props, {
36
41
  isGlobal: isGlobal,
37
- ref: setNavbarElement
38
- }), /*#__PURE__*/_react.default.createElement(_fixedNavigationBar.FixedNavigationBarContextProvider, {
39
- orientation: isGlobal ? "top" : orientation,
40
- offset: isGlobal ? "0px" : offset,
41
- position: isGlobal ? "fixed" : position,
42
- navbarElement: navbarElement
43
- }, !isLoading && children));
42
+ ref: navbarRef
43
+ }), !isLoading && children));
44
44
  };
45
45
  exports.NavigationBar = NavigationBar;
46
46
  NavigationBar.propTypes = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "123.2.0",
3
+ "version": "123.2.1",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",