@carbon/react
Version:
React components for the Carbon Design System
98 lines (92 loc) • 3.34 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.
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var cx = require('classnames');
var PropTypes = require('prop-types');
var React = require('react');
var usePrefix = require('../../internal/usePrefix.js');
var useId = require('../../internal/useId.js');
var TableContext = require('./TableContext.js');
var index = require('../Heading/index.js');
const TableContainer = ({
aiEnabled,
className,
children,
decorator,
title,
description,
stickyHeader,
useStaticWidth,
...rest
}) => {
const baseId = useId.useId('tc');
const titleId = `${baseId}-title`;
const descriptionId = `${baseId}-description`;
const prefix = usePrefix.usePrefix();
const tableContainerClasses = cx(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 = React.useMemo(() => {
return {
titleId: title ? titleId : undefined,
descriptionId: description ? descriptionId : undefined
};
}, [title, description, titleId, descriptionId]);
return /*#__PURE__*/React.createElement(TableContext.TableContext.Provider, {
value: value
}, /*#__PURE__*/React.createElement(index.Section, _rollupPluginBabelHelpers.extends({}, rest, {
className: tableContainerClasses
}), (title || description || decorator) && /*#__PURE__*/React.createElement("div", {
className: cx(`${prefix}--data-table-header`, {
[`${prefix}--data-table-header__with-decorator`]: decorator,
[`${prefix}--data-table-header__with-decorator--standalone`]: decorator && !title && !description
})
}, (title || description) && /*#__PURE__*/React.createElement("div", {
className: `${prefix}--data-table-header__content`
}, title && /*#__PURE__*/React.createElement(index.Heading, {
className: `${prefix}--data-table-header__title`,
id: titleId
}, title), description && /*#__PURE__*/React.createElement("p", {
className: `${prefix}--data-table-header__description`,
id: descriptionId
}, description)), decorator && /*#__PURE__*/React.createElement("div", {
className: `${prefix}--data-table-header__decorator`
}, decorator)), children));
};
TableContainer.propTypes = {
/**
* Specify if the entire table has AI generated contents
*/
aiEnabled: PropTypes.bool,
children: PropTypes.node,
className: PropTypes.string,
/**
* **Experimental**: Provide a `decorator` component to be rendered inside the `TableContainer` component
*/
decorator: PropTypes.node,
/**
* Optional description text for the Table
*/
description: PropTypes.node,
/**
* Specify whether the table should have a sticky header
*/
stickyHeader: PropTypes.bool,
/**
* Provide a title for the Table
*/
title: PropTypes.node,
/**
* If true, will use a width of 'fit-content' to match the inner table width
*/
useStaticWidth: PropTypes.bool
};
exports.default = TableContainer;