@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
61 lines (57 loc) • 1.84 kB
JavaScript
/**
* MSKCC 2021, 2024
*/
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
import cx from 'classnames';
import PropTypes from 'prop-types';
import React__default, { useRef } from 'react';
import TableCell from './TableCell.js';
import { usePrefix } from '../../internal/usePrefix.js';
const TableExpandedRow = _ref => {
let {
className: customClassName,
children,
colSpan,
...rest
} = _ref;
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__default.createElement("tr", _extends({
ref: rowRef,
onMouseEnter: () => toggleParentHoverClass('enter'),
onMouseLeave: () => toggleParentHoverClass('leave')
}, rest, {
className: className,
"data-child-row": true
}), /*#__PURE__*/React__default.createElement(TableCell, {
colSpan: colSpan
}, /*#__PURE__*/React__default.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 };