UNPKG

@carbon/react

Version:

React components for the Carbon Design System

43 lines (41 loc) 1.3 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 from "react"; import PropTypes from "prop-types"; //#region src/tools/wrapComponent.ts /** * 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. */ /** * @param {{ name: string, type: string, className?: string | (prefix: string) => string }} props * @returns */ const wrapComponent = ({ name, className: getClassName, type }) => { /** * * @param {{ className?: string, [x: string]: any}} param0 * @returns */ function Component({ className: baseClassName, ...other }) { const prefix = usePrefix(); const componentClass = classNames(typeof getClassName === "function" ? getClassName(prefix) : getClassName, baseClassName); return React.createElement(type, { ...other, className: !!componentClass ? componentClass : void 0 }); } Component.displayName = name; Component.propTypes = { className: PropTypes.string }; return Component; }; //#endregion export { wrapComponent as default };