@carbon/react
Version:
React components for the Carbon Design System
51 lines (49 loc) • 1.3 kB
JavaScript
/**
* Copyright IBM Corp. 2016, 2026
*
* 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 React from "react";
import PropTypes from "prop-types";
import { jsx } from "react/jsx-runtime";
//#region src/components/Grid/GridContext.tsx
/**
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Provides a grid context for communication the grid "mode" (flexbox or
* css-grid) along with subgrid information.
*/
const GridSettingsContext = React.createContext({
mode: "flexbox",
subgrid: false
});
const GridSettings = ({ children, mode, subgrid = false }) => {
const value = React.useMemo(() => {
return {
mode,
subgrid
};
}, [mode, subgrid]);
return /* @__PURE__ */ jsx(GridSettingsContext.Provider, {
value,
children
});
};
GridSettings.propTypes = {
children: PropTypes.node,
mode: PropTypes.oneOf(["flexbox", "css-grid"]).isRequired,
subgrid: PropTypes.bool
};
/**
* Helper function for accessing the GridContext value
*/
const useGridSettings = () => {
return React.useContext(GridSettingsContext);
};
//#endregion
export { GridSettings, useGridSettings };