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.

118 lines (102 loc) 5.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.StyledTextLink = void 0; var React = _interopRequireWildcard(require("react")); var _styledComponents = _interopRequireDefault(require("styled-components")); var _defaultTokens = _interopRequireDefault(require("../defaultTokens")); var _consts = _interopRequireDefault(require("./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)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } 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, _consts.default.PRIMARY, theme.orbit.colorTextLinkPrimary), _defineProperty(_tokens, _consts.default.SECONDARY, theme.orbit.colorTextLinkSecondary), _tokens); return tokens[type]; }; var IconContainer = (0, _styledComponents.default)(function (_ref2) { var children = _ref2.children, className = _ref2.className; return React.createElement("span", { className: className }, children); }).withConfig({ displayName: "TextLink__IconContainer", componentId: "sc-1bvlje4-0" })(["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: _defaultTokens.default }; var StyledTextLink = (0, _styledComponents.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", componentId: "sc-1bvlje4-1" })(["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 === [_consts.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 === [_consts.default.SECONDARY] ? theme.orbit.textDecorationTextLinkSecondaryHover : theme.orbit.textDecorationTextLinkPrimaryHover; }, function (_ref11) { var theme = _ref11.theme, type = _ref11.type; return type === [_consts.default.SECONDARY] ? theme.orbit.colorTextLinkSecondaryHover : theme.orbit.colorTextLinkPrimaryHover; }, IconContainer, function (_ref12) { var theme = _ref12.theme, type = _ref12.type; return type === [_consts.default.SECONDARY] ? theme.orbit.colorTextLinkSecondaryHover : theme.orbit.colorTextLinkPrimaryHover; }); exports.StyledTextLink = StyledTextLink; StyledTextLink.defaultProps = { theme: _defaultTokens.default }; var TextLink = function TextLink(_ref13) { var _ref13$type = _ref13.type, type = _ref13$type === void 0 ? _consts.default.PRIMARY : _ref13$type, children = _ref13.children, href = _ref13.href, _ref13$external = _ref13.external, external = _ref13$external === void 0 ? 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)); }; var _default = TextLink; exports.default = _default;