UNPKG

@carbon/react

Version:

React components for the Carbon Design System

68 lines (64 loc) 2.16 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. */ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js'; import React, { Children } from 'react'; import PropTypes from 'prop-types'; import cx from 'classnames'; import { usePrefix } from '../../internal/usePrefix.js'; import TableSlugRow from './TableSlugRow.js'; import TableDecoratorRow from './TableDecoratorRow.js'; import { AILabel } from '../AILabel/index.js'; import { isComponentElement } from '../../internal/utils.js'; const TableRow = /*#__PURE__*/React.forwardRef((props, ref) => { const prefix = 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? Children.toArray(props.children).map(child => { if (isComponentElement(child, TableSlugRow)) { if (child.props.slug) { rowHasAILabel = true; } } else if (isComponentElement(child, TableDecoratorRow) && isComponentElement(child.props.decorator, 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", _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 }; export { TableRow as default };