UNPKG

@carbon/react

Version:

React components for the Carbon Design System

41 lines (39 loc) 1.48 kB
/** * Copyright IBM Corp. 2016, 2026 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ import { Escape } from "../../internal/keyboard/keys.js"; import { match } from "../../internal/keyboard/match.js"; import { useWindowEvent } from "../../internal/useEvent.js"; import { useCallback, useState } from "react"; import PropTypes from "prop-types"; import { jsx } from "react/jsx-runtime"; //#region src/components/UIShell/HeaderContainer.tsx /** * Copyright IBM Corp. 2016, 2023 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ function HeaderContainer({ render: Children, isSideNavExpanded = false, ...rest }) { const [isSideNavExpandedState, setIsSideNavExpandedState] = useState(isSideNavExpanded); useWindowEvent("keydown", (event) => { if (match(event, Escape)) setIsSideNavExpandedState(false); }); const handleHeaderMenuButtonClick = useCallback(() => { setIsSideNavExpandedState((prevIsSideNavExpanded) => !prevIsSideNavExpanded); }, [setIsSideNavExpandedState]); return /* @__PURE__ */ jsx(Children, { ...rest, isSideNavExpanded: isSideNavExpandedState, onClickSideNavExpand: handleHeaderMenuButtonClick }); } HeaderContainer.propTypes = { isSideNavExpanded: PropTypes.bool, render: PropTypes.elementType.isRequired }; //#endregion export { HeaderContainer as default };