UNPKG

@carbon/react

Version:

React components for the Carbon Design System

98 lines (94 loc) 3.41 kB
/** * 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. */ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js'; import { ChevronRight } from '@carbon/icons-react'; import cx from 'classnames'; import PropTypes from 'prop-types'; import React from 'react'; import { usePrefix } from '../../internal/usePrefix.js'; import { deprecate } from '../../prop-types/deprecate.js'; import requiredIfGivenPropIsTruthy from '../../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(); const className = cx(`${prefix}--table-expand`, headerClassName); const previousValue = isExpanded ? 'collapsed' : undefined; return /*#__PURE__*/React.createElement("th", _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(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(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 };