@airplane/views
Version:
A React library for building Airplane views. Views components are optimized in style and functionality to produce internal apps that are easy to build and maintain.
57 lines (56 loc) • 1.79 kB
JavaScript
import { jsx, jsxs } from "react/jsx-runtime";
import { Anchor } from "@mantine/core";
import { forwardRef, useState, useEffect } from "react";
import { ComponentErrorBoundary } from "../errorBoundary/ComponentErrorBoundary.js";
import { ArrowTopRightOnSquareIconMini } from "@airplane/views/icons/index.js";
import { THEME } from "../theme/theme.js";
import { useRouter } from "../../routing/useRouter.js";
const LinkWithoutRef = ({
innerRef,
children,
newTab,
href,
...props
}) => {
const [linkHref, setLinkHref] = useState(() => typeof href === "string" ? href : "");
const {
getHref
} = useRouter();
useEffect(() => {
const setNavigationHref = async (navigationHref) => {
const rhr = await getHref(navigationHref);
setLinkHref(rhr);
};
if (typeof href === "string") {
setLinkHref(href);
} else {
setNavigationHref(href);
}
}, [href, getHref]);
const target = props.target ?? newTab ? "_blank" : "_top";
return /* @__PURE__ */ jsxs(Anchor, { ...props, target, ref: innerRef, sx: {
display: "inline-flex",
alignItems: "center",
...props.sx
}, href: linkHref || void 0, children: [
children,
target === "_blank" && /* @__PURE__ */ jsx(ArrowTopRightOnSquareIconMini, { size: THEME.fontSizes[props.size] * 0.9, style: {
marginLeft: ".1em",
flexShrink: 0
} })
] });
};
const Link = /* @__PURE__ */ forwardRef(({
newTab = true,
size = "md",
...props
}, ref) => {
return /* @__PURE__ */ jsx(ComponentErrorBoundary, { componentName: DISPLAY_NAME, children: /* @__PURE__ */ jsx(LinkWithoutRef, { ...props, newTab, size, innerRef: ref }) });
});
const DISPLAY_NAME = "Link";
Link.displayName = DISPLAY_NAME;
export {
Link,
LinkWithoutRef
};
//# sourceMappingURL=Link.js.map