@carbon/react
Version:
React components for the Carbon Design System
48 lines (44 loc) • 1.47 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.
*/
import cx from 'classnames';
import PropTypes from 'prop-types';
import React, { cloneElement } from 'react';
import { usePrefix } from '../../internal/usePrefix.js';
import { AILabel } from '../AILabel/index.js';
import { isComponentElement } from '../../internal/utils.js';
const TableDecoratorRow = ({
className,
decorator
}) => {
const prefix = usePrefix();
const TableDecoratorRowClasses = cx({
...(className && {
[className]: true
}),
[`${prefix}--table-column-decorator`]: true,
[`${prefix}--table-column-decorator--active`]: decorator
});
const decoratorIsAILabel = isComponentElement(decorator, AILabel);
const normalizedDecorator = decoratorIsAILabel ? /*#__PURE__*/cloneElement(decorator, {
size: 'mini'
}) : null;
return /*#__PURE__*/React.createElement("td", {
className: TableDecoratorRowClasses
}, normalizedDecorator);
};
TableDecoratorRow.displayName = 'TableDecoratorRow';
TableDecoratorRow.propTypes = {
/**
* The CSS class names of the cell that wraps the underlying input control
*/
className: PropTypes.string,
/**
* **Experimental**: Provide a `decorator` component to be rendered inside the `TableDecoratorRow` component
*/
decorator: PropTypes.node
};
export { TableDecoratorRow as default };