@carbon/react
Version:
React components for the Carbon Design System
63 lines (59 loc) • 1.93 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.
*/
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
import cx from 'classnames';
import PropTypes from 'prop-types';
import React, { useRef } from 'react';
import TableCell from './TableCell.js';
import { usePrefix } from '../../internal/usePrefix.js';
const TableExpandedRow = ({
className: customClassName,
children,
colSpan,
...rest
}) => {
const rowRef = useRef(null);
const prefix = usePrefix();
const className = cx(`${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__*/React.createElement("tr", _extends({
ref: rowRef,
onMouseEnter: () => toggleParentHoverClass('enter'),
onMouseLeave: () => toggleParentHoverClass('leave')
}, rest, {
className: className,
"data-child-row": true
}), /*#__PURE__*/React.createElement(TableCell, {
colSpan: colSpan
}, /*#__PURE__*/React.createElement("div", {
className: `${prefix}--child-row-inner-container`
}, children)));
};
TableExpandedRow.propTypes = {
/**
* Pass in the contents for your TableExpandedRow
*/
children: PropTypes.node,
/**
* Specify an optional className to be applied to the container node
*/
className: PropTypes.string,
/**
* The width of the expanded row's internal cell
*/
colSpan: PropTypes.number.isRequired
};
export { TableExpandedRow as default };