one
Version:
One is a new React Framework that makes Vite serve both native and web.
84 lines (83 loc) • 2.07 kB
JavaScript
import { Slot } from "@radix-ui/react-slot";
import * as React from "react";
import { resolveHref } from "./href.mjs";
import { useLinkTo } from "./useLinkTo.mjs";
import { jsx } from "react/jsx-runtime";
const Link = React.forwardRef(function Link2({
href,
replace,
push: _push,
id,
mask,
asChild,
rel,
target,
download,
className,
style,
onPress,
disabled,
accessibilityLabel,
// rn-flavored prop shared code passes; rnw translated it, the dom link must too
testID,
...rest
}, ref) {
const resolvedHref = React.useMemo(() => {
if (href == null) {
throw new Error("Link: href is required");
}
return resolveHref(href);
}, [href]);
const resolvedMask = React.useMemo(() => mask ? resolveHref(mask) : void 0, [mask]);
const link = useLinkTo({
href: resolvedHref,
replace,
mask: resolvedMask
});
const flattenedStyle = React.useMemo(() => {
const styleValue = style;
const styleValues = Array.isArray(styleValue) ? styleValue.flat(Number.POSITIVE_INFINITY) : [styleValue];
return styleValues.reduce((result, value) => value && typeof value === "object" ? Object.assign(result, value) : result, {});
}, [style]);
const Element = asChild ? Slot : "a";
return /* @__PURE__ */jsx(Element, {
ref,
...rest,
href: link.href,
role: link.role,
className,
style: flattenedStyle,
...(id == null ? null : {
id
}),
...(rel == null ? null : {
rel
}),
...(target == null ? null : {
target
}),
...(download == null ? null : {
download
}),
...(testID == null ? null : {
"data-testid": testID
}),
...(accessibilityLabel == null ? null : {
"aria-label": accessibilityLabel
}),
...(disabled ? {
"aria-disabled": true
} : null),
onClick: event => {
if (disabled) {
event.preventDefault();
return;
}
onPress?.(event);
link.onPress(event);
}
});
});
Link.resolveHref = resolveHref;
export { Link };
//# sourceMappingURL=Link.mjs.map