@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.
192 lines (163 loc) • 8.38 kB
JavaScript
"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), (0, _defineProperty2.default)(_tokens, _consts.TYPE_OPTIONS.SUCCESS, theme.orbit.paletteGreenDark), (0, _defineProperty2.default)(_tokens, _consts.TYPE_OPTIONS.INFO, theme.orbit.paletteBlueDark), (0, _defineProperty2.default)(_tokens, _consts.TYPE_OPTIONS.WARNING, theme.orbit.paletteOrangeDark), (0, _defineProperty2.default)(_tokens, _consts.TYPE_OPTIONS.CRITICAL, theme.orbit.paletteRedDark), (0, _defineProperty2.default)(_tokens, _consts.TYPE_OPTIONS.WHITE, theme.orbit.paletteWhite), _tokens);
return tokens[type];
};
var getHoverColor = function getHoverColor(_ref2) {
var _tokens2;
var type = _ref2.type,
theme = _ref2.theme;
var tokens = (_tokens2 = {}, (0, _defineProperty2.default)(_tokens2, _consts.TYPE_OPTIONS.PRIMARY, theme.orbit.paletteProductNormalHover), (0, _defineProperty2.default)(_tokens2, _consts.TYPE_OPTIONS.SECONDARY, theme.orbit.paletteProductNormalHover), (0, _defineProperty2.default)(_tokens2, _consts.TYPE_OPTIONS.SUCCESS, theme.orbit.paletteGreenDarkHover), (0, _defineProperty2.default)(_tokens2, _consts.TYPE_OPTIONS.INFO, theme.orbit.paletteBlueDarkHover), (0, _defineProperty2.default)(_tokens2, _consts.TYPE_OPTIONS.WARNING, theme.orbit.paletteOrangeDarkHover), (0, _defineProperty2.default)(_tokens2, _consts.TYPE_OPTIONS.CRITICAL, theme.orbit.paletteRedDarkHover), (0, _defineProperty2.default)(_tokens2, _consts.TYPE_OPTIONS.WHITE, theme.orbit.paletteProductLight), _tokens2);
return tokens[type];
};
var getSizeToken = function getSizeToken() {
return function (_ref3) {
var _sizeTokens;
var theme = _ref3.theme,
size = _ref3.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 (_ref4) {
var children = _ref4.children,
className = _ref4.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 (_ref5) {
var theme = _ref5.theme;
return theme.orbit.widthIconSmall;
}, function (_ref6) {
var theme = _ref6.theme;
return theme.orbit.heightIconSmall;
}); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledIconContainer.defaultProps = {
theme: _defaultTheme.default
};
var resolveUnderline = function resolveUnderline(_ref7) {
var type = _ref7.type,
theme = _ref7.theme,
noUnderline = _ref7.noUnderline;
if (noUnderline) return "none";
return type === _consts.TYPE_OPTIONS.SECONDARY ? theme.orbit.textDecorationTextLinkSecondary : theme.orbit.textDecorationTextLinkPrimary;
};
var getLinkStyle = function getLinkStyle(_ref8) {
var theme = _ref8.theme,
type = _ref8.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, getHoverColor({
theme: theme,
type: type
}));
};
exports.getLinkStyle = getLinkStyle;
var StyledTextLink = (0, _styledComponents.default)(function (_ref9) {
var theme = _ref9.theme,
type = _ref9.type,
standAlone = _ref9.standAlone,
noUnderline = _ref9.noUnderline,
Component = _ref9.asComponent,
props = (0, _objectWithoutProperties2.default)(_ref9, ["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 (_ref10) {
var theme = _ref10.theme;
return theme.orbit.fontFamily;
}, function (_ref11) {
var theme = _ref11.theme;
return theme.orbit.fontWeightLinks;
}, getSizeToken, function (_ref12) {
var theme = _ref12.theme;
return theme.orbit.durationFast;
}, function (_ref13) {
var standAlone = _ref13.standAlone,
theme = _ref13.theme;
return standAlone && theme.orbit.heightButtonNormal;
}, getLinkStyle); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
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(_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 ? _consts.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: (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;