@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.
115 lines (106 loc) • 3.84 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
const _excluded = ["type", "theme"];
import * as React from "react";
import styled, { css } from "styled-components";
import defaultTheme from "../../defaultTheme";
import CircleSmall from "../../icons/CircleSmall";
import { rtlSpacing } from "../../utils/rtl";
import { StyledCarrierLogo } from "../../CarrierLogo";
import { SIZES, TYPES } from "../consts";
import { StyledText } from "../../Text";
import ListContext from "../ListContext";
export const getLineHeightToken = ({
theme,
size
}) => {
const lineHeightTokens = {
[SIZES.SMALL]: theme.orbit.lineHeightTextSmall,
[SIZES.NORMAL]: theme.orbit.lineHeightTextNormal,
[SIZES.LARGE]: theme.orbit.lineHeightTextLarge
};
return lineHeightTokens[size];
};
const getSizeTokenLabel = ({
theme,
size
}) => {
const sizeTokens = {
[SIZES.SMALL]: theme.orbit.fontSizeTextSmall,
[SIZES.NORMAL]: theme.orbit.fontSizeTextSmall,
[SIZES.LARGE]: theme.orbit.fontSizeTextNormal
};
return sizeTokens[size];
};
const getIconSizeFromType = ({
theme,
type
}) => {
const tokens = {
[TYPES.PRIMARY]: css(["height:", ";width:", ";"], theme.orbit.heightIconSmall, theme.orbit.widthIconSmall),
[TYPES.SECONDARY]: css(["height:", ";width:", ";"], theme.orbit.heightIconSmall, theme.orbit.widthIconSmall)
};
return tokens[type];
};
export const Item = styled((_ref) => {
let {
type,
theme
} = _ref,
props = _objectWithoutProperties(_ref, _excluded);
return /*#__PURE__*/React.createElement("li", props);
}).withConfig({
displayName: "ListItem__Item",
componentId: "sc-1vmzvju-0"
})(["", ""], ({
theme
}) => css(["font-family:", ";display:flex;flex-direction:row;margin-bottom:", ";&:last-child,&:last-of-type{margin:0;}", "{line-height:inherit;font-size:inherit;}"], theme.orbit.fontFamily, theme.orbit.spaceXXSmall, StyledText)); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
Item.defaultProps = {
theme: defaultTheme
};
export const IconContainer = styled.div.withConfig({
displayName: "ListItem__IconContainer",
componentId: "sc-1vmzvju-1"
})(["", ""], ({
theme,
size
}) => css(["display:flex;align-items:center;margin:", ";flex:0 0 auto;height:", ";", "{", ";img{", ";}}svg{", ";}"], rtlSpacing(`0 ${theme.orbit.spaceXSmall} 0 0`), getLineHeightToken({
theme,
size
}), StyledCarrierLogo, getIconSizeFromType, getIconSizeFromType, getIconSizeFromType)); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
IconContainer.defaultProps = {
theme: defaultTheme
};
const StyledLabel = styled.div.withConfig({
displayName: "ListItem__StyledLabel",
componentId: "sc-1vmzvju-2"
})(["", ""], ({
theme
}) => css(["font-family:", ";font-weight:", ";color:", ";font-size:", ";"], theme.orbit.fontFamily, theme.orbit.fontWeightNormal, theme.orbit.colorTextSecondary, getSizeTokenLabel));
const StyledSpan = styled.span.withConfig({
displayName: "ListItem__StyledSpan",
componentId: "sc-1vmzvju-3"
})(["width:100%;"]); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledLabel.defaultProps = {
theme: defaultTheme
};
const ListItem = ({
label,
children,
icon = /*#__PURE__*/React.createElement(CircleSmall, null),
dataTest
}) => {
const {
size,
type
} = React.useContext(ListContext);
return /*#__PURE__*/React.createElement(Item, {
"data-test": dataTest,
type: type
}, icon && /*#__PURE__*/React.createElement(IconContainer, {
type: type,
size: size
}, icon), /*#__PURE__*/React.createElement(StyledSpan, null, label && /*#__PURE__*/React.createElement(StyledLabel, {
size: size
}, label), children));
};
export default ListItem;