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.

179 lines (154 loc) 6.78 kB
"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.StyledTextLink = exports.getLinkStyle = 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 _consts = require("./consts"); var _createRel = _interopRequireDefault(require("../primitives/ButtonPrimitive/common/createRel")); var getColor = function getColor(_ref) { var _tokens; var theme = _ref.theme, type = _ref.type; var tokens = (_tokens = {}, (0, _defineProperty2.default)(_tokens, _consts.TYPE_OPTIONS.PRIMARY, theme.orbit.colorTextLinkPrimary), (0, _defineProperty2.default)(_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 = {}, (0, _defineProperty2.default)(_sizeTokens, _consts.SIZE_OPTIONS.LARGE, theme.orbit.fontSizeTextLarge), (0, _defineProperty2.default)(_sizeTokens, _consts.SIZE_OPTIONS.NORMAL, theme.orbit.fontSizeTextNormal), (0, _defineProperty2.default)(_sizeTokens, _consts.SIZE_OPTIONS.SMALL, theme.orbit.fontSizeTextSmall), _sizeTokens); return size && sizeTokens[size]; }; }; var StyledIconContainer = (0, _styledComponents.default)(function (_ref3) { var children = _ref3.children, className = _ref3.className; return /*#__PURE__*/React.createElement("span", { className: className }, children); }).withConfig({ displayName: "TextLink__StyledIconContainer", componentId: "sc-1bvlje4-0" })(["display:flex;align-items:center;& svg{width:", ";height:", ";}"], function (_ref4) { var theme = _ref4.theme; return theme.orbit.widthIconSmall; }, function (_ref5) { var theme = _ref5.theme; return theme.orbit.heightIconSmall; }); StyledIconContainer.defaultProps = { theme: _defaultTheme.default }; var resolveUnderline = function resolveUnderline(_ref6) { var type = _ref6.type, theme = _ref6.theme, noUnderline = _ref6.noUnderline; if (noUnderline) return "none"; return type === _consts.TYPE_OPTIONS.SECONDARY ? theme.orbit.textDecorationTextLinkSecondary : theme.orbit.textDecorationTextLinkPrimary; }; 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,:focus{outline:none;text-decoration:none;color:", ";}"], getColor({ theme: theme, type: type }), resolveUnderline, theme.orbit.fontWeightLinks, theme.orbit.paletteProductNormalHover); }; exports.getLinkStyle = getLinkStyle; var StyledTextLink = (0, _styledComponents.default)(function (_ref8) { var theme = _ref8.theme, type = _ref8.type, standAlone = _ref8.standAlone, noUnderline = _ref8.noUnderline, Component = _ref8.asComponent, props = (0, _objectWithoutProperties2.default)(_ref8, ["theme", "type", "standAlone", "noUnderline", "asComponent"]); return /*#__PURE__*/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;height:", ";", ";"], 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; }, function (_ref12) { var standAlone = _ref12.standAlone, theme = _ref12.theme; return standAlone && theme.orbit.heightButtonNormal; }, getLinkStyle); exports.StyledTextLink = StyledTextLink; StyledTextLink.defaultProps = { theme: _defaultTheme.default }; // eslint-disable-next-line jsx-a11y/anchor-has-content var DefaultComponent = function DefaultComponent(props) { return /*#__PURE__*/React.createElement("a", props); }; var IconContainer = function IconContainer(_ref13) { var children = _ref13.children; if (!children) return null; return /*#__PURE__*/React.createElement(StyledIconContainer, null, children); }; var TextLink = function TextLink(_ref14) { var ariaCurrent = _ref14.ariaCurrent, _ref14$type = _ref14.type, type = _ref14$type === void 0 ? _consts.TYPE_OPTIONS.PRIMARY : _ref14$type, size = _ref14.size, children = _ref14.children, href = _ref14.href, _ref14$external = _ref14.external, external = _ref14$external === void 0 ? false : _ref14$external, rel = _ref14.rel, iconLeft = _ref14.iconLeft, iconRight = _ref14.iconRight, onClick = _ref14.onClick, dataTest = _ref14.dataTest, tabIndex = _ref14.tabIndex, _ref14$asComponent = _ref14.asComponent, asComponent = _ref14$asComponent === void 0 ? DefaultComponent : _ref14$asComponent, _ref14$stopPropagatio = _ref14.stopPropagation, stopPropagation = _ref14$stopPropagatio === void 0 ? false : _ref14$stopPropagatio, title = _ref14.title, standAlone = _ref14.standAlone, noUnderline = _ref14.noUnderline; var onClickHandler = function onClickHandler(ev) { if (stopPropagation) { ev.stopPropagation(); if (onClick) onClick(ev); } if (onClick) onClick(ev); }; return /*#__PURE__*/React.createElement(StyledTextLink, { "aria-current": ariaCurrent, type: type, size: size, href: href, target: external ? "_blank" : undefined, rel: (0, _createRel.default)({ href: href, external: external, rel: rel }), onClick: onClickHandler, "data-test": dataTest, tabIndex: tabIndex || (!href ? "0" : undefined), role: !href ? "button" : undefined, asComponent: asComponent, title: title, noUnderline: noUnderline, standAlone: standAlone }, /*#__PURE__*/React.createElement(IconContainer, null, iconLeft), children, /*#__PURE__*/React.createElement(IconContainer, null, iconRight)); }; var _default = TextLink; exports.default = _default;