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.

156 lines (132 loc) 7.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.StyledTextLink = exports.getLinkStyle = void 0; var React = _interopRequireWildcard(require("react")); var _styledComponents = _interopRequireWildcard(require("styled-components")); var _defaultTheme = _interopRequireDefault(require("../defaultTheme")); var _consts = require("./consts"); 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 getColor = function getColor(_ref) { var _tokens; var theme = _ref.theme, type = _ref.type; var tokens = (_tokens = {}, _defineProperty(_tokens, _consts.TYPE_OPTIONS.PRIMARY, theme.orbit.colorTextLinkPrimary), _defineProperty(_tokens, _consts.TYPE_OPTIONS.SECONDARY, theme.orbit.colorTextLinkSecondary), _tokens); return tokens[type]; }; var getSizeToken = function getSizeToken() { return function (_ref2) { var _sizeTokens; var theme = _ref2.theme, size = _ref2.size; var sizeTokens = (_sizeTokens = {}, _defineProperty(_sizeTokens, _consts.SIZE_OPTIONS.LARGE, theme.orbit.fontSizeTextLarge), _defineProperty(_sizeTokens, _consts.SIZE_OPTIONS.NORMAL, theme.orbit.fontSizeTextNormal), _defineProperty(_sizeTokens, _consts.SIZE_OPTIONS.SMALL, theme.orbit.fontSizeTextSmall), _sizeTokens); return size && sizeTokens[size]; }; }; var IconContainer = (0, _styledComponents.default)(function (_ref3) { var children = _ref3.children, className = _ref3.className; return React.createElement("span", { className: className }, children); }).withConfig({ displayName: "TextLink__IconContainer", componentId: "sc-1bvlje4-0" })(["display:flex;align-items:center;color:", ";transition:color ", " ease-in-out;& svg{width:", ";height:", ";}"], getColor, function (_ref4) { var theme = _ref4.theme; return theme.orbit.durationFast; }, function (_ref5) { var theme = _ref5.theme; return theme.orbit.widthIconSmall; }, function (_ref6) { var theme = _ref6.theme; return theme.orbit.heightIconSmall; }); IconContainer.defaultProps = { theme: _defaultTheme.default }; var getLinkStyle = function getLinkStyle(_ref7) { var theme = _ref7.theme, type = _ref7.type; return (0, _styledComponents.css)(["&,&:link,&:visited{color:", ";text-decoration:", ";font-weight:", ";}&:hover,&:active{text-decoration:", ";color:", ";"], getColor({ theme: theme, type: type }), type === _consts.TYPE_OPTIONS.SECONDARY ? theme.orbit.textDecorationTextLinkSecondary : theme.orbit.textDecorationTextLinkPrimary, theme.orbit.fontWeightLinks, type === _consts.TYPE_OPTIONS.SECONDARY ? theme.orbit.textDecorationTextLinkSecondaryHover : theme.orbit.textDecorationTextLinkPrimaryHover, type === _consts.TYPE_OPTIONS.SECONDARY ? theme.orbit.colorTextLinkSecondaryHover : theme.orbit.colorTextLinkPrimaryHover); }; exports.getLinkStyle = getLinkStyle; var StyledTextLink = (0, _styledComponents.default)(function (_ref8) { var theme = _ref8.theme, type = _ref8.type, Component = _ref8.asComponent, props = _objectWithoutProperties(_ref8, ["theme", "type", "asComponent"]); return React.createElement(Component, props, props.children); }).withConfig({ displayName: "TextLink__StyledTextLink", componentId: "sc-1bvlje4-1" })(["font-family:", ";font-weight:", ";font-size:", ";cursor:pointer;display:inline-flex;align-items:center;transition:color ", " ease-in-out;", ";", "{color:", ";}}&:focus{outline-width:3px;}"], function (_ref9) { var theme = _ref9.theme; return theme.orbit.fontFamily; }, function (_ref10) { var theme = _ref10.theme; return theme.orbit.fontWeightLinks; }, getSizeToken, function (_ref11) { var theme = _ref11.theme; return theme.orbit.durationFast; }, getLinkStyle, IconContainer, function (_ref12) { var theme = _ref12.theme, type = _ref12.type; return type === _consts.TYPE_OPTIONS.SECONDARY ? theme.orbit.colorTextLinkSecondaryHover : theme.orbit.colorTextLinkPrimaryHover; }); exports.StyledTextLink = StyledTextLink; StyledTextLink.defaultProps = { theme: _defaultTheme.default }; // eslint-disable-next-line jsx-a11y/anchor-has-content var DefaultComponent = function DefaultComponent(props) { return React.createElement("a", props); }; var TextLink = function TextLink(_ref13) { var _ref13$type = _ref13.type, type = _ref13$type === void 0 ? _consts.TYPE_OPTIONS.PRIMARY : _ref13$type, size = _ref13.size, children = _ref13.children, href = _ref13.href, _ref13$external = _ref13.external, external = _ref13$external === void 0 ? false : _ref13$external, rel = _ref13.rel, icon = _ref13.icon, onClick = _ref13.onClick, dataTest = _ref13.dataTest, tabIndex = _ref13.tabIndex, _ref13$asComponent = _ref13.asComponent, asComponent = _ref13$asComponent === void 0 ? DefaultComponent : _ref13$asComponent; var relValues = rel ? rel.split(" ") : []; // add noopener and noreferrer whenever external if (relValues && external) { if (!relValues.includes("noopener")) { relValues.push("noopener"); } if (!relValues.includes("noreferrer")) { relValues.push("noreferrer"); } } return React.createElement(StyledTextLink, { type: type, size: size, href: href, target: external ? "_blank" : undefined, rel: relValues && relValues.join(" "), onClick: onClick, "data-test": dataTest, tabIndex: tabIndex || (!href ? "0" : undefined), role: !href ? "button" : undefined, asComponent: asComponent }, children, icon && React.createElement(IconContainer, { type: type }, icon)); }; var _default = TextLink; exports.default = _default;