@carbon/react
Version:
React components for the Carbon Design System
96 lines (94 loc) • 4.02 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.
*/
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_usePrefix = require("../../internal/usePrefix.js");
const require_utils = require("../../internal/utils.js");
const require_index = require("../AILabel/index.js");
const require_TableCell = require("./TableCell.js");
const require_TableDecoratorRow = require("./TableDecoratorRow.js");
const require_TableSlugRow = require("./TableSlugRow.js");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
prop_types = require_runtime.__toESM(prop_types);
let react_jsx_runtime = require("react/jsx-runtime");
let _carbon_icons_react = require("@carbon/icons-react");
//#region src/components/DataTable/TableExpandRow.tsx
/**
* 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.
*/
const TableExpandRow = (0, react.forwardRef)(({ ["aria-controls"]: ariaControls, ["aria-label"]: ariaLabel, ariaLabel: deprecatedAriaLabel, className: rowClassName, children, isExpanded, onExpand, expandIconDescription, isSelected, expandHeader = "expand", ...rest }, ref) => {
const prefix = require_usePrefix.usePrefix();
let rowHasAILabel;
const decorator = react.Children.toArray(children).map((child) => {
if (require_utils.isComponentElement(child, require_TableSlugRow.default)) {
if (child.props.slug) rowHasAILabel = true;
return child;
} else if (require_utils.isComponentElement(child, require_TableDecoratorRow.default)) {
if (require_utils.isComponentElement(child.props.decorator, require_index.AILabel)) rowHasAILabel = true;
return child;
}
});
const normalizedChildren = react.Children.toArray(children).map((child) => {
if (!require_utils.isComponentElement(child, require_TableSlugRow.default) && !require_utils.isComponentElement(child, require_TableDecoratorRow.default)) return child;
});
const className = (0, classnames.default)({
[`${prefix}--parent-row`]: true,
[`${prefix}--expandable-row`]: isExpanded,
[`${prefix}--data-table--selected`]: isSelected,
[`${prefix}--data-table--slug-row ${prefix}--data-table--ai-label-row`]: rowHasAILabel
}, rowClassName);
const previousValue = isExpanded ? "collapsed" : void 0;
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("tr", {
...rest,
ref,
className,
"data-parent-row": true,
children: [
decorator,
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_TableCell.default, {
className: `${prefix}--table-expand`,
"data-previous-value": previousValue,
headers: expandHeader,
children: /* @__PURE__ */ (0, react_jsx_runtime.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__ */ (0, react_jsx_runtime.jsx)(_carbon_icons_react.ChevronRight, {
className: `${prefix}--table-expand__svg`,
"aria-label": expandIconDescription
})
})
}),
normalizedChildren
]
});
});
TableExpandRow.propTypes = {
"aria-controls": prop_types.default.string,
"aria-label": prop_types.default.string,
ariaLabel: prop_types.default.string,
children: prop_types.default.node,
className: prop_types.default.string,
expandHeader: prop_types.default.string,
expandIconDescription: prop_types.default.string,
isExpanded: prop_types.default.bool,
isSelected: prop_types.default.bool,
onExpand: prop_types.default.func.isRequired
};
TableExpandRow.displayName = "TableExpandRow";
//#endregion
exports.default = TableExpandRow;