UNPKG

@kiwicom/orbit-components

Version:

<div align="center"> <a href="https://orbit.kiwi" target="_blank"> <img alt="orbit-components" src="https://orbit.kiwi/wp-content/uploads/2018/08/orbit-components.png" srcset="https://orbit.kiwi/wp-content/uploads/2018/08/orbit-components@2x.png 2x"

138 lines (115 loc) 4.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StyledTextLink = undefined; var _react = require("react"); var React = _interopRequireWildcard(_react); var _styledComponents = require("styled-components"); var _styledComponents2 = _interopRequireDefault(_styledComponents); var _defaultTokens = require("../defaultTokens"); var _defaultTokens2 = _interopRequireDefault(_defaultTokens); var _consts = require("./consts"); var _consts2 = _interopRequireDefault(_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)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } 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, _consts2.default.PRIMARY, theme.orbit.colorTextLinkPrimary), _defineProperty(_tokens, _consts2.default.SECONDARY, theme.orbit.colorTextLinkSecondary), _tokens); return tokens[type]; }; var IconContainer = (0, _styledComponents2.default)(function (_ref2) { var children = _ref2.children, className = _ref2.className; return React.createElement( "span", { className: className }, children ); }).withConfig({ displayName: "TextLink__IconContainer" })(["display:block;color:", ";transition:color ", " ease-in-out;& svg{width:", ";height:", ";}"], getColor, function (_ref3) { var theme = _ref3.theme; return theme.orbit.durationFast; }, function (_ref4) { var theme = _ref4.theme; return theme.orbit.widthIconSmall; }, function (_ref5) { var theme = _ref5.theme; return theme.orbit.heightIconSmall; }); IconContainer.defaultProps = { theme: _defaultTokens2.default }; var StyledTextLink = (0, _styledComponents2.default)(function (_ref6) { var theme = _ref6.theme, type = _ref6.type, props = _objectWithoutProperties(_ref6, ["theme", "type"]); return React.createElement( "a", props, props.children ); }).withConfig({ displayName: "TextLink__StyledTextLink" })(["color:", ";font-weight:", ";text-decoration:", ";cursor:pointer;display:inline-flex;align-items:center;transition:color ", " ease-in-out;&:hover{text-decoration:", ";color:", ";", "{color:", ";}}&:focus{outline-width:3px;}"], getColor, function (_ref7) { var theme = _ref7.theme; return theme.orbit.fontWeightLinks; }, function (_ref8) { var theme = _ref8.theme, type = _ref8.type; return type === [_consts2.default.SECONDARY] ? theme.orbit.textDecorationTextLinkSecondary : theme.orbit.textDecorationTextLinkPrimary; }, function (_ref9) { var theme = _ref9.theme; return theme.orbit.durationFast; }, function (_ref10) { var theme = _ref10.theme, type = _ref10.type; return type === [_consts2.default.SECONDARY] ? theme.orbit.textDecorationTextLinkSecondaryHover : theme.orbit.textDecorationTextLinkPrimaryHover; }, function (_ref11) { var theme = _ref11.theme, type = _ref11.type; return type === [_consts2.default.SECONDARY] ? theme.orbit.colorTextLinkSecondaryHover : theme.orbit.colorTextLinkPrimaryHover; }, IconContainer, function (_ref12) { var theme = _ref12.theme, type = _ref12.type; return type === [_consts2.default.SECONDARY] ? theme.orbit.colorTextLinkSecondaryHover : theme.orbit.colorTextLinkPrimaryHover; }); exports.StyledTextLink = StyledTextLink; StyledTextLink.defaultProps = { theme: _defaultTokens2.default }; var TextLink = function TextLink(_ref13) { var _ref13$type = _ref13.type, type = _ref13$type === undefined ? _consts2.default.PRIMARY : _ref13$type, children = _ref13.children, href = _ref13.href, _ref13$external = _ref13.external, external = _ref13$external === undefined ? false : _ref13$external, rel = _ref13.rel, icon = _ref13.icon, onClick = _ref13.onClick, dataTest = _ref13.dataTest; return React.createElement( StyledTextLink, { type: type, href: href, target: external ? "_blank" : undefined, rel: rel, onClick: onClick, "data-test": dataTest }, children, icon && React.createElement( IconContainer, { type: type }, icon ) ); }; exports.default = TextLink;