@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
83 lines (79 loc) • 2.93 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 from 'react';
import { usePrefix } from '../../internal/usePrefix.js';
import deprecate from '../../prop-types/deprecate.js';
import requiredIfGivenPropIsTruthy from '../../prop-types/requiredIfGivenPropIsTruthy.js';
import { Icon } from '../Icon/MskIcon.js';
const TableExpandHeader = _ref => {
let {
ariaLabel,
className: headerClassName,
enableExpando,
enableToggle,
id = 'expand',
isExpanded,
onExpand,
expandIconDescription,
children,
...rest
} = _ref;
const prefix = usePrefix();
const className = cx(`${prefix}--table-expand`, headerClassName);
const previousValue = isExpanded ? 'collapsed' : undefined;
return /*#__PURE__*/React__default.createElement("th", _extends({
scope: "col",
className: className,
"data-previous-value": previousValue,
id: id
}, rest), enableExpando || enableToggle ? /*#__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
})) : null, children);
};
TableExpandHeader.propTypes = {
/**
* Specify the string read by a voice reader when the expand trigger is
* focused
*/
ariaLabel: PropTypes.oneOfType([requiredIfGivenPropIsTruthy('enableExpando', PropTypes.string), requiredIfGivenPropIsTruthy('enableToggle', PropTypes.string)]),
children: PropTypes.node,
className: PropTypes.string,
/**
* The enableExpando prop is being replaced by enableToggle
*/
enableExpando: deprecate(PropTypes.bool, 'The `enableExpando` prop has been deprecated in favor of `enableToggle`. This prop will be removed in the next major release.'),
/**
* Specify whether an expand all button should be displayed
*/
enableToggle: PropTypes.bool,
/**
* The description of the chevron right icon, to be put in its SVG `<title>` element.
*/
expandIconDescription: PropTypes.string,
/**
* Supply an id to the th element.
*/
id: PropTypes.string,
/**
* Specify whether this row is expanded or not. This helps coordinate data
* attributes so that `TableExpandRow` and `TableExpandedRow` work together
*/
isExpanded: requiredIfGivenPropIsTruthy('enableToggle', PropTypes.bool),
/**
* Hook for when a listener initiates a request to expand the given row
*/
onExpand: PropTypes.oneOfType([requiredIfGivenPropIsTruthy('enableExpando', PropTypes.func), requiredIfGivenPropIsTruthy('enableToggle', PropTypes.func)])
};
export { TableExpandHeader as default };