@carbon/react
Version:
React components for the Carbon Design System
76 lines (74 loc) • 2.37 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 Button_default from "../Button/index.js";
import { AriaLabelPropType } from "../../prop-types/AriaPropTypes.js";
import classNames from "classnames";
import React from "react";
import PropTypes from "prop-types";
import { jsx } from "react/jsx-runtime";
//#region src/components/UIShell/HeaderGlobalAction.tsx
/**
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* HeaderGlobalAction is used as a part of the `HeaderGlobalBar`. It is
* essentially an Icon Button with an additional state to indicate whether it is
* "active". The active state comes from when a user clicks on the global action
* which should trigger a panel to appear.
*
* Note: children passed to this component should be an Icon.
*/
const HeaderGlobalAction = React.forwardRef(({ "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, children, className: customClassName, onClick, tooltipHighContrast = true, tooltipDropShadow, isActive, tooltipAlignment, ...rest }, ref) => {
const prefix = usePrefix();
const className = classNames({
[customClassName]: !!customClassName,
[`${prefix}--header__action`]: true,
[`${prefix}--header__action--active`]: isActive
});
const accessibilityLabel = {
"aria-label": ariaLabel,
"aria-labelledby": ariaLabelledBy
};
return /* @__PURE__ */ jsx(Button_default, {
...rest,
...accessibilityLabel,
className,
onClick,
type: "button",
hasIconOnly: true,
size: "lg",
kind: "ghost",
iconDescription: ariaLabel,
tooltipPosition: "bottom",
tooltipAlignment,
tooltipDropShadow,
tooltipHighContrast,
ref,
children
});
});
HeaderGlobalAction.propTypes = {
...AriaLabelPropType,
children: PropTypes.node.isRequired,
className: PropTypes.string,
isActive: PropTypes.bool,
onClick: PropTypes.func,
tooltipAlignment: PropTypes.oneOf([
"start",
"center",
"end"
]),
tooltipDropShadow: PropTypes.bool,
tooltipHighContrast: PropTypes.bool
};
HeaderGlobalAction.displayName = "HeaderGlobalAction";
//#endregion
export { HeaderGlobalAction as default };