1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
6 | var box = require('@spark-web/box');
|
7 | var ts = require('@spark-web/utils/ts');
|
8 | var _taggedTemplateLiteral = require('@babel/runtime/helpers/taggedTemplateLiteral');
|
9 | var dedent = require('dedent');
|
10 | var emery = require('emery');
|
11 | var react = require('react');
|
12 | var jsxRuntime = require('react/jsx-runtime');
|
13 |
|
14 | function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
15 |
|
16 | var dedent__default = _interopDefault(dedent);
|
17 |
|
18 | var _templateObject;
|
19 | var makeLinkComponent = function makeLinkComponent(render) {
|
20 | return {
|
21 | __forwardRef__: react.forwardRef(render)
|
22 | };
|
23 | };
|
24 | var DefaultLinkComponent = makeLinkComponent(function (props, ref) {
|
25 | return jsxRuntime.jsx("a", _objectSpread({
|
26 | ref: ref
|
27 | }, props));
|
28 | });
|
29 | var LinkComponentContext = react.createContext(DefaultLinkComponent);
|
30 | var 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 |
|
39 | var Link = ts.forwardRefWithAs(function (props, ref) {
|
40 | var LinkComponent = useLinkComponent(ref);
|
41 | return jsxRuntime.jsx(box.Box, _objectSpread({
|
42 | as: LinkComponent,
|
43 | asElement: "a",
|
44 | ref: ref
|
45 | }, props));
|
46 | });
|
47 |
|
48 | exports.DefaultLinkComponent = DefaultLinkComponent;
|
49 | exports.Link = Link;
|
50 | exports.LinkComponentContext = LinkComponentContext;
|
51 | exports.makeLinkComponent = makeLinkComponent;
|
52 | exports.useLinkComponent = useLinkComponent;
|