@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
93 lines (85 loc) • 3.32 kB
JavaScript
/**
* MSKCC 2021, 2024
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var cx = require('classnames');
var PropTypes = require('prop-types');
var React = require('react');
var TableCell = require('./TableCell.js');
var usePrefix = require('../../internal/usePrefix.js');
var MskIcon = require('../Icon/MskIcon.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
const TableExpandRow = _ref => {
let {
ariaLabel,
className: rowClassName,
children,
isExpanded,
onExpand,
expandIconDescription,
isSelected,
expandHeader = 'expand',
...rest
} = _ref;
const prefix = usePrefix.usePrefix();
const className = cx__default["default"]({
[`${prefix}--parent-row`]: true,
[`${prefix}--expandable-row`]: isExpanded,
[`${prefix}--data-table--selected`]: isSelected
}, rowClassName);
const previousValue = isExpanded ? 'collapsed' : undefined;
return /*#__PURE__*/React__default["default"].createElement("tr", _rollupPluginBabelHelpers["extends"]({}, rest, {
className: className,
"data-parent-row": true
}), /*#__PURE__*/React__default["default"].createElement(TableCell["default"], {
className: `${prefix}--table-expand`,
"data-previous-value": previousValue,
headers: expandHeader
}, /*#__PURE__*/React__default["default"].createElement("button", {
type: "button",
className: `${prefix}--table-expand__button`,
onClick: onExpand,
title: expandIconDescription,
"aria-label": ariaLabel
}, /*#__PURE__*/React__default["default"].createElement(MskIcon.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__default["default"].string.isRequired,
children: PropTypes__default["default"].node,
className: PropTypes__default["default"].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__default["default"].string,
/**
* The description of the chevron right icon, to be put in its SVG `<title>` element.
*/
expandIconDescription: PropTypes__default["default"].string,
/**
* Specify whether this row is expanded or not. This helps coordinate data
* attributes so that `TableExpandRow` and `TableExpandedRow` work together
*/
isExpanded: PropTypes__default["default"].bool.isRequired,
/**
* Specify if the row is selected
*/
isSelected: PropTypes__default["default"].bool,
/**
* Hook for when a listener initiates a request to expand the given row
*/
onExpand: PropTypes__default["default"].func.isRequired
};
exports["default"] = TableExpandRow;