UNPKG

@kiwicom/orbit-components

Version:

Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.

43 lines (35 loc) 2.18 kB
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } import * as React from "react"; import styled, { css } from "styled-components"; import defaultTheme from "../defaultTheme"; import Grid from "../utils/Grid"; import { LAYOUT_SETTINGS } from "./consts"; import mq from "../utils/mediaQuery"; const getChildrenProps = (type, key) => { if (LAYOUT_SETTINGS[type].layoutColumns && LAYOUT_SETTINGS[type].layoutColumns[key]) { return LAYOUT_SETTINGS[type].layoutColumns[key]; } return null; }; const StyledLayout = styled(Grid).withConfig({ displayName: "Layout__StyledLayout", componentId: "vx9wse-0" })(["box-sizing:border-box;margin:0 auto;width:100%;padding:0 ", ";", ";"], ({ theme }) => theme.orbit.spaceMedium, mq.desktop(css(["padding:", ";"], ({ theme }) => theme.orbit.spaceLarge))); StyledLayout.defaultProps = { theme: defaultTheme }; const Layout = ({ children, type, dataTest }) => React.createElement(StyledLayout, _extends({}, LAYOUT_SETTINGS[type], { dataTest: dataTest }), React.Children.map(children, (item, key) => React.cloneElement(item, _objectSpread({}, getChildrenProps(type, key))))); export default Layout; export { default as LayoutColumn } from "./LayoutColumn";