@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.
152 lines (118 loc) • 6.02 kB
JavaScript
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.IconContainer = exports.Item = exports.getLineHeightToken = void 0;
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var React = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
var _defaultTheme = _interopRequireDefault(require("../../defaultTheme"));
var _CircleSmall = _interopRequireDefault(require("../../icons/CircleSmall"));
var _rtl = require("../../utils/rtl");
var _CarrierLogo = require("../../CarrierLogo");
var _consts = require("../consts");
var _Text = require("../../Text");
var _ListContext = _interopRequireDefault(require("../ListContext"));
var getLineHeightToken = function getLineHeightToken(_ref) {
var _lineHeightTokens;
var theme = _ref.theme,
size = _ref.size;
var lineHeightTokens = (_lineHeightTokens = {}, (0, _defineProperty2.default)(_lineHeightTokens, _consts.SIZES.SMALL, theme.orbit.lineHeightTextSmall), (0, _defineProperty2.default)(_lineHeightTokens, _consts.SIZES.NORMAL, theme.orbit.lineHeightTextNormal), (0, _defineProperty2.default)(_lineHeightTokens, _consts.SIZES.LARGE, theme.orbit.lineHeightTextLarge), _lineHeightTokens);
return lineHeightTokens[size];
};
exports.getLineHeightToken = getLineHeightToken;
var getSizeTokenLabel = function getSizeTokenLabel(_ref2) {
var _sizeTokens;
var theme = _ref2.theme,
size = _ref2.size;
var sizeTokens = (_sizeTokens = {}, (0, _defineProperty2.default)(_sizeTokens, _consts.SIZES.SMALL, theme.orbit.fontSizeTextSmall), (0, _defineProperty2.default)(_sizeTokens, _consts.SIZES.NORMAL, theme.orbit.fontSizeTextSmall), (0, _defineProperty2.default)(_sizeTokens, _consts.SIZES.LARGE, theme.orbit.fontSizeTextNormal), _sizeTokens);
return sizeTokens[size];
};
var getIconSizeFromType = function getIconSizeFromType(_ref3) {
var _tokens;
var theme = _ref3.theme,
type = _ref3.type;
var tokens = (_tokens = {}, (0, _defineProperty2.default)(_tokens, _consts.TYPES.PRIMARY, (0, _styledComponents.css)(["height:", ";width:", ";"], theme.orbit.heightIconSmall, theme.orbit.widthIconSmall)), (0, _defineProperty2.default)(_tokens, _consts.TYPES.SECONDARY, (0, _styledComponents.css)(["height:", ";width:", ";"], theme.orbit.heightIconSmall, theme.orbit.widthIconSmall)), _tokens);
return tokens[type];
};
var Item = (0, _styledComponents.default)(function (_ref4) {
var type = _ref4.type,
theme = _ref4.theme,
props = (0, _objectWithoutProperties2.default)(_ref4, ["type", "theme"]);
return /*#__PURE__*/React.createElement("li", props);
}).withConfig({
displayName: "ListItem__Item",
componentId: "sc-1vswvev-0"
})(["font-family:", ";display:flex;flex-direction:row;margin-bottom:", ";&:last-child,&:last-of-type{margin:0;}", "{line-height:inherit;font-size:inherit;}"], function (_ref5) {
var theme = _ref5.theme;
return theme.orbit.fontFamily;
}, function (_ref6) {
var theme = _ref6.theme;
return theme.orbit.spaceXXSmall;
}, _Text.StyledText); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
exports.Item = Item;
Item.defaultProps = {
theme: _defaultTheme.default
};
var IconContainer = _styledComponents.default.div.withConfig({
displayName: "ListItem__IconContainer",
componentId: "sc-1vswvev-1"
})(["display:flex;align-items:center;margin:", ";flex:0 0 auto;height:", ";", "{", ";img{", ";}}svg{", ";}"], function (_ref7) {
var theme = _ref7.theme;
return (0, _rtl.rtlSpacing)("0 ".concat(theme.orbit.spaceXSmall, " 0 0"));
}, function (_ref8) {
var theme = _ref8.theme,
size = _ref8.size;
return getLineHeightToken({
theme: theme,
size: size
});
}, _CarrierLogo.StyledCarrierLogo, getIconSizeFromType, getIconSizeFromType, getIconSizeFromType); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
exports.IconContainer = IconContainer;
IconContainer.defaultProps = {
theme: _defaultTheme.default
};
var StyledLabel = _styledComponents.default.div.withConfig({
displayName: "ListItem__StyledLabel",
componentId: "sc-1vswvev-2"
})(["font-family:", ";font-weight:", ";color:", ";font-size:", ";"], function (_ref9) {
var theme = _ref9.theme;
return theme.orbit.fontFamily;
}, function (_ref10) {
var theme = _ref10.theme;
return theme.orbit.fontWeightNormal;
}, function (_ref11) {
var theme = _ref11.theme;
return theme.orbit.colorTextSecondary;
}, getSizeTokenLabel);
var StyledSpan = _styledComponents.default.span.withConfig({
displayName: "ListItem__StyledSpan",
componentId: "sc-1vswvev-3"
})(["width:100%;"]); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledLabel.defaultProps = {
theme: _defaultTheme.default
};
var ListItem = function ListItem(_ref12) {
var label = _ref12.label,
children = _ref12.children,
_ref12$icon = _ref12.icon,
icon = _ref12$icon === void 0 ? /*#__PURE__*/React.createElement(_CircleSmall.default, null) : _ref12$icon,
dataTest = _ref12.dataTest;
var _React$useContext = React.useContext(_ListContext.default),
size = _React$useContext.size,
type = _React$useContext.type;
return /*#__PURE__*/React.createElement(Item, {
"data-test": dataTest,
type: type
}, /*#__PURE__*/React.createElement(IconContainer, {
type: type,
size: size
}, icon), /*#__PURE__*/React.createElement(StyledSpan, null, label && /*#__PURE__*/React.createElement(StyledLabel, {
size: size
}, label), children));
};
var _default = ListItem;
exports.default = _default;