@carbon/react
Version:
React components for the Carbon Design System
78 lines (74 loc) • 2.35 kB
JavaScript
/**
* 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.
*/
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
import { Menu, Close } from '@carbon/icons-react';
import cx from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import { AriaLabelPropType } from '../../prop-types/AriaPropTypes.js';
import { usePrefix } from '../../internal/usePrefix.js';
var _Menu, _Close;
function HeaderMenuButton({
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledBy,
className: customClassName,
renderMenuIcon,
renderCloseIcon,
isActive,
isCollapsible,
...rest
}) {
const prefix = usePrefix();
const className = cx({
...(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 : _Menu || (_Menu = /*#__PURE__*/React.createElement(Menu, {
size: 20
}));
const closeIcon = renderCloseIcon ? renderCloseIcon : _Close || (_Close = /*#__PURE__*/React.createElement(Close, {
size: 20
}));
return /*#__PURE__*/React.createElement("button", _extends({}, rest, {
"aria-label": ariaLabel,
"aria-labelledby": ariaLabelledBy,
className: className,
title: ariaLabel,
type: "button"
}), isActive ? closeIcon : menuIcon);
}
HeaderMenuButton.propTypes = {
/**
* Required props for accessibility label on the underlying menu button
*/
...AriaLabelPropType,
/**
* Optionally provide a custom class name that is applied to the underlying
* button
*/
className: PropTypes.string,
/**
* Specify whether the menu button is "active".
*/
isActive: PropTypes.bool,
/**
* Specify whether the menu button is collapsible.
*/
isCollapsible: PropTypes.bool,
/**
* Optionally provide an onClick handler that is called when the underlying
* button fires it's onclick event
*/
onClick: PropTypes.func
};
export { HeaderMenuButton as default };