UNPKG

@mskcc/carbon-react

Version:

Carbon react components for the MSKCC DSM

73 lines (69 loc) 2.25 kB
/** * MSKCC 2021, 2024 */ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js'; import cx from 'classnames'; import PropTypes from 'prop-types'; import React__default, { useMemo } from 'react'; import { usePrefix } from '../../internal/usePrefix.js'; import { useId } from '../../internal/useId.js'; import { TableContext } from './TableContext.js'; const TableContainer = _ref => { let { className, children, title, description, stickyHeader, useStaticWidth, ...rest } = _ref; const baseId = useId('tc'); const titleId = `${baseId}-title`; const descriptionId = `${baseId}-description`; const prefix = usePrefix(); const tableContainerClasses = cx(className, `${prefix}--data-table-container`, { [`${prefix}--data-table--max-width`]: stickyHeader, [`${prefix}--data-table-container--static`]: useStaticWidth }); const value = useMemo(() => { return { titleId: title ? titleId : undefined, descriptionId: description ? descriptionId : undefined }; }, [title, description, titleId, descriptionId]); return /*#__PURE__*/React__default.createElement(TableContext.Provider, { value: value }, /*#__PURE__*/React__default.createElement("div", _extends({}, rest, { className: tableContainerClasses }), title && /*#__PURE__*/React__default.createElement("div", { className: `${prefix}--data-table-header` }, /*#__PURE__*/React__default.createElement("h4", { className: `${prefix}--data-table-header__title`, id: titleId }, title), /*#__PURE__*/React__default.createElement("p", { className: `${prefix}--data-table-header__description`, id: descriptionId }, description)), children)); }; TableContainer.propTypes = { children: PropTypes.node, className: PropTypes.string, /** * 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 }; export { TableContainer as default };