@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
56 lines (51 loc) • 1.64 kB
JavaScript
/**
* MSKCC 2021, 2024
*/
import { extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers.js';
import cx from 'classnames';
import React__default from 'react';
import PropTypes from 'prop-types';
import { usePrefix } from '../../../internal/usePrefix.js';
import { Icon } from '../../Icon/MskIcon.js';
var _Icon;
/**
* `ListBoxTrigger` is used to orient the icon up or down depending on the
* state of the menu for a given `ListBox`
*/
const ListBoxTrigger = _ref => {
let {
isOpen,
translateWithId: t,
...rest
} = _ref;
const prefix = 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__default.createElement("button", _extends({}, rest, {
"aria-label": description,
title: description,
className: className,
type: "button",
tabIndex: "-1"
}), _Icon || (_Icon = /*#__PURE__*/React__default.createElement(Icon, {
icon: "expand_more"
})));
};
ListBoxTrigger.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
};
var ListBoxTrigger$1 = ListBoxTrigger;
export { ListBoxTrigger$1 as default };