UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

1 lines • 3.44 kB
{"version":3,"file":"Link.js","names":[],"sources":["esm/link/Link.js"],"sourcesContent":["import { Slot } from \"@radix-ui/react-slot\";\nimport * as React from \"react\";\nimport { resolveHref } from \"./href\";\nimport { useLinkTo } from \"./useLinkTo\";\nimport { jsx } from \"react/jsx-runtime\";\nconst Link = React.forwardRef(function Link2({\n href,\n replace,\n push: _push,\n id,\n mask,\n asChild,\n rel,\n target,\n download,\n className,\n style,\n onPress,\n disabled,\n accessibilityLabel,\n // rn-flavored prop shared code passes; rnw translated it, the dom link must too\n testID,\n ...rest\n}, ref) {\n const resolvedHref = React.useMemo(() => {\n if (href == null) {\n throw new Error(\"Link: href is required\");\n }\n return resolveHref(href);\n }, [href]);\n const resolvedMask = React.useMemo(() => mask ? resolveHref(mask) : void 0, [mask]);\n const link = useLinkTo({ href: resolvedHref, replace, mask: resolvedMask });\n const flattenedStyle = React.useMemo(() => {\n const styleValue = style;\n const styleValues = Array.isArray(styleValue) ? styleValue.flat(Number.POSITIVE_INFINITY) : [styleValue];\n return styleValues.reduce(\n (result, value) => value && typeof value === \"object\" ? Object.assign(result, value) : result,\n {}\n );\n }, [style]);\n const Element = asChild ? Slot : \"a\";\n const anchorProps = rest;\n return /* @__PURE__ */ jsx(\n Element,\n {\n ref,\n ...anchorProps,\n href: link.href,\n role: link.role,\n className,\n style: flattenedStyle,\n ...id == null ? null : { id },\n ...rel == null ? null : { rel },\n ...target == null ? null : { target },\n ...download == null ? null : { download },\n ...testID == null ? null : { \"data-testid\": testID },\n ...accessibilityLabel == null ? null : { \"aria-label\": accessibilityLabel },\n ...disabled ? { \"aria-disabled\": true } : null,\n onClick: (event) => {\n if (disabled) {\n event.preventDefault();\n return;\n }\n onPress?.(event);\n link.onPress(event);\n }\n }\n );\n});\nLink.resolveHref = resolveHref;\nexport {\n Link\n};\n//# sourceMappingURL=Link.web.js.map\n"],"mappings":";;;;;;;AAKA,MAAM,OAAO,M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