UNPKG

@carbon/react

Version:

React components for the Carbon Design System

64 lines (62 loc) 2.15 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. */ const require_runtime = require("../../../_virtual/_rolldown/runtime.js"); const require_usePrefix = require("../../../internal/usePrefix.js"); let classnames = require("classnames"); classnames = require_runtime.__toESM(classnames); let react = require("react"); react = require_runtime.__toESM(react); let prop_types = require("prop-types"); prop_types = require_runtime.__toESM(prop_types); let react_jsx_runtime = require("react/jsx-runtime"); let _carbon_icons_react = require("@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.default.forwardRef(({ isOpen, translateWithId: t = defaultTranslateWithId, ...rest }, ref) => { const prefix = require_usePrefix.usePrefix(); const className = (0, classnames.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__ */ (0, react_jsx_runtime.jsx)("button", { ...rest, "aria-label": description, title: description, className, type: "button", tabIndex: -1, ref, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_carbon_icons_react.ChevronDown, {}) }); }); ListBoxTrigger.propTypes = { isOpen: prop_types.default.bool.isRequired, translateWithId: prop_types.default.func }; //#endregion exports.default = ListBoxTrigger;