@carbon/react
Version:
React components for the Carbon Design System
53 lines (51 loc) • 1.93 kB
JavaScript
/**
* 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 { usePrefix } from "../../internal/usePrefix.js";
import { AriaLabelPropType } from "../../prop-types/AriaPropTypes.js";
import classNames from "classnames";
import "react";
import PropTypes from "prop-types";
import { jsx } from "react/jsx-runtime";
import { Close, Menu } from "@carbon/icons-react";
//#region src/components/UIShell/HeaderMenuButton.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 HeaderMenuButton({ "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, className: customClassName, renderMenuIcon, renderCloseIcon, isActive, isCollapsible, ...rest }) {
const prefix = usePrefix();
const className = classNames({
...typeof customClassName === "string" && { [customClassName]: !!customClassName },
[`${prefix}--header__action`]: true,
[`${prefix}--header__menu-trigger`]: true,
[`${prefix}--header__action--active`]: isActive,
[`${prefix}--header__menu-toggle`]: true,
[`${prefix}--header__menu-toggle__hidden`]: !isCollapsible
});
const menuIcon = renderMenuIcon ? renderMenuIcon : /* @__PURE__ */ jsx(Menu, { size: 20 });
const closeIcon = renderCloseIcon ? renderCloseIcon : /* @__PURE__ */ jsx(Close, { size: 20 });
return /* @__PURE__ */ jsx("button", {
...rest,
"aria-label": ariaLabel,
"aria-labelledby": ariaLabelledBy,
className,
title: ariaLabel,
type: "button",
children: isActive ? closeIcon : menuIcon
});
}
HeaderMenuButton.propTypes = {
...AriaLabelPropType,
className: PropTypes.string,
isActive: PropTypes.bool,
isCollapsible: PropTypes.bool,
onClick: PropTypes.func
};
//#endregion
export { HeaderMenuButton as default };