@carbon/react
Version:
React components for the Carbon Design System
60 lines (58 loc) • 1.78 kB
JavaScript
/**
* Copyright IBM Corp. 2016, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
import { usePrefix } from "../../../internal/usePrefix.js";
import classNames from "classnames";
import React from "react";
import PropTypes from "prop-types";
import { jsx } from "react/jsx-runtime";
import { ChevronDown } from "@carbon/icons-react";
//#region src/components/ListBox/next/ListBoxTrigger.tsx
/**
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
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`
*/
const ListBoxTrigger = React.forwardRef(({ isOpen, translateWithId: t = defaultTranslateWithId, ...rest }, ref) => {
const prefix = usePrefix();
const className = classNames({
[`${prefix}--list-box__menu-icon`]: true,
[`${prefix}--list-box__menu-icon--open`]: isOpen
});
const description = isOpen ? t("close.menu") : t("open.menu");
return /* @__PURE__ */ jsx("button", {
...rest,
"aria-label": description,
title: description,
className,
type: "button",
tabIndex: -1,
ref,
children: /* @__PURE__ */ jsx(ChevronDown, {})
});
});
ListBoxTrigger.propTypes = {
isOpen: PropTypes.bool.isRequired,
translateWithId: PropTypes.func
};
//#endregion
export { ListBoxTrigger as default };