UNPKG

@mskcc/carbon-react

Version:

Carbon react components for the MSKCC DSM

126 lines (121 loc) 3.56 kB
/** * MSKCC 2021, 2024 */ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js'; import cx from 'classnames'; import PropTypes from 'prop-types'; import React__default from 'react'; import { usePrefix } from '../../internal/usePrefix.js'; import { useGridSettings, GridSettings } from './GridContext.js'; function CSSGrid(_ref) { let { as: BaseComponent = 'div', children, className: customClassName, condensed = false, fullWidth = false, narrow = false, ...rest } = _ref; const prefix = usePrefix(); const { subgrid } = useGridSettings(); let mode = 'wide'; if (narrow) { mode = 'narrow'; } else if (condensed) { mode = 'condensed'; } if (subgrid) { return /*#__PURE__*/React__default.createElement(GridSettings, { mode: "css-grid", subgrid: true }, /*#__PURE__*/React__default.createElement(Subgrid, _extends({ as: BaseComponent, className: customClassName, mode: mode }, rest), children)); } const className = cx(customClassName, { [`${prefix}--css-grid`]: true, [`${prefix}--css-grid--condensed`]: mode === 'condensed', [`${prefix}--css-grid--narrow`]: mode === 'narrow', [`${prefix}--css-grid--full-width`]: fullWidth }); // cast as any to let TypeScript allow passing in attributes to base component const BaseComponentAsAny = BaseComponent; return /*#__PURE__*/React__default.createElement(GridSettings, { mode: "css-grid", subgrid: true }, /*#__PURE__*/React__default.createElement(BaseComponentAsAny, _extends({ className: className }, rest), children)); } CSSGrid.propTypes = { /** * Provide a custom element to render instead of the default <div> */ as: PropTypes.oneOfType([PropTypes.string, PropTypes.elementType]), /** * Pass in content that will be rendered within the `Grid` */ children: PropTypes.node, /** * Specify a custom className to be applied to the `Grid` */ className: PropTypes.string, /** * Collapse the gutter to 1px. Useful for fluid layouts. * Rows have 1px of margin between them to match gutter. */ condensed: PropTypes.bool, /** * Remove the default max width that the grid has set */ fullWidth: PropTypes.bool, /** * Container hangs 16px into the gutter. Useful for * typographic alignment with and without containers. */ narrow: PropTypes.bool }; const Subgrid = _ref2 => { let { as: BaseComponent = 'div', className: customClassName, children, mode, ...rest } = _ref2; const prefix = usePrefix(); const className = cx(customClassName, { [`${prefix}--subgrid`]: true, [`${prefix}--subgrid--condensed`]: mode === 'condensed', [`${prefix}--subgrid--narrow`]: mode === 'narrow', [`${prefix}--subgrid--wide`]: mode === 'wide' }); return /*#__PURE__*/React__default.createElement(BaseComponent, _extends({}, rest, { className: className }), children); }; Subgrid.propTypes = { /** * Provide a custom element to render instead of the default <div> */ as: PropTypes.oneOfType([PropTypes.string, PropTypes.elementType]), /** * Pass in content that will be rendered within the `Subgrid` */ children: PropTypes.node, /** * Specify a custom className to be applied to the `Subgrid` */ className: PropTypes.string, /** * Specify the grid mode for the subgrid */ mode: PropTypes.oneOf(['wide', 'narrow', 'condensed']) }; const CSSGridComponent = CSSGrid; export { CSSGridComponent as CSSGrid };