doom-design-system 0.4.4 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,11 +13,11 @@ var __rest = (this && this.__rest) || function (s, e) {
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import clsx from "clsx";
15
15
  import styles from "./Link.module.css";
16
- import React from "react";
16
+ import { useState, useEffect } from "react";
17
17
  import { ExternalLink } from "lucide-react";
18
18
  export function Link(_a) {
19
19
  var { children, variant = "default", prefetch, isExternal, disabled, className, onClick, onMouseEnter } = _a, props = __rest(_a, ["children", "variant", "prefetch", "isExternal", "disabled", "className", "onClick", "onMouseEnter"]);
20
- const [shouldPrefetch, setShouldPrefetch] = React.useState(false);
20
+ const [shouldPrefetch, setShouldPrefetch] = useState(false);
21
21
  const handleMouseEnter = (e) => {
22
22
  if (disabled)
23
23
  return;
@@ -33,8 +33,20 @@ export function Link(_a) {
33
33
  }
34
34
  onClick === null || onClick === void 0 ? void 0 : onClick(e);
35
35
  };
36
+ useEffect(() => {
37
+ if (shouldPrefetch && props.href && typeof document !== "undefined") {
38
+ const link = document.createElement("link");
39
+ link.rel = "prefetch";
40
+ link.href = props.href;
41
+ link.as = "document";
42
+ document.head.appendChild(link);
43
+ return () => {
44
+ document.head.removeChild(link);
45
+ };
46
+ }
47
+ }, [shouldPrefetch, props.href]);
36
48
  const externalProps = isExternal
37
49
  ? { target: "_blank", rel: "noopener noreferrer" }
38
50
  : {};
39
- return (_jsxs("a", Object.assign({ className: clsx(styles.link, styles[variant], disabled && styles.disabled, className), onMouseEnter: handleMouseEnter, onClick: handleClick, "aria-disabled": disabled }, externalProps, props, { children: [children, isExternal && _jsx(ExternalLink, { size: 14, className: "ml-1" }), shouldPrefetch && props.href && (_jsx("link", { rel: "prefetch", href: props.href, as: "document" }))] })));
51
+ return (_jsxs("a", Object.assign({ className: clsx(styles.link, styles[variant], disabled && styles.disabled, className), onMouseEnter: handleMouseEnter, onClick: handleClick, "aria-disabled": disabled }, externalProps, props, { children: [children, isExternal && _jsx(ExternalLink, { size: 14, className: "ml-1" })] })));
40
52
  }