@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.
95 lines (91 loc) • 3.42 kB
JavaScript
import * as React from "react";
import styled, { css } from "styled-components";
import defaultTheme from "../defaultTheme";
import mediaQueries from "../utils/mediaQuery";
import { ALIGNS, JUSTIFY, DIRECTIONS, SPACINGS } from "./consts";
import { DEVICES } from "../utils/mediaQuery/consts";
import isDefined from "./helpers/isDefined";
import shouldUseFlex from "./helpers/shouldUseFlex";
import getViewportFlexStyles from "./helpers/getViewportFlexStyles";
import getChildrenMargin from "./helpers/getChildrenMargin";
var StyledStack = styled(function (_ref) {
var className = _ref.className,
Element = _ref.element,
children = _ref.children,
dataTest = _ref.dataTest;
return /*#__PURE__*/React.createElement(Element, {
className: className,
"data-test": dataTest
}, children);
}).withConfig({
displayName: "Stack__StyledStack",
componentId: "sc-1t576ow-0"
})(["", ";"], function (props) {
return DEVICES.map(function (viewport, index, devices) {
return viewport in mediaQueries ? mediaQueries[viewport](css(["", ";", ""], isDefined(props[viewport]) && getViewportFlexStyles(viewport), getChildrenMargin({
viewport: viewport,
index: index,
devices: devices
}))) : viewport === "smallMobile" && css(["", ";", ""], getViewportFlexStyles(viewport), getChildrenMargin({
viewport: viewport,
index: index,
devices: devices
}));
});
});
StyledStack.defaultProps = {
theme: defaultTheme
};
var Stack = function Stack(props) {
var dataTest = props.dataTest,
_props$inline = props.inline,
inline = _props$inline === void 0 ? false : _props$inline,
_props$spacing = props.spacing,
spacing = _props$spacing === void 0 ? SPACINGS.NATURAL : _props$spacing,
_props$align = props.align,
align = _props$align === void 0 ? ALIGNS.START : _props$align,
_props$justify = props.justify,
justify = _props$justify === void 0 ? JUSTIFY.START : _props$justify,
_props$grow = props.grow,
grow = _props$grow === void 0 ? true : _props$grow,
_props$wrap = props.wrap,
wrap = _props$wrap === void 0 ? false : _props$wrap,
_props$shrink = props.shrink,
shrink = _props$shrink === void 0 ? false : _props$shrink,
basis = props.basis,
spaceAfter = props.spaceAfter,
children = props.children,
mediumMobile = props.mediumMobile,
largeMobile = props.largeMobile,
tablet = props.tablet,
desktop = props.desktop,
largeDesktop = props.largeDesktop,
_props$as = props.as,
as = _props$as === void 0 ? "div" : _props$as; // turn on FLEX automatically or manually with prop flex
var flex = shouldUseFlex(props); // when flex - use direction, otherwise column because it's block element
var direction = props.direction || (flex ? DIRECTIONS.ROW : DIRECTIONS.COLUMN);
var smallMobile = {
direction: direction,
align: align,
justify: justify,
wrap: wrap,
grow: grow,
basis: basis,
inline: inline,
shrink: shrink,
spacing: spacing,
spaceAfter: spaceAfter
};
return /*#__PURE__*/React.createElement(StyledStack, {
dataTest: dataTest,
flex: flex,
smallMobile: smallMobile,
mediumMobile: mediumMobile,
largeMobile: largeMobile,
tablet: tablet,
desktop: desktop,
largeDesktop: largeDesktop,
element: as
}, children);
};
export default Stack;