@theguild/components
Version:
31 lines (30 loc) • 938 B
JavaScript
import { jsx } from "react/jsx-runtime";
import React from "react";
import { cn } from "../cn";
import { Anchor } from "./anchor";
import { ArrowIcon } from "./icons";
function TextLink({ className, children, ...rest }) {
const hasArrow = children && flattenFragments(children).some(
(child) => typeof child === "object" && child && "type" in child && child.type === ArrowIcon
);
return /* @__PURE__ */ jsx(
Anchor,
{
className: cn(
"hive-focus -mx-1 -my-0.5 rounded px-1 py-0.5 hover:text-blue-700 dark:hover:text-blue-500",
hasArrow ? "inline-flex items-center gap-2" : "underline",
className
),
...rest,
children
}
);
}
function flattenFragments(children) {
return React.Children.toArray(children).flatMap(
(child) => typeof child === "object" && "type" in child && child.type === React.Fragment ? child.props.children : child
);
}
export {
TextLink
};