UNPKG

@atlaskit/page

Version:

A page layout organizes sections on a page using a grid and grid columns.

65 lines (62 loc) 3.31 kB
"use strict"; 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 _gridColumnContext = require("./grid-column-context"); var _gridContext = require("./grid-context"); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } /** * __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)(_gridColumnContext.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;