@carbon/react
Version:
React components for the Carbon Design System
78 lines (70 loc) • 2.72 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 _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var PropTypes = require('prop-types');
var cx = require('classnames');
var usePrefix = require('../../internal/usePrefix.js');
var TableSlugRow = require('./TableSlugRow.js');
var TableDecoratorRow = require('./TableDecoratorRow.js');
var index = require('../AILabel/index.js');
var utils = require('../../internal/utils.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
const TableRow = /*#__PURE__*/React__default["default"].forwardRef((props, ref) => {
const prefix = usePrefix.usePrefix();
let rowHasAILabel;
if (props?.children) {
// TODO: Why is this loop a `map`? It's not returning anything. Ideally,
// it seems that it should be a `some`. Maybe I'm missing something?
React.Children.toArray(props.children).map(child => {
if (utils.isComponentElement(child, TableSlugRow["default"])) {
if (child.props.slug) {
rowHasAILabel = true;
}
} else if (utils.isComponentElement(child, TableDecoratorRow["default"]) && utils.isComponentElement(child.props.decorator, index.AILabel)) {
rowHasAILabel = true;
}
});
}
// Remove unnecessary props if provided to this component, these are
// only useful in `TableExpandRow`
const className = cx__default["default"](props.className, {
[`${prefix}--data-table--selected`]: props.isSelected,
[`${prefix}--data-table--slug-row ${prefix}--data-table--ai-label-row`]: rowHasAILabel
});
const {
ariaLabel,
'aria-label': ariaLabelAlt,
'aria-controls': ariaControls,
onExpand,
isExpanded,
isSelected,
...cleanProps
} = props;
if (className) {
cleanProps.className = className;
}
return /*#__PURE__*/React__default["default"].createElement("tr", _rollupPluginBabelHelpers["extends"]({
ref: ref
}, cleanProps));
});
TableRow.propTypes = {
/**
* Specify an optional className to be applied to the container node
*/
className: PropTypes__default["default"].string,
/**
* Specify if the row is selected
*/
isSelected: PropTypes__default["default"].bool
};
exports["default"] = TableRow;