@carbon/react
Version:
React components for the Carbon Design System
75 lines (70 loc) • 2.29 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.
*/
;
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 GridContext = require('./GridContext.js');
// eslint-disable-next-line react/display-name -- https://github.com/carbon-design-system/carbon/issues/20452
const FlexGrid = /*#__PURE__*/React.forwardRef(({
as,
condensed = false,
narrow = false,
fullWidth = false,
className: containerClassName,
children,
...rest
}, ref) => {
const prefix = usePrefix.usePrefix();
const className = cx(containerClassName, {
[`${prefix}--grid`]: true,
[`${prefix}--grid--condensed`]: condensed,
[`${prefix}--grid--narrow`]: narrow,
[`${prefix}--grid--full-width`]: fullWidth
});
// cast as any to let TypeScript allow passing in attributes to base component
const BaseComponent = as || 'div';
return /*#__PURE__*/React.createElement(GridContext.GridSettings, {
mode: "flexbox",
subgrid: false
}, /*#__PURE__*/React.createElement(BaseComponent, _rollupPluginBabelHelpers.extends({
className: className,
ref: ref
}, rest), children));
});
FlexGrid.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 `FlexGrid`
*/
children: PropTypes.node,
/**
* Specify a custom className to be applied to the `FlexGrid`
*/
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 FlexGridComponent = FlexGrid;
exports.FlexGrid = FlexGridComponent;