@carbon/react
Version:
React components for the Carbon Design System
62 lines (56 loc) • 1.8 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.
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var cx = require('classnames');
var React = require('react');
var PropTypes = require('prop-types');
var iconsReact = require('@carbon/icons-react');
var usePrefix = require('../../internal/usePrefix.js');
const translationIds = {
'close.menu': 'close.menu',
'open.menu': 'open.menu'
};
const defaultTranslations = {
[translationIds['close.menu']]: 'Close menu',
[translationIds['open.menu']]: 'Open menu'
};
const defaultTranslateWithId = messageId => {
return defaultTranslations[messageId];
};
/**
* `ListBoxMenuIcon` is used to orient the icon up or down depending on the
* state of the menu for a given `ListBox`
*/
const ListBoxMenuIcon = ({
isOpen,
translateWithId: t = defaultTranslateWithId
}) => {
const prefix = usePrefix.usePrefix();
const className = cx(`${prefix}--list-box__menu-icon`, {
[`${prefix}--list-box__menu-icon--open`]: isOpen
});
const description = isOpen ? t('close.menu') : t('open.menu');
return /*#__PURE__*/React.createElement("div", {
className: className
}, /*#__PURE__*/React.createElement(iconsReact.ChevronDown, {
name: "chevron--down",
"aria-label": description
}, /*#__PURE__*/React.createElement("title", null, description)));
};
ListBoxMenuIcon.propTypes = {
/**
* Specify whether the menu is currently open, which will influence the
* direction of the menu icon
*/
isOpen: PropTypes.bool.isRequired,
/**
* Translates component strings using your i18n tool.
*/
translateWithId: PropTypes.func
};
exports.default = ListBoxMenuIcon;