@carbon/react
Version:
React components for the Carbon Design System
55 lines (53 loc) • 1.81 kB
JavaScript
/**
* 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 TableCell from "./TableCell.js";
import classNames from "classnames";
import { useRef } from "react";
import PropTypes from "prop-types";
import { jsx } from "react/jsx-runtime";
//#region src/components/DataTable/TableExpandedRow.tsx
/**
* Copyright IBM Corp. 2016, 2025
*
* 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 TableExpandedRow = ({ className: customClassName, children, colSpan, ...rest }) => {
const rowRef = useRef(null);
const prefix = usePrefix();
const className = classNames(`${prefix}--expandable-row`, customClassName);
const toggleParentHoverClass = (eventType) => {
if (rowRef && rowRef.current && rowRef.current.previousElementSibling) {
const parentNode = rowRef.current.previousElementSibling;
if (eventType === "enter") parentNode.classList.add(`${prefix}--expandable-row--hover`);
else parentNode.classList.remove(`${prefix}--expandable-row--hover`);
}
};
return /* @__PURE__ */ jsx("tr", {
ref: rowRef,
onMouseEnter: () => toggleParentHoverClass("enter"),
onMouseLeave: () => toggleParentHoverClass("leave"),
...rest,
className,
"data-child-row": true,
children: /* @__PURE__ */ jsx(TableCell, {
colSpan,
children: /* @__PURE__ */ jsx("div", {
className: `${prefix}--child-row-inner-container`,
children
})
})
});
};
TableExpandedRow.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
colSpan: PropTypes.number.isRequired
};
//#endregion
export { TableExpandedRow as default };