@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.
80 lines (71 loc) • 2.76 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
const _excluded = ["spacing", "direction"],
_excluded2 = ["theme", "direction"];
import * as React from "react";
import styled, { css } from "styled-components";
import { left, rtlSpacing } from "../utils/rtl";
import mq from "../utils/mediaQuery";
import { StyledTextLink } from "../TextLink";
import defaultTheme from "../defaultTheme";
import { SPACINGS } from "../utils/layout/consts";
import getSpacing from "../Stack/helpers/getSpacing";
import getDirectionSpacingTemplate from "../Stack/helpers/getDirectionSpacingTemplate";
const StyledLinkList = styled.ul.withConfig({
displayName: "LinkList__StyledLinkList",
componentId: "sc-18aq27r-0"
})(["display:flex;flex-direction:", ";width:100%;margin:0;padding:0;padding-", ":", ";list-style:none;font-size:", ";"], ({
direction
}) => direction, left, ({
indent,
theme
}) => indent && theme.orbit.spaceXXSmall, ({
theme
}) => theme.orbit.fontSizeTextNormal); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledLinkList.defaultProps = {
theme: defaultTheme
};
const resolveSpacings = (_ref) => {
let {
spacing,
direction
} = _ref,
props = _objectWithoutProperties(_ref, _excluded);
const margin = spacing && direction && String(getDirectionSpacingTemplate(direction)).replace("__spacing__", getSpacing(props)[spacing]);
return css(["margin:", ";&:last-child{margin:0;}"], margin && rtlSpacing(margin));
};
const StyledNavigationLinkListChild = styled((_ref2) => {
let {
theme,
direction
} = _ref2,
props = _objectWithoutProperties(_ref2, _excluded2);
return /*#__PURE__*/React.createElement("li", props);
}).withConfig({
displayName: "LinkList__StyledNavigationLinkListChild",
componentId: "sc-18aq27r-1"
})(["", "{text-decoration:none;}", ";", ";"], StyledTextLink, resolveSpacings, ({
direction
}) => direction === "column" && css(["width:100%;", "{width:100%;", ";}"], StyledTextLink, mq.tablet(css(["width:auto;"])))); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledNavigationLinkListChild.defaultProps = {
theme: defaultTheme
};
const LinkList = ({
direction = "column",
indent,
spacing = SPACINGS.MEDIUM,
children,
dataTest
}) => /*#__PURE__*/React.createElement(StyledLinkList, {
indent: indent,
direction: direction,
"data-test": dataTest
}, React.Children.map(children, item => {
if ( /*#__PURE__*/React.isValidElement(item)) {
return /*#__PURE__*/React.createElement(StyledNavigationLinkListChild, {
direction: direction,
spacing: spacing
}, item);
}
return null;
}));
export default LinkList;