UNPKG

@carbon/react

Version:

React components for the Carbon Design System

55 lines (53 loc) 1.75 kB
/** * 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"; import PropTypes from "prop-types"; import { jsx } from "react/jsx-runtime"; import { ChevronDown } from "@carbon/icons-react"; //#region src/components/ListBox/ListBoxMenuIcon.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 menu", [translationIds["open.menu"]]: "Open menu" }; const defaultTranslateWithId = (messageId) => { return defaultTranslations[messageId]; }; /** * `ListBoxMenuIcon` is used to orient the icon up or down depending on the * state of the menu for a given `ListBox` */ const ListBoxMenuIcon = ({ isOpen, translateWithId: t = defaultTranslateWithId }) => { const prefix = usePrefix(); const className = classNames(`${prefix}--list-box__menu-icon`, { [`${prefix}--list-box__menu-icon--open`]: isOpen }); const description = isOpen ? t("close.menu") : t("open.menu"); return /* @__PURE__ */ jsx("div", { className, children: /* @__PURE__ */ jsx(ChevronDown, { name: "chevron--down", "aria-label": description, children: /* @__PURE__ */ jsx("title", { children: description }) }) }); }; ListBoxMenuIcon.propTypes = { isOpen: PropTypes.bool.isRequired, translateWithId: PropTypes.func }; //#endregion export { ListBoxMenuIcon as default };