UNPKG

@carbon/react

Version:

React components for the Carbon Design System

72 lines (66 loc) 2.3 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 _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 TableRow = /*#__PURE__*/React.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(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.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 }; exports.default = TableRow;