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.

157 lines (124 loc) 7.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.Item = exports.getLineHeightToken = void 0; 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")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; 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; } var getLineHeightToken = function getLineHeightToken(_ref) { var _lineHeightTokens; var theme = _ref.theme, size = _ref.size; var lineHeightTokens = (_lineHeightTokens = {}, _defineProperty(_lineHeightTokens, _consts.SIZES.SMALL, theme.orbit.lineHeightTextSmall), _defineProperty(_lineHeightTokens, _consts.SIZES.NORMAL, theme.orbit.lineHeightTextNormal), _defineProperty(_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 = {}, _defineProperty(_sizeTokens, _consts.SIZES.SMALL, theme.orbit.fontSizeTextSmall), _defineProperty(_sizeTokens, _consts.SIZES.NORMAL, theme.orbit.fontSizeTextSmall), _defineProperty(_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 = {}, _defineProperty(_tokens, _consts.TYPES.PRIMARY, (0, _styledComponents.css)(["height:", ";width:", ";"], theme.orbit.heightIconSmall, theme.orbit.widthIconSmall)), _defineProperty(_tokens, _consts.TYPES.SECONDARY, (0, _styledComponents.css)(["height:", ";width:", ";"], theme.orbit.heightIconSmall, theme.orbit.widthIconSmall)), _defineProperty(_tokens, _consts.TYPES.SEPARATED, (0, _styledComponents.css)(["height:", ";width:", ";"], theme.orbit.heightIconMedium, theme.orbit.widthIconMedium)), _tokens); return tokens[type]; }; var Item = (0, _styledComponents.default)(function (_ref4) { var type = _ref4.type, theme = _ref4.theme, props = _objectWithoutProperties(_ref4, ["type", "theme"]); return _react.default.createElement("li", props); }).withConfig({ displayName: "ListItem__Item", componentId: "sc-1vswvev-0" })(["font-family:", ";display:flex;flex-direction:row;align-items:flex-start;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, function (_ref7) { var type = _ref7.type, theme = _ref7.theme; return type === _consts.TYPES.SEPARATED && (0, _styledComponents.css)(["border-bottom:1px solid ", ";padding:", ";&,", "{font-weight:", ";}:last-child{border-bottom:none;}"], theme.orbit.paletteCloudDark, theme.orbit.spaceXSmall, _Text.StyledText, theme.orbit.fontWeightMedium); }); 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 (_ref8) { var theme = _ref8.theme, type = _ref8.type; return (0, _rtl.rtlSpacing)("".concat(type === _consts.TYPES.SEPARATED ? theme.orbit.spaceXXSmall : 0, " ").concat(theme.orbit.spaceXSmall, " 0 0")); }, function (_ref9) { var theme = _ref9.theme, type = _ref9.type, size = _ref9.size; return type === _consts.TYPES.SEPARATED ? theme.heightIconLarge : getLineHeightToken({ theme: theme, size: size }); }, _CarrierLogo.StyledCarrierLogo, getIconSizeFromType, getIconSizeFromType, getIconSizeFromType); 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 (_ref10) { var theme = _ref10.theme; return theme.orbit.fontFamily; }, function (_ref11) { var theme = _ref11.theme; return theme.orbit.fontWeightNormal; }, function (_ref12) { var theme = _ref12.theme; return theme.orbit.colorTextSecondary; }, getSizeTokenLabel); var StyledSpan = _styledComponents.default.span.withConfig({ displayName: "ListItem__StyledSpan", componentId: "sc-1vswvev-3" })(["width:100%;"]); StyledLabel.defaultProps = { theme: _defaultTheme.default }; var ListItem = function ListItem(_ref13) { var label = _ref13.label, children = _ref13.children, _ref13$icon = _ref13.icon, icon = _ref13$icon === void 0 ? _react.default.createElement(_CircleSmall.default, null) : _ref13$icon, dataTest = _ref13.dataTest; var _useContext = (0, _react.useContext)(_ListContext.default), size = _useContext.size, type = _useContext.type; return _react.default.createElement(Item, { "data-test": dataTest, type: type }, _react.default.createElement(IconContainer, { type: type, size: size }, icon), _react.default.createElement(StyledSpan, null, label && _react.default.createElement(StyledLabel, { size: size }, label), children)); }; var _default = ListItem; exports.default = _default;