Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F100038230
createGrid.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jan 27, 20:24
Size
8 KB
Mime Type
text/x-java
Expires
Wed, Jan 29, 20:24 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23871451
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
createGrid.js
View Options
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["className", "columns", "container", "component", "direction", "wrap", "spacing", "rowSpacing", "columnSpacing", "disableEqualOverflow"];
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { unstable_composeClasses as composeClasses, unstable_generateUtilityClass as generateUtilityClass } from '@mui/utils';
import systemStyled from '../styled';
import useThemePropsSystem from '../useThemeProps';
import useTheme from '../useTheme';
import { extendSxProp } from '../styleFunctionSx';
import createTheme from '../createTheme';
import { generateGridStyles, generateGridSizeStyles, generateGridColumnsStyles, generateGridColumnSpacingStyles, generateGridRowSpacingStyles, generateGridDirectionStyles, generateGridOffsetStyles, generateSizeClassNames, generateSpacingClassNames, generateDirectionClasses } from './gridGenerator';
import { jsx as _jsx } from "react/jsx-runtime";
const defaultTheme = createTheme();
// widening Theme to any so that the consumer can own the theme structure.
const defaultCreateStyledComponent = systemStyled('div', {
name: 'MuiGrid',
slot: 'Root',
overridesResolver: (props, styles) => styles.root
});
function useThemePropsDefault(props) {
return useThemePropsSystem({
props,
name: 'MuiGrid',
defaultTheme
});
}
export default function createGrid(options = {}) {
const {
// This will allow adding custom styled fn (for example for custom sx style function)
createStyledComponent = defaultCreateStyledComponent,
useThemeProps = useThemePropsDefault,
componentName = 'MuiGrid'
} = options;
const NestedContext = /*#__PURE__*/React.createContext(false);
const OverflowContext = /*#__PURE__*/React.createContext(undefined);
const useUtilityClasses = (ownerState, theme) => {
const {
container,
direction,
spacing,
wrap,
gridSize
} = ownerState;
const slots = {
root: ['root', container && 'container', wrap !== 'wrap' && `wrap-xs-${String(wrap)}`, ...generateDirectionClasses(direction), ...generateSizeClassNames(gridSize), ...(container ? generateSpacingClassNames(spacing, theme.breakpoints.keys[0]) : [])]
};
return composeClasses(slots, slot => generateUtilityClass(componentName, slot), {});
};
const GridRoot = createStyledComponent(generateGridColumnsStyles, generateGridColumnSpacingStyles, generateGridRowSpacingStyles, generateGridSizeStyles, generateGridDirectionStyles, generateGridStyles, generateGridOffsetStyles);
const Grid = /*#__PURE__*/React.forwardRef(function Grid(inProps, ref) {
var _inProps$columns, _inProps$spacing, _ref, _inProps$rowSpacing, _ref2, _inProps$columnSpacin, _ref3, _disableEqualOverflow;
const theme = useTheme();
const themeProps = useThemeProps(inProps);
const props = extendSxProp(themeProps); // `color` type conflicts with html color attribute.
const nested = React.useContext(NestedContext);
const overflow = React.useContext(OverflowContext);
const {
className,
columns: columnsProp = 12,
container = false,
component = 'div',
direction = 'row',
wrap = 'wrap',
spacing: spacingProp = 0,
rowSpacing: rowSpacingProp = spacingProp,
columnSpacing: columnSpacingProp = spacingProp,
disableEqualOverflow: themeDisableEqualOverflow
} = props,
rest = _objectWithoutPropertiesLoose(props, _excluded);
// Because `disableEqualOverflow` can be set from the theme's defaultProps, the **nested** grid should look at the instance props instead.
let disableEqualOverflow = themeDisableEqualOverflow;
if (nested && themeDisableEqualOverflow !== undefined) {
disableEqualOverflow = inProps.disableEqualOverflow;
}
// collect breakpoints related props because they can be customized from the theme.
const gridSize = {};
const gridOffset = {};
const other = {};
Object.entries(rest).forEach(([key, val]) => {
if (theme.breakpoints.values[key] !== undefined) {
gridSize[key] = val;
} else if (theme.breakpoints.values[key.replace('Offset', '')] !== undefined) {
gridOffset[key.replace('Offset', '')] = val;
} else {
other[key] = val;
}
});
const columns = (_inProps$columns = inProps.columns) != null ? _inProps$columns : nested ? undefined : columnsProp;
const spacing = (_inProps$spacing = inProps.spacing) != null ? _inProps$spacing : nested ? undefined : spacingProp;
const rowSpacing = (_ref = (_inProps$rowSpacing = inProps.rowSpacing) != null ? _inProps$rowSpacing : inProps.spacing) != null ? _ref : nested ? undefined : rowSpacingProp;
const columnSpacing = (_ref2 = (_inProps$columnSpacin = inProps.columnSpacing) != null ? _inProps$columnSpacin : inProps.spacing) != null ? _ref2 : nested ? undefined : columnSpacingProp;
const ownerState = _extends({}, props, {
nested,
columns,
container,
direction,
wrap,
spacing,
rowSpacing,
columnSpacing,
gridSize,
gridOffset,
disableEqualOverflow: (_ref3 = (_disableEqualOverflow = disableEqualOverflow) != null ? _disableEqualOverflow : overflow) != null ? _ref3 : false,
// use context value if exists.
parentDisableEqualOverflow: overflow // for nested grid
});
const classes = useUtilityClasses(ownerState, theme);
let result = /*#__PURE__*/_jsx(GridRoot, _extends({
ref: ref,
as: component,
ownerState: ownerState,
className: clsx(classes.root, className)
}, other));
if (!nested) {
result = /*#__PURE__*/_jsx(NestedContext.Provider, {
value: true,
children: result
});
}
if (disableEqualOverflow !== undefined && disableEqualOverflow !== (overflow != null ? overflow : false)) {
// There are 2 possibilities that should wrap with the OverflowContext to communicate with the nested grids:
// 1. It is the root grid with `disableEqualOverflow`.
// 2. It is a nested grid with different `disableEqualOverflow` from the context.
result = /*#__PURE__*/_jsx(OverflowContext.Provider, {
value: disableEqualOverflow,
children: result
});
}
return result;
});
process.env.NODE_ENV !== "production" ? Grid.propTypes /* remove-proptypes */ = {
children: PropTypes.node,
className: PropTypes.string,
columns: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.number, PropTypes.object]),
columnSpacing: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.string]),
component: PropTypes.elementType,
container: PropTypes.bool,
direction: PropTypes.oneOfType([PropTypes.oneOf(['column-reverse', 'column', 'row-reverse', 'row']), PropTypes.arrayOf(PropTypes.oneOf(['column-reverse', 'column', 'row-reverse', 'row'])), PropTypes.object]),
disableEqualOverflow: PropTypes.bool,
lg: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
lgOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
md: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
mdOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
rowSpacing: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.string]),
sm: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
smOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
spacing: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.string]),
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
wrap: PropTypes.oneOf(['nowrap', 'wrap-reverse', 'wrap']),
xl: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
xlOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
xs: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
xsOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number])
} : void 0;
return Grid;
}
Event Timeline
Log In to Comment