@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
57 lines (52 loc) • 1.22 kB
JavaScript
/**
* MSKCC 2021, 2024
*/
import PropTypes from 'prop-types';
import * as 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 = _ref => {
let {
children,
mode,
subgrid = false
} = _ref;
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 grid 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 };