UNPKG

@carbon/react

Version:

React components for the Carbon Design System

59 lines (54 loc) 1.34 kB
/** * 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. */ import PropTypes from 'prop-types'; import React from 'react'; /** * Provides a grid context for communication the grid "mode" (flexbox or * css-grid) along with subgrid information. */ const GridSettingsContext = /*#__PURE__*/React.createContext({ mode: 'flexbox', subgrid: false }); const GridSettings = ({ children, mode, subgrid = false }) => { const value = React.useMemo(() => { return { mode, subgrid }; }, [mode, subgrid]); return /*#__PURE__*/React.createElement(GridSettingsContext.Provider, { value: value }, children); }; const gridModes = ['flexbox', 'css-grid']; GridSettings.propTypes = { /** * Pass in components which will be rendered within the `GridSettings` * component */ children: PropTypes.node, /** * Specify the gutter mode for the GridContext */ mode: PropTypes.oneOf(gridModes).isRequired, /** * Specify whether subgrid should be enabled */ subgrid: PropTypes.bool }; /** * Helper function for accessing the GridContext value */ const useGridSettings = () => { return React.useContext(GridSettingsContext); }; export { GridSettings, useGridSettings };