UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

59 lines 2.62 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; const _excluded = ["columns", "rowGap", "columnGap", "style", "className", "children", "element"]; import "core-js/modules/es.string.replace.js"; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import React from 'react'; import classnames from 'classnames'; import Space from '../space/Space'; function GridContainer(props) { const { columns, rowGap, columnGap, style, className, children, element = 'div' } = props, rest = _objectWithoutProperties(props, _excluded); const styleObj = _objectSpread(_objectSpread({}, compute(columns)), style); const n = 'dnb-grid-container'; const unsetClasses = []; for (const prop in styleObj) { if (styleObj[prop] === 'unset') { const disableClass = `${n}__disabled--${prop.replace(/--([a-z]+)-.*/, '$1')}`; unsetClasses.push(disableClass); } } const cn = classnames(n, className, unsetClasses, columnGap && `${n}--column-gap-${columnGap === true ? 'small' : columnGap}`, rowGap && `${n}--row-gap-${rowGap === true ? 'small' : rowGap}`); return React.createElement(Space, _extends({ element: element, className: cn, style: styleObj }, rest), children); } GridContainer._supportsSpacingProps = true; export default GridContainer; function compute(columns) { if (!columns) { return null; } const result = {}; if (typeof columns === 'number') { columns = { small: columns, medium: columns, large: columns }; } for (const media in columns) { var _columns; const value = (_columns = columns) === null || _columns === void 0 ? void 0 : _columns[media]; result[`--${media}-columns`] = value || 'unset'; } return result; } //# sourceMappingURL=Container.js.map