1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
6 | var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
7 | var css = require('@emotion/css');
|
8 | var box = require('@spark-web/box');
|
9 | var link = require('@spark-web/link');
|
10 | var ts = require('@spark-web/utils/ts');
|
11 | var text = require('@spark-web/text');
|
12 | var theme = require('@spark-web/theme');
|
13 | var internal = require('@spark-web/utils/internal');
|
14 | var jsxRuntime = require('react/jsx-runtime');
|
15 | var utils = require('@spark-web/utils');
|
16 | var react = require('react');
|
17 |
|
18 | var TEXT_LINK_ERROR_MESSAGE = 'TextLink components must be inside `Text`.';
|
19 | function useTextLink(tag) {
|
20 | var textContext = text.useTextContext();
|
21 |
|
22 |
|
23 | if (!textContext) {
|
24 | throw new Error(TEXT_LINK_ERROR_MESSAGE);
|
25 | }
|
26 | var theme$1 = theme.useTheme();
|
27 | var textColor = text.useForegroundTone(textContext.tone);
|
28 | var resetStyles = internal.resetElementStyles(tag);
|
29 | var linkStyles = {
|
30 | color: textColor,
|
31 | cursor: 'pointer',
|
32 | textDecoration: 'underline',
|
33 | fontWeight: theme$1.typography.fontWeight.semibold
|
34 | };
|
35 | var styles = [resetStyles, linkStyles];
|
36 | return styles;
|
37 | }
|
38 |
|
39 | var _excluded$1 = ["as", "data"];
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | var TextLink = ts.forwardRefWithAs(
|
47 |
|
48 |
|
49 | function (_ref, ref) {
|
50 | _ref.as;
|
51 | var data = _ref.data,
|
52 | consumerProps = _objectWithoutProperties(_ref, _excluded$1);
|
53 | var LinkComponent = link.useLinkComponent(ref);
|
54 | var styles = useTextLink('a');
|
55 | return jsxRuntime.jsx(box.Box, _objectSpread({
|
56 | as: LinkComponent,
|
57 | asElement: "a",
|
58 | ref: ref,
|
59 | className: css.css(styles),
|
60 | data: data
|
61 | }, consumerProps));
|
62 | });
|
63 |
|
64 | var _excluded = ["data"];
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | var TextLinkButton = react.forwardRef(function (_ref, forwardedRef) {
|
73 | var data = _ref.data,
|
74 | consumerProps = _objectWithoutProperties(_ref, _excluded);
|
75 | var styles = useTextLink('span');
|
76 | var internalRef = react.useRef(null);
|
77 | var ref = utils.useComposedRefs(internalRef, forwardedRef);
|
78 | var handleKeyDown = react.useCallback(function (event) {
|
79 | if (event.key === 'Enter' || event.key === ' ') {
|
80 | var _internalRef$current;
|
81 | event.preventDefault();
|
82 | (_internalRef$current = internalRef.current) === null || _internalRef$current === void 0 ? void 0 : _internalRef$current.click();
|
83 | }
|
84 | }, [internalRef]);
|
85 | return jsxRuntime.jsx("span", _objectSpread(_objectSpread({
|
86 | role: "button",
|
87 | ref: ref,
|
88 | className: css.css(styles),
|
89 | tabIndex: 0,
|
90 | onKeyDown: handleKeyDown
|
91 | }, data ? internal.buildDataAttributes(data) : undefined), consumerProps));
|
92 | });
|
93 | TextLinkButton.displayName = 'TextLinkButton';
|
94 |
|
95 | exports.TextLink = TextLink;
|
96 | exports.TextLinkButton = TextLinkButton;
|