@theguild/components
Version:
31 lines (30 loc) • 1.03 kB
JavaScript
import { Fragment, jsx } from "react/jsx-runtime";
import { forwardRef } from "react";
import NextLink from "next/link";
import clsx from "clsx";
const Anchor = forwardRef(function Anchor2({ href = "", children, newWindow, className, ...props }, forwardedRef) {
const classes = clsx(className, "outline-none transition focus-visible:ring");
if (typeof href === "string") {
if (href.startsWith("#")) {
return /* @__PURE__ */ jsx("a", { ref: forwardedRef, href, className: classes, ...props, children });
}
if (newWindow && /^https?:\/\//.test(href)) {
return /* @__PURE__ */ jsx(
"a",
{
ref: forwardedRef,
href,
target: "_blank",
rel: "noreferrer",
className: classes,
...props,
children
}
);
}
}
return /* @__PURE__ */ jsx(NextLink, { ref: forwardedRef, href, ...props, className: classes, legacyBehavior: false, children: /* @__PURE__ */ jsx(Fragment, { children }) });
});
export {
Anchor
};