UNPKG

@carbon/react

Version:

React components for the Carbon Design System

59 lines (51 loc) 1.81 kB
/** * 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. */ 'use strict'; 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'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx); var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes); var React__default = /*#__PURE__*/_interopDefaultLegacy(React); /** * @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__default["default"](typeof getClassName === 'function' ? getClassName(prefix) : getClassName, baseClassName); return /*#__PURE__*/React__default["default"].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__default["default"].string }; return Component; }; exports["default"] = wrapComponent;