@carbon/react
Version:
React components for the Carbon Design System
92 lines (86 loc) • 3.24 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');
const frFn = React.forwardRef;
const TableRow = frFn((props, ref) => {
// Remove unnecessary props if provided to this component, these are
// only useful in `TableExpandRow`
const {
ariaLabel,
// eslint-disable-line @typescript-eslint/no-unused-vars -- https://github.com/carbon-design-system/carbon/issues/20452
'aria-label': ariaLabelAlt,
// eslint-disable-line @typescript-eslint/no-unused-vars -- https://github.com/carbon-design-system/carbon/issues/20452
'aria-controls': ariaControls,
// eslint-disable-line @typescript-eslint/no-unused-vars -- https://github.com/carbon-design-system/carbon/issues/20452
onExpand,
// eslint-disable-line @typescript-eslint/no-unused-vars -- https://github.com/carbon-design-system/carbon/issues/20452
isExpanded,
// eslint-disable-line @typescript-eslint/no-unused-vars -- https://github.com/carbon-design-system/carbon/issues/20452
isSelected,
expandHeader,
// eslint-disable-line @typescript-eslint/no-unused-vars
...cleanProps
} = props;
const prefix = usePrefix.usePrefix();
const rowHasAILabel = React.Children.toArray(props.children).some(child => {
if (utils.isComponentElement(child, TableSlugRow.default)) {
return !!child.props.slug;
}
return utils.isComponentElement(child, TableDecoratorRow.default) && utils.isComponentElement(child.props.decorator, index.AILabel);
});
const className = cx(props.className, {
[`${prefix}--data-table--selected`]: isSelected,
[`${prefix}--data-table--slug-row ${prefix}--data-table--ai-label-row`]: rowHasAILabel
});
if (className) {
cleanProps.className = className;
}
return /*#__PURE__*/React.createElement("tr", _rollupPluginBabelHelpers.extends({
ref: ref
}, cleanProps));
});
TableRow.propTypes = {
/**
* Specify an optional className to be applied to the container node
*/
className: PropTypes.string,
/**
* Specify if the row is selected
*/
isSelected: PropTypes.bool,
/**
* Non-standard alias for `aria-label`.
*/
ariaLabel: PropTypes.string,
/**
* Accessible label for the row element.
*/
'aria-label': PropTypes.string,
/**
* Associates this row with the id of the corresponding expanded row content.
*/
'aria-controls': PropTypes.string,
/**
* Handler called when the row’s expand toggle is clicked.
*/
onExpand: PropTypes.func,
/**
* Flag indicating whether the row is currently expanded.
*/
isExpanded: PropTypes.bool
};
exports.default = TableRow;