UNPKG

@carbon/react

Version:

React components for the Carbon Design System

54 lines (50 loc) 1.7 kB
/** * 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 cx from 'classnames'; import React from 'react'; import PropTypes from 'prop-types'; import { ChevronDown } from '@carbon/icons-react'; import { usePrefix } from '../../internal/usePrefix.js'; const defaultTranslations = { 'close.menu': 'Close menu', 'open.menu': 'Open menu' }; const defaultTranslateWithId = id => defaultTranslations[id]; /** * `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(); 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(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, /** * i18n hook used to provide the appropriate description for the given menu * icon. This function takes a ListBoxMenuIconTranslationKey and should * return a string message for that given message id. */ translateWithId: PropTypes.func }; export { ListBoxMenuIcon as default };