@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
78 lines (69 loc) • 2.48 kB
JavaScript
/**
* MSKCC 2021, 2024
*/
;
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 usePrefix = require('../../../internal/usePrefix.js');
var MskIcon = require('../../Icon/MskIcon.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);
var _Icon;
const translationIds = {
'close.menu': 'close.menu',
'open.menu': 'open.menu'
};
const defaultTranslations = {
[translationIds['close.menu']]: 'Close',
[translationIds['open.menu']]: 'Open'
};
/**
* `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.usePrefix();
const className = cx__default["default"]({
[`${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["default"].createElement("button", _rollupPluginBabelHelpers["extends"]({}, rest, {
"aria-label": description,
title: description,
className: className,
type: "button",
tabIndex: "-1"
}), _Icon || (_Icon = /*#__PURE__*/React__default["default"].createElement(MskIcon.Icon, {
icon: "expand_more"
})));
};
ListBoxTrigger.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
};
ListBoxTrigger.defaultProps = {
translateWithId: id => defaultTranslations[id]
};
var ListBoxTrigger$1 = ListBoxTrigger;
exports["default"] = ListBoxTrigger$1;
exports.translationIds = translationIds;