@carbon/react
Version:
React components for the Carbon Design System
106 lines (100 loc) • 3.9 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.
*/
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var iconsReact = require('@carbon/icons-react');
var cx = require('classnames');
var PropTypes = require('prop-types');
var React = require('react');
var usePrefix = require('../../internal/usePrefix.js');
var deprecate = require('../../prop-types/deprecate.js');
var requiredIfGivenPropIsTruthy = require('../../prop-types/requiredIfGivenPropIsTruthy.js');
const TableExpandHeader = ({
['aria-controls']: ariaControls,
['aria-label']: ariaLabel,
ariaLabel: deprecatedAriaLabel,
className: headerClassName,
enableExpando,
enableToggle,
id = 'expand',
isExpanded,
onExpand,
expandIconDescription,
children,
...rest
}) => {
const prefix = usePrefix.usePrefix();
const className = cx(`${prefix}--table-expand`, headerClassName);
const previousValue = isExpanded ? 'collapsed' : undefined;
return /*#__PURE__*/React.createElement("th", _rollupPluginBabelHelpers.extends({
scope: "col",
className: className,
"data-previous-value": previousValue,
id: id
}, rest), enableExpando || enableToggle ? /*#__PURE__*/React.createElement("button", {
type: "button",
className: `${prefix}--table-expand__button`,
onClick: onExpand,
title: expandIconDescription,
"aria-label": deprecatedAriaLabel || ariaLabel,
"aria-expanded": isExpanded,
"aria-controls": ariaControls
}, /*#__PURE__*/React.createElement(iconsReact.ChevronRight, {
className: `${prefix}--table-expand__svg`,
"aria-label": expandIconDescription
})) : null, children);
};
TableExpandHeader.propTypes = {
/**
* Space separated list of one or more ID values referencing the TableExpandedRow(s) being controlled by the TableExpandHeader
*/
['aria-controls']: PropTypes.string,
/**
* Specify the string read by a voice reader when the expand trigger is
* focused
*/
['aria-label']: PropTypes.string,
/**
* Deprecated, please use `aria-label` instead.
* Specify the string read by a voice reader when the expand trigger is
* focused
*/
ariaLabel: PropTypes.string,
children: PropTypes.node,
className: PropTypes.string,
/**
* The enableExpando prop is being replaced by TableExpandHeader
*/
enableExpando: deprecate.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.requiredIfGivenPropIsTruthy('enableToggle', PropTypes.bool),
/**
* Hook for when a listener initiates a request to expand the given row
*/
onExpand: PropTypes.oneOfType([requiredIfGivenPropIsTruthy.requiredIfGivenPropIsTruthy('enableExpando', PropTypes.func
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- https://github.com/carbon-design-system/carbon/issues/20452
), requiredIfGivenPropIsTruthy.requiredIfGivenPropIsTruthy('enableToggle', PropTypes.func
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- https://github.com/carbon-design-system/carbon/issues/20452
)])
};
exports.default = TableExpandHeader;