UNPKG

@mskcc/carbon-react

Version:

Carbon react components for the MSKCC DSM

56 lines (52 loc) 1.76 kB
/** * MSKCC 2021, 2024 */ import cx from 'classnames'; import React__default from 'react'; import PropTypes from 'prop-types'; import { ChevronDown } from '@carbon/icons-react'; import { usePrefix } from '../../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 = 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 = _ref => { let { isOpen, translateWithId: t = defaultTranslateWithId } = _ref; 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__default.createElement("div", { className: className }, /*#__PURE__*/React__default.createElement(ChevronDown, { name: "chevron--down", "aria-label": description }, /*#__PURE__*/React__default.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 in an id defined in `translationIds` and should * return a string message for that given message id. */ translateWithId: PropTypes.func.isRequired }; export { ListBoxMenuIcon as default, translationIds };