UNPKG

1.63 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _react = _interopRequireDefault(require("react"));
9
10function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
12// NOTE: this is a copy of `lib/components/src/navigation/RoutedLink.tsx`.
13// It's duplicated here because that copy has an explicit dependency on
14// React 16.3+, which breaks older versions of React running in the preview.
15// The proper DRY solution is to create a new package that doesn't depend
16// on a specific react version. However, that's a heavy-handed solution for
17// one trivial file.
18var LEFT_BUTTON = 0; // Cmd/Ctrl/Shift/Alt + Click should trigger default browser behaviour. Same applies to non-left clicks
19
20var isPlainLeftClick = function isPlainLeftClick(e) {
21 return e.button === LEFT_BUTTON && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey;
22};
23
24var RoutedLink = function RoutedLink(_ref) {
25 var _ref$href = _ref.href,
26 href = _ref$href === void 0 ? '#' : _ref$href,
27 children = _ref.children,
28 onClick = _ref.onClick,
29 className = _ref.className,
30 style = _ref.style;
31
32 var handleClick = function handleClick(e) {
33 if (isPlainLeftClick(e)) {
34 e.preventDefault();
35 onClick(e);
36 }
37 };
38
39 var props = onClick ? {
40 href: href,
41 className: className,
42 style: style,
43 onClick: handleClick
44 } : {
45 href: href,
46 className: className,
47 style: style
48 };
49 return /*#__PURE__*/_react.default.createElement("a", props, children);
50};
51
52var _default = RoutedLink;
53exports.default = _default;
\No newline at end of file