@carbon/react
Version:
React components for the Carbon Design System
54 lines (48 loc) • 1.56 kB
JavaScript
/**
* 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.
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var cx = require('classnames');
var PropTypes = require('prop-types');
var React = require('react');
var usePrefix = require('../internal/usePrefix.js');
/**
* @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.usePrefix();
const componentClass = cx(typeof getClassName === 'function' ? getClassName(prefix) : getClassName, baseClassName);
return /*#__PURE__*/React.createElement(type, {
...other,
// Prevent Weird quirk where `cx` will evaluate to an empty string, '',
// and so we have empty `class` attributes in the resulting markup
// eslint-disable-next-line no-extra-boolean-cast
className: !!componentClass ? componentClass : undefined
});
}
Component.displayName = name;
Component.propTypes = {
className: PropTypes.string
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- https://github.com/carbon-design-system/carbon/issues/20452
return Component;
};
exports.default = wrapComponent;