UNPKG

2.22 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
6var box = require('@spark-web/box');
7var ts = require('@spark-web/utils/ts');
8var _taggedTemplateLiteral = require('@babel/runtime/helpers/taggedTemplateLiteral');
9var dedent = require('dedent');
10var emery = require('emery');
11var react = require('react');
12var jsxRuntime = require('react/jsx-runtime');
13
14function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
15
16var dedent__default = /*#__PURE__*/_interopDefault(dedent);
17
18var _templateObject;
19var makeLinkComponent = function makeLinkComponent(render) {
20 return {
21 __forwardRef__: /*#__PURE__*/react.forwardRef(render)
22 };
23};
24var DefaultLinkComponent = makeLinkComponent(function (props, ref) {
25 return /*#__PURE__*/jsxRuntime.jsx("a", _objectSpread({
26 ref: ref
27 }, props));
28});
29var LinkComponentContext = /*#__PURE__*/react.createContext(DefaultLinkComponent);
30var useLinkComponent = function useLinkComponent(ref) {
31 var linkComponent = react.useContext(LinkComponentContext);
32 emery.assert(!ref || '__forwardRef__' in linkComponent, dedent__default["default"](_templateObject || (_templateObject = _taggedTemplateLiteral(["\n You're passing a ref to a Spark link, but your app is providing a custom link component to 'SparkProvider' that doesn't appear to support refs.\n\n To fix this, you need to use Spark's 'makeLinkComponent' helper function when creating your custom link component. This ensures that refs are forwarded correctly, and allows us to silence this error message.\n "]))));
33 if ('__forwardRef__' in linkComponent) {
34 return linkComponent.__forwardRef__;
35 }
36 return linkComponent;
37};
38
39var Link = ts.forwardRefWithAs(function (props, ref) {
40 var LinkComponent = useLinkComponent(ref);
41 return /*#__PURE__*/jsxRuntime.jsx(box.Box, _objectSpread({
42 as: LinkComponent,
43 asElement: "a",
44 ref: ref
45 }, props));
46});
47
48exports.DefaultLinkComponent = DefaultLinkComponent;
49exports.Link = Link;
50exports.LinkComponentContext = LinkComponentContext;
51exports.makeLinkComponent = makeLinkComponent;
52exports.useLinkComponent = useLinkComponent;