UNPKG

@carbon/react

Version:

React components for the Carbon Design System

52 lines (50 loc) 1.91 kB
/** * Copyright IBM Corp. 2016, 2026 * * 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 { usePrefix } from "../../internal/usePrefix.js"; import { isComponentElement } from "../../internal/utils.js"; import { AILabel } from "../AILabel/index.js"; import TableDecoratorRow from "./TableDecoratorRow.js"; import TableSlugRow from "./TableSlugRow.js"; import classNames from "classnames"; import { Children, forwardRef } from "react"; import PropTypes from "prop-types"; import { jsx } from "react/jsx-runtime"; //#region src/components/DataTable/TableRow.tsx /** * Copyright IBM Corp. 2016, 2026 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ const TableRow = forwardRef((props, ref) => { const { ariaLabel, "aria-label": ariaLabelAlt, "aria-controls": ariaControls, onExpand, isExpanded, isSelected, expandHeader, ...cleanProps } = props; const prefix = usePrefix(); const rowHasAILabel = Children.toArray(props.children).some((child) => { if (isComponentElement(child, TableSlugRow)) return !!child.props.slug; return isComponentElement(child, TableDecoratorRow) && isComponentElement(child.props.decorator, AILabel); }); const className = classNames(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__ */ jsx("tr", { ref, ...cleanProps }); }); TableRow.propTypes = { className: PropTypes.string, isSelected: PropTypes.bool, ariaLabel: PropTypes.string, "aria-label": PropTypes.string, "aria-controls": PropTypes.string, onExpand: PropTypes.func, isExpanded: PropTypes.bool }; //#endregion export { TableRow as default };