@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.
168 lines (147 loc) • 7.94 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 type = _ref.type;
return function (_ref2) {
var _tokens;
var theme = _ref2.theme;
var tokens = (_tokens = {}, _defineProperty(_tokens, TYPE_OPTIONS.PRIMARY, theme.orbit.colorTextLinkPrimary), _defineProperty(_tokens, TYPE_OPTIONS.SECONDARY, theme.orbit.colorTextLinkSecondary), _defineProperty(_tokens, TYPE_OPTIONS.SUCCESS, theme.orbit.paletteGreenDark), _defineProperty(_tokens, TYPE_OPTIONS.INFO, theme.orbit.paletteBlueDark), _defineProperty(_tokens, TYPE_OPTIONS.WARNING, theme.orbit.paletteOrangeDark), _defineProperty(_tokens, TYPE_OPTIONS.CRITICAL, theme.orbit.paletteRedDark), _defineProperty(_tokens, TYPE_OPTIONS.WHITE, theme.orbit.paletteWhite), _tokens);
return tokens[type];
};
};
var getHoverColor = function getHoverColor(_ref3) {
var type = _ref3.type;
return function (_ref4) {
var _tokens2;
var theme = _ref4.theme;
var tokens = (_tokens2 = {}, _defineProperty(_tokens2, TYPE_OPTIONS.PRIMARY, theme.orbit.paletteProductDarkHover), _defineProperty(_tokens2, TYPE_OPTIONS.SECONDARY, theme.orbit.paletteProductDarkHover), _defineProperty(_tokens2, TYPE_OPTIONS.SUCCESS, theme.orbit.paletteGreenDarkHover), _defineProperty(_tokens2, TYPE_OPTIONS.INFO, theme.orbit.paletteBlueDarkHover), _defineProperty(_tokens2, TYPE_OPTIONS.WARNING, theme.orbit.paletteOrangeDarkHover), _defineProperty(_tokens2, TYPE_OPTIONS.CRITICAL, theme.orbit.paletteRedDarkHover), _defineProperty(_tokens2, TYPE_OPTIONS.WHITE, theme.orbit.paletteProductLight), _tokens2);
return tokens[type];
};
};
var getActiveColor = function getActiveColor(_ref5) {
var type = _ref5.type;
return function (_ref6) {
var _tokens3;
var theme = _ref6.theme;
var tokens = (_tokens3 = {}, _defineProperty(_tokens3, TYPE_OPTIONS.PRIMARY, theme.orbit.paletteProductDarker), _defineProperty(_tokens3, TYPE_OPTIONS.SECONDARY, theme.orbit.paletteProductDarker), _defineProperty(_tokens3, TYPE_OPTIONS.SUCCESS, theme.orbit.paletteGreenDarker), _defineProperty(_tokens3, TYPE_OPTIONS.INFO, theme.orbit.paletteBlueDarker), _defineProperty(_tokens3, TYPE_OPTIONS.WARNING, theme.orbit.paletteOrangeDarker), _defineProperty(_tokens3, TYPE_OPTIONS.CRITICAL, theme.orbit.paletteRedDarker), _defineProperty(_tokens3, TYPE_OPTIONS.WHITE, theme.orbit.paletteProductLight), _tokens3);
return tokens[type];
};
};
var getSizeToken = function getSizeToken() {
return function (_ref7) {
var _sizeTokens;
var theme = _ref7.theme,
size = _ref7.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 (_ref8) {
var children = _ref8.children,
className = _ref8.className;
return /*#__PURE__*/React.createElement("span", {
className: className
}, children);
}).withConfig({
displayName: "TextLink__StyledIconContainer",
componentId: "sc-c161ak-0"
})(["", ""], function (_ref9) {
var theme = _ref9.theme;
return css(["display:flex;align-items:center;svg{width:", ";height:", ";}"], theme.orbit.widthIconSmall, theme.orbit.heightIconSmall);
}); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledIconContainer.defaultProps = {
theme: defaultTheme
};
var resolveUnderline = function resolveUnderline(_ref10) {
var type = _ref10.type,
theme = _ref10.theme,
noUnderline = _ref10.noUnderline;
if (noUnderline) return "none";
return type === TYPE_OPTIONS.SECONDARY ? theme.orbit.textDecorationTextLinkSecondary : theme.orbit.textDecorationTextLinkPrimary;
};
export var getLinkStyle = function getLinkStyle(_ref11) {
var theme = _ref11.theme;
return css(["&,&:link,&:visited{color:", ";text-decoration:", ";font-weight:", ";}&:hover{outline:none;text-decoration:none;color:", ";}&:active,&:focus{outline:none;text-decoration:none;color:", ";}"], getColor, resolveUnderline, theme.orbit.fontWeightLinks, getHoverColor, getActiveColor);
};
export var StyledTextLink = styled(function (_ref12) {
var theme = _ref12.theme,
type = _ref12.type,
standAlone = _ref12.standAlone,
noUnderline = _ref12.noUnderline,
Component = _ref12.asComponent,
props = _objectWithoutProperties(_ref12, ["theme", "type", "standAlone", "noUnderline", "asComponent"]);
return /*#__PURE__*/React.createElement(Component, props, props.children);
}).withConfig({
displayName: "TextLink__StyledTextLink",
componentId: "sc-c161ak-1"
})(["", ""], function (_ref13) {
var theme = _ref13.theme,
standAlone = _ref13.standAlone;
return css(["font-family:", ";font-weight:", ";font-size:", ";cursor:pointer;display:inline-flex;align-items:center;transition:color ", " ease-in-out;height:", ";", ";"], theme.orbit.fontFamily, theme.orbit.fontWeightLinks, getSizeToken, theme.orbit.durationFast, standAlone && theme.orbit.heightButtonNormal, getLinkStyle);
}); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
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(_ref14) {
var children = _ref14.children;
if (!children) return null;
return /*#__PURE__*/React.createElement(StyledIconContainer, null, children);
};
var TextLink = function TextLink(_ref15) {
var ariaCurrent = _ref15.ariaCurrent,
_ref15$type = _ref15.type,
type = _ref15$type === void 0 ? TYPE_OPTIONS.PRIMARY : _ref15$type,
size = _ref15.size,
children = _ref15.children,
href = _ref15.href,
_ref15$external = _ref15.external,
external = _ref15$external === void 0 ? false : _ref15$external,
rel = _ref15.rel,
iconLeft = _ref15.iconLeft,
iconRight = _ref15.iconRight,
onClick = _ref15.onClick,
dataTest = _ref15.dataTest,
tabIndex = _ref15.tabIndex,
_ref15$asComponent = _ref15.asComponent,
asComponent = _ref15$asComponent === void 0 ? DefaultComponent : _ref15$asComponent,
_ref15$stopPropagatio = _ref15.stopPropagation,
stopPropagation = _ref15$stopPropagatio === void 0 ? false : _ref15$stopPropagatio,
title = _ref15.title,
standAlone = _ref15.standAlone,
noUnderline = _ref15.noUnderline;
var onClickHandler = function onClickHandler(ev) {
if (stopPropagation) {
ev.stopPropagation();
}
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;