UNPKG

@navinc/base-react-components

Version:
73 lines (71 loc) 3.08 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { jsx as _jsx } from "react/jsx-runtime"; import { useEffect } from 'react'; import { func, node, shape, string, bool, oneOfType, object } from 'prop-types'; import styled from 'styled-components'; import { Link as ReactRouterLink } from 'react-router-dom'; import { deprecationWarning, track } from '@navinc/utils'; import Text from './text'; const StyledLink = styled(Text) ` font-size: inherit; color: ${({ theme }) => theme.bubbleBlue500}; text-decoration: none; &:hover { color: ${({ theme }) => theme.oceanBoat}; } &:active { color: ${({ theme }) => theme.oceanBoat}; } `; StyledLink.displayName = 'StyledLink'; const Link = (_a) => { var { to = '', href = to, target = '', onClick = () => { }, className = '', children, bold } = _a, _b = _a.trackingContext, _c = _b === void 0 ? {} : _b, { context = 'link', category = 'link', type = `interaction_${context}`, options } = _c, payload = __rest(_c, ["context", "category", "type", "options"]), props = __rest(_a, ["to", "href", "target", "onClick", "className", "children", "bold", "trackingContext"]); useEffect(() => deprecationWarning(to, ` The \`to\` prop on BRC Link component is deprecated and support will be removed in a future version. Please use \`href\` instead. If you need to bypass React Router, add a \`target="_self"\` prop to your link.`), [to]); return (_jsx(StyledLink, Object.assign({ target: target }, (target ? { href } : { to: href }), { as: target ? 'a' : href ? ReactRouterLink : 'span', className: className, onClick: (event) => { event.persist(); const { target = {} } = event; track({ type, payload: Object.assign({ category, label: target.innerText, name: target.innerText, target: target.href }, payload), options, }); onClick(event); }, rel: target === '_blank' ? 'noopener noreferrer' : undefined, "$bold": bold }, props, { children: children }), void 0)); }; Link.propTypes = { href: oneOfType([string, object]), target: string, onClick: func, className: string, children: node, trackingContext: shape({ type: string, context: string, category: string, payload: shape({ category: string, label: string, name: string, }), options: shape({ integrations: shape({ Salesforce: bool, }), }), }), }; Link.displayName = 'Link'; export default styled(Link) ``; //# sourceMappingURL=link.js.map