@atlaskit/page
Version:
A page layout organizes sections on a page using a grid and grid columns.
66 lines (63 loc) • 3.46 kB
JavaScript
;
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _constants = require("./constants");
var _grid = require("./grid");
var _gridColumn = require("./grid-column");
var _gridContext = require("./grid-context");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
/**
* __Grid__
*
* A grid contains one or more `GridColumn` to provide a grid layout.
*
* - [Examples](https://atlaskit.atlassian.com/packages/design-system/page)
*/
var GridWrapper = function GridWrapper(_ref) {
var _ref2, _ref3, _theme$isNestedGrid;
var spacingProp = _ref.spacing,
columnsProp = _ref.columns,
layout = _ref.layout,
testId = _ref.testId,
children = _ref.children,
theme = _ref.theme;
/**
* isRoot is `true` only in the default context (i.e. no ancestor Grid).
*/
var _useContext = (0, _react.useContext)(_gridContext.GridContext),
isRoot = _useContext.isRoot;
var _useContext2 = (0, _react.useContext)(_gridColumn.GridColumnContext),
medium = _useContext2.medium;
/**
* The colspan of the current containing GridColumn provides
* the default amount of columns in a nested grid.
*/
var defaultColumns = medium > 0 ? medium : _constants.defaultGridColumns;
/**
* This is to account for the eventual removal of the `theme` prop. In theory, this should not be exposed.
* However, consumers are still using it - there should be a major rerelease with the complete removal of this prop later.
*/
var spacing = (_ref2 = spacingProp !== null && spacingProp !== void 0 ? spacingProp : theme === null || theme === void 0 ? void 0 : theme.spacing) !== null && _ref2 !== void 0 ? _ref2 : _constants.defaultSpacing;
var columns = (_ref3 = columnsProp !== null && columnsProp !== void 0 ? columnsProp : theme === null || theme === void 0 ? void 0 : theme.columns) !== null && _ref3 !== void 0 ? _ref3 : defaultColumns;
var isNested = (_theme$isNestedGrid = theme === null || theme === void 0 ? void 0 : theme.isNestedGrid) !== null && _theme$isNestedGrid !== void 0 ? _theme$isNestedGrid : !isRoot;
var contextValue = (0, _react.useMemo)(function () {
return {
isRoot: false,
isNested: isNested,
spacing: spacing,
columns: columns
};
}, [spacing, columns, isNested]);
return /*#__PURE__*/_react.default.createElement(_gridContext.GridContext.Provider, {
value: contextValue
}, /*#__PURE__*/_react.default.createElement(_grid.Grid, {
layout: layout,
testId: testId
}, children));
};
var _default = exports.default = GridWrapper;