@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.
159 lines (144 loc) • 5.97 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import * as React from "react";
import styled, { css } from "styled-components";
import defaultTheme from "../defaultTheme";
import { TYPE_OPTIONS, SIZE_OPTIONS } from "./consts";
import createRel from "../primitives/ButtonPrimitive/common/createRel";
var getColor = function getColor(_ref) {
var _tokens;
var theme = _ref.theme,
type = _ref.type;
var tokens = (_tokens = {}, _defineProperty(_tokens, TYPE_OPTIONS.PRIMARY, theme.orbit.colorTextLinkPrimary), _defineProperty(_tokens, 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, SIZE_OPTIONS.LARGE, theme.orbit.fontSizeTextLarge), _defineProperty(_sizeTokens, SIZE_OPTIONS.NORMAL, theme.orbit.fontSizeTextNormal), _defineProperty(_sizeTokens, SIZE_OPTIONS.SMALL, theme.orbit.fontSizeTextSmall), _sizeTokens);
return size && sizeTokens[size];
};
};
var StyledIconContainer = styled(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
};
var resolveUnderline = function resolveUnderline(_ref6) {
var type = _ref6.type,
theme = _ref6.theme,
noUnderline = _ref6.noUnderline;
if (noUnderline) return "none";
return type === TYPE_OPTIONS.SECONDARY ? theme.orbit.textDecorationTextLinkSecondary : theme.orbit.textDecorationTextLinkPrimary;
};
export var getLinkStyle = function getLinkStyle(_ref7) {
var theme = _ref7.theme,
type = _ref7.type;
return 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);
};
export var StyledTextLink = styled(function (_ref8) {
var theme = _ref8.theme,
type = _ref8.type,
standAlone = _ref8.standAlone,
noUnderline = _ref8.noUnderline,
Component = _ref8.asComponent,
props = _objectWithoutProperties(_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);
StyledTextLink.defaultProps = {
theme: defaultTheme
}; // 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 ? 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: createRel({
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));
};
export default TextLink;