UNPKG

@carbon/react

Version:

React components for the Carbon Design System

70 lines (63 loc) 2.14 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. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js'); 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'); var _ChevronDown; const translationIds = { 'close.menu': 'close.menu', 'open.menu': 'open.menu' }; const defaultTranslations = { [translationIds['close.menu']]: 'Close', [translationIds['open.menu']]: 'Open' }; const defaultTranslateWithId = messageId => { return defaultTranslations[messageId]; }; /** * `ListBoxTrigger` is used to orient the icon up or down depending on the * state of the menu for a given `ListBox` */ // eslint-disable-next-line react/display-name -- https://github.com/carbon-design-system/carbon/issues/20452 const ListBoxTrigger = /*#__PURE__*/React.forwardRef(({ isOpen, translateWithId: t = defaultTranslateWithId, ...rest }, ref) => { const prefix = usePrefix.usePrefix(); const className = cx({ [`${prefix}--list-box__menu-icon`]: true, [`${prefix}--list-box__menu-icon--open`]: isOpen }); const description = isOpen ? t('close.menu') : t('open.menu'); return /*#__PURE__*/React.createElement("button", _rollupPluginBabelHelpers.extends({}, rest, { "aria-label": description, title: description, className: className, type: "button", tabIndex: -1, ref: ref }), _ChevronDown || (_ChevronDown = /*#__PURE__*/React.createElement(iconsReact.ChevronDown, null))); }); ListBoxTrigger.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 = ListBoxTrigger;