@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.
79 lines (78 loc) • 2.8 kB
JavaScript
;
"use client";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _clsx = _interopRequireDefault(require("clsx"));
var _consts = require("./consts");
var _createRel = _interopRequireDefault(require("../primitives/ButtonPrimitive/common/createRel"));
var _twClasses = require("./helpers/twClasses");
// eslint-disable-next-line jsx-a11y/anchor-has-content
const DefaultComponent = props => /*#__PURE__*/React.createElement("a", props);
const IconContainer = ({
children,
size
}) => {
if (!children) return null;
return /*#__PURE__*/React.createElement("span", {
className: (0, _clsx.default)("flex items-center", {
"[&_svg]:w-icon-large [&_svg]:h-icon-large": size === _consts.SIZE_OPTIONS.LARGE,
"[&_svg]:w-icon-small [&_svg]:h-icon-small": size === _consts.SIZE_OPTIONS.SMALL,
"[&_svg]:w-icon-medium [&_svg]:h-icon-medium": !size || size !== _consts.SIZE_OPTIONS.SMALL && size !== _consts.SIZE_OPTIONS.LARGE
})
}, children);
};
const TextLink = ({
ariaCurrent,
type = _consts.TYPE_OPTIONS.PRIMARY,
size,
children,
href,
external = false,
rel,
iconLeft,
iconRight,
onClick,
dataTest,
download,
id,
tabIndex,
asComponent: Component = DefaultComponent,
stopPropagation = false,
title,
standAlone,
noUnderline
}) => {
const onClickHandler = ev => {
if (stopPropagation) {
ev.stopPropagation();
}
if (onClick) onClick(ev);
};
return /*#__PURE__*/React.createElement(Component, {
"aria-current": ariaCurrent,
id: id,
href: href,
target: external ? "_blank" : undefined,
rel: (0, _createRel.default)({
href,
external,
rel
}),
onClick: onClickHandler,
"data-test": dataTest,
tabIndex: tabIndex || (!href ? 0 : undefined),
role: !href ? "button" : undefined,
title: title,
download: download,
className: (0, _clsx.default)("orbit-text-link font-base duration-fast inline-flex cursor-pointer items-center font-medium transition-colors delay-0 ease-in-out hover:no-underline hover:outline-none active:no-underline active:outline-none", type === "secondary" && "orbit-text-link--secondary", standAlone && "h-form-box-normal", _twClasses.typeClasses[type], size != null && _twClasses.sizeClasses[size], noUnderline ? "no-underline" : "underline")
}, /*#__PURE__*/React.createElement(IconContainer, {
size: size
}, iconLeft), children, /*#__PURE__*/React.createElement(IconContainer, {
size: size
}, iconRight));
};
var _default = TextLink;
exports.default = _default;