@shopify/polaris
Version:
Shopify’s product component library
38 lines (31 loc) • 1.32 kB
JavaScript
import { objectWithoutProperties as _objectWithoutProperties } from '../../_virtual/_rollupPluginBabelHelpers.js';
import React$1, { memo, forwardRef } from 'react';
import { unstyled } from '../shared.js';
import { useLink } from '../../utilities/link/hooks.js';
// that the interface defining the props is defined in this file, not imported
// from elsewhere. This silly workaround ensures that the Props Explorer table
// is generated correctly.
// Wrapping forwardRef in a memo gets a name set since
// https://github.com/facebook/react/issues/16722
// but eslint-plugin-react doesn't know that just yet
// eslint-disable-next-line react/display-name
var UnstyledLink = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function UnstyledLink(props, _ref) {
var LinkComponent = useLink();
if (LinkComponent) {
return /*#__PURE__*/React$1.createElement(LinkComponent, Object.assign({}, unstyled.props, props));
}
var {
external,
url
} = props,
rest = _objectWithoutProperties(props, ["external", "url"]);
var target = external ? '_blank' : undefined;
var rel = external ? 'noopener noreferrer' : undefined;
return /*#__PURE__*/React$1.createElement("a", Object.assign({
target: target
}, rest, {
href: url,
rel: rel
}, unstyled.props));
}));
export { UnstyledLink };