@carbon/react
Version:
React components for the Carbon Design System
85 lines (83 loc) • 2.94 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 { useId } from "../../internal/useId.js";
import { TableContext } from "./TableContext.js";
import { Heading, Section } from "../Heading/index.js";
import classNames from "classnames";
import { useMemo } from "react";
import PropTypes from "prop-types";
import { jsx, jsxs } from "react/jsx-runtime";
//#region src/components/DataTable/TableContainer.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 TableContainer = ({ aiEnabled, className, children, decorator, title, description, stickyHeader, useStaticWidth, ...rest }) => {
const baseId = useId("tc");
const titleId = `${baseId}-title`;
const descriptionId = `${baseId}-description`;
const prefix = usePrefix();
const tableContainerClasses = classNames(className, `${prefix}--data-table-container`, {
[`${prefix}--data-table--max-width`]: stickyHeader,
[`${prefix}--data-table-container--static`]: useStaticWidth,
[`${prefix}--data-table-container--ai-enabled`]: aiEnabled
});
const value = useMemo(() => {
return {
titleId: title ? titleId : void 0,
descriptionId: description ? descriptionId : void 0
};
}, [
title,
description,
titleId,
descriptionId
]);
return /* @__PURE__ */ jsx(TableContext.Provider, {
value,
children: /* @__PURE__ */ jsxs(Section, {
...rest,
className: tableContainerClasses,
children: [(title || description || decorator) && /* @__PURE__ */ jsxs("div", {
className: classNames(`${prefix}--data-table-header`, {
[`${prefix}--data-table-header__with-decorator`]: decorator,
[`${prefix}--data-table-header__with-decorator--standalone`]: decorator && !title && !description
}),
children: [(title || description) && /* @__PURE__ */ jsxs("div", {
className: `${prefix}--data-table-header__content`,
children: [title && /* @__PURE__ */ jsx(Heading, {
className: `${prefix}--data-table-header__title`,
id: titleId,
children: title
}), description && /* @__PURE__ */ jsx("p", {
className: `${prefix}--data-table-header__description`,
id: descriptionId,
children: description
})]
}), decorator && /* @__PURE__ */ jsx("div", {
className: `${prefix}--data-table-header__decorator`,
children: decorator
})]
}), children]
})
});
};
TableContainer.propTypes = {
aiEnabled: PropTypes.bool,
children: PropTypes.node,
className: PropTypes.string,
decorator: PropTypes.node,
description: PropTypes.node,
stickyHeader: PropTypes.bool,
title: PropTypes.node,
useStaticWidth: PropTypes.bool
};
//#endregion
export { TableContainer as default };