@carbon/react
Version:
React components for the Carbon Design System
61 lines (59 loc) • 2.54 kB
JavaScript
/**
* Copyright IBM Corp. 2016, 2026
*
* 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 { usePrefix } from "../../internal/usePrefix.js";
import { deprecate } from "../../prop-types/deprecate.js";
import { requiredIfGivenPropIsTruthy } from "../../prop-types/requiredIfGivenPropIsTruthy.js";
import classNames from "classnames";
import "react";
import PropTypes from "prop-types";
import { jsx, jsxs } from "react/jsx-runtime";
import { ChevronRight } from "@carbon/icons-react";
//#region src/components/DataTable/TableExpandHeader.tsx
/**
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const TableExpandHeader = ({ ["aria-controls"]: ariaControls, ["aria-label"]: ariaLabel, ariaLabel: deprecatedAriaLabel, className: headerClassName, enableExpando, enableToggle, id = "expand", isExpanded, onExpand, expandIconDescription, children, ...rest }) => {
const prefix = usePrefix();
return /* @__PURE__ */ jsxs("th", {
scope: "col",
className: classNames(`${prefix}--table-expand`, headerClassName),
"data-previous-value": isExpanded ? "collapsed" : void 0,
id,
...rest,
children: [enableExpando || enableToggle ? /* @__PURE__ */ jsx("button", {
type: "button",
className: `${prefix}--table-expand__button`,
onClick: onExpand,
title: expandIconDescription,
"aria-label": deprecatedAriaLabel || ariaLabel,
"aria-expanded": isExpanded,
"aria-controls": ariaControls,
children: /* @__PURE__ */ jsx(ChevronRight, {
className: `${prefix}--table-expand__svg`,
"aria-label": expandIconDescription
})
}) : null, children]
});
};
TableExpandHeader.propTypes = {
["aria-controls"]: PropTypes.string,
["aria-label"]: PropTypes.string,
ariaLabel: PropTypes.string,
children: PropTypes.node,
className: PropTypes.string,
enableExpando: deprecate(PropTypes.bool, "The `enableExpando` prop has been deprecated in favor of `enableToggle`. This prop will be removed in the next major release."),
enableToggle: PropTypes.bool,
expandIconDescription: PropTypes.string,
id: PropTypes.string,
isExpanded: requiredIfGivenPropIsTruthy("enableToggle", PropTypes.bool),
onExpand: PropTypes.oneOfType([requiredIfGivenPropIsTruthy("enableExpando", PropTypes.func), requiredIfGivenPropIsTruthy("enableToggle", PropTypes.func)])
};
//#endregion
export { TableExpandHeader as default };