UNPKG

@mskcc/carbon-react

Version:

Carbon react components for the MSKCC DSM

67 lines (59 loc) 2.29 kB
/** * MSKCC 2021, 2024 */ 'use strict'; 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'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx); var React__default = /*#__PURE__*/_interopDefaultLegacy(React); var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes); 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.usePrefix(); const className = cx__default["default"](`${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["default"].createElement("div", { className: className }, /*#__PURE__*/React__default["default"].createElement(iconsReact.ChevronDown, { name: "chevron--down", "aria-label": description }, /*#__PURE__*/React__default["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__default["default"].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__default["default"].func.isRequired }; exports["default"] = ListBoxMenuIcon; exports.translationIds = translationIds;