UNPKG

@mskcc/carbon-react

Version:

Carbon react components for the MSKCC DSM

83 lines (79 loc) 2.64 kB
/** * MSKCC 2021, 2024 */ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js'; import cx from 'classnames'; import PropTypes from 'prop-types'; import React__default from 'react'; import TableCell from './TableCell.js'; import { usePrefix } from '../../internal/usePrefix.js'; import { Icon } from '../Icon/MskIcon.js'; const TableExpandRow = _ref => { let { ariaLabel, className: rowClassName, children, isExpanded, onExpand, expandIconDescription, isSelected, expandHeader = 'expand', ...rest } = _ref; const prefix = usePrefix(); const className = cx({ [`${prefix}--parent-row`]: true, [`${prefix}--expandable-row`]: isExpanded, [`${prefix}--data-table--selected`]: isSelected }, rowClassName); const previousValue = isExpanded ? 'collapsed' : undefined; return /*#__PURE__*/React__default.createElement("tr", _extends({}, rest, { className: className, "data-parent-row": true }), /*#__PURE__*/React__default.createElement(TableCell, { className: `${prefix}--table-expand`, "data-previous-value": previousValue, headers: expandHeader }, /*#__PURE__*/React__default.createElement("button", { type: "button", className: `${prefix}--table-expand__button`, onClick: onExpand, title: expandIconDescription, "aria-label": ariaLabel }, /*#__PURE__*/React__default.createElement(Icon, { icon: "chevron_right", className: `${prefix}--table-expand__svg`, "aria-label": expandIconDescription }))), children); }; TableExpandRow.propTypes = { /** * Specify the string read by a voice reader when the expand trigger is * focused */ ariaLabel: PropTypes.string.isRequired, children: PropTypes.node, className: PropTypes.string, /** * The id of the matching th node in the table head. Addresses a11y concerns outlined here: https://www.ibm.com/able/guidelines/ci162/info_and_relationships.html and https://www.w3.org/TR/WCAG20-TECHS/H43 */ expandHeader: PropTypes.string, /** * The description of the chevron right icon, to be put in its SVG `<title>` element. */ expandIconDescription: PropTypes.string, /** * Specify whether this row is expanded or not. This helps coordinate data * attributes so that `TableExpandRow` and `TableExpandedRow` work together */ isExpanded: PropTypes.bool.isRequired, /** * Specify if the row is selected */ isSelected: PropTypes.bool, /** * Hook for when a listener initiates a request to expand the given row */ onExpand: PropTypes.func.isRequired }; export { TableExpandRow as default };