@carbon/react
Version:
React components for the Carbon Design System
69 lines (67 loc) • 2.14 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 { useId } from "../../internal/useId.js";
import classNames from "classnames";
import { forwardRef } from "react";
import PropTypes from "prop-types";
import { jsx, jsxs } from "react/jsx-runtime";
import { ChevronDown } from "@carbon/icons-react";
//#region src/components/UIShell/SideNavSwitcher.tsx
/**
* Copyright IBM Corp. 2016, 2023
*
* 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 SideNavSwitcher = forwardRef((props, ref) => {
const id = useId("side-nav-switcher");
const prefix = usePrefix();
const { className: customClassName, labelText, onChange, options } = props;
return /* @__PURE__ */ jsxs("div", {
className: classNames(`${prefix}--side-nav__switcher`, customClassName),
children: [
/* @__PURE__ */ jsx("label", {
htmlFor: id,
className: `${prefix}--assistive-text`,
children: labelText
}),
/* @__PURE__ */ jsxs("select", {
id,
className: `${prefix}--side-nav__select`,
defaultValue: "",
onBlur: onChange,
onChange,
ref,
children: [/* @__PURE__ */ jsx("option", {
className: `${prefix}--side-nav__option`,
disabled: true,
hidden: true,
value: "",
children: labelText
}), options.map((option) => /* @__PURE__ */ jsx("option", {
className: `${prefix}--side-nav__option`,
value: option,
children: option
}, option))]
}),
/* @__PURE__ */ jsx("div", {
className: `${prefix}--side-nav__switcher-chevron`,
children: /* @__PURE__ */ jsx(ChevronDown, { size: 20 })
})
]
});
});
SideNavSwitcher.displayName = "SideNavSwitcher";
SideNavSwitcher.propTypes = {
className: PropTypes.string,
labelText: PropTypes.string.isRequired,
onChange: PropTypes.func,
options: PropTypes.arrayOf(PropTypes.string).isRequired
};
//#endregion
export { SideNavSwitcher as default };