UNPKG

@theguild/components

Version:
31 lines (30 loc) 1.02 kB
import { Fragment, jsx } from "react/jsx-runtime"; import { forwardRef } from "react"; import NextLink from "next/link"; import { cn } from "../cn"; const Anchor = forwardRef(function Anchor2({ href = "", children, newWindow, className, ...props }, forwardedRef) { const classes = cn("outline-none focus-visible:ring", className); 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 };