@carbon/react
Version:
React components for the Carbon Design System
108 lines (100 loc) • 4.25 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');
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 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__default["default"](`${prefix}--table-expand`, headerClassName);
const previousValue = isExpanded ? 'collapsed' : undefined;
return /*#__PURE__*/React__default["default"].createElement("th", _rollupPluginBabelHelpers["extends"]({
scope: "col",
className: className,
"data-previous-value": previousValue,
id: id
}, rest), enableExpando || enableToggle ? /*#__PURE__*/React__default["default"].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__default["default"].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__default["default"].string,
/**
* Specify the string read by a voice reader when the expand trigger is
* focused
*/
['aria-label']: PropTypes__default["default"].string,
/**
* Deprecated, please use `aria-label` instead.
* Specify the string read by a voice reader when the expand trigger is
* focused
*/
ariaLabel: PropTypes__default["default"].string,
children: PropTypes__default["default"].node,
className: PropTypes__default["default"].string,
/**
* The enableExpando prop is being replaced by TableExpandHeader
*/
enableExpando: deprecate["default"](PropTypes__default["default"].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__default["default"].bool,
/**
* The description of the chevron right icon, to be put in its SVG `<title>` element.
*/
expandIconDescription: PropTypes__default["default"].string,
/**
* Supply an id to the th element.
*/
id: 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: requiredIfGivenPropIsTruthy["default"]('enableToggle', PropTypes__default["default"].bool),
/**
* Hook for when a listener initiates a request to expand the given row
*/
onExpand: PropTypes__default["default"].oneOfType([requiredIfGivenPropIsTruthy["default"]('enableExpando', PropTypes__default["default"].func), requiredIfGivenPropIsTruthy["default"]('enableToggle', PropTypes__default["default"].func)])
};
exports["default"] = TableExpandHeader;