@primer/react
Version:
An implementation of GitHub's Primer Design System using React
85 lines (84 loc) • 2.42 kB
JavaScript
import { useMergedRefs } from "../hooks/useMergedRefs.js";
import { fixedForwardRef } from "../utils/modern-polymorphic.js";
import { useDevOnlyEffect } from "../internal/hooks/useDevOnlyEffect.js";
import Link_module_css_default from "./Link.module.css.js";
import { c } from "react-compiler-runtime";
import { clsx } from "clsx";
import { jsx } from "react/jsx-runtime";
import React from "react";
//#region src/Link/Link.tsx
const UnwrappedLink = (props, ref) => {
const $ = c(19);
let className;
let hoverColor;
let inline;
let muted;
let restProps;
let t0;
if ($[0] !== props) {
({as: t0, className, inline, muted, hoverColor, ...restProps} = props);
$[0] = props;
$[1] = className;
$[2] = hoverColor;
$[3] = inline;
$[4] = muted;
$[5] = restProps;
$[6] = t0;
} else {
className = $[1];
hoverColor = $[2];
inline = $[3];
muted = $[4];
restProps = $[5];
t0 = $[6];
}
const Component = t0 === void 0 ? "a" : t0;
const innerRef = React.useRef(null);
const mergedRef = useMergedRefs(ref, innerRef);
let t1;
let t2;
if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
t1 = () => {
if (innerRef.current && !(innerRef.current instanceof HTMLButtonElement) && !(innerRef.current instanceof HTMLAnchorElement)) console.error("Error: Found `Link` component that renders an inaccessible element", innerRef.current, "Please ensure `Link` always renders as <a> or <button>");
};
t2 = [innerRef];
$[7] = t1;
$[8] = t2;
} else {
t1 = $[7];
t2 = $[8];
}
useDevOnlyEffect(t1, t2);
let t3;
if ($[9] !== className) {
t3 = clsx(className, Link_module_css_default.Link);
$[9] = className;
$[10] = t3;
} else t3 = $[10];
const t4 = mergedRef;
let t5;
if ($[11] !== Component || $[12] !== hoverColor || $[13] !== inline || $[14] !== muted || $[15] !== restProps || $[16] !== t3 || $[17] !== t4) {
t5 = /*#__PURE__*/ jsx(Component, {
className: t3,
"data-component": "Link",
"data-muted": muted,
"data-inline": inline,
"data-hover-color": hoverColor,
...restProps,
ref: t4
});
$[11] = Component;
$[12] = hoverColor;
$[13] = inline;
$[14] = muted;
$[15] = restProps;
$[16] = t3;
$[17] = t4;
$[18] = t5;
} else t5 = $[18];
return t5;
};
const LinkComponent = fixedForwardRef(UnwrappedLink);
const Link = Object.assign(LinkComponent, { displayName: "Link" });
//#endregion
export { UnwrappedLink, Link as default };